Skip to content

Commit

Permalink
CARMACloudPlugin: TCR oldest issue in simulation environment (#611)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# 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.

<!--- Describe your changes in detail -->

## Related Issue
NA
<!--- 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
XIL integration testing
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
integration tested
<!--- 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)
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
  • Loading branch information
dan-du-car authored Apr 30, 2024
1 parent 2cc9a4a commit 9a21060
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
24 changes: 10 additions & 14 deletions src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mutex> lock(_cfgLock);
Expand All @@ -36,10 +37,8 @@ CARMACloudPlugin::CARMACloudPlugin(string name) :PluginClient(name) {
_tcm_broadcast_starting_time = std::make_shared<std::map<string, std::time_t>>();
std::thread Broadcast_t(&CARMACloudPlugin::TCMAckCheckAndRebroadcastTCM, this);
Broadcast_t.detach();

}


void CARMACloudPlugin::HandleCARMARequest(tsm4Message &msg, routeable_message &routeableMsg)
{
auto carmaRequest = msg.get_j2735_data();
Expand All @@ -63,31 +62,28 @@ 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(cnt<totBounds)
while (cnt < totBounds)
{

uint32_t oldest=tm;
long lat = carmaRequest->body.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;
long dty1 = carmaRequest->body.choice.tcrV01.bounds.list.array[cnt]->offsets.list.array[1]->deltay;
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),"<bounds><oldest>%u</oldest><reflon>%ld</reflon><reflat>%ld</reflat><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets></bounds>",oldest,longg,lat,dtx0,dty0,dtx1,dty1,dtx2,dty2);
sprintf(bounds_str + strlen(bounds_str), "<bounds><oldest>%u</oldest><reflon>%ld</reflon><reflat>%ld</reflat><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets><offsets><deltax>%ld</deltax><deltay>%ld</deltay></offsets></bounds>", oldest, longg, lat, dtx0, dty0, dtx1, dty1, dtx2, dty2);

cnt++;


}

char xml_str[10000];
Expand Down
9 changes: 4 additions & 5 deletions src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@

#include <curl/curl.h>
#include <algorithm>


#include <PluginClientClockAware.h>

using namespace std;

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9a21060

Please sign in to comment.