diff --git a/src/tmx/TmxUtils/src/PluginClientClockAware.cpp b/src/tmx/TmxUtils/src/PluginClientClockAware.cpp index a3dae0c2f..9c770f24d 100644 --- a/src/tmx/TmxUtils/src/PluginClientClockAware.cpp +++ b/src/tmx/TmxUtils/src/PluginClientClockAware.cpp @@ -14,14 +14,13 @@ namespace tmx::utils { clock = std::make_shared(_simulation_mode); if (_simulation_mode) { AddMessageFilter(this, &PluginClientClockAware::HandleTimeSyncMessage); - } } void PluginClientClockAware::HandleTimeSyncMessage(tmx::messages::TimeSyncMessage &msg, routeable_message &routeableMsg ) { - if (sim::is_simulation_mode() ) { + if (_simulation_mode ) { PLOG(logDEBUG) << "Message Received " << msg.to_string() << std::endl; this->getClock()->update( msg.get_timestep() ); SetStatus(Key_Simulation_Time_Step, Clock::ToUtcPreciseTimeString(msg.get_timestep())); diff --git a/src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp b/src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp index a25b8194b..2514b3923 100644 --- a/src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp +++ b/src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp @@ -24,7 +24,8 @@ namespace SpatPlugin { SpatPlugin::SpatPlugin(const std::string &name) :PluginClientClockAware(name) { spatReceiverThread = std::make_unique(std::chrono::milliseconds(5)); - if ( PluginClientClockAware::isSimulationMode() ) { + if (PluginClientClockAware::isSimulationMode()) { + PLOG(logDEBUG1) << "Subscribing to TimeSyncMessages ... " ; SubscribeToMessages(); } } @@ -64,6 +65,10 @@ namespace SpatPlugin { try { spatReceiverThread->AddPeriodicTick([this]() { + // Ensure Clock has received its first update + if (PluginClientClockAware::isSimulationMode()) { + PluginClientClockAware::getClock()->wait_for_initialization(); + } this->processSpat(); if (!this->isConnected) { SetStatus(keyConnectionStatus, "CONNECTED"); @@ -72,7 +77,7 @@ namespace SpatPlugin { }, // end of lambda expression std::chrono::milliseconds(5) ); - PluginClientClockAware::getClock()->wait_for_initialization(); + spatReceiverThread->Start(); } catch (const TmxException &e) { @@ -110,6 +115,7 @@ namespace SpatPlugin { PLOG(tmx::utils::logWARNING) << spatMode << " is an unsupport SPAT MODE. Defaulting to BINARY. Supported options are BINARY and J2735_HEX"; } auto spat_ptr = std::make_shared(); + PLOG(logDEBUG) << "Starting SPaT Receiver ..."; scConnection->receiveBinarySPAT(spat_ptr, PluginClientClockAware::getClock()->nowInMilliseconds()); tmx::messages::SpatMessage _spatMessage(spat_ptr); auto spatEncoded_ptr = std::make_shared(); @@ -133,7 +139,7 @@ namespace SpatPlugin { } } void SpatPlugin::OnConfigChanged(const char *key, const char *value) { - PluginClientClockAware::OnConfigChanged(key, value); + PluginClient::OnConfigChanged(key, value); UpdateConfigSettings(); }