Simple example to demonstrate custom made BLE service and characteristics.
Fork of BLE_GATT_Example by
AckService.h@23:924d0ef8f1cb, 2017-11-09 (annotated)
- Committer:
- jurica238814
- Date:
- Thu Nov 09 16:08:04 2017 +0000
- Revision:
- 23:924d0ef8f1cb
0xBABE and 0xDEAD works.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 23:924d0ef8f1cb | 1 | |
jurica238814 | 23:924d0ef8f1cb | 2 | #define MAC_ADDR_SIZE_B (6) |
jurica238814 | 23:924d0ef8f1cb | 3 | |
jurica238814 | 23:924d0ef8f1cb | 4 | // Template allows you to use 'constant' values on non-constant places (XD) |
jurica238814 | 23:924d0ef8f1cb | 5 | template<uint8_t dataSize> |
jurica238814 | 23:924d0ef8f1cb | 6 | |
jurica238814 | 23:924d0ef8f1cb | 7 | class ACKService{ |
jurica238814 | 23:924d0ef8f1cb | 8 | public: |
jurica238814 | 23:924d0ef8f1cb | 9 | const static uint16_t ACK_SERVICE_UUID = 0xA000; |
jurica238814 | 23:924d0ef8f1cb | 10 | const static uint16_t ACK_CHARA_UUID = 0xA001; |
jurica238814 | 23:924d0ef8f1cb | 11 | const static uint16_t ACK_MAC_CHAR_UUID = 0xA002; |
jurica238814 | 23:924d0ef8f1cb | 12 | |
jurica238814 | 23:924d0ef8f1cb | 13 | ACKService(BLEDevice &_ble, uint8_t *_initValues) : ble(_ble), ACK(ACK_CHARA_UUID, _initValues), MAC(ACK_MAC_CHAR_UUID, _initValues, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY){ |
jurica238814 | 23:924d0ef8f1cb | 14 | GattCharacteristic *charTable[] = {&ACK, &MAC}; // Add characteristick in table |
jurica238814 | 23:924d0ef8f1cb | 15 | GattService AckService(ACK_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *)); |
jurica238814 | 23:924d0ef8f1cb | 16 | ble.addService(AckService); // Add service in the BLE |
jurica238814 | 23:924d0ef8f1cb | 17 | } |
jurica238814 | 23:924d0ef8f1cb | 18 | void updateMacAddress(uint8_t *MacAddress){ |
jurica238814 | 23:924d0ef8f1cb | 19 | ble.gattServer().write(MAC.getValueHandle(), MacAddress, MAC_ADDR_SIZE_B); |
jurica238814 | 23:924d0ef8f1cb | 20 | } |
jurica238814 | 23:924d0ef8f1cb | 21 | private: |
jurica238814 | 23:924d0ef8f1cb | 22 | BLEDevice &ble; |
jurica238814 | 23:924d0ef8f1cb | 23 | // Create new characteristic |
jurica238814 | 23:924d0ef8f1cb | 24 | WriteOnlyArrayGattCharacteristic<uint8_t, dataSize> ACK; |
jurica238814 | 23:924d0ef8f1cb | 25 | ReadOnlyArrayGattCharacteristic<uint8_t, MAC_ADDR_SIZE_B> MAC; |
jurica238814 | 23:924d0ef8f1cb | 26 | }; |