Bike service
Fork of BLE_API by
Diff: ble/Gap.h
- Revision:
- 1194:c8bbf3a6712d
- Parent:
- 1193:718787de23b7
diff -r 718787de23b7 -r c8bbf3a6712d ble/Gap.h --- a/ble/Gap.h Wed Apr 06 19:15:46 2016 +0100 +++ b/ble/Gap.h Wed Apr 06 19:15:48 2016 +0100 @@ -848,7 +848,6 @@ return INIT_POLICY_IGNORE_WHITELIST; } - protected: /* Override the following in the underlying adaptation layer to provide the functionality of scanning. */ @@ -940,7 +939,6 @@ */ ble_error_t startAdvertising(void) { ble_error_t rc; - setAdvertisingData(); /* Update the underlying stack. */ if ((rc = startAdvertising(_advParams)) == BLE_ERROR_NONE) { state.advertising = 1; } @@ -954,7 +952,7 @@ */ void clearAdvertisingPayload(void) { _advPayload.clear(); - setAdvertisingData(); + setAdvertisingData(_advPayload, _scanResponse); } /** @@ -972,12 +970,18 @@ * advertising payload. */ ble_error_t accumulateAdvertisingPayload(uint8_t flags) { + GapAdvertisingData advPayloadCopy = _advPayload; ble_error_t rc; - if ((rc = _advPayload.addFlags(flags)) != BLE_ERROR_NONE) { + if ((rc = advPayloadCopy.addFlags(flags)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(advPayloadCopy, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = advPayloadCopy; + } + + return rc; } /** @@ -993,14 +997,18 @@ * advertising payload. */ ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) { - setAppearance(app); - + GapAdvertisingData advPayloadCopy = _advPayload; ble_error_t rc; - if ((rc = _advPayload.addAppearance(app)) != BLE_ERROR_NONE) { + if ((rc = advPayloadCopy.addAppearance(app)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(advPayloadCopy, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = advPayloadCopy; + } + + return rc; } /** @@ -1016,12 +1024,18 @@ * advertising payload. */ ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power) { + GapAdvertisingData advPayloadCopy = _advPayload; ble_error_t rc; - if ((rc = _advPayload.addTxPower(power)) != BLE_ERROR_NONE) { + if ((rc = advPayloadCopy.addTxPower(power)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(advPayloadCopy, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = advPayloadCopy; + } + + return rc; } /** @@ -1048,16 +1062,18 @@ * payload. */ ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { - if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { - setDeviceName(data); - } - + GapAdvertisingData advPayloadCopy = _advPayload; ble_error_t rc; - if ((rc = _advPayload.addData(type, data, len)) != BLE_ERROR_NONE) { + if ((rc = advPayloadCopy.addData(type, data, len)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(advPayloadCopy, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = advPayloadCopy; + } + + return rc; } /** @@ -1077,16 +1093,18 @@ * matching AD type; otherwise, an appropriate error. */ ble_error_t updateAdvertisingPayload(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { - if (type == GapAdvertisingData::COMPLETE_LOCAL_NAME) { - setDeviceName(data); - } - + GapAdvertisingData advPayloadCopy = _advPayload; ble_error_t rc; - if ((rc = _advPayload.updateData(type, data, len)) != BLE_ERROR_NONE) { + if ((rc = advPayloadCopy.updateData(type, data, len)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(advPayloadCopy, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = advPayloadCopy; + } + + return rc; } /** @@ -1103,8 +1121,12 @@ * set. */ ble_error_t setAdvertisingPayload(const GapAdvertisingData &payload) { - _advPayload = payload; - return setAdvertisingData(); + ble_error_t rc = setAdvertisingData(payload, _scanResponse); + if (rc == BLE_ERROR_NONE) { + _advPayload = payload; + } + + return rc; } /** @@ -1133,12 +1155,18 @@ * response payload. */ ble_error_t accumulateScanResponse(GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) { + GapAdvertisingData scanResponseCopy = _scanResponse; ble_error_t rc; - if ((rc = _scanResponse.addData(type, data, len)) != BLE_ERROR_NONE) { + if ((rc = scanResponseCopy.addData(type, data, len)) != BLE_ERROR_NONE) { return rc; } - return setAdvertisingData(); + rc = setAdvertisingData(_advPayload, scanResponseCopy); + if (rc == BLE_ERROR_NONE) { + _scanResponse = scanResponseCopy; + } + + return rc; } /** @@ -1150,7 +1178,7 @@ */ void clearScanResponse(void) { _scanResponse.clear(); - setAdvertisingData(); + setAdvertisingData(_advPayload, _scanResponse); } /** @@ -1381,16 +1409,6 @@ private: /** - * Helper function used to set the advertising data in the underlying BLE stack. - * - * @return BLE_ERROR_NONE if the advertising data was successfully set. - */ - ble_error_t setAdvertisingData(void) { - return setAdvertisingData(_advPayload, _scanResponse); - } - -private: - /** * Functionality that is BLE stack-dependent and must be implemented by the * ported. This is a helper function to set the advertising data in the * BLE stack.