Skip to content

Commit 8ad6e80

Browse files
committed
Jira 544 BLE peripheral disconnect and end functions
The state not aligned and make disconnect failed. Update when connect and disconnect event received
1 parent ae50215 commit 8ad6e80

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

libraries/CurieBLE/src/BLECentralHelper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,3 @@ BLECentralHelper::disconnect() {
9292
return false;
9393
}
9494

95-
void
96-
BLECentralHelper::setAddress(bt_addr_le_t address) {
97-
_address = address;
98-
}
99-
100-
void
101-
BLECentralHelper::clearAddress() {
102-
memset(&_address, 0x00, sizeof(_address));
103-
}

libraries/CurieBLE/src/BLECentralHelper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class BLECentralHelper: public BLEHelper{
6161

6262
protected:
6363
BLECentralHelper(BLEPeripheralRole* peripheral);
64-
void setAddress(bt_addr_le_t address);
65-
void clearAddress();
6664

6765
private:
6866
BLEPeripheralRole* _peripheral;

libraries/CurieBLE/src/BLEHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ BLEHelper::poll() {
106106
}
107107

108108
void
109-
BLEHelper::setAddress(bt_addr_le_t address) {
110-
_address = address;
109+
BLEHelper::setAddress(const bt_addr_le_t &address) {
110+
memcpy(&_address, &address, sizeof(bt_addr_le_t));
111111
}
112112

113113
void

libraries/CurieBLE/src/BLEHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BLEHelper {
6363
uint16_t timeout);
6464

6565
protected:
66-
void setAddress(bt_addr_le_t address);
66+
void setAddress(const bt_addr_le_t &address);
6767
void clearAddress();
6868
BLEHelper();
6969
virtual ~BLEHelper();

libraries/CurieBLE/src/BLEPeripheralRole.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ bool
128128
BLEPeripheralRole::disconnect()
129129
{
130130
BleStatus status = BLE_STATUS_WRONG_STATE;
131+
int err;
131132

132133
if (BLE_PERIPH_STATE_CONNECTED == _state)
133134
{
134135
struct bt_conn *central_conn = bt_conn_lookup_addr_le(_central.bt_le_address());
135136
if (NULL != central_conn)
136137
{
137-
status = bt_conn_disconnect (central_conn,
138-
BT_HCI_ERR_REMOTE_USER_TERM_CONN);
138+
err = bt_conn_disconnect (central_conn,
139+
BT_HCI_ERR_REMOTE_USER_TERM_CONN);
140+
status = errorno_to_ble_status(err);
139141
bt_conn_unref(central_conn);
140142
}
141143
}
@@ -246,6 +248,9 @@ void BLEPeripheralRole::handleConnectEvent(struct bt_conn *conn, uint8_t err)
246248
// Call the CB
247249
if (_event_handlers[BLEConnected])
248250
_event_handlers[BLEConnected](_central);
251+
252+
if (BLE_PERIPH_STATE_ADVERTISING == _state)
253+
_state = BLE_PERIPH_STATE_CONNECTED;
249254
}
250255

251256

@@ -263,6 +268,9 @@ void BLEPeripheralRole::handleDisconnectEvent(struct bt_conn *conn, uint8_t reas
263268
{
264269
bt_conn_unref(central_conn);
265270
}
271+
272+
if (BLE_PERIPH_STATE_CONNECTED == _state)
273+
_state = BLE_PERIPH_STATE_ADVERTISING;
266274
}
267275

268276
void BLEPeripheralRole::handleParamUpdated(struct bt_conn *conn,

0 commit comments

Comments
 (0)