Skip to content

Commit

Permalink
modified: src/install_coverage_dependencies.sh
Browse files Browse the repository at this point in the history
	modified:   src/tmx/TmxUtils/test/J2735MessageTest.cpp
	new file:   src/v2i-hub/RSAPlugin/CMakeLists.txt
	new file:   src/v2i-hub/RSAPlugin/manifest.json
	new file:   src/v2i-hub/RSAPlugin/src/RsaPlugin.cpp
	new file:   src/v2i-hub/RSAPlugin/src/RsaPluginWorker.cpp
	new file:   src/v2i-hub/RSAPlugin/src/include/RsaPlugin.hpp
	new file:   src/v2i-hub/RSAPlugin/src/include/RsaPluginWorker.hpp
  • Loading branch information
jwillmartin committed Jan 3, 2024
1 parent 70e798b commit 2084ae1
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/install_coverage_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ set -ex

apt update
export DEBIAN_FRONTEND=noninteractive
apt-get install -y curl zip git gcovr
apt-get install -y curl zip git gcovr
14 changes: 14 additions & 0 deletions src/tmx/TmxUtils/test/J2735MessageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,20 @@ TEST_F(J2735MessageTest, EncodePersonalSafetyMessage){
std::cout << psmENC.get_payload_str()<<std::endl;
ASSERT_EQ(32, psmENC.get_msgId());
}

// TEST_F(J2735MessageTest, EncodeRoadSideAlertMessage){
// string rsa="<RoadSideAlert><basicType><aPEDESTRIAN/></basicType><secMark>109</secMark><msgCnt>0</msgCnt><id>115eadf0</id><position><lat>389549376</lat><long>-771491840</long></position><accuracy><semiMajor>255</semiMajor><semiMinor>255</semiMinor><orientation>65535</orientation></accuracy><speed>0</speed><heading>16010</heading><pathHistory><crumbData><PathHistoryPoint><latOffset>0</latOffset><lonOffset>0</lonOffset><elevationOffset>0</elevationOffset><timeOffset>1</timeOffset></PathHistoryPoint></crumbData></pathHistory></PersonalSafetyMessage>";
// std::stringstream ss;
// PsmMessage rsamessage;
// PsmEncodedMessage rsaENC;
// tmx::message_container_type container;
// ss<<rsa;
// container.load<XML>(ss);
// rsamessage.set_contents(container.get_storage().get_tree());
// rsaENC.encode_j2735_message(rsamessage);
// std::cout << rsaENC.get_payload_str()<<std::endl;
// ASSERT_EQ(32, rsaENC.get_msgId());
// }

TEST_F(J2735MessageTest, EncodeTrafficControlRequest){
string tsm4str="<TestMessage04><body><tcrV01><reqid>C7C9A13FE6AC464E</reqid><reqseq>0</reqseq><scale>0</scale><bounds><TrafficControlBounds><oldest>27493419</oldest><reflon>-818349472</reflon><reflat>281118677</reflat><offsets><OffsetPoint><deltax>376</deltax><deltay>0</deltay></OffsetPoint><OffsetPoint><deltax>376</deltax><deltay>1320</deltay></OffsetPoint><OffsetPoint><deltax>0</deltax><deltay>1320</deltay></OffsetPoint></offsets></TrafficControlBounds></bounds></tcrV01> </body></TestMessage04>";
Expand Down
36 changes: 36 additions & 0 deletions src/v2i-hub/RSAPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PROJECT ( RsaPlugin VERSION 7.5.1 LANGUAGES CXX )

SET (TMX_PLUGIN_NAME "RSA")
add_compile_options(-fPIC)
FIND_PACKAGE (XercesC REQUIRED)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)

find_package(qserverPedestrian REQUIRED)

include_directories(${Qt5Widgets_INCLUDE_DIRS})

include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

find_library(libasn1c .)

include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
)


BuildTmxPlugin ()



TARGET_INCLUDE_DIRECTORIES ( ${PROJECT_NAME} PUBLIC ${XercesC_INCLUDE_DIRS} ${NETSNMP_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS})

TARGET_LINK_LIBRARIES ( ${PROJECT_NAME} PUBLIC tmxutils ${XercesC_LIBRARY} ${NETSNMP_LIBRARIES} ${QHttpEngine_LIBRARY} Qt5Widgets Qt5Core Qt5Network ssl crypto qhttpengine qserverPedestrian)


link_directories(${CMAKE_PREFIX_PATH}/lib)

38 changes: 38 additions & 0 deletions src/v2i-hub/RSAPlugin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name":"RSA",
"description":"Provides Roadside Alert Message (RSA).",
"version":"@PROJECT_VERSION@",
"exeLocation":"/bin/RsaPlugin",
"coreIpAddr":"127.0.0.1",
"corePort":24601,
"messageTypes":[
{
"type":"J2735",
"subtype":"RSA",
"description":"Roadside Alert Message used to send alerts for nearby hazards to travelers."
}
],
"configuration":[
{
"key":"Interval",
"default":"1000",
"description":"The interval to send the RSA, in milliseconds."
},
{
"key":"WebServiceIP",
"default":"127.0.0.1",
"description":"IP address at which the web service exists"
},
{
"key":"WebServicePort",
"default":"11000",
"description":"Port at which Web service exists"
},
{
"key":"LogLevel",
"default":"DEBUG",
"description": "RSA Plugin Log Level controls which log statements are printed to the terminal."
}

]
}
207 changes: 207 additions & 0 deletions src/v2i-hub/RSAPlugin/src/RsaPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
//==========================================================================
// Name : RsaPlugin.cpp
// Author : FHWA Saxton Transportation Operations Laboratory
// Version :
// Copyright : Copyright (c) 2019 FHWA Saxton Transportation Operations Laboratory. All rights reserved.
// Description : Rsa Plugin
//==========================================================================

#include "include/RsaPlugin.hpp"

namespace RsaPlugin
{
/**
* Construct a new RsaPlugin with the given name.
*
* @param name The name to give the plugin for identification purposes.
*/
RsaPlugin::RsaPlugin(string name): PluginClient(name)
{
// The log level can be changed from the default here.
FILELog::ReportingLevel() = FILELog::FromString("DEBUG");

// Subscribe to all messages specified by the filters above.
SubscribeToMessages();
}

void RsaPlugin::RsaRequestHandler(QHttpEngine::Socket *socket)
{
auto router = QSharedPointer<OpenAPI::OAIApiRouter>::create();
QString st;
while(socket->bytesAvailable()>0)
{
st.append(socket->readAll());
}
QByteArray array = st.toLocal8Bit();

char* rsaMsgdef = array.data();
// Catch parse exceptions
try {
BroadcastRsa(rsaMsgdef);
writeResponse(QHttpEngine::Socket::Created, socket);
}
catch(const J2735Exception &e) {
PLOG(logERROR) << "Error parsing file: " << e.what() << std::endl;
writeResponse(QHttpEngine::Socket::BadRequest, socket);
}
}


int RsaPlugin::StartWebService()
{
//Web services
char *placeholderX[1]={0};
int placeholderC=1;
QCoreApplication a(placeholderC,placeholderX);

QHostAddress address = QHostAddress(QString::fromStdString (webip));
quint16 port = static_cast<quint16>(webport);


QSharedPointer<OpenAPI::OAIApiRequestHandler> handler(new OpenAPI::OAIApiRequestHandler());
handler = QSharedPointer<OpenAPI::OAIApiRequestHandler> (new OpenAPI::OAIApiRequestHandler());

QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) {

this->RsaRequestHandler(socket);
});

QHttpEngine::Server server(handler.data());

if (!server.listen(address, port)) {
qCritical("Unable to listen on the specified port.");
return 1;
}
return a.exec();

}

RsaPlugin::~RsaPlugin()
{
if (_signSimClient != NULL)
delete _signSimClient;
}

void RsaPlugin::UpdateConfigSettings()
{
// Configuration settings are retrieved from the API using the GetConfigValue template class.
// This method does NOT execute in the main thread, so variables must be protected
// (e.g. using std::atomic, std::mutex, etc.).

int instance;
std::lock_guard<mutex> lock(_cfgLock);

GetConfigValue<string>("WebServiceIP",webip);
GetConfigValue<uint16_t>("WebServicePort",webport);
GetConfigValue<int>("Instance", instance);

std::thread webthread(&RsaPlugin::StartWebService,this);
webthread.detach(); // wait for the thread to finish
}

void RsaPlugin::OnConfigChanged(const char *key, const char *value)
{
PluginClient::OnConfigChanged(key, value);
UpdateConfigSettings();
}

void RsaPlugin::OnStateChange(IvpPluginState state)
{
PluginClient::OnStateChange(state);

if (state == IvpPluginState_registered)
{
UpdateConfigSettings();
}
}


void RsaPlugin::BroadcastRsa(char * rsaJson)
{ //overloaded

RsaMessage rsamessage;
RsaEncodedMessage rsaENC;
tmx::message_container_type container;
std::unique_ptr<RsaEncodedMessage> msg;

try
{
std::stringstream ss;
ss << rsaJson;

container.load<XML>(ss);
rsamessage.set_contents(container.get_storage().get_tree());

const std::string rsaString(rsaJson);

rsaENC.encode_j2735_message(rsamessage);

msg.reset();
msg.reset(dynamic_cast<RsaEncodedMessage*>(factory.NewMessage(api::MSGSUBTYPE_ROADSIDEALERT_STRING)));

string enc = rsaENC.get_encoding();
msg->refresh_timestamp();
msg->set_payload(rsaENC.get_payload_str());
msg->set_encoding(enc);
msg->set_flags(IvpMsgFlags_RouteDSRC);
msg->addDsrcMetadata(0x8003);
msg->refresh_timestamp();

routeable_message *rMsg = dynamic_cast<routeable_message *>(msg.get());
BroadcastMessage(*rMsg);

PLOG(logINFO) << " RSA Plugin :: Broadcast RSA:: " << rsaENC.get_payload_str();
}
catch(const std::exception& e)
{
PLOG(logWARNING) << "Error: " << e.what() << " broadcasting RSA for xml: " << rsaJson << std::endl;
}



}

/**
* Write HTTP response.
*/
void RsaPlugin::writeResponse(int responseCode , QHttpEngine::Socket *socket) {
socket->setStatusCode(responseCode);
socket->writeHeaders();
if(socket->isOpen()){
socket->close();
}

}


int RsaPlugin::Main()
{
PLOG(logINFO) << "Starting plugin.";

uint msCount = 0;
while (_plugin->state != IvpPluginState_error)
{

msCount += 10;

if (_plugin->state == IvpPluginState_registered)
{
RoadSideAlert rsa_1;
RoadSideAlert &rsa = rsa_1;

this_thread::sleep_for(chrono::milliseconds(100));

msCount = 0;
}
}

PLOG(logINFO) << "Plugin terminating gracefully.";
return EXIT_SUCCESS;
}

} /* namespace RsaPlugin */

int main(int argc, char *argv[])
{
return run_plugin<RsaPlugin::RsaPlugin>("RsaPlugin", argc, argv);
}
15 changes: 15 additions & 0 deletions src/v2i-hub/RSAPlugin/src/RsaPluginWorker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//==========================================================================
// Name : RsaPlugin.cpp
// Author : FHWA Saxton Transportation Operations Laboratory
// Version :
// Copyright : Copyright (c) 2023 FHWA Saxton Transportation Operations Laboratory. All rights reserved.
// Description : RSA Plugin
//==========================================================================

#include "include/RsaPluginWorker.hpp"

using namespace std;

namespace RsaPlugin {

};
Loading

0 comments on commit 2084ae1

Please sign in to comment.