diff --git a/libs/BLEKit/include/BLEKit.h b/libs/BLEKit/include/BLEKit.h index d94344cbca..756e75c08b 100644 --- a/libs/BLEKit/include/BLEKit.h +++ b/libs/BLEKit/include/BLEKit.h @@ -7,7 +7,6 @@ #include #include -#include "BLEServiceBattery.h" #include "ble/BLE.h" #include "CoreEventQueue.h" diff --git a/libs/BLEKit/include/BLEServiceBattery.h b/libs/BLEKit/include/BLEServiceBattery.h index 45498f4108..990c2f81ce 100644 --- a/libs/BLEKit/include/BLEServiceBattery.h +++ b/libs/BLEKit/include/BLEServiceBattery.h @@ -25,7 +25,7 @@ class BLEServiceBattery : public interface::BLEService } else { _battery_level_characteristic_value = 100; } - auto data = std::make_tuple(_battery_level_writable_characteristic.getValueHandle(), + auto data = std::make_tuple(&_battery_level_writable_characteristic, std::span(&_battery_level_characteristic_value, 1)); sendData(data); } @@ -41,8 +41,6 @@ class BLEServiceBattery : public interface::BLEService } private: - data_to_send_handle_t send_data_function {}; - uint8_t _battery_level_characteristic_value {}; ReadOnlyGattCharacteristic _battery_level_writable_characteristic { service::battery::characteristic::level, &_battery_level_characteristic_value, diff --git a/libs/BLEKit/include/BLEServiceConfig.h b/libs/BLEKit/include/BLEServiceConfig.h index 2ade43a14d..26679e4013 100644 --- a/libs/BLEKit/include/BLEServiceConfig.h +++ b/libs/BLEKit/include/BLEServiceConfig.h @@ -25,7 +25,7 @@ class BLEServiceConfig : public interface::BLEService { std::copy(std::begin(robot_name), std::begin(robot_name) + std::size(_robot_name), _robot_name.begin()); - auto data = std::make_tuple(_robot_name_characteristic.getValueHandle(), _robot_name); + auto data = std::make_tuple(&_robot_name_characteristic, _robot_name); sendData(data); } diff --git a/libs/BLEKit/include/BLEServiceDeviceInformation.h b/libs/BLEKit/include/BLEServiceDeviceInformation.h index 643d938ea6..3bab877ce4 100644 --- a/libs/BLEKit/include/BLEServiceDeviceInformation.h +++ b/libs/BLEKit/include/BLEServiceDeviceInformation.h @@ -25,7 +25,7 @@ class BLEServiceDeviceInformation : public interface::BLEService { std::copy(std::begin(value), std::begin(value) + std::size(_serial_number), _serial_number.begin()); - auto data = std::make_tuple(_serial_number_characteristic.getValueHandle(), _serial_number); + auto data = std::make_tuple(&_serial_number_characteristic, std::span(_serial_number)); sendData(data); } @@ -36,7 +36,7 @@ class BLEServiceDeviceInformation : public interface::BLEService std::copy(std::begin(version_cstr), std::begin(version_cstr) + std::size(_os_version), _os_version.begin()); - auto data = std::make_tuple(_os_version_characteristic.getValueHandle(), _os_version); + auto data = std::make_tuple(&_os_version_characteristic, std::span(_os_version)); sendData(data); } diff --git a/libs/BLEKit/include/BLEServiceFileExchange.h b/libs/BLEKit/include/BLEServiceFileExchange.h index 7f645e7778..ae0f9f8412 100644 --- a/libs/BLEKit/include/BLEServiceFileExchange.h +++ b/libs/BLEKit/include/BLEServiceFileExchange.h @@ -24,8 +24,7 @@ class BLEServiceFileExchange : public interface::BLEService { set_file_exchange_state = static_cast(value); - auto data = std::make_tuple(set_file_exchange_state_characteristic.getValueHandle(), - std::span(&set_file_exchange_state, 1)); + auto data = std::make_tuple(&set_file_exchange_state_characteristic, std::span(&set_file_exchange_state, 1)); sendData(data); } @@ -35,7 +34,7 @@ class BLEServiceFileExchange : public interface::BLEService { clear_file = 0; - auto data = std::make_tuple(clear_file_characteristic.getValueHandle(), std::span(&clear_file, 1)); + auto data = std::make_tuple(&clear_file_characteristic, std::span(&clear_file, 1)); sendData(data); } @@ -43,7 +42,7 @@ class BLEServiceFileExchange : public interface::BLEService { std::copy(std::begin(sha256), std::begin(sha256) + std::size(sha256), file_sha256.begin()); - auto data = std::make_tuple(file_sha256_characteristic.getValueHandle(), file_sha256); + auto data = std::make_tuple(&file_sha256_characteristic, file_sha256); sendData(data); } diff --git a/libs/BLEKit/include/BLEServiceMagicCard.h b/libs/BLEKit/include/BLEServiceMagicCard.h index 6af30519ea..0b172b60aa 100644 --- a/libs/BLEKit/include/BLEServiceMagicCard.h +++ b/libs/BLEKit/include/BLEServiceMagicCard.h @@ -39,7 +39,7 @@ class BLEServiceMagicCard : public interface::BLEService raw_data[1] = utils::memory::getLowByte(id); raw_data[2] = static_cast(language); - auto data = std::make_tuple(raw_data_characteristic.getValueHandle(), raw_data); + auto data = std::make_tuple(&raw_data_characteristic, raw_data); sendData(data); } diff --git a/libs/BLEKit/include/BLEServiceMonitoring.h b/libs/BLEKit/include/BLEServiceMonitoring.h index e1244f1aa2..5405afab49 100644 --- a/libs/BLEKit/include/BLEServiceMonitoring.h +++ b/libs/BLEKit/include/BLEServiceMonitoring.h @@ -26,7 +26,7 @@ class BLEServiceMonitoring : public interface::BLEService { _charging_status = static_cast(value); - auto data = std::make_tuple(_charging_status_characteristic.getValueHandle(), std::span(&_charging_status, 1)); + auto data = std::make_tuple(&_charging_status_characteristic, std::span(&_charging_status, 1)); sendData(data); } @@ -37,8 +37,7 @@ class BLEServiceMonitoring : public interface::BLEService auto _high_byte = utils::memory::getHighByte(_negotiated_mtu); auto _low_byte = utils::memory::getLowByte(_negotiated_mtu); - auto data = - std::make_tuple(_negotiated_mtu_characteristic.getValueHandle(), std::to_array({_high_byte, _low_byte})); + auto data = std::make_tuple(&_negotiated_mtu_characteristic, std::to_array({_high_byte, _low_byte})); sendData(data); } diff --git a/libs/BLEKit/include/CoreGattServer.h b/libs/BLEKit/include/CoreGattServer.h index aa0caa8d77..e4f7c913e9 100644 --- a/libs/BLEKit/include/CoreGattServer.h +++ b/libs/BLEKit/include/CoreGattServer.h @@ -6,7 +6,6 @@ #include -#include "BLEServiceBattery.h" #include "ble/BLE.h" #include "ble/GattServer.h" @@ -26,7 +25,7 @@ class CoreGattServer void onMTUNegotiated(const std::function &callback); private: - void write(GattAttribute::Handle_t characteristic_updated, std::span data); + void write(const GattCharacteristic *characteristic_updated, std::span data); ble::GattServer &_gatt_server; leka::CoreGattServerEventHandler _gatt_server_event_handler; diff --git a/libs/BLEKit/include/internal/BLEService.h b/libs/BLEKit/include/internal/BLEService.h index 9d7bc31d97..3796f2ced2 100644 --- a/libs/BLEKit/include/internal/BLEService.h +++ b/libs/BLEKit/include/internal/BLEService.h @@ -26,7 +26,7 @@ class BLEService : public GattService using data_received_handle_t = GattWriteCallbackParams; using data_requested_handle_t = GattReadCallbackParams; - using data_to_send_handle_t = std::tuple>; + using data_to_send_handle_t = std::tuple>; virtual void onDataReceived(const data_received_handle_t &handle) = 0; virtual void onDataRequested(const data_requested_handle_t &handle) = 0; diff --git a/libs/BLEKit/source/CoreGattServer.cpp b/libs/BLEKit/source/CoreGattServer.cpp index 6f328fef7f..0558e4e51b 100644 --- a/libs/BLEKit/source/CoreGattServer.cpp +++ b/libs/BLEKit/source/CoreGattServer.cpp @@ -26,9 +26,9 @@ void CoreGattServer::setServices(std::span services) _gatt_server_event_handler.setServices(services); } -void CoreGattServer::write(GattAttribute::Handle_t characteristic_updated, std::span data) +void CoreGattServer::write(const GattCharacteristic *characteristic_updated, std::span data) { - _gatt_server.write(characteristic_updated, data.data(), static_cast(std::size(data))); + _gatt_server.write(characteristic_updated->getValueHandle(), data.data(), static_cast(std::size(data))); } void CoreGattServer::onMTUNegotiated(const std::function &callback) diff --git a/libs/BLEKit/tests/CoreGattServer_test.cpp b/libs/BLEKit/tests/CoreGattServer_test.cpp index ce77296b67..3d78da0384 100644 --- a/libs/BLEKit/tests/CoreGattServer_test.cpp +++ b/libs/BLEKit/tests/CoreGattServer_test.cpp @@ -74,13 +74,12 @@ TEST_F(CoreGattServerTest, onDataReadyToSend) gatt_server.setServices(services); - auto handle = GattAttribute::Handle_t {}; auto data_to_send = std::to_array({0x2A, 0x2B, 0x2C, 0x2D}); - auto tuple = std::make_tuple(handle, data_to_send); + auto tuple = std::make_tuple(&characteristic, data_to_send); const auto &[h, d] = tuple; // need for the EXPECT_CALL: addresses must be the same - EXPECT_CALL(mbed_mock_gatt, write(h, d.data(), std::size(d), _)).Times(1); + EXPECT_CALL(mbed_mock_gatt, write(h->getValueHandle(), d.data(), std::size(d), _)).Times(1); mock_service.sendData(tuple); }