Bluetooth Low Energy template with prewritten functions and callbacks for BLE events.
aconnoBLE/service.h@0:dbe0ce913311, 2018-06-22 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Jun 22 15:05:42 2018 +0200
- Revision:
- 0:dbe0ce913311
init commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jurica238814 | 0:dbe0ce913311 | 1 | /* |
| jurica238814 | 0:dbe0ce913311 | 2 | * Made by Jurica @ aconno |
| jurica238814 | 0:dbe0ce913311 | 3 | * All rights reserved |
| jurica238814 | 0:dbe0ce913311 | 4 | * |
| jurica238814 | 0:dbe0ce913311 | 5 | */ |
| jurica238814 | 0:dbe0ce913311 | 6 | |
| jurica238814 | 0:dbe0ce913311 | 7 | #ifndef SERVICE_H |
| jurica238814 | 0:dbe0ce913311 | 8 | #define SERVICE_H |
| jurica238814 | 0:dbe0ce913311 | 9 | |
| jurica238814 | 0:dbe0ce913311 | 10 | #define TIMESTAMP_SIZE_B (6) |
| jurica238814 | 0:dbe0ce913311 | 11 | |
| jurica238814 | 0:dbe0ce913311 | 12 | static const uint16_t SERVICE_UUID = 0xA3B6; |
| jurica238814 | 0:dbe0ce913311 | 13 | static const uint16_t NTP_CHARACTERISTIC_UUID = 0x33CC; |
| jurica238814 | 0:dbe0ce913311 | 14 | |
| jurica238814 | 0:dbe0ce913311 | 15 | class Service{ |
| jurica238814 | 0:dbe0ce913311 | 16 | public: |
| jurica238814 | 0:dbe0ce913311 | 17 | Service(BLEDevice &ble) : ble(ble), time(NTP_CHARACTERISTIC_UUID, 0){ |
| jurica238814 | 0:dbe0ce913311 | 18 | // Add characteristics to the table |
| jurica238814 | 0:dbe0ce913311 | 19 | GattCharacteristic *characteristics[] = {&time}; |
| jurica238814 | 0:dbe0ce913311 | 20 | GattService service(SERVICE_UUID, characteristics, |
| jurica238814 | 0:dbe0ce913311 | 21 | sizeof(characteristics)/sizeof(*characteristics)); |
| jurica238814 | 0:dbe0ce913311 | 22 | ble.addService(service); // Add service in the BLE |
| jurica238814 | 0:dbe0ce913311 | 23 | } |
| jurica238814 | 0:dbe0ce913311 | 24 | inline GattAttribute::Handle_t getTimeCharacteristicHandle() |
| jurica238814 | 0:dbe0ce913311 | 25 | { |
| jurica238814 | 0:dbe0ce913311 | 26 | return time.getValueHandle(); |
| jurica238814 | 0:dbe0ce913311 | 27 | } |
| jurica238814 | 0:dbe0ce913311 | 28 | private: |
| jurica238814 | 0:dbe0ce913311 | 29 | BLEDevice &ble; |
| jurica238814 | 0:dbe0ce913311 | 30 | // New characteristics names time |
| jurica238814 | 0:dbe0ce913311 | 31 | WriteOnlyArrayGattCharacteristic<uint8_t, TIMESTAMP_SIZE_B> time; |
| jurica238814 | 0:dbe0ce913311 | 32 | }; |
| jurica238814 | 0:dbe0ce913311 | 33 | #endif |