Skip to content

Commit 4bba18e

Browse files
committed
Check for incoming status.
1 parent d64c0b4 commit 4bba18e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lib/ConvoyLeader/src/App.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
static void App_cmdRspChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
6969
static void App_currentVehicleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
70+
static void App_statusChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
7071

7172
/******************************************************************************
7273
* Local Variables
@@ -234,6 +235,16 @@ void App::setErrorState()
234235
m_systemStateMachine.setState(&ErrorState::getInstance());
235236
}
236237

238+
void App::systemStatusCallback(SMPChannelPayload::Status status)
239+
{
240+
if (SMPChannelPayload::STATUS_FLAG_ERROR == status)
241+
{
242+
setErrorState();
243+
}
244+
245+
m_statusTimeoutTimer.restart();
246+
}
247+
237248
/******************************************************************************
238249
* Protected Methods
239250
*****************************************************************************/
@@ -407,6 +418,17 @@ void App::processPeriodicTasks()
407418

408419
m_statusTimer.restart();
409420
}
421+
422+
if ((false == m_statusTimeoutTimer.isTimerRunning()) && (true == m_smpServer.isSynced()))
423+
{
424+
/* Start status timeout timer once SMP is synced the first time. */
425+
m_statusTimeoutTimer.start(STATUS_TIMEOUT_TIMER_INTERVAL);
426+
}
427+
else if (true == m_statusTimeoutTimer.isTimeout())
428+
{
429+
/* Not receiving status from RU. Go to error state. */
430+
setErrorState();
431+
}
410432
}
411433

412434
/******************************************************************************
@@ -480,3 +502,20 @@ void App_currentVehicleChannelCallback(const uint8_t* payload, const uint8_t pay
480502
CURRENT_VEHICLE_DATA_CHANNEL_DLC, payloadSize);
481503
}
482504
}
505+
506+
/**
507+
* Receives current status of the RU over SerialMuxProt channel.
508+
*
509+
* @param[in] payload Status of the RU.
510+
* @param[in] payloadSize Size of the Status Flag
511+
* @param[in] userData Instance of App class.
512+
*/
513+
void App_statusChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData)
514+
{
515+
if ((nullptr != payload) && (STATUS_CHANNEL_DLC == payloadSize) && (nullptr != userData))
516+
{
517+
const Status* currentStatus = reinterpret_cast<const Status*>(payload);
518+
App* application = reinterpret_cast<App*>(userData);
519+
application->systemStatusCallback(currentStatus->status);
520+
}
521+
}

lib/ConvoyLeader/src/App.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class App
7878
m_sendWaypointTimer(),
7979
m_commandTimer(),
8080
m_motorSpeedTimer(),
81-
m_statusTimer()
81+
m_statusTimer(),
82+
m_statusTimeoutTimer()
8283
{
8384
}
8485

@@ -111,6 +112,13 @@ class App
111112
*/
112113
void setErrorState();
113114

115+
/**
116+
* System Status callback.
117+
*
118+
* @param[in] status System status
119+
*/
120+
void systemStatusCallback(SMPChannelPayload::Status status);
121+
114122
private:
115123
/** Minimum battery level in percent. */
116124
static const uint8_t MIN_BATTERY_LEVEL = 10U;
@@ -127,6 +135,9 @@ class App
127135
/** Send status timer interval in ms. */
128136
static const uint32_t SEND_STATUS_TIMER_INTERVAL = 1000U;
129137

138+
/** Status timeout timer interval in ms. */
139+
static const uint32_t STATUS_TIMEOUT_TIMER_INTERVAL = 2U * SEND_STATUS_TIMER_INTERVAL;
140+
130141
/** MQTT topic name for birth messages. */
131142
static const char* TOPIC_NAME_BIRTH;
132143

@@ -192,6 +203,11 @@ class App
192203
*/
193204
SimpleTimer m_statusTimer;
194205

206+
/**
207+
* Timer for timeout of system status of RU.
208+
*/
209+
SimpleTimer m_statusTimeoutTimer;
210+
195211
private:
196212
/**
197213
* Handler of fatal errors in the Application.

0 commit comments

Comments
 (0)