Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A2
Fork of Node_BLE_Switch_Device by
Bluetooth Low Energy enabled device with environmental and inertial features, i.e. "Pressure", "Humidity", "Temperature", "Accelerometer", "Gyroscope", and "Magnetometer", plus "Switch" feature, compatible with BlueST Protocol.
Diff: source/CustomService.h
- Revision:
- 7:2b5ed57b088c
- Parent:
- 6:01d49589410e
--- a/source/CustomService.h Tue May 22 16:35:05 2018 +0000 +++ b/source/CustomService.h Mon Aug 06 09:57:49 2018 +0000 @@ -50,8 +50,7 @@ /* Definitions ---------------------------------------------------------------*/ #define TIMESTAMP_LENGTH (sizeof(uint16_t)) -#define STATE_LENGTH (sizeof(uint8_t)) -#define COMMAND_LENGTH (sizeof(uint8_t)) +#define SWITCH_LENGTH (sizeof(uint8_t)) #define PRESSURE_LENGTH (sizeof(uint32_t)) #define HUMIDITY_LENGTH (sizeof(uint16_t)) #define TEMPERATURE_LENGTH (sizeof(uint16_t)) @@ -59,8 +58,8 @@ #define GYROSCOPE_LENGTH (sizeof(uint16_t)) #define MAGNETOMETER_LENGTH (sizeof(uint16_t)) -#define STATE_DATA_LENGTH (TIMESTAMP_LENGTH + STATE_LENGTH) -#define COMMAND_DATA_LENGTH (COMMAND_LENGTH) +#define SWITCH_DATA_INDEX (TIMESTAMP_LENGTH) +#define SWITCH_DATA_LENGTH (TIMESTAMP_LENGTH + SWITCH_LENGTH) #define ENV_SENSORS_DATA_LENGTH (TIMESTAMP_LENGTH + PRESSURE_LENGTH + HUMIDITY_LENGTH + TEMPERATURE_LENGTH) #define INE_SENSORS_DATA_LENGTH (TIMESTAMP_LENGTH + (3 * ACCELEROMETER_LENGTH) + (3 * GYROSCOPE_LENGTH) + (3 * MAGNETOMETER_LENGTH)) @@ -78,7 +77,7 @@ /* Constants -----------------------------------------------------------------*/ -const UUID::LongUUIDBytes_t CUSTOM_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; +const UUID::LongUUIDBytes_t CUSTOM_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,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}; const UUID::LongUUIDBytes_t CUSTOM_ENV_SENSORS_CHARACTERISTIC_UUID = {0x00,0x1c,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; const UUID::LongUUIDBytes_t CUSTOM_INE_SENSORS_CHARACTERISTIC_UUID = {0x00,0xe0,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; @@ -98,7 +97,7 @@ CustomService(BLEDevice &_ble) : ble(_ble), - state_command(CUSTOM_SWITCH_CHARACTERISTIC_UUID, packed_state_command, STATE_DATA_LENGTH, STATE_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), env_sensors(CUSTOM_ENV_SENSORS_CHARACTERISTIC_UUID, packed_env_sensors, ENV_SENSORS_DATA_LENGTH, ENV_SENSORS_DATA_LENGTH, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), @@ -108,16 +107,16 @@ GattCharacteristic *char_table[] = {&state_command, &env_sensors, &ine_sensors}; GattService iot_service(CUSTOM_SERVICE_UUID, char_table, sizeof(char_table) / sizeof(GattCharacteristic *)); ble.addService(iot_service); - memset (packed_state_command, 0, STATE_DATA_LENGTH); + memset (packed_state_command, 0, SWITCH_DATA_LENGTH); memset (packed_env_sensors, 0, ENV_SENSORS_DATA_LENGTH); memset (packed_ine_sensors, 0, INE_SENSORS_DATA_LENGTH); } void send_state(uint16_t time_stamp, uint8_t current_state) { - memset (packed_state_command, 0, STATE_DATA_LENGTH); + memset (packed_state_command, 0, SWITCH_DATA_LENGTH); STORE_LE_16(packed_state_command, time_stamp); - packed_state_command[TIMESTAMP_LENGTH] = current_state; - ble.gattServer().write(get_state_command_handle(), (uint8_t *) &packed_state_command, STATE_DATA_LENGTH, 0); + packed_state_command[SWITCH_DATA_INDEX] = current_state; + ble.gattServer().write(get_state_command_handle(), (uint8_t *) &packed_state_command, SWITCH_DATA_LENGTH, 0); } void send_env_sensors( @@ -184,7 +183,7 @@ GattCharacteristic state_command; GattCharacteristic env_sensors; GattCharacteristic ine_sensors; - uint8_t packed_state_command[STATE_DATA_LENGTH]; + uint8_t packed_state_command[SWITCH_DATA_LENGTH]; uint8_t packed_env_sensors[ENV_SENSORS_DATA_LENGTH]; uint8_t packed_ine_sensors[INE_SENSORS_DATA_LENGTH]; };