![](/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
- Committer:
- hux
- Date:
- 2017-01-06
- Revision:
- 25:231d3f382583
- Parent:
- 24:0f08f68579bd
- Child:
- 26:fd06c8b57d16
File content as of revision 25:231d3f382583:
// service.h - declaring services and definitions // // Example 1: A protocol might be declared as a class as follows // // Collection col; // collection used during setup // // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID"); // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name"); // Characteristic<Digital> presence(col,0x2A56,"r","Presence"); // // Service presenceDetection(col,0xA001); // instantiate service // // onSetup(Blob &blue) // { // blue.service(presenceDetection); // use service // } // // Example 2: service definition by means of a service definition class // // class PresenceDetector // { // public: // Collection col; // collection used during setup // // Characteristic<ObjectId> id; // ID of presence detector // Characteristic<ObjectName> name; // name of presence detector // Characteristic<Digital> presence; // digital presence value // Characteristic<DateTime> timestamp; // last detection change's time // Characteristic<ObjectName> layout; // name of model railway layout // // Service presenceDetection; // the service // // public: // PresenceDetector(Blob &blue, cost UUID uuid) : // list; // init service list // id(list,0x2AC3,"rw","ID"), // instantiate characteristic // name(list,0x2ABE,"rw","Name"), // instantiate characteristic // presence(list,0x2A56,"r","Presence"),// instantiate characteristic // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic // presenceDetection(list,uuid) // instantiate service // { // Blob blue; // blue.service(presenceDetection); // use service // } // }; // #ifndef _SERVICE_H_ #define _SERVICE_H_ #include "ble/BLE.h" #include "ble/Gap.h" #include "bricks/blob.h" #include "bricks/collection.h" class Service { private: // private properties Collection collection; // collection of characteristics UUID uuid; // UUID of service const char *name; // name of service public: // public methods Service(UUID _uuid, const char* _name = NULL) : collection() { uuid = _uuid; name = _name; } void add(GattCharacteristic *pChr) // add a characteristic to collection { collection.add(pChr); } void enroll(Blob &blue) // enroll the service { static const uint16_t list[] = {0xFFFF}; // Custom UUID, FFFF is reserved for development // Used for UUID's broadcast in advertising packet GattService service(uuid, collection.plist, collection.count); blue.pble->gap().accumulateAdvertisingPayload( GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)list, sizeof(list)); blue.pble->addService(service); } }; #endif // _SERVICE_H_