From 9a21060ae4ecfefaf4bd5e2bef5e58ee21e6ba61 Mon Sep 17 00:00:00 2001 From: dan-du-car <62157949+dan-du-car@users.noreply.github.com> Date: Tue, 30 Apr 2024 17:14:52 -0400 Subject: [PATCH] CARMACloudPlugin: TCR oldest issue in simulation environment (#611) # PR Details ## Description Current TCR message is populated with oldest value based on the epoch timestamp, and defined as how many minutes from now. However, in simulation environment, the clock reference is not epoch time, it is customized clock starting from 0. This can be an issue with the current oldest implementation in v2xhub because the carma-cloud application in simulation environment uses the oldest value generated by V2xHub and reference it based on the simulation time rather than epoch time. Also, carma-platform running in the vehicle cannot control the oldest value generation. This PR is to update the TCR message oldest field with data sent by carma-platform in simulation mode. ## Related Issue NA ## Motivation and Context XIL integration testing ## How Has This Been Tested? integration tested ## Types of changes - [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: - [ ] 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) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. --- .../CARMACloudPlugin/src/CARMACloudPlugin.cpp | 24 ++++++++----------- .../CARMACloudPlugin/src/CARMACloudPlugin.h | 9 ++++--- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp index d2110c575..54aa176ae 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp @@ -16,7 +16,8 @@ namespace CARMACloudPlugin { * * @param name The name to give the plugin for identification purposes */ -CARMACloudPlugin::CARMACloudPlugin(string name) :PluginClient(name) { +CARMACloudPlugin::CARMACloudPlugin(string name) : PluginClientClockAware(name) +{ UpdateConfigSettings(); std::lock_guard lock(_cfgLock); @@ -36,10 +37,8 @@ CARMACloudPlugin::CARMACloudPlugin(string name) :PluginClient(name) { _tcm_broadcast_starting_time = std::make_shared>(); std::thread Broadcast_t(&CARMACloudPlugin::TCMAckCheckAndRebroadcastTCM, this); Broadcast_t.detach(); - } - void CARMACloudPlugin::HandleCARMARequest(tsm4Message &msg, routeable_message &routeableMsg) { auto carmaRequest = msg.get_j2735_data(); @@ -63,19 +62,18 @@ void CARMACloudPlugin::HandleCARMARequest(tsm4Message &msg, routeable_message &r int totBounds = carmaRequest->body.choice.tcrV01.bounds.list.count; int cnt=0; char bounds_str[5000]; - strcpy(bounds_str,""); - - // get current time - std::time_t tm = std::time(0)/60-fetchtime*24*60; // T minus 24 hours in min + strcpy(bounds_str, ""); + + int oldestInMins = getClock()->nowInSeconds() / 60 - fetchtime * 24 * 60; // T minus 24 hours in min - while(cntbody.choice.tcrV01.bounds.list.array[cnt]->reflat; + long lat = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->reflat; long longg = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->reflon; - + auto oldest = std::max(oldestInMins, 0); // Replace tm with 0 if negative + long dtx0 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[0]->deltax; long dty0 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[0]->deltay; long dtx1 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[1]->deltax; @@ -83,11 +81,9 @@ void CARMACloudPlugin::HandleCARMARequest(tsm4Message &msg, routeable_message &r long dtx2 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[2]->deltax; long dty2 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[2]->deltay; - sprintf(bounds_str+strlen(bounds_str),"%u%ld%ld%ld%ld%ld%ld%ld%ld",oldest,longg,lat,dtx0,dty0,dtx1,dty1,dtx2,dty2); + sprintf(bounds_str + strlen(bounds_str), "%u%ld%ld%ld%ld%ld%ld%ld%ld", oldest, longg, lat, dtx0, dty0, dtx1, dty1, dtx2, dty2); cnt++; - - } char xml_str[10000]; diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h index 9a9d85061..e092c03ab 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h @@ -73,8 +73,7 @@ #include #include - - +#include using namespace std; @@ -92,7 +91,8 @@ enum acknowledgement_status { acknowledgement_status__not_acknowledged = 3 //CMV does not respond at all within the v2xhub repeatedly broadcast time period }; -class CARMACloudPlugin: public PluginClient { +class CARMACloudPlugin : public PluginClientClockAware +{ public: CARMACloudPlugin(std::string); virtual ~CARMACloudPlugin(); @@ -212,8 +212,7 @@ class CARMACloudPlugin: public PluginClient { const char *CONTENT_ENCODING_VALUE = "gzip"; std::string list_tcm = "true"; //API URL to accept TCM response - const QString TCM_REPLY="tcmreply"; - + const QString TCM_REPLY = "tcmreply"; }; std::mutex _cfgLock; }