Bluetooth Connected TOF Sensor

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Wed Feb 01 22:08:56 2017 +0000
Revision:
28:def5e0f0fb06
First S16_Blue_ToF application which runs nicely!; Digital display can be switched on/off with red slider

Who changed what in which revision?

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