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 9abb47b commit 55221e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ namespace CDASimAdapter{
}

bool CDASimConnection::connect() {
//Read local sensor file and populate the sensors JSON
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)) {
_connected = false;
return _connected;
}
Expand All @@ -40,7 +34,7 @@ namespace CDASimAdapter{
}

std::string CDASimConnection::get_handshake_json(const std::string &infrastructure_id, const std::string &local_ip, const uint time_sync_port, const uint v2x_port,
const Point &location, const Json::Value& sensors_json_v) const
const Point &location) const

{
Json::Value message;
Expand All @@ -53,6 +47,13 @@ namespace CDASimAdapter{
message["location"]["x"] = location.X;
message["location"]["y"] = location.Y;
message["location"]["z"] = location.Z;

//Read local sensor file and populate the sensors JSON
auto sensors_json_v = read_json_file(_sensor_json_file_path);
if(sensors_json_v.empty())
{
PLOG(logWARNING) << "Sensors JSON is empty!" << std::endl;
}
message["sensors"] = sensors_json_v;
Json::StyledWriter writer;
message_str = writer.write(message);
Expand All @@ -61,12 +62,12 @@ namespace CDASimAdapter{

bool CDASimConnection::carma_simulation_handshake(const std::string &simulation_ip, const std::string &infrastructure_id, const uint simulation_registration_port,
const std::string &local_ip, const uint time_sync_port, const uint v2x_port,
const Point &location, const Json::Value& sensors_json_v )
const Point &location)
{
// Create JSON message with the content
std::string payload = "";

payload = get_handshake_json(infrastructure_id, local_ip, time_sync_port, v2x_port, location, sensors_json_v);
payload = get_handshake_json(infrastructure_id, local_ip, time_sync_port, v2x_port, location);

try
{
Expand Down
6 changes: 2 additions & 4 deletions src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ namespace CDASimAdapter {
* @param time_sync_port port assigned to listening for time sychronization messages from CARMA-Simulation.
* @param v2x_port port assigned to listening for v2x messages from CARMA-Simulation.
* @param location simulated location of infrastructure hardware.
* @param sensors_json_v A list of sensors sent to CARLA for sensor generation.
* @return true if handshake successful and false if handshake unsuccessful.
*/
bool carma_simulation_handshake(const std::string &simulation_ip, const std::string &infrastructure_id, const uint simulation_registration_port,
const std::string &local_ip, const uint time_sync_port, const uint v2x_port,
const tmx::utils::Point &location, const Json::Value& sensors_json_v);
const tmx::utils::Point &location);

/**
* @brief Method to setup UDP Servers and Clients after handshake to facilate message forwarding.
Expand Down Expand Up @@ -130,11 +129,10 @@ namespace CDASimAdapter {
* @param time_sync_port port assigned to listening for time sychronization messages from CARMA-Simulation.
* @param v2x_port port assigned to listening for v2x messages from CARMA-Simulation.
* @param location simulated location of infrastructure hardware.
* @param sensors_json_v A list of sensors sent to CARLA for sensor generation.
* @return true if handshake successful and false if handshake unsuccessful.
*/
std::string get_handshake_json(const std::string &infrastructure_id, const std::string &local_ip, const uint time_sync_port,
const uint v2x_port, const tmx::utils::Point &location, const Json::Value& sensors_json_v) const;
const uint v2x_port, const tmx::utils::Point &location) const;

/**
* @brief Read local file that has the sensor information in JSON format from disk. Populate global sensor json variable with the information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ namespace CDASimAdapter {
location.X = 1000;
location.Y = 38.955;
location.Z = -77.149;
Json::Value sensorsJsonV;
ASSERT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, location, sensorsJsonV),
ASSERT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, location),
"{\n \"infrastructureId\" : \"4566\",\n \"location\" : {\n \"x\" : 1000.0,\n \"y\" : 38.954999999999998,\n \"z\" : -77.149000000000001\n },\n \"rxMessageIpAddress\" : \"127.0.0.1\",\n \"rxMessagePort\" : 4568,\n \"sensors\" : null,\n \"timeSyncPort\" : 4567\n}\n");
}

TEST_F( TestCARMASimulationConnection, carma_simulation_handshake) {
Point location;
Json::Value sensorsJsonV;
// UDP creation error
ASSERT_FALSE(connection->carma_simulation_handshake("", "45", NULL,
"", 45, 45, location, sensorsJsonV));
"", 45, 45, location));
}

TEST_F(TestCARMASimulationConnection, connect) {
Expand Down

0 comments on commit 55221e3

Please sign in to comment.