Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jul 8, 2024
1 parent 54dfc3a commit 47256d8
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/tmx/TmxUtils/src/PluginClientClockAware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace tmx::utils {


void PluginClientClockAware::HandleTimeSyncMessage(tmx::messages::TimeSyncMessage &msg, routeable_message &routeableMsg ) {
PLOG(logDEBUG) << "Message Received " << msg.to_string() << std::endl;
this->getClock()->update( msg.get_timestep() );
if (sim::is_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()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tmx/TmxUtils/test/J2735MessageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ TEST_F(J2735MessageTest, EncodeSDSM)
tmx::messages::SdsmEncodedMessage SdsmEncodeMessage;
auto _sdsmMessage = new tmx::messages::SdsmMessage(message);
tmx::messages::MessageFrameMessage frame_msg(_sdsmMessage->get_j2735_data());
SdsmEncodeMessage.set_data(TmxJ2735EncodedMessage<SignalRequestMessage>::encode_j2735_message<codec::uper<MessageFrameMessage>>(frame_msg));
SdsmEncodeMessage.set_data(TmxJ2735EncodedMessage<SdsmMessage>::encode_j2735_message<codec::uper<MessageFrameMessage>>(frame_msg));
free(message);
free(frame_msg.get_j2735_data().get());
ASSERT_EQ(41, SdsmEncodeMessage.get_msgId());
Expand Down
5 changes: 5 additions & 0 deletions src/v2i-hub/SpatPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"default":"<snmp port used in signal controller>",
"description":"The destination port on the Traffic Signal Controller (TSC) for SNMP NTCIP communication."
},
{
"key":"SPAT_Mode",
"default":"BINARY",
"description":"The format of received SPAT from Traffic Signal Controller (TSC). Acceptance values are BINARY and J2735_HEX."
},
{
"key":"LogLevel",
"default":"INFO",
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/SpatPlugin/src/NTCIP1202.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Ntcip1202::printDebug()
for(int i=0; i<16; i++)
{
int phaseNum = i+1;
PLOG(logDEBUG3) << "Phase " << phaseNum <<
PLOG(logDEBUG) << "Phase " << phaseNum <<
", Green " << getPhaseGreensStatus(phaseNum) <<
", Yellow " << getPhaseYellowStatus(phaseNum) <<
", Red " << getPhaseRedStatus(phaseNum) <<
Expand Down
35 changes: 22 additions & 13 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,38 @@ namespace SpatPlugin {
resp.val_int = 2;
return scSNMPClient->process_snmp_request("1.3.6.1.4.1.1206.3.5.2.9.44.1.0", tmx::utils::request_type::SET, resp);
};
tmx::messages::SpatEncodedMessage SignalControllerConnection::receiveSPAT(uint64_t timeMs, const SPAT_MODE &spatMode)
tmx::messages::SpatEncodedMessage SignalControllerConnection::receiveSPAT(SPAT *spat, uint64_t timeMs, const SPAT_MODE &spatMode)
{
if ( spatMode == SPAT_MODE::BINARY ) {
FILE_LOG(tmx::utils::logDEBUG) << "Receiving binary SPAT..." << std::endl;
FILE_LOG(tmx::utils::logDEBUG) << "Receiving binary SPAT ..." << std::endl;
char buf[1000];
auto numBytes = spatPacketReceiver->TimedReceive(buf, 1000, 1000);
auto ntcip1202 = std::make_unique<Ntcip1202>();

ntcip1202->setSignalGroupMappingList(this->signalGroupMapping);

if ( numBytes > 0 ) {
// TODO: Revist this implementation. See if we can make SPAT a shared pointer
// and skipe the SPAT to SpatMessage conversion.
FILE_LOG(tmx::utils::logDEBUG) << "Decoding binary SPAT from " << numBytes << " bytes ..." << std::endl;
ntcip1202->copyBytesIntoNtcip1202(buf, numBytes);
SPAT *_spat = (SPAT *) calloc(1, sizeof(SPAT));
if ( tmx::utils::FILELog::ReportingLevel() == tmx::utils::logDEBUG) {
xer_fprint(stdout, &asn_DEF_SPAT, _spat);
FILE_LOG(tmx::utils::logDEBUG) << "Read SPAT Bytes ..." << std::endl;


ntcip1202->ToJ2735SPAT(spat,timeMs, intersectionName, intersectionId);
FILE_LOG(tmx::utils::logDEBUG) << "Copied into SPAT object ..." << std::endl;
if ( tmx::utils::FILELog::ReportingLevel() >= tmx::utils::logDEBUG) {
xer_fprint(stdout, &asn_DEF_SPAT, spat);
}
ntcip1202->ToJ2735SPAT(_spat,timeMs, intersectionName, intersectionId);
auto _spatMessage = std::make_unique<tmx::messages::SpatMessage>(_spat);
tmx::messages::MessageFrameMessage frame(_spatMessage->get_j2735_data());
tmx::messages::SpatMessage _spatMessage(spat);
tmx::messages::SpatEncodedMessage spatEncodedMsg;
spatEncodedMsg.set_data(tmx::messages::TmxJ2735EncodedMessage<SPAT>::encode_j2735_message<tmx::messages::codec::uper<tmx::messages::MessageFrameMessage>>(frame));
//Free the memory allocated for MessageFrame
free(_spat);
spatEncodedMsg.initialize(_spatMessage);
// tmx::messages::MessageFrameMessage frame(_spatMessage.get_j2735_data());
// FILE_LOG(tmx::utils::logDEBUG) << "Copied into SPAT Message Frame..." << std::endl;
// spatEncodedMsg.set_data(tmx::messages::TmxJ2735EncodedMessage<SPAT>::encode_j2735_message<tmx::messages::codec::uper<tmx::messages::MessageFrameMessage>>(frame));
FILE_LOG(tmx::utils::logDEBUG) << "Copied into encoded SPAT Message" << std::endl;
return spatEncodedMsg;
}else {
}
else {
throw std::runtime_error("Something went wrong");
}
}
Expand All @@ -47,6 +54,8 @@ namespace SpatPlugin {

if ( numBytes > 0 ) {
spatEncodedMsg.set_payload_bytes(buf);
xer_fprint(stdout, &asn_DEF_SPAT, spatEncodedMsg.decode_j2735_message().get_j2735_data().get());

return spatEncodedMsg;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/SpatPlugin/src/SignalControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace SpatPlugin {
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);
bool initializeSignalControllerConnection();
tmx::messages::SpatEncodedMessage receiveSPAT(uint64_t timeMs , const SPAT_MODE &spat_mode = SPAT_MODE::BINARY);
tmx::messages::SpatEncodedMessage receiveSPAT(SPAT *spat, uint64_t timeMs , const SPAT_MODE &spat_mode = SPAT_MODE::BINARY);

};
}
31 changes: 25 additions & 6 deletions src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace SpatPlugin {
unsigned int scSNMPPort;
std::string intersectionName;
unsigned int intersectionId;
GetConfigValue<string>("SignalGroupMapping", signalGroupMappingJson, &data_lock);
GetConfigValue<std::string>("SignalGroupMapping", signalGroupMappingJson, &data_lock);
GetConfigValue<std::string>("Local_IP", ip_address, &data_lock);
GetConfigValue<unsigned int>("Local_UDP_Port", port, &data_lock);
GetConfigValue<string>("TSC_IP", scIp, &data_lock);
GetConfigValue<std::string>("TSC_IP", scIp, &data_lock);
GetConfigValue<unsigned int>("TSC_Remote_SNMP_Port", scSNMPPort,&data_lock);
GetConfigValue<string>("Intersection_Name", intersectionName,&data_lock);
GetConfigValue<std::string>("Intersection_Name", intersectionName,&data_lock);
GetConfigValue<unsigned int>("Intersection_Id", intersectionId, &data_lock);
GetConfigValue<std::string>("SPAT_Mode", spatMode, &data_lock);

if (scConnection) {
scConnection.reset(new SignalControllerConnection(ip_address, port, signalGroupMappingJson, scIp, scSNMPPort, intersectionName, intersectionId));
}
Expand All @@ -51,6 +53,7 @@ namespace SpatPlugin {
this->processSpat();
}, // end of lambda expression
std::chrono::milliseconds(5));
PluginClientClockAware::getClock()->wait_for_initialization();
spatReceiverThread->Start();
}
else {
Expand All @@ -62,12 +65,28 @@ namespace SpatPlugin {
void SpatPlugin::processSpat() {
if (this->scConnection ) {
PLOG(tmx::utils::logDEBUG) << "Processing SPAT ... " << std::endl;
auto spatMessage = scConnection->receiveSPAT(PluginClientClockAware::getClock()->nowInMilliseconds());
SPAT_MODE mode;
if (spatMode == "BINARY")
{
mode = SPAT_MODE::BINARY;
}
else if (spatMode == "J2735_HEX") {
mode = SPAT_MODE::J2735_HEX;
}
else {
PLOG(tmx::utils::logWARNING) << "SPAT Mode " << spatMode << " is unrecognized. Defaulting to BINARY." << std::endl;
}
// auto spat_ptr = std::make_shared<SPAT>();
SPAT *spat_ptr = (SPAT *) calloc(1, sizeof(SPAT));
auto spatMessage = scConnection->receiveSPAT(spat_ptr, PluginClientClockAware::getClock()->nowInMilliseconds(), mode);

spatMessage.set_flags(IvpMsgFlags_RouteDSRC);
spatMessage.addDsrcMetadata(0x8002);
spatMessage.addDsrcMetadata(tmx::messages::api::msgPSID::signalPhaseAndTimingMessage_PSID);

BroadcastMessage(static_cast<routeable_message &>(spatMessage));
SetStatus(keyConnectionStatus, "CONNECTED");
PLOG(tmx::utils::logDEBUG) << "Broadcasting SPAT" << std::endl;

SetStatus(keyConnectionStatus, "CONNECTED");
}
}
void SpatPlugin::OnConfigChanged(const char *key, const char *value) {
Expand Down
2 changes: 2 additions & 0 deletions src/v2i-hub/SpatPlugin/src/SpatPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SpatPlugin: public tmx::utils::PluginClientClockAware {

std::unique_ptr<SignalControllerConnection> scConnection;

std::string spatMode = "";

const char* keyConnectionStatus = "Connection Status";


Expand Down

0 comments on commit 47256d8

Please sign in to comment.