Bluetooth Low Energy enabled device with "Switch" feature, compatible with BlueST Protocol.

Bluetooth Low Energy enabled device with "Switch" feature, compatible with BlueST Protocol.

Revision:
4:67ff1ddd11e2
Parent:
0:6b34c49b5285
Child:
5:1651815d2a74
--- a/source/CustomService.h	Thu May 10 11:59:17 2018 +0000
+++ b/source/CustomService.h	Thu May 31 18:30:29 2018 +0000
@@ -43,9 +43,8 @@
 
 #include "ble_utils.h"
 
-#define STATE_DATA_LENGTH   (sizeof(uint16_t) + sizeof(uint8_t))
-#define COMMAND_DATA_LENGTH (sizeof(uint8_t))
-#define MAX_DATA_LENGTH     (STATE_DATA_LENGTH)
+#define SWITCH_DATA_LENGTH (sizeof(uint16_t) + sizeof(uint8_t))
+#define SWITCH_DATA_INDEX  (sizeof(uint16_t))
 
 const UUID::LongUUIDBytes_t CUSTOM_SWITCH_SERVICE_UUID        = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 const UUID::LongUUIDBytes_t CUSTOM_SWITCH_CHARACTERISTIC_UUID = {0x20,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
@@ -62,20 +61,20 @@
 
     CustomService(BLEDevice &_ble) :
         ble(_ble),
-        state_command(CUSTOM_SWITCH_CHARACTERISTIC_UUID, packed_state_command, MAX_DATA_LENGTH, MAX_DATA_LENGTH,
+        state_command(CUSTOM_SWITCH_CHARACTERISTIC_UUID, packed_state_command, SWITCH_DATA_LENGTH, SWITCH_DATA_LENGTH,
             /*GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | */GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
     {
         GattCharacteristic *char_table[] = {&state_command};
         GattService switch_service(CUSTOM_SWITCH_SERVICE_UUID, char_table, sizeof(char_table) / sizeof(GattCharacteristic *));
         ble.addService(switch_service);
-        memset (packed_state_command, 0, MAX_DATA_LENGTH);
+        memset (packed_state_command, 0, SWITCH_DATA_LENGTH);
     }
 
     void send_state(uint16_t time_stamp, uint8_t current_state) {
-        memset (packed_state_command, 0, MAX_DATA_LENGTH);
+        memset (packed_state_command, 0, SWITCH_DATA_LENGTH);
         STORE_LE_16(packed_state_command, time_stamp);
-        packed_state_command[2] = current_state;
-        ble.gattServer().write(state_command.getValueAttribute().getHandle(), (uint8_t *) &packed_state_command, STATE_DATA_LENGTH, 0);
+        packed_state_command[SWITCH_DATA_INDEX] = current_state;
+        ble.gattServer().write(state_command.getValueAttribute().getHandle(), (uint8_t *) &packed_state_command, SWITCH_DATA_LENGTH, 0);
     }
 
     GattAttribute::Handle_t getValueHandle() const
@@ -86,7 +85,7 @@
 private:
     BLEDevice &ble;
     GattCharacteristic state_command;
-    uint8_t packed_state_command[MAX_DATA_LENGTH];
+    uint8_t packed_state_command[SWITCH_DATA_LENGTH];
 };
 
 #endif /* #ifndef __BLE_CUSTOM_SERVICE_H__ */