@@ -178,7 +178,7 @@ void App::loop()
178178 /* Process SerialMuxProt. */
179179 m_smpServer.process (millis ());
180180
181- if (false == m_initialDataSent)
181+ if (( false == m_initialDataSent) && ( true == m_smpServer. isSynced ()) )
182182 {
183183 SettingsHandler& settings = SettingsHandler::getInstance ();
184184 Command cmd = {SMPChannelPayload::CMD_ID_SET_INIT_POS, settings.getInitialXPosition (),
@@ -189,6 +189,10 @@ void App::loop()
189189 LOG_DEBUG (" Initial vehicle data sent." );
190190 m_initialDataSent = true ;
191191 }
192+ else
193+ {
194+ LOG_WARNING (" Failed to send initial vehicle data." );
195+ }
192196 }
193197
194198 if ((true == m_statusTimer.isTimeout ()) && (true == m_smpServer.isSynced ()))
@@ -231,14 +235,16 @@ bool App::setupSerialMuxProtServer()
231235 m_serialMuxProtChannelIdRemoteCtrl = m_smpServer.createChannel (COMMAND_CHANNEL_NAME, COMMAND_CHANNEL_DLC);
232236 m_serialMuxProtChannelIdMotorSpeeds =
233237 m_smpServer.createChannel (MOTOR_SPEED_SETPOINT_CHANNEL_NAME, MOTOR_SPEED_SETPOINT_CHANNEL_DLC);
238+ m_serialMuxProtChannelIdRobotSpeeds =
239+ m_smpServer.createChannel (ROBOT_SPEED_SETPOINT_CHANNEL_NAME, ROBOT_SPEED_SETPOINT_CHANNEL_DLC);
234240 m_serialMuxProtChannelIdStatus = m_smpServer.createChannel (STATUS_CHANNEL_NAME, STATUS_CHANNEL_DLC);
235241
236242 m_smpServer.subscribeToChannel (COMMAND_RESPONSE_CHANNEL_NAME, App_cmdRspChannelCallback);
237243 m_smpServer.subscribeToChannel (LINE_SENSOR_CHANNEL_NAME, App_lineSensorChannelCallback);
238244 m_smpServer.subscribeToChannel (CURRENT_VEHICLE_DATA_CHANNEL_NAME, App_currentVehicleChannelCallback);
239245
240246 if ((0U == m_serialMuxProtChannelIdRemoteCtrl) || (0U == m_serialMuxProtChannelIdMotorSpeeds) ||
241- (0U == m_serialMuxProtChannelIdStatus))
247+ (0U == m_serialMuxProtChannelIdRobotSpeeds) || ( 0U == m_serialMuxProtChannelIdStatus))
242248 {
243249 LOG_ERROR (" Failed to create SerialMuxProt channels." );
244250 }
@@ -278,13 +284,13 @@ bool App::setupMqtt(const String& clientId, const String& brokerAddr, uint16_t b
278284 else if (false == m_mqttClient.subscribe (TOPIC_NAME_CMD, true ,
279285 [this ](const String& payload) { cmdTopicCallback (payload); }))
280286 {
281- LOG_FATAL (" Could not subcribe to MQTT topic: %s." , TOPIC_NAME_CMD);
287+ LOG_FATAL (" Could not subscribe to MQTT topic: %s." , TOPIC_NAME_CMD);
282288 }
283289 /* Subscribe to Motor Speeds Topic. */
284290 else if (false == m_mqttClient.subscribe (TOPIC_NAME_MOTOR_SPEEDS, true ,
285291 [this ](const String& payload) { motorSpeedsTopicCallback (payload); }))
286292 {
287- LOG_FATAL (" Could not subcribe to MQTT topic: %s." , TOPIC_NAME_MOTOR_SPEEDS);
293+ LOG_FATAL (" Could not subscribe to MQTT topic: %s." , TOPIC_NAME_MOTOR_SPEEDS);
288294 }
289295 else
290296 {
@@ -341,10 +347,25 @@ void App::cmdTopicCallback(const String& payload)
341347 break ;
342348
343349 case 6U :
344- cmd.commandId = SMPChannelPayload::CmdId::CMD_ID_SET_INIT_POS;
345- LOG_WARNING (" Setting initial position is not supported." );
346- isValid = false ;
350+ {
351+ JsonVariantConst xPos = jsonPayload[" X" ];
352+ JsonVariantConst yPos = jsonPayload[" Y" ];
353+ JsonVariantConst heading = jsonPayload[" HEADING" ];
354+
355+ if (xPos.isNull () || yPos.isNull () || heading.isNull ())
356+ {
357+ LOG_WARNING (" CMD_ID_SET_INIT_POS requires X, Y and HEADING fields." );
358+ isValid = false ;
359+ }
360+ else
361+ {
362+ cmd.commandId = SMPChannelPayload::CmdId::CMD_ID_SET_INIT_POS;
363+ cmd.xPos = xPos.as <int32_t >();
364+ cmd.yPos = yPos.as <int32_t >();
365+ cmd.orientation = heading.as <int32_t >();
366+ }
347367 break ;
368+ }
348369
349370 default :
350371 isValid = false ;
0 commit comments