diff --git a/src/tmx/TmxApi/tmx/j2735_messages/J2735MessageFactory.hpp b/src/tmx/TmxApi/tmx/j2735_messages/J2735MessageFactory.hpp index b62862281..740c7d5de 100644 --- a/src/tmx/TmxApi/tmx/j2735_messages/J2735MessageFactory.hpp +++ b/src/tmx/TmxApi/tmx/j2735_messages/J2735MessageFactory.hpp @@ -43,7 +43,7 @@ #include #include #include -// #include +#include namespace tmx { namespace messages { @@ -79,8 +79,8 @@ using message_types = message_type_list< tsm0Message, tsm1Message, tsm2Message, - tsm3Message - // SdsmMessage + tsm3Message, + SdsmMessage >; /// Base allocator type @@ -205,7 +205,7 @@ class J2735MessageFactory add_allocator_to_maps(); add_allocator_to_maps(); add_allocator_to_maps(); - // add_allocator_to_maps(); + add_allocator_to_maps(); // #if SAEJ2735_SPEC < 63 // add_allocator_to_maps(); // #endif diff --git a/src/tmx/TmxUtils/test/J2735MessageTest.cpp b/src/tmx/TmxUtils/test/J2735MessageTest.cpp index 4689dc548..bc5bd555e 100644 --- a/src/tmx/TmxUtils/test/J2735MessageTest.cpp +++ b/src/tmx/TmxUtils/test/J2735MessageTest.cpp @@ -204,212 +204,212 @@ vector J2735MessageTest::enumNames(api::J2735_end); vector J2735MessageTest::msgTypes(api::J2735_end); vector J2735MessageTest::testBytes(api::J2735_end); -// TEST_F(J2735MessageTest, EncodeMobilityOperation) -// { -// TestMessage03_t* message = (TestMessage03_t*) malloc( sizeof(TestMessage03_t) ); +TEST_F(J2735MessageTest, EncodeMobilityOperation) +{ + TestMessage03_t* message = (TestMessage03_t*) malloc( sizeof(TestMessage03_t) ); -// /** -// * Populate MobilityHeader -// */ + /** + * Populate MobilityHeader + */ -// char* my_str = (char *) "sender_id"; -// uint8_t * my_bytes = reinterpret_cast(my_str); -// message->header.hostStaticId.buf = my_bytes; -// message->header.hostStaticId.size = strlen(my_str); -// message->header.targetStaticId.buf = my_bytes; -// message->header.targetStaticId.size = strlen(my_str); - -// my_str = (char *) "bsm_idXX"; -// my_bytes = reinterpret_cast(my_str); -// message->header.hostBSMId.buf = my_bytes; -// message->header.hostBSMId.size = strlen(my_str); - -// my_str = (char *) "00000000-0000-0000-0000-000000000000"; -// my_bytes = reinterpret_cast(my_str); -// message->header.planId.buf = my_bytes; -// message->header.planId.size = strlen(my_str); - -// unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); -// std::string timestamp_str = std::to_string(timestamp_ll).c_str(); -// char * my_str_1 = new char[strlen(timestamp_str.c_str())]; -// uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; -// strcpy(my_str_1, timestamp_str.c_str()); -// for(int i = 0; i< strlen(my_str_1); i++) -// { -// my_bytes_1[i] = (uint8_t)my_str_1[i]; -// } -// message->header.timestamp.buf = my_bytes_1; -// message->header.timestamp.size = strlen(my_str_1); - -// /** -// * Populate MobilityOperation Body -// */ -// my_str = (char *) "traffic_control_id: traffic_control_id, acknowledgement: true, reason: optional reason text"; -// my_bytes = reinterpret_cast(my_str); -// message->body.operationParams.buf = my_bytes; -// message->body.operationParams.size = strlen(my_str); - -// my_str = (char *) "carma3/Geofence_Acknowledgement"; -// my_bytes = reinterpret_cast(my_str); -// message->body.strategy.buf = my_bytes; -// message->body.strategy.size = strlen(my_str); - -// tmx::messages::tsm3EncodedMessage tsm3EncodeMessage; -// tmx::messages::tsm3Message* _tsm3Message = new tmx::messages::tsm3Message(message); -// tmx::messages::MessageFrameMessage frame_msg(_tsm3Message->get_j2735_data()); -// tsm3EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); + char* my_str = (char *) "sender_id"; + uint8_t * my_bytes = reinterpret_cast(my_str); + message->header.hostStaticId.buf = my_bytes; + message->header.hostStaticId.size = strlen(my_str); + message->header.targetStaticId.buf = my_bytes; + message->header.targetStaticId.size = strlen(my_str); + + my_str = (char *) "bsm_idXX"; + my_bytes = reinterpret_cast(my_str); + message->header.hostBSMId.buf = my_bytes; + message->header.hostBSMId.size = strlen(my_str); + + my_str = (char *) "00000000-0000-0000-0000-000000000000"; + my_bytes = reinterpret_cast(my_str); + message->header.planId.buf = my_bytes; + message->header.planId.size = strlen(my_str); + + unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); + std::string timestamp_str = std::to_string(timestamp_ll).c_str(); + char * my_str_1 = new char[strlen(timestamp_str.c_str())]; + uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; + strcpy(my_str_1, timestamp_str.c_str()); + for(int i = 0; i< strlen(my_str_1); i++) + { + my_bytes_1[i] = (uint8_t)my_str_1[i]; + } + message->header.timestamp.buf = my_bytes_1; + message->header.timestamp.size = strlen(my_str_1); + + /** + * Populate MobilityOperation Body + */ + my_str = (char *) "traffic_control_id: traffic_control_id, acknowledgement: true, reason: optional reason text"; + my_bytes = reinterpret_cast(my_str); + message->body.operationParams.buf = my_bytes; + message->body.operationParams.size = strlen(my_str); + + my_str = (char *) "carma3/Geofence_Acknowledgement"; + my_bytes = reinterpret_cast(my_str); + message->body.strategy.buf = my_bytes; + message->body.strategy.size = strlen(my_str); + + tmx::messages::tsm3EncodedMessage tsm3EncodeMessage; + tmx::messages::tsm3Message* _tsm3Message = new tmx::messages::tsm3Message(message); + tmx::messages::MessageFrameMessage frame_msg(_tsm3Message->get_j2735_data()); + tsm3EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); -// free(message); -// delete my_bytes_1; -// delete my_str_1; -// free(frame_msg.get_j2735_data().get()); -// ASSERT_EQ(243, tsm3EncodeMessage.get_msgId()); -// } + free(message); + delete my_bytes_1; + delete my_str_1; + free(frame_msg.get_j2735_data().get()); + ASSERT_EQ(243, tsm3EncodeMessage.get_msgId()); +} -// TEST_F(J2735MessageTest, EncodeMobilityRequest) -// { -// TestMessage00_t* message = (TestMessage00_t*) calloc(1, sizeof(TestMessage00_t) ); +TEST_F(J2735MessageTest, EncodeMobilityRequest) +{ + TestMessage00_t* message = (TestMessage00_t*) calloc(1, sizeof(TestMessage00_t) ); -// /** -// * Populate MobilityHeader -// */ + /** + * Populate MobilityHeader + */ -// char* my_str = (char *) "sender_id"; -// uint8_t* my_bytes = reinterpret_cast(my_str); -// message->header.hostStaticId.buf = my_bytes; -// message->header.hostStaticId.size = strlen(my_str); -// message->header.targetStaticId.buf = my_bytes; -// message->header.targetStaticId.size = strlen(my_str); - -// my_str = (char *) "bsm_idXX"; -// my_bytes = reinterpret_cast(my_str); -// message->header.hostBSMId.buf = my_bytes; -// message->header.hostBSMId.size = strlen(my_str); - -// my_str = (char *) "00000000-0000-0000-0000-000000000000"; -// my_bytes = reinterpret_cast(my_str); -// message->header.planId.buf = my_bytes; -// message->header.planId.size = strlen(my_str); - -// unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); -// std::string timestamp_str = std::to_string(timestamp_ll).c_str(); -// char * my_str_1 = new char[strlen(timestamp_str.c_str())]; -// uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; -// strcpy(my_str_1, timestamp_str.c_str()); -// for(int i = 0; i< strlen(my_str_1); i++) -// { -// my_bytes_1[i] = (uint8_t)my_str_1[i]; -// } -// message->header.timestamp.buf = my_bytes_1; -// message->header.timestamp.size = strlen(my_str_1); - -// /** -// * Populate MobilityRequest Body -// */ -// my_str = (char *) "traffic_control_id: traffic_control_id, acknowledgement: true, reason: optional reason text"; -// my_bytes = reinterpret_cast(my_str); -// message->body.strategyParams.buf = my_bytes; -// message->body.strategyParams.size = strlen(my_str); - -// my_str = (char *) "carma3/Geofence_Acknowledgement"; -// my_bytes = reinterpret_cast(my_str); -// message->body.strategy.buf = my_bytes; -// message->body.strategy.size = strlen(my_str); - -// message->body.urgency = 1; -// message->body.planType = 0; -// message->body.location.ecefX = 1; -// message->body.location.ecefY = 1; -// message->body.location.ecefZ = 1; -// message->body.location.timestamp.buf = my_bytes_1; -// message->body.location.timestamp.size = strlen(my_str_1); + char* my_str = (char *) "sender_id"; + uint8_t* my_bytes = reinterpret_cast(my_str); + message->header.hostStaticId.buf = my_bytes; + message->header.hostStaticId.size = strlen(my_str); + message->header.targetStaticId.buf = my_bytes; + message->header.targetStaticId.size = strlen(my_str); + + my_str = (char *) "bsm_idXX"; + my_bytes = reinterpret_cast(my_str); + message->header.hostBSMId.buf = my_bytes; + message->header.hostBSMId.size = strlen(my_str); + + my_str = (char *) "00000000-0000-0000-0000-000000000000"; + my_bytes = reinterpret_cast(my_str); + message->header.planId.buf = my_bytes; + message->header.planId.size = strlen(my_str); + + unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); + std::string timestamp_str = std::to_string(timestamp_ll).c_str(); + char * my_str_1 = new char[strlen(timestamp_str.c_str())]; + uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; + strcpy(my_str_1, timestamp_str.c_str()); + for(int i = 0; i< strlen(my_str_1); i++) + { + my_bytes_1[i] = (uint8_t)my_str_1[i]; + } + message->header.timestamp.buf = my_bytes_1; + message->header.timestamp.size = strlen(my_str_1); + + /** + * Populate MobilityRequest Body + */ + my_str = (char *) "traffic_control_id: traffic_control_id, acknowledgement: true, reason: optional reason text"; + my_bytes = reinterpret_cast(my_str); + message->body.strategyParams.buf = my_bytes; + message->body.strategyParams.size = strlen(my_str); + + my_str = (char *) "carma3/Geofence_Acknowledgement"; + my_bytes = reinterpret_cast(my_str); + message->body.strategy.buf = my_bytes; + message->body.strategy.size = strlen(my_str); + + message->body.urgency = 1; + message->body.planType = 0; + message->body.location.ecefX = 1; + message->body.location.ecefY = 1; + message->body.location.ecefZ = 1; + message->body.location.timestamp.buf = my_bytes_1; + message->body.location.timestamp.size = strlen(my_str_1); -// message->body.expiration.buf = my_bytes_1; -// message->body.expiration.size = strlen(my_str_1); + message->body.expiration.buf = my_bytes_1; + message->body.expiration.size = strlen(my_str_1); -// MobilityECEFOffset_t* offset = (MobilityECEFOffset_t*)calloc(1, sizeof(MobilityECEFOffset_t) ); -// offset->offsetX = 1; -// offset->offsetY = 1; -// offset->offsetZ = 1; -// ASN_SEQUENCE_ADD(&message->body.trajectory.list.array, offset); -// ASN_SEQUENCE_ADD(&message->body.trajectory.list.array, offset); - -// message->body.trajectoryStart.ecefX = 1; -// message->body.trajectoryStart.ecefY = 1; -// message->body.trajectoryStart.ecefZ = 1; -// message->body.trajectoryStart.timestamp.buf = my_bytes_1; -// message->body.trajectoryStart.timestamp.size = strlen(my_str_1); + MobilityECEFOffset_t* offset = (MobilityECEFOffset_t*)calloc(1, sizeof(MobilityECEFOffset_t) ); + offset->offsetX = 1; + offset->offsetY = 1; + offset->offsetZ = 1; + ASN_SEQUENCE_ADD(&message->body.trajectory.list.array, offset); + ASN_SEQUENCE_ADD(&message->body.trajectory.list.array, offset); + + message->body.trajectoryStart.ecefX = 1; + message->body.trajectoryStart.ecefY = 1; + message->body.trajectoryStart.ecefZ = 1; + message->body.trajectoryStart.timestamp.buf = my_bytes_1; + message->body.trajectoryStart.timestamp.size = strlen(my_str_1); -// tmx::messages::tsm0EncodedMessage tsm0EncodeMessage; -// tmx::messages::tsm0Message* _tsm0Message = new tmx::messages::tsm0Message(message); -// tmx::messages::MessageFrameMessage frame_msg(_tsm0Message->get_j2735_data()); -// tsm0EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); + tmx::messages::tsm0EncodedMessage tsm0EncodeMessage; + tmx::messages::tsm0Message* _tsm0Message = new tmx::messages::tsm0Message(message); + tmx::messages::MessageFrameMessage frame_msg(_tsm0Message->get_j2735_data()); + tsm0EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); -// free(message); -// delete my_bytes_1; -// delete my_str_1; -// free(offset); -// free(frame_msg.get_j2735_data().get()); -// ASSERT_EQ(240, tsm0EncodeMessage.get_msgId()); -// } - - -// TEST_F(J2735MessageTest, EncodeMobilityResponse) -// { -// TestMessage01_t* message = (TestMessage01_t*) malloc( sizeof(TestMessage01_t) ); - -// /** -// * Populate MobilityHeader -// */ + free(message); + delete my_bytes_1; + delete my_str_1; + free(offset); + free(frame_msg.get_j2735_data().get()); + ASSERT_EQ(240, tsm0EncodeMessage.get_msgId()); +} + + +TEST_F(J2735MessageTest, EncodeMobilityResponse) +{ + TestMessage01_t* message = (TestMessage01_t*) malloc( sizeof(TestMessage01_t) ); + + /** + * Populate MobilityHeader + */ -// char* my_str = (char *) "sender_id"; -// uint8_t* my_bytes = reinterpret_cast(my_str); -// message->header.hostStaticId.buf = my_bytes; -// message->header.hostStaticId.size = strlen(my_str); -// message->header.targetStaticId.buf = my_bytes; -// message->header.targetStaticId.size = strlen(my_str); - -// my_str = (char *) "bsm_idXX"; -// my_bytes = reinterpret_cast(my_str); -// message->header.hostBSMId.buf = my_bytes; -// message->header.hostBSMId.size = strlen(my_str); - -// my_str = (char *) "00000000-0000-0000-0000-000000000000"; -// my_bytes = reinterpret_cast(my_str); -// message->header.planId.buf = my_bytes; -// message->header.planId.size = strlen(my_str); - -// unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); -// std::string timestamp_str = std::to_string(timestamp_ll).c_str(); -// char * my_str_1 = new char[strlen(timestamp_str.c_str())]; -// uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; -// strcpy(my_str_1, timestamp_str.c_str()); -// for(int i = 0; i< strlen(my_str_1); i++) -// { -// my_bytes_1[i] = (uint8_t)my_str_1[i]; -// } -// message->header.timestamp.buf = my_bytes_1; -// message->header.timestamp.size = strlen(my_str_1); - -// /** -// * Populate MobilityResponse Body -// */ -// message->body.isAccepted = 1; -// message->body.urgency = 1; - -// tmx::messages::tsm1EncodedMessage tsm1EncodeMessage; -// tmx::messages::tsm1Message* _tsm1Message = new tmx::messages::tsm1Message(message); -// tmx::messages::MessageFrameMessage frame_msg(_tsm1Message->get_j2735_data()); -// tsm1EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); + char* my_str = (char *) "sender_id"; + uint8_t* my_bytes = reinterpret_cast(my_str); + message->header.hostStaticId.buf = my_bytes; + message->header.hostStaticId.size = strlen(my_str); + message->header.targetStaticId.buf = my_bytes; + message->header.targetStaticId.size = strlen(my_str); + + my_str = (char *) "bsm_idXX"; + my_bytes = reinterpret_cast(my_str); + message->header.hostBSMId.buf = my_bytes; + message->header.hostBSMId.size = strlen(my_str); + + my_str = (char *) "00000000-0000-0000-0000-000000000000"; + my_bytes = reinterpret_cast(my_str); + message->header.planId.buf = my_bytes; + message->header.planId.size = strlen(my_str); + + unsigned long timestamp_ll = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); + std::string timestamp_str = std::to_string(timestamp_ll).c_str(); + char * my_str_1 = new char[strlen(timestamp_str.c_str())]; + uint8_t * my_bytes_1 = new uint8_t[strlen(timestamp_str.c_str())]; + strcpy(my_str_1, timestamp_str.c_str()); + for(int i = 0; i< strlen(my_str_1); i++) + { + my_bytes_1[i] = (uint8_t)my_str_1[i]; + } + message->header.timestamp.buf = my_bytes_1; + message->header.timestamp.size = strlen(my_str_1); + + /** + * Populate MobilityResponse Body + */ + message->body.isAccepted = 1; + message->body.urgency = 1; + + tmx::messages::tsm1EncodedMessage tsm1EncodeMessage; + tmx::messages::tsm1Message* _tsm1Message = new tmx::messages::tsm1Message(message); + tmx::messages::MessageFrameMessage frame_msg(_tsm1Message->get_j2735_data()); + tsm1EncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); -// free(message); -// delete my_bytes_1; -// delete my_str_1; -// free(frame_msg.get_j2735_data().get()); -// ASSERT_EQ(241, tsm1EncodeMessage.get_msgId()); -// } + free(message); + delete my_bytes_1; + delete my_str_1; + free(frame_msg.get_j2735_data().get()); + ASSERT_EQ(241, tsm1EncodeMessage.get_msgId()); +} TEST_F(J2735MessageTest, EncodeBasicSafetyMessage) @@ -542,26 +542,26 @@ TEST_F(J2735MessageTest, EncodeBasicSafetyMessage_PartII) // BSM regional extension auto regional = (BasicSafetyMessage::BasicSafetyMessage__regional *)calloc(1, sizeof(BasicSafetyMessage::BasicSafetyMessage__regional)); auto reg_bsm = (Reg_BasicSafetyMessage *)calloc(1, sizeof(Reg_BasicSafetyMessage)); - // reg_bsm->regionId = 128; - // reg_bsm->regExtValue.present = Reg_BasicSafetyMessage__regExtValue_PR_BasicSafetyMessage_addGrpCarma; - - // auto carma_bsm_data = (BasicSafetyMessage_addGrpCarma_t *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma_t)); - // auto carma_bsm_destination_points = (BasicSafetyMessage_addGrpCarma::BasicSafetyMessage_addGrpCarma__routeDestinationPoints *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma::BasicSafetyMessage_addGrpCarma__routeDestinationPoints)); - // auto point = (Position3D_t *)calloc(1, sizeof(Position3D_t)); - // auto dummy_lat = 12; - // auto dummy_long = 1312; - // point->lat = dummy_lat; - // point->Long = dummy_long; - // asn_sequence_add(&carma_bsm_destination_points->list.array, point); - // auto point2 = (Position3D_t *)calloc(1, sizeof(Position3D_t)); - // point2->lat = dummy_lat + 1000; - // point2->Long = dummy_long + 1000; - // asn_sequence_add(&carma_bsm_destination_points->list.array, point2); - // carma_bsm_data->routeDestinationPoints = carma_bsm_destination_points; - // reg_bsm->regExtValue.choice.BasicSafetyMessage_addGrpCarma = *carma_bsm_data; - - // asn_sequence_add(®ional->list.array, reg_bsm); - // message->regional = regional; + reg_bsm->regionId = 128; + reg_bsm->regExtValue.present = Reg_BasicSafetyMessage__regExtValue_PR_BasicSafetyMessage_addGrpCarma; + + auto carma_bsm_data = (BasicSafetyMessage_addGrpCarma_t *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma_t)); + auto carma_bsm_destination_points = (BasicSafetyMessage_addGrpCarma::BasicSafetyMessage_addGrpCarma__routeDestinationPoints *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma::BasicSafetyMessage_addGrpCarma__routeDestinationPoints)); + auto point = (Position3D_t *)calloc(1, sizeof(Position3D_t)); + auto dummy_lat = 12; + auto dummy_long = 1312; + point->lat = dummy_lat; + point->Long = dummy_long; + asn_sequence_add(&carma_bsm_destination_points->list.array, point); + auto point2 = (Position3D_t *)calloc(1, sizeof(Position3D_t)); + point2->lat = dummy_lat + 1000; + point2->Long = dummy_long + 1000; + asn_sequence_add(&carma_bsm_destination_points->list.array, point2); + carma_bsm_data->routeDestinationPoints = carma_bsm_destination_points; + reg_bsm->regExtValue.choice.BasicSafetyMessage_addGrpCarma = *carma_bsm_data; + + asn_sequence_add(®ional->list.array, reg_bsm); + message->regional = regional; //Encode BSM tmx::messages::BsmEncodedMessage bsmEncodeMessage; @@ -578,15 +578,15 @@ TEST_F(J2735MessageTest, EncodeBasicSafetyMessage_PartII) auto decoded_bsm_ptr = bsmEncodeMessage.decode_j2735_message().get_j2735_data(); ASSERT_EQ(LightbarInUse_inUse, decoded_bsm_ptr->partII->list.array[0]->partII_Value.choice.SpecialVehicleExtensions.vehicleAlerts->lightsUse); ASSERT_EQ(SirenInUse_inUse, decoded_bsm_ptr->partII->list.array[0]->partII_Value.choice.SpecialVehicleExtensions.vehicleAlerts->sirenUse); - // auto decoded_regional = (BasicSafetyMessage::BasicSafetyMessage__regional *)calloc(1, sizeof(BasicSafetyMessage::BasicSafetyMessage__regional)); - // auto decoded_reg_bsm = (Reg_BasicSafetyMessage *)calloc(1, sizeof(Reg_BasicSafetyMessage)); - // auto decode_carma_bsm_data = (BasicSafetyMessage_addGrpCarma_t *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma_t)); - // decoded_regional = decoded_bsm_ptr->regional; - // decoded_reg_bsm = decoded_regional->list.array[0]; - // ASSERT_EQ(dummy_lat, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[0]->lat); - // ASSERT_EQ(dummy_long, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[0]->Long); - // ASSERT_EQ(dummy_lat + 1000, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[1]->lat); - // ASSERT_EQ(dummy_long + 1000, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[1]->Long); + auto decoded_regional = (BasicSafetyMessage::BasicSafetyMessage__regional *)calloc(1, sizeof(BasicSafetyMessage::BasicSafetyMessage__regional)); + auto decoded_reg_bsm = (Reg_BasicSafetyMessage *)calloc(1, sizeof(Reg_BasicSafetyMessage)); + auto decode_carma_bsm_data = (BasicSafetyMessage_addGrpCarma_t *)calloc(1, sizeof(BasicSafetyMessage_addGrpCarma_t)); + decoded_regional = decoded_bsm_ptr->regional; + decoded_reg_bsm = decoded_regional->list.array[0]; + ASSERT_EQ(dummy_lat, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[0]->lat); + ASSERT_EQ(dummy_long, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[0]->Long); + ASSERT_EQ(dummy_lat + 1000, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[1]->lat); + ASSERT_EQ(dummy_long + 1000, decoded_bsm_ptr->regional->list.array[0]->regExtValue.choice.BasicSafetyMessage_addGrpCarma.routeDestinationPoints->list.array[1]->Long); } @@ -600,44 +600,45 @@ TEST_F(J2735MessageTest, EncodePersonalSafetyMessage){ container.load(ss); psmmessage.set_contents(container.get_storage().get_tree()); psmENC.encode_j2735_message(psmmessage); +} -// TEST_F(J2735MessageTest, EncodeTrafficControlRequest){ -// string tsm4str="C7C9A13FE6AC464E0027493419-8183494722811186773760376132001320 "; -// std::stringstream ss; -// tsm4Message tsm4msg; -// tsm4EncodedMessage tsm4Enc; -// tmx::message_container_type container; -// ss<(ss); -// tsm4msg.set_contents(container.get_storage().get_tree()); -// tsm4Enc.encode_j2735_message(tsm4msg); -// std::cout << tsm4Enc.get_payload_str()< tag in TCM -// string tsm5str=" 30642B129B984162 0 9 9 0034b8d88d084ffdaf23837926031658 0 0034b8d88d084ffdaf23837926031658 27506547 153722867280912 1111111 epsg:3785 WGS84 27506547 -818331529 281182119 0 424 3403 000 -2037220 -2037220 -2037220 -2037210 -2037220 -2037220 -2047222 -2037220 -203722-2 -2037210 -2037220 -2037220 -2037220 -2037220 -13460 "; -// std::stringstream ss; -// tsm5Message tsm5msg; -// tsm5EncodedMessage tsm5Enc; -// tmx::message_container_type container; -// ss<(ss); -// tsm5msg.set_contents(container.get_storage().get_tree()); -// tsm5Enc.encode_j2735_message(tsm5msg); -// std::cout << tsm5Enc.get_payload_str()< tag in TCM -// tsm5str="D0E0C6E650394C06011002740591d261d2e99e477df0a82db260002740591d261d2e99e477df0a82db26277773121537228672809121111111epsg:3785WGS8427777312-77148351938954910903312100-1498-262-1497457-14979111-370342"; -// ss<(ss); -// tsm5msg.set_contents(container.get_storage().get_tree()); -// tsm5Enc.encode_j2735_message(tsm5msg); -// std::cout << tsm5Enc.get_payload_str()<(ss); + tsm4msg.set_contents(container.get_storage().get_tree()); + tsm4Enc.encode_j2735_message(tsm4msg); + std::cout << tsm4Enc.get_payload_str()< tag in TCM + string tsm5str=" 30642B129B984162 0 9 9 0034b8d88d084ffdaf23837926031658 0 0034b8d88d084ffdaf23837926031658 27506547 153722867280912 1111111 epsg:3785 WGS84 27506547 -818331529 281182119 0 424 3403 000 -2037220 -2037220 -2037220 -2037210 -2037220 -2037220 -2047222 -2037220 -203722-2 -2037210 -2037220 -2037220 -2037220 -2037220 -13460 "; + std::stringstream ss; + tsm5Message tsm5msg; + tsm5EncodedMessage tsm5Enc; + tmx::message_container_type container; + ss<(ss); + tsm5msg.set_contents(container.get_storage().get_tree()); + tsm5Enc.encode_j2735_message(tsm5msg); + std::cout << tsm5Enc.get_payload_str()< tag in TCM + tsm5str="D0E0C6E650394C06011002740591d261d2e99e477df0a82db260002740591d261d2e99e477df0a82db26277773121537228672809121111111epsg:3785WGS8427777312-77148351938954910903312100-1498-262-1497457-14979111-370342"; + ss<(ss); + tsm5msg.set_contents(container.get_storage().get_tree()); + tsm5Enc.encode_j2735_message(tsm5msg); + std::cout << tsm5Enc.get_payload_str()<msgCnt = 10; -// uint8_t my_bytes_id[4] = {(uint8_t)1, (uint8_t)12, (uint8_t)12, (uint8_t)10}; -// message->sourceID.buf = my_bytes_id; -// message->sourceID.size = sizeof(my_bytes_id); -// message->equipmentType = EquipmentType_unknown; +TEST_F(J2735MessageTest, EncodeSDSM) +{ + auto message = (SensorDataSharingMessage_t*)calloc(1, sizeof(SensorDataSharingMessage_t)); + message->msgCnt = 10; + uint8_t my_bytes_id[4] = {(uint8_t)1, (uint8_t)12, (uint8_t)12, (uint8_t)10}; + message->sourceID.buf = my_bytes_id; + message->sourceID.size = sizeof(my_bytes_id); + message->equipmentType = EquipmentType_unknown; -// auto sDSMTimeStamp = (DDateTime_t*) calloc(1, sizeof(DDateTime_t)); -// auto year = (DYear_t*) calloc(1, sizeof(DYear_t)); -// *year= 2023; -// sDSMTimeStamp->year = year; -// message->sDSMTimeStamp = *sDSMTimeStamp; - -// message->refPos.lat = 38.121212; -// message->refPos.Long = -77.121212; - -// message->refPosXYConf.orientation = 10; -// message->refPosXYConf.semiMajor = 12; -// message->refPosXYConf.semiMinor = 52; - -// auto objects = (DetectedObjectList_t*) calloc(1, sizeof(DetectedObjectList_t)); -// auto objectData = (DetectedObjectData_t*) calloc(1, sizeof(DetectedObjectData_t)); -// objectData->detObjCommon.objType = ObjectType_unknown; -// objectData->detObjCommon.objTypeCfd = 1; -// objectData->detObjCommon.measurementTime = 1; -// objectData->detObjCommon.timeConfidence = 1; -// objectData->detObjCommon.pos.offsetX = 1; -// objectData->detObjCommon.pos.offsetY = 1; -// objectData->detObjCommon.posConfidence.elevation = 1; -// objectData->detObjCommon.posConfidence.pos = 1; -// objectData->detObjCommon.speed = 1; -// objectData->detObjCommon.speedConfidence = 1; -// objectData->detObjCommon.heading = 1; -// objectData->detObjCommon.headingConf = 1; -// ASN_SEQUENCE_ADD(&objects->list.array, objectData); -// message->objects = *objects; -// xer_fprint(stdout, &asn_DEF_SensorDataSharingMessage, message); - -// //Encode SDSM -// tmx::messages::SdsmEncodedMessage SdsmEncodeMessage; -// auto _sdsmMessage = new tmx::messages::SdsmMessage(message); -// tmx::messages::MessageFrameMessage frame_msg(_sdsmMessage->get_j2735_data()); -// SdsmEncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); -// free(message); -// free(frame_msg.get_j2735_data().get()); -// ASSERT_EQ(41, SdsmEncodeMessage.get_msgId()); -// std::string expectedSDSMEncHex = "0029250a010c0c0a101f9c35a4e9266b49d1b20c34000a00000020000bba0a000200004400240009"; -// ASSERT_EQ(expectedSDSMEncHex, SdsmEncodeMessage.get_payload_str()); - -// //Decode SDSM -// auto sdsm_ptr = SdsmEncodeMessage.decode_j2735_message().get_j2735_data(); -// ASSERT_EQ(10, sdsm_ptr->msgCnt); -// } + auto sDSMTimeStamp = (DDateTime_t*) calloc(1, sizeof(DDateTime_t)); + auto year = (DYear_t*) calloc(1, sizeof(DYear_t)); + *year= 2023; + sDSMTimeStamp->year = year; + message->sDSMTimeStamp = *sDSMTimeStamp; + + message->refPos.lat = 38.121212; + message->refPos.Long = -77.121212; + + message->refPosXYConf.orientation = 10; + message->refPosXYConf.semiMajor = 12; + message->refPosXYConf.semiMinor = 52; + + auto objects = (DetectedObjectList_t*) calloc(1, sizeof(DetectedObjectList_t)); + auto objectData = (DetectedObjectData_t*) calloc(1, sizeof(DetectedObjectData_t)); + objectData->detObjCommon.objType = ObjectType_unknown; + objectData->detObjCommon.objTypeCfd = 1; + objectData->detObjCommon.measurementTime = 1; + objectData->detObjCommon.timeConfidence = 1; + objectData->detObjCommon.pos.offsetX = 1; + objectData->detObjCommon.pos.offsetY = 1; + objectData->detObjCommon.posConfidence.elevation = 1; + objectData->detObjCommon.posConfidence.pos = 1; + objectData->detObjCommon.speed = 1; + objectData->detObjCommon.speedConfidence = 1; + objectData->detObjCommon.heading = 1; + objectData->detObjCommon.headingConf = 1; + ASN_SEQUENCE_ADD(&objects->list.array, objectData); + message->objects = *objects; + xer_fprint(stdout, &asn_DEF_SensorDataSharingMessage, message); + + //Encode SDSM + tmx::messages::SdsmEncodedMessage SdsmEncodeMessage; + auto _sdsmMessage = new tmx::messages::SdsmMessage(message); + tmx::messages::MessageFrameMessage frame_msg(_sdsmMessage->get_j2735_data()); + SdsmEncodeMessage.set_data(TmxJ2735EncodedMessage::encode_j2735_message>(frame_msg)); + free(message); + free(frame_msg.get_j2735_data().get()); + ASSERT_EQ(41, SdsmEncodeMessage.get_msgId()); + std::string expectedSDSMEncHex = "0029250a010c0c0a101f9c35a4e9266b49d1b20c34000a00000020000bba0a000200004400240009"; + ASSERT_EQ(expectedSDSMEncHex, SdsmEncodeMessage.get_payload_str()); + + //Decode SDSM + auto sdsm_ptr = SdsmEncodeMessage.decode_j2735_message().get_j2735_data(); + ASSERT_EQ(10, sdsm_ptr->msgCnt); +} }