From cecb42785792d8087cf4acb0841b0d71aa7e15f3 Mon Sep 17 00:00:00 2001 From: Akram Date: Thu, 22 Aug 2024 11:44:16 +0200 Subject: [PATCH] Reset sendLineSensorsData function to its original state to fix issues with sensor data transmission. --- lib/APPReinforcementLearning/src/App.cpp | 40 ++++++++++++++---------- lib/APPReinforcementLearning/src/App.h | 7 ++++- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/APPReinforcementLearning/src/App.cpp b/lib/APPReinforcementLearning/src/App.cpp index 623ff63..d3e212a 100644 --- a/lib/APPReinforcementLearning/src/App.cpp +++ b/lib/APPReinforcementLearning/src/App.cpp @@ -133,23 +133,7 @@ void App::loop() if (true == m_sendLineSensorsDataInterval.isTimeout() && (&DrivingState::getInstance() == m_systemStateMachine.getState())) { - ILineSensors& lineSensors = Board::getInstance().getLineSensors(); - uint8_t maxLineSensors = lineSensors.getNumLineSensors(); - const uint16_t* lineSensorValues = lineSensors.getSensorValues(); - uint8_t lineSensorIdx = 0U; - LineSensorData payload; - - if (LINE_SENSOR_CHANNEL_DLC == (maxLineSensors * sizeof(uint16_t))) - { - while (maxLineSensors > lineSensorIdx) - { - payload.lineSensorData[lineSensorIdx] = lineSensorValues[lineSensorIdx]; - - ++lineSensorIdx; - } - } - - m_data_sent = m_smpServer.sendData(m_serialMuxProtChannelIdLineSensors, &payload, sizeof(payload)); + sendLineSensorsData(); m_sendLineSensorsDataInterval.restart(); } @@ -217,6 +201,28 @@ void App::handleRemoteCommand(const Command& cmd) * Private Methods *****************************************************************************/ +void App::sendLineSensorsData() +{ + ILineSensors& lineSensors = Board::getInstance().getLineSensors(); + uint8_t maxLineSensors = lineSensors.getNumLineSensors(); + const uint16_t* lineSensorValues = lineSensors.getSensorValues(); + uint8_t lineSensorIdx = 0U; + LineSensorData payload; + + if (LINE_SENSOR_CHANNEL_DLC == (maxLineSensors * sizeof(uint16_t))) + { + while (maxLineSensors > lineSensorIdx) + { + payload.lineSensorData[lineSensorIdx] = lineSensorValues[lineSensorIdx]; + + ++lineSensorIdx; + } + } + + /* Ignoring return value, as error handling is not available. */ + m_data_sent = m_smpServer.sendData(m_serialMuxProtChannelIdLineSensors, &payload, sizeof(payload)); +} + bool App::setupSerialMuxProt() { bool isSuccessful = false; diff --git a/lib/APPReinforcementLearning/src/App.h b/lib/APPReinforcementLearning/src/App.h index 4d73fc4..2683c30 100644 --- a/lib/APPReinforcementLearning/src/App.h +++ b/lib/APPReinforcementLearning/src/App.h @@ -150,7 +150,12 @@ class App * * @return If successful returns true, otherwise false. */ - bool setupSerialMuxProt(); + bool setupSerialMuxProt() + + /** + * Send line sensors data via SerialMuxProt. + */ + void sendLineSensorsData() ; /** * Copy construction of an instance.