From 39550fe6d54d710950f36af50bd7a23a4d60585e Mon Sep 17 00:00:00 2001 From: CARMA Developer Date: Mon, 11 Sep 2023 07:48:41 -0700 Subject: [PATCH] Added sourceID/lights, plugin manifest changes --- src/v2i-hub/CARMAStreetsPlugin/manifest.json | 10 ++++++ .../src/CARMAStreetsPlugin.cpp | 4 +-- .../src/CARMAStreetsPlugin.h | 2 +- .../src/JsonToJ3224SDSMConverter.cpp | 34 ++++++++++++++----- .../test/test_JsonToJ3224SDSMConverter.cpp | 13 ++++--- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/v2i-hub/CARMAStreetsPlugin/manifest.json b/src/v2i-hub/CARMAStreetsPlugin/manifest.json index 22fb4a912..acd398414 100644 --- a/src/v2i-hub/CARMAStreetsPlugin/manifest.json +++ b/src/v2i-hub/CARMAStreetsPlugin/manifest.json @@ -116,6 +116,16 @@ "key": "SimSensorDetectedObjTopic", "default": "v2xhub_sim_sensor_detected_object", "description": "Apache Kafka topic plugin will transmit simulated sensor detected object to." + }, + { + "key": "SdsmSubscribeTopic", + "default": "v2xhub_sdsm_sub", + "description": "Apache Kafka topic plugin that will subscribe to SDSM streams." + }, + { + "key": "SdsmTransmitTopic", + "default": "v2xhub_sdsm_tra", + "description": "Apache Kafka topic plugin that will transmit SDSMs." } ] diff --git a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp index 5a6f465b7..22c1425c9 100755 --- a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp +++ b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp @@ -49,8 +49,8 @@ void CARMAStreetsPlugin::UpdateConfigSettings() { GetConfigValue("MapTopic", _transmitMAPTopic); GetConfigValue("SRMTopic", _transmitSRMTopic); GetConfigValue("SimSensorDetectedObjTopic", _transmitSimSensorDetectedObjTopic); - GetConfigValue("SdsmTopic", _subscribeToSdsmTopic); - GetConfigValue("SdsmTopic", _transmitSDSMTopic); + GetConfigValue("SdsmSubscribeTopic", _subscribeToSdsmTopic); + GetConfigValue("SdsmTransmitTopic", _transmitSDSMTopic); // Populate strategies config string config; GetConfigValue("MobilityOperationStrategies", config); diff --git a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h index e485450fe..f6008d76a 100755 --- a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h +++ b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h @@ -70,7 +70,7 @@ class CARMAStreetsPlugin: public PluginClientClockAware { */ void HandleMapMessage(MapDataMessage &msg, routeable_message &routeableMsg); /** - * @brief Subscribe to SDSM broadcast. + * @brief Subscribes to incoming ASN.1, C-Struct formatted SDSMs generated from broadcasting RSUs. These SDSM C-Structs are then converted to JSON to be forwarded to CARMA Streets/Kafka by the handler. * @param msg The J3224 SDSM received from the internal * @param routeableMsg */ diff --git a/src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp b/src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp index d248f4e68..0dd47c2b1 100644 --- a/src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp +++ b/src/v2i-hub/CARMAStreetsPlugin/src/JsonToJ3224SDSMConverter.cpp @@ -42,7 +42,18 @@ namespace CARMAStreetsPlugin std::vector> shared_ptrs; sdsm->msgCnt = sdsm_json["msg_cnt"].asInt64(); - // TODO: convert input sourceID from JSON to C struct octet appropriately + + // TODO: confirm input sourceID from JSON to C struct constructs octet appropriately + // sourceID + TemporaryID_t tempID; + + std::string id_data = sdsm_json["source_id"].asString(); + std::vector id_vector(id_data.begin(), id_data.end()); + uint8_t *id_ptr = &id_vector[0]; + tempID.buf = id_ptr; + tempID.size = sizeof(id_ptr); + sdsm->sourceID = tempID; + sdsm->equipmentType = sdsm_json["equipment_type"].asInt64(); @@ -190,14 +201,18 @@ namespace CARMAStreetsPlugin // set presence val to veh optional_data_ptr->present = DetectedObjectOptionalData_PR_detVeh; - // TODO: fix casting issue, won't take the json input value - // // lights - // auto lights = static_cast((*itr)["detected_object_data"]["detected_object_optional_data"]["detected_vehicle_data"]["lights"].asInt()); - // optional_data_ptr->choice.detVeh.lights->buf = (uint8_t *)calloc(2, sizeof(uint8_t)); // TODO: find calloc alternative if possible - // optional_data_ptr->choice.detVeh.lights->size = 2 * sizeof(uint8_t); - // optional_data_ptr->choice.detVeh.lights->bits_unused = 0; - // optional_data_ptr->choice.detVeh.lights->buf[1] = static_cast(lights); - // optional_data_ptr->choice.detVeh.lights->buf[0] = (lights >> 8); + // TODO: find a better way to convert lights val + // lights + auto lights_ptr = CARMAStreetsPlugin::create_store_shared(shared_ptrs); + auto lights = static_cast((*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 + lights_ptr->size = 2 * sizeof(uint8_t); + lights_ptr->bits_unused = 0; + lights_ptr->buf[1] = static_cast(lights); + lights_ptr->buf[0] = (lights >> 8); + + optional_data_ptr->choice.detVeh.lights = lights_ptr; + // vehAttitude auto attitude_ptr = CARMAStreetsPlugin::create_store_shared(shared_ptrs); @@ -338,6 +353,7 @@ namespace CARMAStreetsPlugin // Set the data to the ASN.1 C struct sdsm->objects = *object_list; + } diff --git a/src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp b/src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp index e138c1cce..8be840b84 100644 --- a/src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp +++ b/src/v2i-hub/CARMAStreetsPlugin/test/test_JsonToJ3224SDSMConverter.cpp @@ -31,7 +31,7 @@ namespace CARMAStreetsPlugin TEST_F(test_JsonToJ3224SDSMConverter, convertJsonToSDSM_header) { JsonToJ3224SDSMConverter converter; - std::string valid_json_str = "{\"equipment_type\":1,\"msg_cnt\":1,\"ref_pos\":{\"Long\":600000000,\"elevation\":30,\"lat\":400000000},\"ref_pos_el_conf\":10,\"ref_pos_xy_conf\":{\"orientation\":25000,\"semi_major\":235,\"semi_minor\":200},\"sdsm_time_stamp\":{\"day\":4,\"hour\":19,\"minute\":15,\"month\":7,\"offset\":400,\"second\":5000,\"year\":2007},\"source_id\":\"01020304\",\"objects\":[{\"detected_object_data\":{\"detected_object_common_data\":{\"acc_cfd_x\":4,\"acc_cfd_y\":5,\"acc_cfd_yaw\":3,\"acc_cfd_z\":6,\"accel_4_way\":{\"lat\":-500,\"Long\":200,\"vert\":1,\"yaw\":400},\"heading\":16000,\"heading_conf\":4,\"measurement_time\":-1100,\"object_id\":12200,\"obj_type\":1,\"obj_type_cfd\":65,\"pos\":{\"offset_x\":4000,\"offset_y\":-720,\"offset_z\":20},\"pos_confidence\":{\"elevation\":5,\"pos\":2},\"speed\":2100,\"speed_confidence\":3,\"speed_confidence_z\":4,\"speed_z\":1000,\"time_confidence\":2}}}]}"; + std::string valid_json_str = "{\"equipment_type\":1,\"msg_cnt\":1,\"ref_pos\":{\"Long\":600000000,\"elevation\":30,\"lat\":400000000},\"ref_pos_el_conf\":10,\"ref_pos_xy_conf\":{\"orientation\":25000,\"semi_major\":235,\"semi_minor\":200},\"sdsm_time_stamp\":{\"day\":4,\"hour\":19,\"minute\":15,\"month\":7,\"offset\":400,\"second\":5000,\"year\":2007},\"source_id\":\"1234\",\"objects\":[{\"detected_object_data\":{\"detected_object_common_data\":{\"acc_cfd_x\":4,\"acc_cfd_y\":5,\"acc_cfd_yaw\":3,\"acc_cfd_z\":6,\"accel_4_way\":{\"lat\":-500,\"Long\":200,\"vert\":1,\"yaw\":400},\"heading\":16000,\"heading_conf\":4,\"measurement_time\":-1100,\"object_id\":12200,\"obj_type\":1,\"obj_type_cfd\":65,\"pos\":{\"offset_x\":4000,\"offset_y\":-720,\"offset_z\":20},\"pos_confidence\":{\"elevation\":5,\"pos\":2},\"speed\":2100,\"speed_confidence\":3,\"speed_confidence_z\":4,\"speed_z\":1000,\"time_confidence\":2}}}]}"; Json::Value root; bool result = converter.parseJsonString(valid_json_str, root); ASSERT_TRUE(result); @@ -39,7 +39,9 @@ namespace CARMAStreetsPlugin converter.convertJsonToSDSM(root, sdsmPtr); ASSERT_EQ(1, sdsmPtr->msgCnt); - // ASSERT_EQ("01020304", sdsmPtr->sourceID); + // TODO: find a way to generate test octet strings for unit test comparisons + size_t test_size = 8; + ASSERT_EQ(test_size, sdsmPtr->sourceID.size); // this only compares size since size is an int, 1234 -> size 8 in hex ASSERT_EQ(1, sdsmPtr->equipmentType); ASSERT_EQ(2007, *sdsmPtr->sDSMTimeStamp.year); @@ -105,14 +107,17 @@ namespace CARMAStreetsPlugin TEST_F(test_JsonToJ3224SDSMConverter, convertJsonToSDSM_veh) { JsonToJ3224SDSMConverter converter; - std::string valid_json_str = "{\"equipment_type\":1,\"msg_cnt\":1,\"objects\":[{\"detected_object_data\":{\"detected_object_common_data\":{\"acc_cfd_x\":4,\"acc_cfd_y\":5,\"acc_cfd_yaw\":3,\"acc_cfd_z\":6,\"accel_4_way\":{\"lat\":-500,\"long\":200,\"vert\":1,\"yaw\":400},\"heading\":16000,\"heading_conf\":4,\"measurement_time\":-1100,\"object_id\":12200,\"obj_type\":1,\"obj_type_cfd\":65,\"pos\":{\"offset_x\":4000,\"offset_y\":-720,\"offset_z\":20},\"pos_confidence\":{\"elevation\":5,\"pos\":2},\"speed\":2100,\"speed_confidence\":3,\"speed_confidence_z\":4,\"speed_z\":1000,\"time_confidence\":2},\"detected_object_optional_data\":{\"detected_vehicle_data\":{\"height\":70,\"lights\":\"8\",\"size\":{\"length\":700,\"width\":300},\"veh_ang_vel\":{\"pitch_rate\":600,\"roll_rate\":-800},\"veh_ang_vel_confidence\":{\"pitch_rate_confidence\":3,\"roll_rate_confidence\":4},\"veh_attitude\":{\"pitch\":2400,\"roll\":-12000,\"yaw\":400},\"veh_attitude_confidence\":{\"pitch_confidence\":2,\"roll_confidence\":3,\"yaw_confidence\":4},\"vehicle_class\":11,\"vehicle_class_conf\":75,\"vehicle_size_confidence\":{\"vehicle_height_confidence\":5,\"vehicle_length_confidence\":6,\"vehicle_width_confidence\":7}}}}}],\"ref_pos\":{\"Long\":600000000,\"elevation\":30,\"lat\":400000000},\"ref_pos_el_conf\":10,\"ref_pos_xy_conf\":{\"orientation\":25000,\"semi_major\":235,\"semi_minor\":200},\"sdsm_time_stamp\":{\"day\":4,\"hour\":19,\"minute\":15,\"month\":7,\"offset\":400,\"second\":5000,\"year\":2007},\"source_id\":\"01020304\"}"; + std::string valid_json_str = "{\"equipment_type\":1,\"msg_cnt\":1,\"objects\":[{\"detected_object_data\":{\"detected_object_common_data\":{\"acc_cfd_x\":4,\"acc_cfd_y\":5,\"acc_cfd_yaw\":3,\"acc_cfd_z\":6,\"accel_4_way\":{\"lat\":-500,\"long\":200,\"vert\":1,\"yaw\":400},\"heading\":16000,\"heading_conf\":4,\"measurement_time\":-1100,\"object_id\":12200,\"obj_type\":1,\"obj_type_cfd\":65,\"pos\":{\"offset_x\":4000,\"offset_y\":-720,\"offset_z\":20},\"pos_confidence\":{\"elevation\":5,\"pos\":2},\"speed\":2100,\"speed_confidence\":3,\"speed_confidence_z\":4,\"speed_z\":1000,\"time_confidence\":2},\"detected_object_optional_data\":{\"detected_vehicle_data\":{\"height\":70,\"lights\":8,\"size\":{\"length\":700,\"width\":300},\"veh_ang_vel\":{\"pitch_rate\":600,\"roll_rate\":-800},\"veh_ang_vel_confidence\":{\"pitch_rate_confidence\":3,\"roll_rate_confidence\":4},\"veh_attitude\":{\"pitch\":2400,\"roll\":-12000,\"yaw\":400},\"veh_attitude_confidence\":{\"pitch_confidence\":2,\"roll_confidence\":3,\"yaw_confidence\":4},\"vehicle_class\":11,\"vehicle_class_conf\":75,\"vehicle_size_confidence\":{\"vehicle_height_confidence\":5,\"vehicle_length_confidence\":6,\"vehicle_width_confidence\":7}}}}}],\"ref_pos\":{\"Long\":600000000,\"elevation\":30,\"lat\":400000000},\"ref_pos_el_conf\":10,\"ref_pos_xy_conf\":{\"orientation\":25000,\"semi_major\":235,\"semi_minor\":200},\"sdsm_time_stamp\":{\"day\":4,\"hour\":19,\"minute\":15,\"month\":7,\"offset\":400,\"second\":5000,\"year\":2007},\"source_id\":\"01020304\"}"; Json::Value root; bool result = converter.parseJsonString(valid_json_str, root); ASSERT_TRUE(result); auto sdsmPtr = std::make_shared(); converter.convertJsonToSDSM(root, sdsmPtr); - // ASSERT_EQ("0106", sdsmPtr->objects.list.array[0]->detObjOptData->choice.detVeh.lights); + // Similar to sourceID, need a better way to compare retrieved ASN.1 values (in this case bit strings) to verify conversion + size_t test_size = 2; + ASSERT_EQ(test_size, sdsmPtr->objects.list.array[0]->detObjOptData->choice.detVeh.lights->size); + ASSERT_EQ(2400, sdsmPtr->objects.list.array[0]->detObjOptData->choice.detVeh.vehAttitude->pitch); ASSERT_EQ(-12000, sdsmPtr->objects.list.array[0]->detObjOptData->choice.detVeh.vehAttitude->roll); ASSERT_EQ(400, sdsmPtr->objects.list.array[0]->detObjOptData->choice.detVeh.vehAttitude->yaw);