Application running on nRF51822 PCA10001
Dependencies: BLE_API MMA8652 nRF51822 mbed-src
Diff: BuddiService.cpp
- Revision:
- 4:630f1560a0f3
- Parent:
- 3:596283411a00
--- a/BuddiService.cpp Fri Aug 29 12:36:01 2014 +0000 +++ b/BuddiService.cpp Wed Sep 03 07:04:54 2014 +0000 @@ -12,12 +12,12 @@ static const uint8_t notificationUUID[] = buddi_UUID(0xBB02); // Storage for the value of the characteristics -struct command_t { +typedef struct { uint8_t module; uint8_t opcode; uint8_t data[15]; -}; -static struct command_t commandPayload; +} Command_t; +static Command_t commandPayload; //uint8_t commandPayload[17] = {0,}; // Other things needed for operation @@ -25,8 +25,8 @@ static GattCharacteristic commandCharacteristic(commandUUID, (uint8_t *)&commandPayload, - sizeof(commandPayload), //1, - sizeof(commandPayload), //8, + sizeof(Command_t), //1, + sizeof(Command_t), //8, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); @@ -81,15 +81,20 @@ } } -void handleDataWritten(uint16_t handle) +void handleDataWritten(uint16_t handle, const GattCharacteristicWriteCBParams *params) { if (!ble) { return; } if (handle == commandCharacteristic.getValueAttribute().getHandle()) { - uint16_t len = sizeof(commandPayload); - ble->readCharacteristicValue(handle, (uint8_t *) &commandPayload, &len); + //uint16_t len = sizeof(commandPayload); + //ble->readCharacteristicValue(handle, (uint8_t *) &commandPayload, &len); + if (params->len != sizeof(Command_t)) { + DEBUG("invalid write into fileInfo characteristic\r\n"); + return; + } + memcpy(&commandPayload, params->data, params->len); DEBUG("RX: MOD: 0x%X OP: 0x%X D0: 0x%X D1: 0x%X", commandPayload.module, commandPayload.opcode, commandPayload.data[0], commandPayload.data[1]); //ble->updateCharacteristicValue(notificationCharacteristic.getValueAttribute().getHandle(), commandPayload, bytesRead);