Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jul 9, 2024
1 parent 47256d8 commit 1173dbb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/v2i-hub/SpatPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
PROJECT ( SpatPlugin VERSION 7.6.0 LANGUAGES CXX )
project( SpatPlugin VERSION 7.6.0 LANGUAGES CXX )

SET (TMX_PLUGIN_NAME "SPAT")
set(TMX_PLUGIN_NAME "SPAT")
set(CMAKE_CXX_STANDARD 17)

FIND_PACKAGE (carma-clock REQUIRED)
find_package(carma-clock REQUIRED)

BuildTmxPlugin ()
BuildTmxPlugin()

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



Expand Down
33 changes: 21 additions & 12 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ namespace SpatPlugin {
// and skipe the SPAT to SpatMessage conversion.
FILE_LOG(tmx::utils::logDEBUG) << "Decoding binary SPAT from " << numBytes << " bytes ..." << std::endl;
ntcip1202->copyBytesIntoNtcip1202(buf, numBytes);
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;
FILE_LOG(tmx::utils::logDEBUG) << "Sending SPAT ..." << std::endl;
if ( tmx::utils::FILELog::ReportingLevel() >= tmx::utils::logDEBUG) {
xer_fprint(stdout, &asn_DEF_SPAT, spat);
}
tmx::messages::SpatMessage _spatMessage(spat);
tmx::messages::SpatEncodedMessage spatEncodedMsg;
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 {
Expand All @@ -49,14 +44,28 @@ namespace SpatPlugin {
FILE_LOG(tmx::utils::logDEBUG) << "Receiving J2725 HEX SPAT ..." << std::endl;

tmx::messages::SpatEncodedMessage spatEncodedMsg;
tmx::byte_stream buf(4000);
int numBytes = spatPacketReceiver->TimedReceive((char *)buf.data(), buf.size(), 3);
auto payload = spatPacketReceiver->stringTimedReceive( 1000 );
auto index = payload.find("Payload=");
FILE_LOG(tmx::utils::logDEBUG) << "Found Payload at index " << index << std::endl;

if ( numBytes > 0 ) {
spatEncodedMsg.set_payload_bytes(buf);
xer_fprint(stdout, &asn_DEF_SPAT, spatEncodedMsg.decode_j2735_message().get_j2735_data().get());
if ( index != std::string::npos ) {
auto hex = payload.substr(index + 8);
hex.erase(std::remove(hex.begin(), hex.end(), '\n'), hex.end());
hex.erase(std::remove(hex.begin(), hex.end(), ' '), hex.end());

return spatEncodedMsg;
FILE_LOG(tmx::utils::logDEBUG) << "Reading HEX String " << hex << std::endl;
tmx::byte_stream bytes = tmx::byte_stream_decode(hex);

FILE_LOG(tmx::utils::logDEBUG) << "Reading Bytes " << tmx::byte_stream_encode(bytes) ;
tmx::messages::J2735MessageFactory myFactory;
auto spatEncodedMsg = dynamic_cast<tmx::messages::SpatEncodedMessage*>(myFactory.NewMessage(bytes));
if (tmx::utils::FILELog::ReportingLevel() >= tmx::utils::logDEBUG)
{
xer_fprint(stdout, &asn_DEF_SPAT, spatEncodedMsg->decode_j2735_message().get_j2735_data().get());
PLOG(tmx::utils::logDEBUG) << "Message is "<< spatEncodedMsg->get_payload_str();
}

return *spatEncodedMsg;
}
else {
throw std::runtime_error("Something went wrong");
Expand Down
2 changes: 2 additions & 0 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <tmx/j2735_messages/SpatMessage.hpp>
#include "NTCIP1202.h"
#include <PluginLog.h>
#include <tmx/messages/byte_stream.hpp>
#include <tmx/j2735_messages/J2735MessageFactory.hpp>

namespace SpatPlugin {
enum class SPAT_MODE
Expand Down
1 change: 0 additions & 1 deletion src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ namespace SpatPlugin {
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);

Expand Down

0 comments on commit 1173dbb

Please sign in to comment.