Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conversion between JSON and ASN.1 C-struct for SDSM with Kafka updates #562

Merged
merged 7 commits into from
Sep 11, 2023

Conversation

willjohnsonk
Copy link
Contributor

@willjohnsonk willjohnsonk commented Sep 7, 2023

PR Details

Description

Added functionality to convert SDSMs from inbound json strings to outbound ASN.1 styled C-structs to facilitate communication over the CARMA Streets plugin in both directions.

Related Issue

CDAR-308
#589

Motivation and Context

How Has This Been Tested?

Tested locally in VSCode with new unit tests for the conversion between jsons and the ASN.1 C-struct messages.

Types of changes

  • Defect fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that cause existing functionality to change)

Checklist:

  • I have added any new packages to the sonar-scanner.properties file
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
    V2XHUB Contributing Guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@willjohnsonk
Copy link
Contributor Author

Needs fixes to sourceID and lights fields - in progress

May consider checking required fields with "isMember" before setting data

Some of the json access statements are very long, I find this more readable from a hierarchy standpoint but may be obtrusive. Can use variables to simply access if needed

@@ -49,6 +49,8 @@ void CARMAStreetsPlugin::UpdateConfigSettings() {
GetConfigValue<string>("MapTopic", _transmitMAPTopic);
GetConfigValue<string>("SRMTopic", _transmitSRMTopic);
GetConfigValue<string>("SimSensorDetectedObjTopic", _transmitSimSensorDetectedObjTopic);
GetConfigValue<string>("SdsmTopic", _subscribeToSdsmTopic);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will need to add this as configuration parameter to the manifest.json for this to work.

@@ -49,6 +49,8 @@ void CARMAStreetsPlugin::UpdateConfigSettings() {
GetConfigValue<string>("MapTopic", _transmitMAPTopic);
GetConfigValue<string>("SRMTopic", _transmitSRMTopic);
GetConfigValue<string>("SimSensorDetectedObjTopic", _transmitSimSensorDetectedObjTopic);
GetConfigValue<string>("SdsmTopic", _subscribeToSdsmTopic);
GetConfigValue<string>("SdsmTopic", _transmitSDSMTopic);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep figured I missed something minor. I meant to ask- can/should these use the same name? The other configs seem to use [x]Topic interchangeably for subscribe/transmit but this one does both

@@ -67,6 +69,12 @@ class CARMAStreetsPlugin: public PluginClientClockAware {
* @param routeableMsg
*/
void HandleMapMessage(MapDataMessage &msg, routeable_message &routeableMsg);
/**
* @brief Subscribe to SDSM broadcast.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have a better description here. This method handles incoming SDSMs received by RSU and forwards them to CARMA Streets as JSON string messages.

SetStatus<uint>(Key_SDSMMessageSkipped, ++_sdsmMessageSkipped);
continue;
}
//Convert the SSM JSON string into J3224 SDSM message and encode it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still referencing SSM. Minor fix comment.

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

//Broadcast the encoded SSM message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSM?

}
}

//std::cout << SDSMDataJson.toStyledString() << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method still exist. Any reason why we would keep this commented out line in the final commit?

namespace CARMAStreetsPlugin
{

// Template to use when created shared pointer objects for optional data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a TODO comment to move this these functions to a more reusable place since they may be helpful in general for manipulating asn1c generated structs.

{

// Template to use when created shared pointer objects for optional data
template <typename T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait why are we redefining functions we already defined in the previous header file?


bool JsonToJ3224SDSMConverter::parseJsonString(const std::string &consumedMsg, Json::Value &sdsmJsonOut) const
{
const auto jsonLen = static_cast<int>(consumedMsg.length());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method at all unique to sdsms or is it just parsing strings into JSON values? If it is not unique maybe we can add a TODO comment to consolidate all the places parse strings into JSON values and try to reuse a single method. Maybe atleast for CARMA-Streets Plugin.

// lights
auto lights_ptr = CARMAStreetsPlugin::create_store_shared<ExteriorLights_t>(shared_ptrs);
auto lights = static_cast<int16_t>((*itr)["detected_object_data"]["detected_object_optional_data"]["detected_vehicle_data"]["lights"].asInt());
lights_ptr->buf = (uint8_t *)calloc(2, sizeof(uint8_t)); // TODO: find calloc alternative if possible, causes a memory leak
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment out and leave a TODO comment to fix this optional fields.

@@ -381,7 +381,7 @@ namespace unit_test
ASSERT_EQ(5, sdsmJson["objects"][0]["detected_object_data"]["detected_object_common_data"]["speed_confidence_z"].asInt());
ASSERT_EQ(15000, sdsmJson["objects"][0]["detected_object_data"]["detected_object_common_data"]["heading"].asInt());
ASSERT_EQ(5, sdsmJson["objects"][0]["detected_object_data"]["detected_object_common_data"]["heading_conf"].asInt());
ASSERT_EQ(200, sdsmJson["objects"][0]["detected_object_data"]["detected_object_common_data"]["accel_4_way"]["long"].asInt());
ASSERT_EQ(200, sdsmJson["objects"][0]["detected_object_data"]["detected_object_common_data"]["accel_4_way"]["Long"].asInt());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this Long instead of long?

Copy link
Contributor

@paulbourelly999 paulbourelly999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@paulbourelly999 paulbourelly999 merged commit 5328f89 into develop Sep 11, 2023
7 of 8 checks passed
@paulbourelly999 paulbourelly999 deleted the feature/sdsm-json-to-cstruct branch September 11, 2023 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants