Skip to content

Commit

Permalink
Add conditions to verify and identify failed data
Browse files Browse the repository at this point in the history
  • Loading branch information
Akram authored and Akram committed Sep 9, 2024
1 parent b399688 commit 0260fad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions lib/APPReinforcementLearning/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void App::loop()
{
Board::getInstance().process();
Speedometer::getInstance().process();
bool isDataSent = true;
bool isSensorDataSent = true;
bool isModeDataSent = true;
bool isStatusDataSent = true;

if (true == m_controlInterval.isTimeout())
{
Expand Down Expand Up @@ -125,7 +127,7 @@ void App::loop()
payload = {SMPChannelPayload::Status::DONE};
}

isDataSent = m_smpServer.sendData(m_serialMuxProtChannelIdStatus, &payload, sizeof(payload));
isStatusDataSent = m_smpServer.sendData(m_serialMuxProtChannelIdStatus, &payload, sizeof(payload));

m_statusTimer.restart();
}
Expand All @@ -134,7 +136,7 @@ void App::loop()
if (true == m_sendLineSensorsDataInterval.isTimeout() &&
(&DrivingState::getInstance() == m_systemStateMachine.getState()))
{
isDataSent = sendLineSensorsData();
isSensorDataSent = sendLineSensorsData();

m_sendLineSensorsDataInterval.restart();
}
Expand All @@ -149,16 +151,30 @@ void App::loop()
SMPChannelPayload::Mode payload =
(1 == mode_options) ? SMPChannelPayload::Mode::DRIVING_MODE : SMPChannelPayload::Mode::TRAINING_MODE;

isDataSent = m_smpServer.sendData(m_serialMuxProtChannelIdMode, &payload, sizeof(payload));
isModeDataSent = m_smpServer.sendData(m_serialMuxProtChannelIdMode, &payload, sizeof(payload));

m_modeSelectionSent = true;
}
}

if (false == isDataSent)
if (false == isSensorDataSent)
{
/* Failed to send data to the supervisor. Go to error state. */
ErrorState::getInstance().setErrorMsg("DSF");
/* Failed to send Senssor data to the supervisor. Go to error state. */
ErrorState::getInstance().setErrorMsg("SEND_SF");
m_systemStateMachine.setState(&ErrorState::getInstance());
}

if (false == isStatusDataSent)
{
/* Failed to send Status data to the supervisor. Go to error state. */
ErrorState::getInstance().setErrorMsg("SD_SF");
m_systemStateMachine.setState(&ErrorState::getInstance());
}

if (false == isModeDataSent)
{
/* Failed to send Mode data to the supervisor. Go to error state. */
ErrorState::getInstance().setErrorMsg("MD_SF");
m_systemStateMachine.setState(&ErrorState::getInstance());
}

Expand Down Expand Up @@ -208,7 +224,7 @@ bool App::sendLineSensorsData() const
uint8_t maxLineSensors = lineSensors.getNumLineSensors();
const uint16_t* lineSensorValues = lineSensors.getSensorValues();
uint8_t lineSensorIdx = 0U;
bool isPayloadSent = true;
bool isPayloadSent = true;
LineSensorData payload;

if (LINE_SENSOR_CHANNEL_DLC == (maxLineSensors * sizeof(uint16_t)))
Expand Down
2 changes: 1 addition & 1 deletion lib/APPReinforcementLearning/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class App
/**
* Send line sensors data via SerialMuxProt.
*
* * @return true if data has been sent, false otherwise.
* @return true if data has been sent, false otherwise.
*/
bool sendLineSensorsData() const;

Expand Down

0 comments on commit 0260fad

Please sign in to comment.