From 8121e182e3f6f1d0e0ddaf745644c1c1e79608cc Mon Sep 17 00:00:00 2001 From: dan-du-car <62157949+dan-du-car@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:11:11 -0700 Subject: [PATCH] Preemption sonar issues (#260) * init * init * test * update * update * update * update * update * update * update * update --- .../PreemptionPlugin/src/PreemptionPlugin.cpp | 10 +--- .../PreemptionPlugin/src/PreemptionPlugin.hpp | 2 +- .../src/include/PreemptionPluginWorker.cpp | 57 +++++++++---------- .../src/include/PreemptionPluginWorker.hpp | 16 +++--- .../PreemptionPlugin/test/PreemptionTest.cpp | 2 +- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.cpp b/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.cpp index a495dddd7..e82dff414 100644 --- a/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.cpp +++ b/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.cpp @@ -105,11 +105,7 @@ void PreemptionPlugin::HandleBasicSafetyMessage(BsmMessage &msg, routeable_messa bsmTmpID = (int32_t)((buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]); - //std::vector::iterator it = std::find(allowedList.begin(),allowedList.end(),bsmTmpID); - - //if( it != allowedList.end()) - //{ - if (bsm->partII != NULL) { + if (bsm->partII != NULL) { if (bsm->partII[0].list.count >= partII_Value_PR_SpecialVehicleExtensions ) { try { if(bsm->partII[0].list.array[1]->partII_Value.choice.SpecialVehicleExtensions.vehicleAlerts != NULL){ @@ -125,9 +121,7 @@ void PreemptionPlugin::HandleBasicSafetyMessage(BsmMessage &msg, routeable_messa PLOG(logDEBUG)<<"Standard Exception:; Vehicle alerts Unavailable"; } } - } - //} - + } } int PreemptionPlugin::Main() diff --git a/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.hpp b/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.hpp index c3731e1e5..b52d18814 100644 --- a/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.hpp +++ b/src/v2i-hub/PreemptionPlugin/src/PreemptionPlugin.hpp @@ -43,7 +43,7 @@ class PreemptionPlugin: public PluginClient } // PreemptionPlugin(PreemptionPlugin &&fp) noexcept { // } - PreemptionPlugin const & operator=(PreemptionPlugin &&fp) { + PreemptionPlugin const & operator=(PreemptionPlugin &&fp) noexcept{ } diff --git a/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.cpp b/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.cpp index 91894ad1a..3ccf07216 100644 --- a/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.cpp +++ b/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.cpp @@ -7,60 +7,58 @@ //========================================================================== #include "PreemptionPluginWorker.hpp" - +#include using namespace std; namespace PreemptionPlugin { - void PreemptionPluginWorker::ProcessMapMessageFile(std::string path){ + void PreemptionPluginWorker::ProcessMapMessageFile(const std::string &path){ if(path != ""){ try { boost::property_tree::read_json(path, geofence_data); BOOST_FOREACH( boost::property_tree::ptree::value_type const& v, geofence_data.get_child( "data" ) ) { - assert(v.first.empty()); // array elements have no names boost::property_tree::ptree subtree = v.second; list geox; list geoy; BOOST_FOREACH( boost::property_tree::ptree::value_type const& u, subtree.get_child( "geox" ) ) { - assert(u.first.empty()); // array elements have no names - // std::cout << u.second.get("") << std::endl; double d = u.second.get(""); geox.push_back(d); } BOOST_FOREACH( boost::property_tree::ptree::value_type const& u, subtree.get_child( "geoy" ) ) { - assert(u.first.empty()); // array elements have no names double d = u.second.get(""); geoy.push_back(d); } - GeofenceObject* geofenceObject = new GeofenceObject(geox,geoy,subtree.get("PreemptCall"),subtree.get("HeadingMin"),subtree.get("HeadingMax")); + GeofenceObject geofenceObject(geox,geoy, static_cast(subtree.get("PreemptCall")),static_cast(subtree.get("HeadingMin")),static_cast(subtree.get("HeadingMax"))); - GeofenceSet.push_back(geofenceObject); + GeofenceSet.push_back(&geofenceObject); } } catch(...) { - std::cout << "Caught exception from reading a file"; + PLUGIN_LOG(logERROR, "Preemptionworker") << "Caught exception from reading a file"; } } - } - bool PreemptionPluginWorker::CarInGeofence(double x, double y, double geox[], double geoy[], int GeoCorners) { - int i, j=GeoCorners-1 ; - bool oddNodes ; + bool PreemptionPluginWorker::CarInGeofence(long double x,long double y, std::vector geox, std::vector geoy, long GeoCorners) const{ + long i = 0 ; + long j = GeoCorners-1; + bool oddNodes = false; for (i=0; i=y - || geoy[j]< y && geoy[i]>=y) - && (geox[i]<=x || geox[j]<=x)) { - oddNodes^=(geox[i]+(y-geoy[i])/(geoy[j]-geoy[i])*(geox[j]-geox[i])=y + || geoy.at(j)< y && geoy.at(i)>=y) + && (geox.at(i)<=x || geox.at(j)<=x) && (geox.at(i)+(y-geoy.at(i))/(geoy.at(j)-geoy.at(i))*(geox.at(j)-geox.at(i))(); + auto vehicle_coordinate = std::make_shared(); auto bsm = msg->get_j2735_data(); int32_t bsmTmpID; @@ -84,16 +81,14 @@ namespace PreemptionPlugin { for (auto const& it: GeofenceSet) { - double geox[it->geox.size()]; - int k = 0; + std::vector geox; for (double const &i: it->geox) { - geox[k++] = i; + geox.push_back(i); } - double geoy[it->geoy.size()]; - k = 0; + std::vector geoy; for (double const &i: it->geoy) { - geoy[k++] = i; + geoy.push_back(i); } bool in_geo = CarInGeofence(vehicle_coordinate->lon, vehicle_coordinate->lat, geoy, geox, it->geox.size()); @@ -119,7 +114,7 @@ namespace PreemptionPlugin { }; - void PreemptionPluginWorker::PreemptionPlaner(PreemptionObject* po){ + void PreemptionPluginWorker::PreemptionPlaner(std::shared_ptr po){ if(po->approach == "1") { @@ -146,7 +141,7 @@ namespace PreemptionPlugin { std::cout << " Finished PreemptionPlaner" << std::endl; }; - void PreemptionPluginWorker::TurnOnPreemption(PreemptionObject* po){ + void PreemptionPluginWorker::TurnOnPreemption(std::shared_ptr po){ std::string preemption_plan_flag = "1"; std::asctime(std::localtime(&(po->time))); @@ -163,7 +158,7 @@ namespace PreemptionPlugin { } } - void PreemptionPluginWorker::TurnOffPreemption(PreemptionObject* po){ + void PreemptionPluginWorker::TurnOffPreemption(std::shared_ptr po){ std::string preemption_plan, preemption_plan_flag = ""; preemption_plan = preemption_map[po ->vehicle_id].preemption_plan; preemption_plan_flag = "0"; diff --git a/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.hpp b/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.hpp index cf76814eb..73d719568 100644 --- a/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.hpp +++ b/src/v2i-hub/PreemptionPlugin/src/include/PreemptionPluginWorker.hpp @@ -40,9 +40,9 @@ namespace PreemptionPlugin { public: struct PreemptionObject { - std::string approach; // 0: egress 1: ingress - std::string preemption_plan; - int vehicle_id; + std::string approach = ""; // 0: egress 1: ingress + std::string preemption_plan = ""; + int vehicle_id = 0; std::time_t time = std::time(nullptr); }; @@ -72,12 +72,12 @@ namespace PreemptionPlugin { std::map preemption_map; - void ProcessMapMessageFile(std::string path); + void ProcessMapMessageFile(const std::string &path); void VehicleLocatorWorker(BsmMessage* msg); - void PreemptionPlaner(PreemptionObject* po); - void TurnOnPreemption(PreemptionObject* po); - void TurnOffPreemption(PreemptionObject* po); - bool CarInGeofence(double x, double y, double geox[], double geoy[], int GeoCorners); + void PreemptionPlaner(std::shared_ptr po); + void TurnOnPreemption(std::shared_ptr po); + void TurnOffPreemption(std::shared_ptr po); + bool CarInGeofence(long double x, long double y, std::vector geox, std::vector geoy, long GeoCorners) const; std::string ip_with_port; int snmp_version = SNMP_VERSION_1; diff --git a/src/v2i-hub/PreemptionPlugin/test/PreemptionTest.cpp b/src/v2i-hub/PreemptionPlugin/test/PreemptionTest.cpp index aa86baf4d..56e7b0347 100644 --- a/src/v2i-hub/PreemptionPlugin/test/PreemptionTest.cpp +++ b/src/v2i-hub/PreemptionPlugin/test/PreemptionTest.cpp @@ -45,7 +45,7 @@ class PreemptionTest : public testing::Test bool CarInGeofence(double x, double y, double geox[], double geoy[], int GeoCorners) { int i, j=GeoCorners-1 ; - bool oddNodes ; + bool oddNodes = 0 ; for (i=0; i=y