Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jul 17, 2024
1 parent a5b11e0 commit 58130d0
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/v2i-hub/SpatPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ find_package(carma-clock REQUIRED)

BuildTmxPlugin()

target_link_libraries(${PROJECT_NAME} tmxutils ::carma-clock jsoncpp)
target_link_libraries(${PROJECT_NAME} tmxutils ::carma-clock)



Expand Down
9 changes: 6 additions & 3 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ namespace SpatPlugin {
FILE_LOG(tmx::utils::logDEBUG) << "Receiving binary SPAT ..." << std::endl;
char buf[1000];
auto numBytes = spatPacketReceiver->TimedReceive(buf, 1000, 1000);

if ( numBytes > 0 ) {
if (numBytes > 0)
{
// Convert Binary buffer to SPAT pointer
Ntcip1202 ntcip1202;
ntcip1202.setSignalGroupMappingList(this->signalGroupMapping);
ntcip1202.copyBytesIntoNtcip1202(buf, numBytes);
ntcip1202.ToJ2735SPAT(spat.get(),timeMs, intersectionName, intersectionId);

if (tmx::utils::FILELog::ReportingLevel() >= tmx::utils::logDEBUG)
{
xer_fprint(stdout, &asn_DEF_SPAT, spat.get());
}
}
else {
throw tmx::utils::UdpServerRuntimeError("UDP Server error occured or socket time out.");
Expand Down
7 changes: 1 addition & 6 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
#include <gtest/gtest_prod.h>



namespace SpatPlugin {
enum class SPAT_MODE
{
J2735_HEX,
BINARY
};

class SignalControllerConnection
{
Expand All @@ -30,7 +26,6 @@ namespace SpatPlugin {
std::string intersectionName;
unsigned int intersectionId;
friend class TestSignalControllerConnection;
FRIEND_TEST(TestSignalControllerConnection, initialize);

public:
SignalControllerConnection(const std::string &localIp, unsigned int localPort, const std::string &signalGroupMapping, const std::string &scIp, unsigned int scSNMPPort, const std::string &intersectionName, unsigned int intersectionID);
Expand Down
36 changes: 20 additions & 16 deletions src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace SpatPlugin {

SpatPlugin::SpatPlugin(const std::string &name) :PluginClientClockAware(name) {
spatReceiverThread = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));

if ( PluginClientClockAware::isSimulationMode() ) {
SubscribeToMessages();
}
Expand Down Expand Up @@ -82,18 +81,8 @@ namespace SpatPlugin {
if (this->scConnection ) {
PLOG(tmx::utils::logDEBUG) << "Processing SPAT ... " << std::endl;
try {
if (spatMode == "BINARY")
{
auto spat_ptr = std::make_shared<SPAT>();
scConnection->receiveBinarySPAT(spat_ptr, PluginClientClockAware::getClock()->nowInMilliseconds());
tmx::messages::SpatMessage _spatMessage(spat_ptr);
auto spatEncoded_ptr = std::make_shared<tmx::messages::SpatEncodedMessage>();
spatEncoded_ptr->initialize(_spatMessage,"", 0U, IvpMsgFlags_RouteDSRC);
spatEncoded_ptr->addDsrcMetadata(tmx::messages::api::msgPSID::signalPhaseAndTimingMessage_PSID);
auto rMsg = dynamic_cast<routeable_message*>(spatEncoded_ptr.get());
BroadcastMessage(*rMsg);
}
else if (spatMode == "J2735_HEX") {

if (spatMode == "J2735_HEX") {
auto spatEncoded_ptr = std::make_shared<tmx::messages::SpatEncodedMessage>();
scConnection->receiveUPERSPAT(spatEncoded_ptr);
spatEncoded_ptr->set_flags(IvpMsgFlags_RouteDSRC);
Expand All @@ -102,15 +91,30 @@ namespace SpatPlugin {
BroadcastMessage(*rMsg);
}
else {
throw TmxException("SPAT Mode " + spatMode + " is not supported. Support SPAT Modes are J2735_HEX and BINARY.");
if ( spatMode != "BINARY"){
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<SPAT>();
scConnection->receiveBinarySPAT(spat_ptr, PluginClientClockAware::getClock()->nowInMilliseconds());
tmx::messages::SpatMessage _spatMessage(spat_ptr);
auto spatEncoded_ptr = std::make_shared<tmx::messages::SpatEncodedMessage>();
spatEncoded_ptr->initialize(_spatMessage,"", 0U, IvpMsgFlags_RouteDSRC);
spatEncoded_ptr->addDsrcMetadata(tmx::messages::api::msgPSID::signalPhaseAndTimingMessage_PSID);
auto rMsg = dynamic_cast<routeable_message*>(spatEncoded_ptr.get());
BroadcastMessage(*rMsg);
}
}
catch (const tmx::J2735Exception &e) {
PLOG(tmx::utils::logERROR) << "Encountered J2735 Exception " << e.what() << " attempting to process SPAT." << std::endl
catch (const UdpServerRuntimeError &e) {
PLOG(tmx::utils::logWARNING) << "Encountered UDP Server Runtime Error" << e.what() << " attempting to process SPAT." << std::endl
<< e.GetBacktrace();
}
catch (const tmx::TmxException &e) {
PLOG(tmx::utils::logERROR) << "Encountered Tmx Exception " << e.what() << " attempting to process SPAT." << std::endl
<< e.GetBacktrace();
skippedMessages++;
SetStatus<uint>(keySkippedMessages, skippedMessages);
}

}
}
void SpatPlugin::OnConfigChanged(const char *key, const char *value) {
Expand Down
1 change: 0 additions & 1 deletion src/v2i-hub/SpatPlugin/test/TestNTCIP1202.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ TEST(NTCIP1202Test, copyBytesIntoNtcip1202)

SPAT *spat_ptr = (SPAT *)calloc(1, sizeof(SPAT));
ntcip1202_p->ToJ2735SPAT(spat_ptr,tsMsec, "test intersection name", 9012);
xer_fprint(stdout, &asn_DEF_SPAT, spat_ptr);

ASSERT_EQ(3, spat_ptr->intersections.list.array[0]->states.list.array[0]->state_time_speed.list.array[0]->eventState);

Expand Down
Loading

0 comments on commit 58130d0

Please sign in to comment.