-
Dependencies: BLE_API nRF51822
Fork of Puck by
Revision 15:bfc682889c15, committed 2015-02-27
- Comitter:
- sigveseb
- Date:
- Fri Feb 27 17:31:47 2015 +0000
- Parent:
- 14:9eda2d99fc1d
- Commit message:
- Update data write callbacks to use new BLE_API flow
Changed in this revision
Puck.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Puck.h Mon Feb 23 15:25:22 2015 +0000 +++ b/Puck.h Fri Feb 27 17:31:47 2015 +0000 @@ -32,7 +32,7 @@ const UUID stringToUUID(const char* str); -typedef void (*CharacteristicWriteCallback)(uint8_t* value); +typedef void (*CharacteristicWriteCallback)(const uint8_t* value, uint8_t length); typedef struct { const UUID* uuid; @@ -53,7 +53,8 @@ std::vector<GattCharacteristic*> characteristics; std::vector<CharacteristicWriteCallbacks*> writeCallbacks; std::vector<CharacteristicWriteCallback> pendingCallbackStack; - std::vector<uint8_t*> pendingCallbackParameterStack; + std::vector<const uint8_t*> pendingCallbackParameterDataStack; + std::vector<uint8_t> pendingCallbackParameterLengthStack; GattCharacteristic **previousCharacteristics; @@ -69,7 +70,7 @@ void disconnect(); bool drive(); int countFreeMemory(); - void onDataWritten(uint16_t handle); + void onDataWritten(GattAttribute::Handle_t handle, const uint8_t* data, const uint8_t length); void addCharacteristic(const UUID serviceUuid, const UUID characteristicUuid, int bytes, int properties = 0xA); void onCharacteristicWrite(const UUID* uuid, CharacteristicWriteCallback callback); @@ -97,7 +98,7 @@ } void onDataWrittenCallback(const GattCharacteristicWriteCBParams *context) { - Puck::getPuck().onDataWritten(context->charHandle); + Puck::getPuck().onDataWritten(context->charHandle, context->data, context->len); } bool isEqualUUID(const UUID* uuidA, const UUID uuidB) { @@ -300,9 +301,10 @@ ble.waitForEvent(); while(pendingCallbackStack.size() > 0) { - pendingCallbackStack.back()(pendingCallbackParameterStack.back()); + pendingCallbackStack.back()(pendingCallbackParameterDataStack.back(), pendingCallbackParameterLengthStack.back()); pendingCallbackStack.pop_back(); - pendingCallbackParameterStack.pop_back(); + pendingCallbackParameterDataStack.pop_back(); + pendingCallbackParameterLengthStack.pop_back(); } return true; } @@ -343,7 +345,7 @@ } -void Puck::onDataWritten(uint16_t handle) { +void Puck::onDataWritten(GattAttribute::Handle_t handle, const uint8_t* data, uint8_t length) { for (int i = 0; i < characteristics.size(); i++) { GattCharacteristic* characteristic = characteristics[i]; @@ -356,7 +358,9 @@ if(isEqualUUID(characteristicWriteCallbacks->uuid, gattAttribute.getUUID())) { for(int k = 0; k < characteristicWriteCallbacks->callbacks->size(); k++) { pendingCallbackStack.push_back(characteristicWriteCallbacks->callbacks->at(k)); - pendingCallbackParameterStack.push_back(gattAttribute.getValuePtr()); + + pendingCallbackParameterDataStack.push_back(data); + pendingCallbackParameterLengthStack.push_back(length); } return; }