GAP based TOF Demo

Dependencies:   BLE_API X_NUCLEO_6180XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Mon Aug 20 16:42:06 2018 +0000
Revision:
29:0f068d70c1a5
made in Shanghai

Who changed what in which revision?

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