jgh
Fork of BLE_API by
Revision 1180:e11b058d005e, committed 2016-04-06
- Comitter:
- vcoubard
- Date:
- Wed Apr 06 19:15:32 2016 +0100
- Parent:
- 1179:4ab722f8dca0
- Child:
- 1181:2361aa870ee5
- Commit message:
- Synchronized with git rev a990f23a
Author: Andres Amaya Garcia
Add connectionCount and fix Gap state updates
Add a connectionCount member to Gap that keeps track of the total number of
open connections. Also, update the Gap state member when a connection is opened
to set advertising to false. Finally modify the processDisconnection member to
unset the connected state if connectionCount is 0.
Changed in this revision
ble/Gap.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ble/Gap.h Wed Apr 06 19:15:30 2016 +0100 +++ b/ble/Gap.h Wed Apr 06 19:15:32 2016 +0100 @@ -1295,6 +1295,7 @@ /* Clear Gap state */ state.advertising = 0; state.connected = 0; + connectionCount = 0; /* Clear scanning state */ scanningActive = false; @@ -1319,6 +1320,7 @@ _advPayload(), _scanningParams(), _scanResponse(), + connectionCount(0), state(), scanningActive(false), timeoutCallbackChain(), @@ -1339,13 +1341,22 @@ BLEProtocol::AddressType_t ownAddrType, const BLEProtocol::AddressBytes_t ownAddr, const ConnectionParams_t *connectionParams) { - state.connected = 1; + /* Update Gap state */ + state.advertising = 0; + state.connected = 1; + ++connectionCount; + ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); connectionCallChain.call(&callbackParams); } void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) { - state.connected = 0; + /* Update Gap state */ + --connectionCount; + if (!connectionCount) { + state.connected = 0; + } + DisconnectionCallbackParams_t callbackParams(handle, reason); disconnectionCallChain.call(&callbackParams); } @@ -1382,6 +1393,10 @@ GapScanningParams _scanningParams; GapAdvertisingData _scanResponse; + /** + * Total number of open connections. + */ + uint8_t connectionCount; GapState_t state; bool scanningActive;