![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluetooth Connected TOF Sensor
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/service.h@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
- Parent:
- 26:fd06c8b57d16
Setup a GATT Detector Service. There is some bug in the GATT setup, resulting in different behavior between Nordic nRF51822-DK and NUCLEO-L476RG, but with the workaround it works also for the NUCLEO board. (using Bricks V1A)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 23:677689000369 | 1 | // service.h - declaring services and definitions |
hux | 23:677689000369 | 2 | // |
hux | 26:fd06c8b57d16 | 3 | // Synopsis |
hux | 26:fd06c8b57d16 | 4 | // |
hux | 23:677689000369 | 5 | // Example 1: A protocol might be declared as a class as follows |
hux | 23:677689000369 | 6 | // |
hux | 23:677689000369 | 7 | // Collection col; // collection used during setup |
hux | 23:677689000369 | 8 | // |
hux | 23:677689000369 | 9 | // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID"); |
hux | 23:677689000369 | 10 | // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name"); |
hux | 23:677689000369 | 11 | // Characteristic<Digital> presence(col,0x2A56,"r","Presence"); |
hux | 23:677689000369 | 12 | // |
hux | 23:677689000369 | 13 | // Service presenceDetection(col,0xA001); // instantiate service |
hux | 23:677689000369 | 14 | // |
hux | 23:677689000369 | 15 | // onSetup(Blob &blue) |
hux | 23:677689000369 | 16 | // { |
hux | 23:677689000369 | 17 | // blue.service(presenceDetection); // use service |
hux | 23:677689000369 | 18 | // } |
hux | 23:677689000369 | 19 | // |
hux | 23:677689000369 | 20 | // Example 2: service definition by means of a service definition class |
hux | 23:677689000369 | 21 | // |
hux | 23:677689000369 | 22 | // class PresenceDetector |
hux | 23:677689000369 | 23 | // { |
hux | 23:677689000369 | 24 | // public: |
hux | 23:677689000369 | 25 | // Collection col; // collection used during setup |
hux | 23:677689000369 | 26 | // |
hux | 23:677689000369 | 27 | // Characteristic<ObjectId> id; // ID of presence detector |
hux | 23:677689000369 | 28 | // Characteristic<ObjectName> name; // name of presence detector |
hux | 23:677689000369 | 29 | // Characteristic<Digital> presence; // digital presence value |
hux | 23:677689000369 | 30 | // Characteristic<DateTime> timestamp; // last detection change's time |
hux | 23:677689000369 | 31 | // Characteristic<ObjectName> layout; // name of model railway layout |
hux | 23:677689000369 | 32 | // |
hux | 23:677689000369 | 33 | // Service presenceDetection; // the service |
hux | 23:677689000369 | 34 | // |
hux | 23:677689000369 | 35 | // public: |
hux | 23:677689000369 | 36 | // PresenceDetector(Blob &blue, cost UUID uuid) : |
hux | 23:677689000369 | 37 | // list; // init service list |
hux | 23:677689000369 | 38 | // id(list,0x2AC3,"rw","ID"), // instantiate characteristic |
hux | 23:677689000369 | 39 | // name(list,0x2ABE,"rw","Name"), // instantiate characteristic |
hux | 23:677689000369 | 40 | // presence(list,0x2A56,"r","Presence"),// instantiate characteristic |
hux | 23:677689000369 | 41 | // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic |
hux | 23:677689000369 | 42 | // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic |
hux | 23:677689000369 | 43 | // presenceDetection(list,uuid) // instantiate service |
hux | 23:677689000369 | 44 | // { |
hux | 23:677689000369 | 45 | // Blob blue; |
hux | 23:677689000369 | 46 | // blue.service(presenceDetection); // use service |
hux | 23:677689000369 | 47 | // } |
hux | 23:677689000369 | 48 | // }; |
hux | 23:677689000369 | 49 | // |
hux | 23:677689000369 | 50 | #ifndef _SERVICE_H_ |
hux | 23:677689000369 | 51 | #define _SERVICE_H_ |
hux | 23:677689000369 | 52 | |
hux | 23:677689000369 | 53 | #include "ble/BLE.h" |
hux | 23:677689000369 | 54 | #include "ble/Gap.h" |
hux | 24:0f08f68579bd | 55 | #include "bricks/blob.h" |
hux | 23:677689000369 | 56 | #include "bricks/collection.h" |
hux | 23:677689000369 | 57 | |
hux | 27:32267cee7cb8 | 58 | // the following #define is helpful if a service is defined on base of the |
hux | 27:32267cee7cb8 | 59 | // BLE API (the tedios way) |
hux | 27:32267cee7cb8 | 60 | |
hux | 27:32267cee7cb8 | 61 | #define GattListLength(list) (sizeof(list)/sizeof(GattCharacteristic*)) |
hux | 27:32267cee7cb8 | 62 | |
hux | 27:32267cee7cb8 | 63 | // Service classs definition |
hux | 27:32267cee7cb8 | 64 | |
hux | 24:0f08f68579bd | 65 | class Service |
hux | 23:677689000369 | 66 | { |
hux | 26:fd06c8b57d16 | 67 | public: // public properties |
hux | 24:0f08f68579bd | 68 | Collection collection; // collection of characteristics |
hux | 26:fd06c8b57d16 | 69 | uint16_t uuid; // UUID of service |
hux | 24:0f08f68579bd | 70 | const char *name; // name of service |
hux | 24:0f08f68579bd | 71 | |
hux | 24:0f08f68579bd | 72 | public: // public methods |
hux | 26:fd06c8b57d16 | 73 | Service(uint16_t _uuid, const char* _name = NULL) : collection() |
hux | 24:0f08f68579bd | 74 | { |
hux | 24:0f08f68579bd | 75 | uuid = _uuid; |
hux | 24:0f08f68579bd | 76 | name = _name; |
hux | 24:0f08f68579bd | 77 | } |
hux | 24:0f08f68579bd | 78 | |
hux | 24:0f08f68579bd | 79 | void add(GattCharacteristic *pChr) // add a characteristic to collection |
hux | 23:677689000369 | 80 | { |
hux | 24:0f08f68579bd | 81 | collection.add(pChr); |
hux | 24:0f08f68579bd | 82 | } |
hux | 23:677689000369 | 83 | }; |
hux | 23:677689000369 | 84 | |
hux | 23:677689000369 | 85 | #endif // _SERVICE_H_ |