Skip to content

Commit

Permalink
Merge branch 'develop' into j2735-2020-upgrade
Browse files Browse the repository at this point in the history
 Conflicts:
	src/tmx/TmxApi/tmx/TmxApiMessages.h
	src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp
	src/v2i-hub/ImmediateForwardPlugin/manifest.json

 Changes to be committed:
	modified:   .github/workflows/sonar-scanner.yml
	modified:   src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp
	modified:   src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp
	modified:   src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.h
	modified:   src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp
	modified:   src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
	modified:   src/v2i-hub/ImmediateForwardPlugin/manifest.json
	modified:   src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp
	modified:   src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp
  • Loading branch information
jwillmartin committed Feb 16, 2024
2 parents 72c6f8d + 623713b commit d80c613
Show file tree
Hide file tree
Showing 9 changed files with 960 additions and 445 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar-scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fetch-depth: 0
submodules: recursive
- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarcloud-github-c-cpp@v1
uses: sonarsource/sonarcloud-github-c-cpp@v2
- name: Run install_dependencies.sh script
run: |
scripts/install_dependencies.sh
Expand Down
24 changes: 14 additions & 10 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,23 +685,19 @@ void CARMAStreetsPlugin::SubscribeSDSMKafkaTopic(){
{
sdsm_convertor.encodeSDSM(sdsm_ptr, sdsmEncodedMsg);
}
catch (TmxException &ex)
catch( std::exception const & x )
{
// Skip messages that fail to encode.
PLOG(logERROR) << "Failed to encoded SDSM message : \n" << payload_str << std::endl << "Exception encountered: "
<< ex.what() << std::endl;
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SensorDataSharingMessage, sdsm_ptr.get()); // may be unnecessary
PLOG(logERROR) << "Failed to encoded SDSM message : " << payload_str << std::endl << boost::diagnostic_information( x ) << std::endl;
SetStatus<uint>(Key_SDSMMessageSkipped, ++_sdsmMessageSkipped);
continue;
}

ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SensorDataSharingMessage, sdsm_ptr.get()); // same as above
PLOG(logDEBUG) << "sdsmEncodedMsg: " << sdsmEncodedMsg;

//Broadcast the encoded SDSM message
sdsmEncodedMsg.set_flags(IvpMsgFlags_RouteDSRC);
sdsmEncodedMsg.addDsrcMetadata(0x8002);
BroadcastMessage(static_cast<routeable_message &>(sdsmEncodedMsg));
sdsmEncodedMsg.addDsrcMetadata(tmx::messages::api::msgPSID::sensorDataSharingMessage_PSID);
BroadcastMessage(static_cast<routeable_message &>(sdsmEncodedMsg));

}
}
}
Expand All @@ -710,8 +706,16 @@ void CARMAStreetsPlugin::SubscribeSDSMKafkaTopic(){

void CARMAStreetsPlugin::HandleSimulatedSensorDetectedMessage(simulation::SensorDetectedObject &msg, routeable_message &routeableMsg)
{
// TODO: This is a temporary fix for tmx message container property tree
// serializing all attributes as strings. This issue needs to be fixed but
// is currently out of scope. TMX Messages should be correctly serialize to
// and from json. This temporary fix simply using regex to look for numeric,
// null, and bool values and removes the quotations around them.
PLOG(logDEBUG) << "Produce sensor detected message in JSON format: " << msg.to_string() <<std::endl;
produce_kafka_msg( msg.to_string(), _transmitSimSensorDetectedObjTopic);
boost::regex exp("\"(null|true|false|-?[0-9]+(\\.[0-9]+)?)\"");
std::stringstream ss;
std::string rv = boost::regex_replace(msg.to_string(), exp, "$1");
produce_kafka_msg( rv, _transmitSimSensorDetectedObjTopic);
}

bool CARMAStreetsPlugin::getEncodedtsm3( tsm3EncodedMessage *tsm3EncodedMsg, Json::Value metadata, Json::Value payload_json )
Expand Down
624 changes: 309 additions & 315 deletions src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ namespace CARMAStreetsPlugin
* @param json Incoming Json value with sdsm information that is consumed from a Kafka topic.
* @param sdsm Outgoing J3224 sdsm object that is populated by the json value.
*/
void convertJsonToSDSM(const Json::Value &sdsm_json, std::shared_ptr<SensorDataSharingMessage> sdsm) const;

void convertJsonToSDSM(const Json::Value &sdsm_json, const std::shared_ptr<SensorDataSharingMessage_t> &sdsm) const;

/***
* @brief Encode J3224 SDSM
* @param Pointer to J3224 SDSM object
* @param Encoded J3224 SDSM
*/
void encodeSDSM(const std::shared_ptr<SensorDataSharingMessage> &sdsmPtr, tmx::messages::SdsmEncodedMessage &encodedSDSM) const;

void encodeSDSM(const std::shared_ptr<SensorDataSharingMessage_t> &sdsmPtr, tmx::messages::SdsmEncodedMessage &encodedSDSM) const;
~JsonToJ3224SDSMConverter() = default;
private:
void populateOptionalData(const Json::Value &optional_data_json, DetectedObjectOptionalData_t *optional_data) const;
};

}
722 changes: 616 additions & 106 deletions src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ namespace CDASimAdapter{

void CDASimAdapter::start_immediate_forward_thread() {
if ( !immediate_forward_timer ) {
immediate_forward_timer = std::make_unique<tmx::utils::ThreadTimer>();
immediate_forward_timer = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));
}
immediate_forward_tick_id = immediate_forward_timer->AddPeriodicTick([this]() {
this->attempt_message_from_v2xhub();

} // end of lambda expression
, std::chrono::milliseconds(100) );
, std::chrono::milliseconds(5) );

immediate_forward_timer->Start();

}

void CDASimAdapter::start_message_receiver_thread() {
if ( !message_receiver_timer ) {
message_receiver_timer = std::make_unique<tmx::utils::ThreadTimer>();
message_receiver_timer = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));
}

message_receiver_tick_id = message_receiver_timer->AddPeriodicTick([this]() {
this->attempt_message_from_simulation();
} // end of lambda expression
, std::chrono::milliseconds(100) );
, std::chrono::milliseconds(5) );
message_receiver_timer->Start();

}
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace CDASimAdapter{
{
if(!external_object_detection_thread_timer)
{
external_object_detection_thread_timer = std::make_unique<tmx::utils::ThreadTimer>();
external_object_detection_thread_timer = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));
}
external_object_detection_thread_timer->AddPeriodicTick([this](){
PLOG(logDEBUG1) << "Listening for Sensor Detected Message from CDASim." << std::endl;
Expand All @@ -187,7 +187,7 @@ namespace CDASimAdapter{
PLOG(logDEBUG1) << "CDASim connection has not yet received an simulated sensor detected message!" << std::endl;
}
}//End lambda
, std::chrono::milliseconds(100));
, std::chrono::milliseconds(5));
external_object_detection_thread_timer->Start();
}
catch ( const UdpServerRuntimeError &e )
Expand Down Expand Up @@ -216,13 +216,13 @@ namespace CDASimAdapter{
void CDASimAdapter::start_time_sync_thread_timer() {
PLOG(logDEBUG) << "Creating Thread Timer for time sync" << std::endl;
if ( !time_sync_timer ) {
time_sync_timer = std::make_unique<tmx::utils::ThreadTimer>();
time_sync_timer = std::make_unique<tmx::utils::ThreadTimer>(std::chrono::milliseconds(5));
}
time_sync_tick_id = time_sync_timer->AddPeriodicTick([this]() {
PLOG(logDEBUG1) << "Listening for time sync messages from CDASim." << std::endl;
this->attempt_time_sync();
} // end of lambda expression
, std::chrono::milliseconds(100));
, std::chrono::milliseconds(5));
time_sync_timer->Start();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/ImmediateForwardPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"key": "Messages_Destination_1",
"default": "{ \"Messages\": [ { \"TmxType\": \"SPAT-P\", \"SendType\": \"SPAT\", \"PSID\": \"0x8002\", \"Channel\": \"183\" }, { \"TmxType\": \"MAP-P\", \"SendType\": \"MAP\", \"PSID\": \"0x8002\", \"Channel\": \"183\" }, { \"TmxType\": \"PSM-P\", \"SendType\": \"PSM\", \"PSID\": \"0x27\", \"Channel\": \"183\" } ,{ \"TmxType\": \"TMSG07-P\", \"SendType\": \"TMSG07\", \"PSID\": \"0x8002\", \"Channel\": \"183\" },{ \"TmxType\": \"TMSG03-P\", \"SendType\": \"TMSG03\", \"PSID\": \"0xBFEE\", \"Channel\": \"183\" },{ \"TmxType\": \"TMSG05-P\", \"SendType\": \"TMSG05\", \"PSID\": \"0xBFEE\", \"Channel\": \"183\" }, { \"TmxType\": \"SSM-P\", \"SendType\": \"SSM\", \"PSID\": \"0x8002\", \"Channel\": \"183\" }] }",
"default": "{ \"Messages\": [ { \"TmxType\": \"SPAT-P\", \"SendType\": \"SPAT\", \"PSID\": \"0x8002\", \"Channel\": \"183\" }, { \"TmxType\": \"MAP-P\", \"SendType\": \"MAP\", \"PSID\": \"0x8002\", \"Channel\": \"183\" }, { \"TmxType\": \"PSM-P\", \"SendType\": \"PSM\", \"PSID\": \"0x27\", \"Channel\": \"183\" } ,{ \"TmxType\": \"TMSG07-P\", \"SendType\": \"TMSG07\", \"PSID\": \"0x8002\", \"Channel\": \"183\" },{ \"TmxType\": \"TMSG03-P\", \"SendType\": \"TMSG03\", \"PSID\": \"0xBFEE\", \"Channel\": \"183\" },{ \"TmxType\": \"TMSG05-P\", \"SendType\": \"TMSG05\", \"PSID\": \"0x8003\", \"Channel\": \"183\" }, { \"TmxType\": \"SSM-P\", \"SendType\": \"SSM\", \"PSID\": \"0x8002\", \"Channel\": \"183\" },{ \"TmxType\": \"SDSM\", \"SendType\": \"SensorDataSharingMessage\", \"PSID\": \"0x8010\", \"Channel\": \"183\" }] }",
"description": "JSON data defining the message types, PSIDs, and channel number for messages forwarded to the V2X radio at destination 1."
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace TelematicBridge
message[TESTING_TYPE_KEY] = testingType;
message[EVENT_NAME_KEY] = eventName;
message[TIMESTAMP_KEY] = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
Json::Value topics;
Json::Value topics = Json::arrayValue;
for (const auto &topic : availableTopicList)
{
if (!boost::icontains(excludedTopics, topic))
Expand Down
4 changes: 4 additions & 0 deletions src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace TelematicBridge
auto reply = TelematicUnit::constructAvailableTopicsReplyString(unit, eventLocation, testingType, eventName, topics, excluded_topic);
auto json = TelematicUnit::parseJson(reply);
ASSERT_EQ("test_topic", json["topics"][0]["name"].asString());

reply = TelematicUnit::constructAvailableTopicsReplyString(unit, eventLocation, testingType, eventName, {}, excluded_topic);
json = TelematicUnit::parseJson(reply);
ASSERT_EQ(1, json["topics"].isArray());
}

TEST_F(test_TelematicUnit, constructPublishedDataString)
Expand Down

0 comments on commit d80c613

Please sign in to comment.