Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Jul 26, 2023
1 parent 85280e4 commit 9abb47b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 73 deletions.
39 changes: 3 additions & 36 deletions src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
7 changes: 0 additions & 7 deletions src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/**
Expand Down Expand Up @@ -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<tmx::utils::UdpServer> carma_simulation_listener;
std::shared_ptr<tmx::utils::UdpClient> carma_simulation_publisher;
Expand Down
26 changes: 0 additions & 26 deletions src/v2i-hub/CDASimAdapter/test/TestCARMASimulationConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CDASimConnection>("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());
}

}

}
6 changes: 2 additions & 4 deletions src/v2i-hub/CDASimAdapter/test/sensors.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
]

0 comments on commit 9abb47b

Please sign in to comment.