diff --git a/src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.cpp b/src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.cpp index 0913db6e7..e7a91e180 100644 --- a/src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.cpp +++ b/src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.cpp @@ -13,7 +13,7 @@ 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); @@ -21,7 +21,9 @@ namespace tmx::utils::sim{ } 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!"); diff --git a/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp b/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp index 3973c1f52..b33ad80a3 100644 --- a/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp +++ b/src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp @@ -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(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip, + if ( sensor_json_file_path.empty()) { + connection = std::make_unique(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(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) { diff --git a/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp b/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp index d7d3fa757..2eadad82f 100644 --- a/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp +++ b/src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp @@ -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;