From 9abb47b58d36e292a3376e47cb87a03f0f7f6c93 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Wed, 26 Jul 2023 18:53:09 +0000 Subject: [PATCH] address comments --- .../CDASimAdapter/src/CDASimConnection.cpp | 39 ++----------------- .../src/include/CDASimConnection.hpp | 7 ---- .../test/TestCARMASimulationConnection.cpp | 26 ------------- src/v2i-hub/CDASimAdapter/test/sensors.json | 6 +-- 4 files changed, 5 insertions(+), 73 deletions(-) diff --git a/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp b/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp index 506fb3638..b17eedb35 100644 --- a/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp +++ b/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp @@ -21,12 +21,12 @@ namespace CDASimAdapter{ bool CDASimConnection::connect() { //Read local sensor file and populate the sensors JSON - _sensors_json_v = read_json_file(_sensor_json_file_path); - if(_sensors_json_v.empty()) + auto sensors_json_v = read_json_file(_sensor_json_file_path); + if(sensors_json_v.empty()) { PLOG(logWARNING) << "Sensors JSON is empty!" << std::endl; } - if (!carma_simulation_handshake(_simulation_ip, _infrastructure_id, _simulation_registration_port, _local_ip, _time_sync_port, _v2x_port, _location, _sensors_json_v)) { + if (!carma_simulation_handshake(_simulation_ip, _infrastructure_id, _simulation_registration_port, _local_ip, _time_sync_port, _v2x_port, _location, sensors_json_v)) { _connected = false; return _connected; } @@ -256,37 +256,4 @@ namespace CDASimAdapter{ } return json_v; } - - Json::Value CDASimConnection::get_sensor_by_id(const std::string &sensor_id) - { - Json::Value result; - if(_sensors_json_v.empty()) - { - PLOG(logERROR) << "CDASimAdapter stored sensors are empty." << std::endl; - return result; - } - - if(_sensors_json_v.isArray()) - { - std::for_each( _sensors_json_v.begin(), _sensors_json_v.end(), [&result, &sensor_id](auto& item){ - if(item.isMember("sensor_id") && item["sensor_id"] == sensor_id) - { - result = item; - } - }); - } - else if(_sensors_json_v.isObject()) - { - if(_sensors_json_v.isMember("sensor_id") && _sensors_json_v["sensor_id"] == sensor_id) - { - result = _sensors_json_v; - } - } - - if(result.empty()) - { - PLOG(logERROR) << "CDASimAdapter stored sensors do not have sensor with id = " << sensor_id << std::endl; - } - return result; - } } diff --git a/src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp b/src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp index 55a1f0a87..83129a0a8 100644 --- a/src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp +++ b/src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp @@ -122,11 +122,6 @@ namespace CDASimAdapter { * @return Returns true if CARMA-Simulation connection is active and false if the connection is inactive. */ bool is_connected() const; - /** - * @brief Search the list of sensors stored by this plugin and identify the sensor based on the input id. - * @param sensor_id A unique sensor identifier - */ - Json::Value get_sensor_by_id(const std::string &sensor_id); private: /** @@ -164,8 +159,6 @@ namespace CDASimAdapter { tmx::utils::Point _location; bool _connected = false; std::string _sensor_json_file_path; - //Global variable to store the sensors information - Json::Value _sensors_json_v; std::shared_ptr carma_simulation_listener; std::shared_ptr carma_simulation_publisher; diff --git a/src/v2i-hub/CDASimAdapter/test/TestCARMASimulationConnection.cpp b/src/v2i-hub/CDASimAdapter/test/TestCARMASimulationConnection.cpp index 41468c542..fdb6ac19c 100644 --- a/src/v2i-hub/CDASimAdapter/test/TestCARMASimulationConnection.cpp +++ b/src/v2i-hub/CDASimAdapter/test/TestCARMASimulationConnection.cpp @@ -122,30 +122,4 @@ namespace CDASimAdapter { auto sensorJsonV = connection->string_to_json("Invalid Json"); ASSERT_TRUE(sensorJsonV.empty()); } - - TEST_F(TestCARMASimulationConnection, get_sensor_by_id) - { - Point location; - auto conn = std::make_shared("127.0.0.1", "1212", 4567, 4678, "127.0.0.1", 1213, 1214, location, ""); - std::string invalidId = "invalidId"; - auto sensor = conn->get_sensor_by_id(invalidId); - ASSERT_TRUE(sensor.empty()); - //Populate connection with sensors upon connect call. - connection->connect(); - std::ifstream in_strm; - in_strm.open(sensors_file_path, std::ifstream::binary); - if(in_strm.is_open()) - { - std::string sensor_id = "SomeID"; - sensor = connection->get_sensor_by_id(sensor_id); - ASSERT_FALSE(sensor.empty()); - ASSERT_EQ("SematicLidar", sensor["type"].asString()); - - sensor_id = "not_found"; - sensor = connection->get_sensor_by_id(sensor_id); - ASSERT_TRUE(sensor.empty()); - } - - } - } \ No newline at end of file diff --git a/src/v2i-hub/CDASimAdapter/test/sensors.json b/src/v2i-hub/CDASimAdapter/test/sensors.json index 8c869554f..958973b9f 100755 --- a/src/v2i-hub/CDASimAdapter/test/sensors.json +++ b/src/v2i-hub/CDASimAdapter/test/sensors.json @@ -11,8 +11,7 @@ "x": 0.0, "y": 0.0, "z": 0.0 - }, - "proj_string": "+proj=tmerc +lat_0=38.95197911150576 +lon_0=-77.14835128349988 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +geoidgrids=egm96_15.gtx +vunits=m +no_defs" + } }, { "sensor_id": "SomeID2", @@ -26,7 +25,6 @@ "x": 23.0, "y": 0.0, "z": 0.0 - }, - "proj_string": "+proj=tmerc +lat_0=38.95197911150576 +lon_0=-77.14835128349988 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +geoidgrids=egm96_15.gtx +vunits=m +no_defs" + } } ] \ No newline at end of file