Skip to content

Commit

Permalink
Update SimulationEnvUtils to acception optional argument to indicate …
Browse files Browse the repository at this point in the history
…whether

environment variable is required or not
  • Loading branch information
paulbourelly999 committed Jun 10, 2024
1 parent 8158b2f commit 5df8ca4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ namespace tmx::utils::sim{

}

std::string get_sim_config(const char *config_name) {
std::string get_sim_config(const char *config_name, bool required = true) {
if (is_simulation_mode() && config_name) {
try {
std::string config = std::getenv(config_name);
return config;
}
catch(const std::logic_error &e) {
std::string config_name_str = config_name;
throw TmxException("Simulation Config " + config_name_str + " not set!");
if ( required ) {
throw TmxException("Required simulation config " + config_name_str + " not set!");
}
}
} else {
throw TmxException("V2X-Hub not in sumulation mode or config param name is null pointer!");
Expand Down
24 changes: 15 additions & 9 deletions src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,30 @@ namespace CDASimAdapter{
// Sensor JSON file path is an optional environment variable that allows configuration of
// simulated sensor if provided.
std::string sensor_json_file_path = "";
try
{
sensor_json_file_path = sim::get_sim_config(sim::SENSOR_JSON_FILE_PATH);
}
catch (const TmxException &e ) {
PLOG(logWARNING) << "Optional " << sim::SENSOR_JSON_FILE_PATH << " is not set. No sensors will be configured for this V2X-Hub instance in simulaton." << std::endl;
}
sensor_json_file_path = sim::get_sim_config(sim::SENSOR_JSON_FILE_PATH, false);

PLOG(logINFO) << "CDASim connecting " << simulation_ip <<
"\nUsing Registration Port : " << std::to_string( simulation_registration_port) <<
" Time Sync Port: " << std::to_string( time_sync_port) << " and V2X Port: " << std::to_string(v2x_port) << std::endl;
if ( connection ) {
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
if ( sensor_json_file_path.empty()) {
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location ));
}
else {
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location, sensor_json_file_path ));
}
}
else {
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
if ( sensor_json_file_path.empty()) {
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location);
}
else {
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location, sensor_json_file_path);
}
}
}
catch (const TmxException &e) {
Expand Down
3 changes: 3 additions & 0 deletions src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ namespace CDASimAdapter{
}
message["sensors"] = sensors_json_v;
}
else {
PLOG(logWARNING) << "No sensors where configured for this V2X-Hub instance."
}
Json::StyledWriter writer;
message_str = writer.write(message);
return message_str;
Expand Down

0 comments on commit 5df8ca4

Please sign in to comment.