BLE NAND for ST Boards

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of N06_NAND by Hugo Pristauz

Committer:
hux
Date:
Sat May 19 14:10:17 2018 +0000
Revision:
26:dce30a5341bb
Parent:
23:2e73c391bb12
Published

Who changed what in which revision?

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