TOF based Presence Detector

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Mon Aug 20 16:43:10 2018 +0000
Revision:
29:eceecbe28088
Parent:
28:a23b16555909
made in Shanghai

Who changed what in which revision?

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