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.
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
Diff: services/URIBeacon2Service.h
- Revision:
- 159:e915a0cebcce
- Parent:
- 158:08f609d8a6d4
- Child:
- 160:155b28cb0e45
--- a/services/URIBeacon2Service.h Fri Nov 28 14:11:20 2014 +0000
+++ b/services/URIBeacon2Service.h Fri Nov 28 14:11:21 2014 +0000
@@ -19,14 +19,29 @@
#include "BLEDevice.h"
+#define UUID_INITIALIZER_LIST(FIRST, SECOND) { \
+ 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \
+ 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \
+}
+const uint8_t URIBeacon2ControlServiceUUID[] = UUID_INITIALIZER_LIST(0x20, 0x80);
+const uint8_t lockedStateCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x81);
+const uint8_t uriDataCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x84);
+
class URIBeacon2Service {
public:
URIBeacon2Service(BLEDevice &ble_, const char *urldata, uint8_t flags_ = 0, uint8_t power_ = 0) :
ble(ble_), payloadIndex(0), serviceDataPayload(),
+ lockedState(false),
uriDataLength(0),
uriDataValue(),
flags(flags_),
- power(power_)
+ power(power_),
+ lockedStateChar(lockedStateCharUUID, (uint8_t *)&lockedState, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
+ uriDataChar(uriDataCharUUID,
+ uriDataValue,
+ MAX_SIZE_URI_DATA_CHAR_VALUE,
+ MAX_SIZE_URI_DATA_CHAR_VALUE,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE)
{
if ((urldata == NULL) || ((uriDataLength = strlen(urldata)) == 0)) {
return;
@@ -34,6 +49,17 @@
strncpy(reinterpret_cast<char *>(uriDataValue), urldata, MAX_SIZE_URI_DATA_CHAR_VALUE);
setup();
+
+ static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
+ if (serviceAdded) {
+ return;
+ }
+
+ GattCharacteristic *charTable[] = {&lockedStateChar, &uriDataChar};
+ GattService beaconControlService(URIBeacon2ControlServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+
+ ble.addService(beaconControlService);
+ serviceAdded = true;
}
void dumpEncodedSeviceData() const {
@@ -147,10 +173,14 @@
size_t payloadIndex;
uint8_t serviceDataPayload[MAX_SIZEOF_SERVICE_DATA_PAYLOAD];
+ bool lockedState;
uint16_t uriDataLength;
uint8_t uriDataValue[MAX_SIZE_URI_DATA_CHAR_VALUE];
uint8_t flags;
uint8_t power;
+
+ GattCharacteristic lockedStateChar;
+ GattCharacteristic uriDataChar;
};
#endif /* #ifndef __BLE_URI_BEACON_2_SERVICE_H__*/
\ No newline at end of file
