![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluetooth Connected TOF Sensor
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: bricks/service.h
- Revision:
- 24:0f08f68579bd
- Parent:
- 23:677689000369
- Child:
- 25:231d3f382583
diff -r 677689000369 -r 0f08f68579bd bricks/service.h --- a/bricks/service.h Fri Jan 06 15:28:18 2017 +0000 +++ b/bricks/service.h Fri Jan 06 20:49:58 2017 +0000 @@ -50,15 +50,42 @@ #include "ble/BLE.h" #include "ble/Gap.h" +#include "bricks/blob.h" #include "bricks/collection.h" - class Service : public GattService + class Service { - public: - Service(Collection &list, UUID uuid) : - GattService(uuid, list.plist, list.count) + private: // private properties + Collection collection; // collection of characteristics + UUID uuid; // UUID of service + const char *name; // name of service + + public: // public methods + Service(UUID _uuid, const char* _name = NULL) : collection() + { + uuid = _uuid; + name = _name; + } + + void add(GattCharacteristic *pChr) // add a characteristic to collection { - // empty + collection.add(pChr); + } + + void config(Blob &blue) // configure the service + { + static const uint16_t list[] = {0xFFFF}; + + // Custom UUID, FFFF is reserved for development + // Used for UUID's broadcast in advertising packet + + GattService service(uuid, collection.plist, collection.count); + + blue.pble->gap().accumulateAdvertisingPayload( + GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, + (uint8_t *)list, sizeof(list)); + + blue.pble->addService(service); } };