diff --git a/config/mbed_app.json b/config/mbed_app.json index d65055a6ce..9279043a66 100644 --- a/config/mbed_app.json +++ b/config/mbed_app.json @@ -23,6 +23,8 @@ "bluenrg_ms.SPI_nCS": "BLE_SPI_NSS", "bluenrg_ms.SPI_SCK": "BLE_SPI_SCK", "cordio.desired-att-mtu": 251, + "cordio.rx-acl-buffer-size": 189, + "cordio.max-prepared-writes": 1, "sd.SPI_CS": "SD_SPI_CS", "sd.SPI_MISO": "SD_SPI_MISO", "sd.SPI_MOSI": "SD_SPI_MOSI", diff --git a/config/os_version b/config/os_version index 88c5fb891d..febd7639fe 100644 --- a/config/os_version +++ b/config/os_version @@ -1 +1 @@ -1.4.0 +1.4.101 diff --git a/libs/BLEKit/include/BLEServiceFileExchange.h b/libs/BLEKit/include/BLEServiceFileExchange.h index 6402728428..7f645e7778 100644 --- a/libs/BLEKit/include/BLEServiceFileExchange.h +++ b/libs/BLEKit/include/BLEServiceFileExchange.h @@ -129,8 +129,8 @@ class BLEServiceFileExchange : public interface::BLEService GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY}; std::function _on_clear_file_requested_callback {}; - std::array file_reception_buffer {}; - WriteOnlyArrayGattCharacteristic file_reception_buffer_characteristic { + std::array file_reception_buffer {}; + WriteOnlyArrayGattCharacteristic file_reception_buffer_characteristic { service::file_exchange::characteristic::file_reception_buffer, file_reception_buffer.begin()}; std::array file_sha256 {}; diff --git a/libs/BLEKit/include/CoreGap.h b/libs/BLEKit/include/CoreGap.h index 5b0f0896e1..c6be542c90 100644 --- a/libs/BLEKit/include/CoreGap.h +++ b/libs/BLEKit/include/CoreGap.h @@ -28,6 +28,8 @@ class CoreGap void startAdvertising(); void setAdvertising(AdvertisingData advertising_data); + void updateConnectionParameters(ble::connection_handle_t handle); + void onConnectionCallback(const std::function &callback); void onDisconnectionCallback(const std::function &callback); [[nodiscard]] auto isConnected() const -> bool; @@ -40,6 +42,8 @@ class CoreGap CoreGapEventHandler _gap_event_handler; ble::Gap &_gap; + + std::function _on_connection_callback {}; }; } // namespace leka diff --git a/libs/BLEKit/include/CoreGapEventHandler.h b/libs/BLEKit/include/CoreGapEventHandler.h index a4700dc46b..c34941d405 100644 --- a/libs/BLEKit/include/CoreGapEventHandler.h +++ b/libs/BLEKit/include/CoreGapEventHandler.h @@ -24,7 +24,7 @@ class CoreGapEventHandler : public ble::Gap::EventHandler void onDisconnectionComplete(ble::DisconnectionCompleteEvent const &event) override; void onAdvertisingEnd(ble::AdvertisingEndEvent const &event) override; - void onConnectionCallback(const std::function &callback); + void onConnectionCallback(const std::function &callback); void onDisconnectionCallback(const std::function &callback); [[nodiscard]] auto isConnected() const -> bool; @@ -33,7 +33,7 @@ class CoreGapEventHandler : public ble::Gap::EventHandler std::function _start_advertising {}; - std::function _on_connection_callback {}; + std::function _on_connection_callback {}; std::function _on_disconnection_callback {}; }; diff --git a/libs/BLEKit/source/CoreGap.cpp b/libs/BLEKit/source/CoreGap.cpp index 14680fd219..34800b4256 100644 --- a/libs/BLEKit/source/CoreGap.cpp +++ b/libs/BLEKit/source/CoreGap.cpp @@ -58,9 +58,27 @@ void CoreGap::setAdvertising(AdvertisingData advertising_data) _gap.setAdvertisingPayload(_advertising_handle, _advertising_data_builder.getAdvertisingData()); } +void CoreGap::updateConnectionParameters(ble::connection_handle_t handle) +{ + // ? : See mbed-os/connectivity/FEATURE_BLE/include/ble/Gap.h for definitions + // ? : Apple guidelines https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf#page=221 + + auto min_connection_interval = conn_interval_t {12}; // Min: 15ms = 12*1,25 + auto max_connection_interval = min_connection_interval; + auto slave_latency = slave_latency_t {0}; + auto supervision_timeout = supervision_timeout_t {500}; + + _gap.updateConnectionParameters(handle, min_connection_interval, max_connection_interval, slave_latency, + supervision_timeout); +} + void CoreGap::onConnectionCallback(const std::function &callback) { - _gap_event_handler.onConnectionCallback(callback); + _on_connection_callback = [&, callback](connection_handle_t handle) { + updateConnectionParameters(handle); + callback(); + }; + _gap_event_handler.onConnectionCallback(_on_connection_callback); } void CoreGap::onDisconnectionCallback(const std::function &callback) diff --git a/libs/BLEKit/source/CoreGapEventHandler.cpp b/libs/BLEKit/source/CoreGapEventHandler.cpp index 5b172a1155..193cb827b7 100644 --- a/libs/BLEKit/source/CoreGapEventHandler.cpp +++ b/libs/BLEKit/source/CoreGapEventHandler.cpp @@ -28,7 +28,8 @@ void CoreGapEventHandler::onConnectionComplete(ConnectionCompleteEvent const &ev } if (_on_connection_callback != nullptr) { - _on_connection_callback(); + auto handle = event.getConnectionHandle(); + _on_connection_callback(handle); } is_connected = true; } @@ -48,7 +49,7 @@ void CoreGapEventHandler::onAdvertisingEnd(AdvertisingEndEvent const &event) _start_advertising(); } -void CoreGapEventHandler::onConnectionCallback(const std::function &callback) +void CoreGapEventHandler::onConnectionCallback(const std::function &callback) { _on_connection_callback = callback; } diff --git a/libs/BLEKit/tests/CoreGapEventHandler_test.cpp b/libs/BLEKit/tests/CoreGapEventHandler_test.cpp index 627a6a356b..71e79d1b79 100644 --- a/libs/BLEKit/tests/CoreGapEventHandler_test.cpp +++ b/libs/BLEKit/tests/CoreGapEventHandler_test.cpp @@ -97,7 +97,7 @@ TEST_F(CoreGapEventHandlerTest, onAdvertisingEnd) TEST_F(CoreGapEventHandlerTest, onConnectionCallback) { - MockFunction mock_on_connection_callback; + MockFunction mock_on_connection_callback; core_gap_event_handler.onConnectionCallback(mock_on_connection_callback.AsStdFunction()); diff --git a/libs/BLEKit/tests/CoreGap_test.cpp b/libs/BLEKit/tests/CoreGap_test.cpp index c0744a1653..bcd36ab0f2 100644 --- a/libs/BLEKit/tests/CoreGap_test.cpp +++ b/libs/BLEKit/tests/CoreGap_test.cpp @@ -14,6 +14,7 @@ using namespace leka; using namespace ble; +using ::testing::_; using ::testing::Return; using ::testing::Sequence; @@ -64,6 +65,11 @@ MATCHER_P(compareAdvertisingPayload, expected_data_builder, "") return expected_data_builder.getAdvertisingData() == arg; } +MATCHER_P(compareSlaveLatency, expected_slave_latency, "") +{ + return expected_slave_latency.value() == arg.value(); +} + TEST_F(CoreGapTest, initialization) { EXPECT_NE(&coregap, nullptr); @@ -136,6 +142,21 @@ TEST_F(CoreGapTest, startAdvertisingAdvertisingWasActive) coregap.startAdvertising(); } +TEST_F(CoreGapTest, updateConnectionParameters) +{ + auto handle = connection_handle_t {}; + auto min_connection_interval = conn_interval_t {12}; // Min: 15ms = 12*1,25 + auto max_connection_interval = min_connection_interval; + auto slave_latency = slave_latency_t {0}; + auto supervision_timeout = supervision_timeout_t {500}; + + EXPECT_CALL(mbed_mock_gap, + updateConnectionParameters(handle, min_connection_interval, max_connection_interval, + compareSlaveLatency(slave_latency), supervision_timeout, _, _)); + + coregap.updateConnectionParameters(handle); +} + TEST_F(CoreGapTest, onInitializationComplete) { BLE::InitializationCompleteCallbackContext context = {ble, BLE_ERROR_NONE}; diff --git a/libs/FileManagerKit/include/FileReception.h b/libs/FileManagerKit/include/FileReception.h index cfdaaf2564..7cdc6f5241 100644 --- a/libs/FileManagerKit/include/FileReception.h +++ b/libs/FileManagerKit/include/FileReception.h @@ -32,7 +32,7 @@ class FileReception CoreEventQueue event_queue {}; CircularQueue _circular_queue {}; - std::array _buffer {}; + std::array _buffer {}; }; } // namespace leka diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index 2f9fd57e3b..87cc0d9b87 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -83,7 +83,7 @@ class RobotController : public interface::RobotController _behaviorkit.launching(); _lcd.turnOn(); - rtos::ThisThread::sleep_for(3s); + rtos::ThisThread::sleep_for(10s); } void startSleepTimeout() final @@ -171,8 +171,10 @@ class RobotController : public interface::RobotController _behaviorkit.chargingMedium(); } else if (level < 90) { _behaviorkit.chargingHigh(); - } else { + } else if (level == 101) { _behaviorkit.chargingFull(); + } else { + _behaviorkit.chargingHigh(); } }