![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TOF based Presence Detector
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/enroll.h@26:fd06c8b57d16, 2017-01-07 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 07 15:38:15 2017 +0000
- Revision:
- 26:fd06c8b57d16
- Parent:
- 25:231d3f382583
change of advertising service UUID in enrollment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 25:231d3f382583 | 1 | // enroll.h - enroll a service |
hux | 25:231d3f382583 | 2 | // |
hux | 25:231d3f382583 | 3 | // Synopsis: |
hux | 25:231d3f382583 | 4 | // |
hux | 26:fd06c8b57d16 | 5 | // void enroll(Blob &o, GattService &gservice); |
hux | 26:fd06c8b57d16 | 6 | // void enroll(Blob &o, uint16_t bcid = 0xFFFF); |
hux | 26:fd06c8b57d16 | 7 | // |
hux | 26:fd06c8b57d16 | 8 | // void enroll(Blob &o, Service &service, uint16_t bcid = 0xFFFF); |
hux | 26:fd06c8b57d16 | 9 | // |
hux | 26:fd06c8b57d16 | 10 | // Arguments: |
hux | 26:fd06c8b57d16 | 11 | // |
hux | 26:fd06c8b57d16 | 12 | // o: Blob object (to avoid name clashes) |
hux | 26:fd06c8b57d16 | 13 | // gservice: The GattService to be enrolled |
hux | 26:fd06c8b57d16 | 14 | // service: The Service to be enrolled |
hux | 26:fd06c8b57d16 | 15 | // bcid: Broadcast ID (optional); if not provided the default value |
hux | 26:fd06c8b57d16 | 16 | // 0xFFFF will be used |
hux | 26:fd06c8b57d16 | 17 | // |
hux | 26:fd06c8b57d16 | 18 | // Description |
hux | 25:231d3f382583 | 19 | // |
hux | 26:fd06c8b57d16 | 20 | // There are three ways to call enrollment. |
hux | 26:fd06c8b57d16 | 21 | // |
hux | 26:fd06c8b57d16 | 22 | // In the first case the service has been setup via a GattService class. |
hux | 26:fd06c8b57d16 | 23 | // The service is enrolled by registering the service @ GAP. On advertising |
hux | 26:fd06c8b57d16 | 24 | // the provided broadcast ID is used (otherwise default ID 0xFFFF). |
hux | 25:231d3f382583 | 25 | // |
hux | 26:fd06c8b57d16 | 26 | // The second case is based on a Service class object which has been setup |
hux | 26:fd06c8b57d16 | 27 | // by having added a set of characteristics to the internal collection. Upon |
hux | 26:fd06c8b57d16 | 28 | // enrollment a GattService instance will be created internally and enroll- |
hux | 26:fd06c8b57d16 | 29 | // ment of this GattService will be performed according to the first case. |
hux | 26:fd06c8b57d16 | 30 | // |
hux | 26:fd06c8b57d16 | 31 | // The third way is to enroll only the service id. This calling syntax is |
hux | 26:fd06c8b57d16 | 32 | // used, if a Gatt servive is pre-enrolled without enrolling the service ID. |
hux | 26:fd06c8b57d16 | 33 | // |
hux | 26:fd06c8b57d16 | 34 | // Example 1: enrollment of GattService |
hux | 26:fd06c8b57d16 | 35 | // |
hux | 26:fd06c8b57d16 | 36 | // enroll(o,gservice); |
hux | 26:fd06c8b57d16 | 37 | // enroll(o,0xFFFF); |
hux | 26:fd06c8b57d16 | 38 | // |
hux | 26:fd06c8b57d16 | 39 | // See also: SERVICE |
hux | 25:231d3f382583 | 40 | // |
hux | 25:231d3f382583 | 41 | #ifndef _ENROLL_H_ |
hux | 25:231d3f382583 | 42 | #define _ENROLL_H_ |
hux | 25:231d3f382583 | 43 | |
hux | 25:231d3f382583 | 44 | #include "bricks/blob.h" |
hux | 25:231d3f382583 | 45 | #include "bricks/service.h" |
hux | 25:231d3f382583 | 46 | |
hux | 26:fd06c8b57d16 | 47 | |
hux | 26:fd06c8b57d16 | 48 | inline void enroll(Blob &o, uint16_t bcid = 0xFFFF) |
hux | 25:231d3f382583 | 49 | { |
hux | 26:fd06c8b57d16 | 50 | static uint16_t list[1]; |
hux | 26:fd06c8b57d16 | 51 | |
hux | 26:fd06c8b57d16 | 52 | // Custom UUID, FFFF is reserved for development |
hux | 26:fd06c8b57d16 | 53 | // Used for UUID's broadcast in advertising packet |
hux | 26:fd06c8b57d16 | 54 | |
hux | 26:fd06c8b57d16 | 55 | list[0] = bcid; // set broadcast ID |
hux | 26:fd06c8b57d16 | 56 | |
hux | 26:fd06c8b57d16 | 57 | o.pble->gap().accumulateAdvertisingPayload( |
hux | 26:fd06c8b57d16 | 58 | GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, |
hux | 26:fd06c8b57d16 | 59 | (uint8_t *)list, sizeof(list)); |
hux | 26:fd06c8b57d16 | 60 | } |
hux | 26:fd06c8b57d16 | 61 | |
hux | 26:fd06c8b57d16 | 62 | |
hux | 26:fd06c8b57d16 | 63 | inline void enroll(Blob &o, GattService &gservice, uint16_t bcid = 0xFFFF) |
hux | 26:fd06c8b57d16 | 64 | { |
hux | 26:fd06c8b57d16 | 65 | o.pble->addService(gservice); // add service to GATT attributes |
hux | 26:fd06c8b57d16 | 66 | enroll(o,bcid); // enroll GattService (without BCID) |
hux | 26:fd06c8b57d16 | 67 | } |
hux | 26:fd06c8b57d16 | 68 | |
hux | 26:fd06c8b57d16 | 69 | |
hux | 26:fd06c8b57d16 | 70 | inline void enroll(Blob &o, Service &service, uint16_t bcid = 0) |
hux | 26:fd06c8b57d16 | 71 | { |
hux | 26:fd06c8b57d16 | 72 | Collection &collection = service.collection; |
hux | 26:fd06c8b57d16 | 73 | GattService gservice(service.uuid, collection.plist, collection.count); |
hux | 26:fd06c8b57d16 | 74 | |
hux | 26:fd06c8b57d16 | 75 | if (bcid == 0) |
hux | 26:fd06c8b57d16 | 76 | bcid = service.uuid; |
hux | 26:fd06c8b57d16 | 77 | |
hux | 26:fd06c8b57d16 | 78 | enroll(o,gservice,bcid); // enroll GattService (with BCID) |
hux | 25:231d3f382583 | 79 | } |
hux | 25:231d3f382583 | 80 | |
hux | 25:231d3f382583 | 81 | #endif // _ENROLL_H_ |