Skip to content

Commit

Permalink
Fix SDSM encoding in CARMA Streets Plugin (#571)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description
<!--- Describe your changes in detail -->
Meant to fix encoding issues faced when attempting to encoded SDSM JSON
messages sent from the SDSM service. Previous encoding logic was attempt
to reduce the amount of raw pointers used in creating the SDSM message
from the JSON payload by creating smart pointers instead. This logic was
able to create seemly valid C Structs, inspected using asn print
functions but encoding these would return errors similar to the one
displayed below

To get functional encoding logic, this PR revert to using raw pointers
and memory allocation
```
[2023-12-07 15:29:47.603] src/CARMAStreetsPlugin.cpp (691) - ERROR  : Failed to encoded SDSM message : 
{"msg_cnt":3,"source_id":"","equipment_type":1,"sdsm_time_stamp":{"second":641000,"minute":29,"hour":20,"day":7,"month":12,"year":2023,"offset":0},"ref_pos":{"long":0,"lat":0},"ref_pos_xy_conf":{"semi_major":0,"semi_minor":0,"orientation":0},"objects":[{"detected_object_data":{"detected_object_common_data":{"obj_type":0,"object_id":1,"obj_type_cfd":70,"measurement_time":0,"time_confidence":0,"pos":{"offset_x":-11,"offset_y":-20,"offset_z":-32},"pos_confidence":{"pos":32734,"elevation":1300573664},"speed":70,"speed_confidence":0,"speed_z":50,"heading":0,"heading_conf":0},"detected_object_optional_data":{"detected_obstacle_data":{"obst_size":{"width":5,"length":20,"height":10},"obst_size_confidence":{"width_confidence":0,"length_confidence":0}}}}}]}
Exception encountered: Unable to encode MessageFrame to bytes.

[2023-12-07 15:29:47.603] Utils/src/PluginClient.cpp (405) - ERROR  : CARMAStreetsPlugin terminating from unhandled exception: Segmentation fault
backtrace: (Hint: Use addr2line -C -e <exe> 0x#######) to find line number)
CARMAStreetsPlugin(+0x3e359) [0x55c14e2e0359]
/usr/local/lib/libasn_j2735_r63.so(OCTET_STRING_free+0xb5) [0x7f4e2ca3a1ba]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f4e2c278520]
/usr/local/lib/libasn_j2735_r63.so(OCTET_STRING_free+0xb5) [0x7f4e2ca3a1ba]
/usr/local/lib/libasn_j2735_r63.so(SEQUENCE_free+0x100) [0x7f4e2ca5964a]
CARMAStreetsPlugin(+0x37015) [0x55c14e2d9015]
CARMAStreetsPlugin(+0x1137c1) [0x55c14e3b57c1]
CARMAStreetsPlugin(+0xf67cb) [0x55c14e3987cb]
CARMAStreetsPlugin(+0xe6e68) [0x55c14e388e68]
CARMAStreetsPlugin(+0xdbe22) [0x55c14e37de22]
/lib/x86_64-linux-gnu/libboost_thread.so.1.74.0(+0x150cb) [0x7f4e2c9ac0cb]
/lib/x86_64-linux-gnu/libc.so.6(+0x94ac3) [0x7f4e2c2caac3]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x44) [0x7f4e2c35bbf4]
diagnostic info:
/home/V2X-Hub/src/tmx/TmxUtils/src/PluginExec.cpp(220): Throw in function HandleSignal
Dynamic exception type: tmx::utils::SignalException
std::exception::what: Segmentation fault
```

## Related Issue
[CDAR-585
](https://usdot-carma.atlassian.net/browse/CDAR-585)<!--- This project
only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context
Get working SDSM encoding logic
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
Unit testing 
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] 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:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] 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.
- [x] I have read the **CONTRIBUTING** document.
[V2XHUB Contributing
Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md)
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
paulbourelly999 authored Dec 18, 2023
1 parent 40d8b14 commit ada57ac
Show file tree
Hide file tree
Showing 4 changed files with 931 additions and 428 deletions.
12 changes: 4 additions & 8 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));
BroadcastMessage(static_cast<routeable_message &>(sdsmEncodedMsg));

}
}
}
Expand Down
Loading

0 comments on commit ada57ac

Please sign in to comment.