GAP based TOF Demo

Dependencies:   BLE_API X_NUCLEO_6180XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Fri Jan 06 21:36:47 2017 +0000
Revision:
25:231d3f382583
Parent:
24:0f08f68579bd
Child:
26:fd06c8b57d16
T07N_Easy_GATT, release 1.1 - all services & required callbacks for handling the services are moved to easy.cpp. Works well - no bug known!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 23:677689000369 1 // service.h - declaring services and definitions
hux 23:677689000369 2 //
hux 23:677689000369 3 // Example 1: A protocol might be declared as a class as follows
hux 23:677689000369 4 //
hux 23:677689000369 5 // Collection col; // collection used during setup
hux 23:677689000369 6 //
hux 23:677689000369 7 // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID");
hux 23:677689000369 8 // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name");
hux 23:677689000369 9 // Characteristic<Digital> presence(col,0x2A56,"r","Presence");
hux 23:677689000369 10 //
hux 23:677689000369 11 // Service presenceDetection(col,0xA001); // instantiate service
hux 23:677689000369 12 //
hux 23:677689000369 13 // onSetup(Blob &blue)
hux 23:677689000369 14 // {
hux 23:677689000369 15 // blue.service(presenceDetection); // use service
hux 23:677689000369 16 // }
hux 23:677689000369 17 //
hux 23:677689000369 18 // Example 2: service definition by means of a service definition class
hux 23:677689000369 19 //
hux 23:677689000369 20 // class PresenceDetector
hux 23:677689000369 21 // {
hux 23:677689000369 22 // public:
hux 23:677689000369 23 // Collection col; // collection used during setup
hux 23:677689000369 24 //
hux 23:677689000369 25 // Characteristic<ObjectId> id; // ID of presence detector
hux 23:677689000369 26 // Characteristic<ObjectName> name; // name of presence detector
hux 23:677689000369 27 // Characteristic<Digital> presence; // digital presence value
hux 23:677689000369 28 // Characteristic<DateTime> timestamp; // last detection change's time
hux 23:677689000369 29 // Characteristic<ObjectName> layout; // name of model railway layout
hux 23:677689000369 30 //
hux 23:677689000369 31 // Service presenceDetection; // the service
hux 23:677689000369 32 //
hux 23:677689000369 33 // public:
hux 23:677689000369 34 // PresenceDetector(Blob &blue, cost UUID uuid) :
hux 23:677689000369 35 // list; // init service list
hux 23:677689000369 36 // id(list,0x2AC3,"rw","ID"), // instantiate characteristic
hux 23:677689000369 37 // name(list,0x2ABE,"rw","Name"), // instantiate characteristic
hux 23:677689000369 38 // presence(list,0x2A56,"r","Presence"),// instantiate characteristic
hux 23:677689000369 39 // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic
hux 23:677689000369 40 // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic
hux 23:677689000369 41 // presenceDetection(list,uuid) // instantiate service
hux 23:677689000369 42 // {
hux 23:677689000369 43 // Blob blue;
hux 23:677689000369 44 // blue.service(presenceDetection); // use service
hux 23:677689000369 45 // }
hux 23:677689000369 46 // };
hux 23:677689000369 47 //
hux 23:677689000369 48 #ifndef _SERVICE_H_
hux 23:677689000369 49 #define _SERVICE_H_
hux 23:677689000369 50
hux 23:677689000369 51 #include "ble/BLE.h"
hux 23:677689000369 52 #include "ble/Gap.h"
hux 24:0f08f68579bd 53 #include "bricks/blob.h"
hux 23:677689000369 54 #include "bricks/collection.h"
hux 23:677689000369 55
hux 24:0f08f68579bd 56 class Service
hux 23:677689000369 57 {
hux 24:0f08f68579bd 58 private: // private properties
hux 24:0f08f68579bd 59 Collection collection; // collection of characteristics
hux 24:0f08f68579bd 60 UUID uuid; // UUID of service
hux 24:0f08f68579bd 61 const char *name; // name of service
hux 24:0f08f68579bd 62
hux 24:0f08f68579bd 63 public: // public methods
hux 24:0f08f68579bd 64 Service(UUID _uuid, const char* _name = NULL) : collection()
hux 24:0f08f68579bd 65 {
hux 24:0f08f68579bd 66 uuid = _uuid;
hux 24:0f08f68579bd 67 name = _name;
hux 24:0f08f68579bd 68 }
hux 24:0f08f68579bd 69
hux 24:0f08f68579bd 70 void add(GattCharacteristic *pChr) // add a characteristic to collection
hux 23:677689000369 71 {
hux 24:0f08f68579bd 72 collection.add(pChr);
hux 24:0f08f68579bd 73 }
hux 24:0f08f68579bd 74
hux 25:231d3f382583 75 void enroll(Blob &blue) // enroll the service
hux 24:0f08f68579bd 76 {
hux 24:0f08f68579bd 77 static const uint16_t list[] = {0xFFFF};
hux 24:0f08f68579bd 78
hux 24:0f08f68579bd 79 // Custom UUID, FFFF is reserved for development
hux 24:0f08f68579bd 80 // Used for UUID's broadcast in advertising packet
hux 24:0f08f68579bd 81
hux 24:0f08f68579bd 82 GattService service(uuid, collection.plist, collection.count);
hux 24:0f08f68579bd 83
hux 24:0f08f68579bd 84 blue.pble->gap().accumulateAdvertisingPayload(
hux 24:0f08f68579bd 85 GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
hux 24:0f08f68579bd 86 (uint8_t *)list, sizeof(list));
hux 24:0f08f68579bd 87
hux 24:0f08f68579bd 88 blue.pble->addService(service);
hux 23:677689000369 89 }
hux 23:677689000369 90 };
hux 23:677689000369 91
hux 23:677689000369 92 #endif // _SERVICE_H_