Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: hw/BLEDevice.h
- Revision:
- 49:03a51f0006f8
- Parent:
- 48:ec0c28e62abf
- Child:
- 63:653378e782ea
--- a/hw/BLEDevice.h Fri May 23 17:28:44 2014 +0100
+++ b/hw/BLEDevice.h Fri May 23 17:45:16 2014 +0100
@@ -116,20 +116,48 @@
*/
void setAdvertisingParams(const GapAdvertisingParams &advParams);
+ void clearAdvertisingPayload(void);
+ ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Flags flags);
+ ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::Appearance app);
+ ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
+ ble_error_t accumulateAdvertisingPayload(GapAdvertisingData::DataType type,
+ const uint8_t *data,
+ uint8_t len);
+
ble_error_t startAdvertising(void);
ble_error_t stopAdvertising(void);
ble_error_t disconnect(void);
+private:
+ /**
+ * Internal helper to udpate the transport backend with advertising data
+ * before starting to advertise.
+ */
+ ble_error_t setAdvertisingDataForTransport(void);
+
public:
- BLEDevice() : transport(createBLEDeviceInstance()), advParams() {
- /* empty */
+ BLEDevice() : transport(createBLEDeviceInstance()),
+ advParams(),
+ advPayload(),
+ scanResponse(),
+ needToUpdateAdvData(true) {
+ advPayload.clear();
+ scanResponse.clear();
}
private:
- BLEDeviceInstanceBase *transport; /* handle to the device specific backend*/
- GapAdvertisingParams advParams;
+ BLEDeviceInstanceBase *const transport; /* the device specific backend */
+ GapAdvertisingParams advParams;
+ GapAdvertisingData advPayload;
+ GapAdvertisingData scanResponse;
+ bool needToUpdateAdvData; /* Accumulation of AD structures
+ * in the advertisement payload should eventually
+ * result in a call to the target's
+ * setAdvertisingData() before the server begins
+ * advertising. This flag marks the status of the
+ * pending update.*/
/**
* DEPRECATED
@@ -194,8 +222,45 @@
advParams = newAdvParams;
}
+inline void
+BLEDevice::clearAdvertisingPayload(void) {
+ needToUpdateAdvData = true;
+ advPayload.clear();
+}
+
+inline ble_error_t
+BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Flags flags) {
+ needToUpdateAdvData = true;
+ return advPayload.addFlags(flags);
+}
+
+inline ble_error_t
+BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::Appearance app) {
+ needToUpdateAdvData = true;
+ return advPayload.addAppearance(app);
+}
+
+inline ble_error_t
+BLEDevice::accumulateAdvertisingPayloadTxPower(int8_t txPower) {
+ needToUpdateAdvData = true;
+ return advPayload.addTxPower(txPower);
+}
+
+inline ble_error_t
+BLEDevice::accumulateAdvertisingPayload(GapAdvertisingData::DataType type,
+ const uint8_t *data,
+ uint8_t len) {
+ needToUpdateAdvData = true;
+ return advPayload.addData(type, data, len);
+}
+
inline ble_error_t
BLEDevice::startAdvertising(void) {
+ if (needToUpdateAdvData) {
+ setAdvertisingDataForTransport();
+ needToUpdateAdvData = false;
+ }
+
return transport->getGap().startAdvertising(advParams);
}
@@ -209,6 +274,11 @@
return transport->getGap().disconnect();
}
+inline ble_error_t
+BLEDevice::setAdvertisingDataForTransport(void) {
+ return transport->getGap().setAdvertisingData(advPayload, scanResponse);
+}
+
/*
* ALL OF THE FOLLOWING METHODS ARE DEPRECATED
*/
