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