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