Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
Send a double array using ReadOnlyGattCharacteristic
I'm trying to send an array of double values over BLE
BLEService.h
... class BLEService { public: BLEService(BLEDevice &_ble); ~BLEService(); void setupService(); void sendData(uint8_t* payload, uint16_t len); private: BLEDevice &ble; double* Buffer; ReadOnlyGattCharacteristic<double, 32> data; GattService* BLEService; ...
BLEService.c
#include "BLEService.h" BLEService::BLEService(BLEDevice &_ble) : ble(_ble) { Buffer = new double [32](); setupService(); } void BLEService::setupService() { const uint8_t SERVICE_UUID[16] = ... const uint8_t DATA_UUID[16] = ... UUID serviceUUID(SERVICE_UUID); UUID dataUUID(DATA_UUID); data(dataUUID, Buffer, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); GattCharacteristic *charTable[] = {&data}; BLEService = new GattService(serviceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic*)); ble.addService(*BLEService ); serviceAdded = true; } void BLEService::sendData(uint8_t* payload, uint16_t len) { memcpy(Buffer, payload, len); ble.updateCharacteristicValue(data.getValueHandle(), (uint8_t*)Buffer, len); }
The first problem is that gcc4mbed gives me an "does not name a type" error for ReadOnlyGattCharacteristic<double, 32>. Not sure I'm using it the correct way.
I'm sure that there is other errors as well as I'm pretty new to C++.
Update: Discovered that I have used an old BLE_API library that didn't include ReadOnly. Now it compiles with:
GattCharacteristic(dataUUID, reinterpret_cast<uint8_t *>(Buffer), sizeof(double) * 32, sizeof(double) * 32, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_FORMAT_FLOAT64);
My library didn't have the function for it.
posted by Johan Westlund 14 Jul 2017