69 std::vector<SensorParameters> config;
71 if (file_path.empty())
75 std::ifstream input_stream(file_path);
76 if (!input_stream.good())
78 throw std::runtime_error(
"Unable to open file for reading " + file_path.string());
84 const YAML::Node& doc = YAML::Load(input_stream);
86 const YAML::Node& sensors_node = doc[
"sensors"];
89 if (sensors_node && sensors_node.IsSequence())
92 for (
const YAML::Node& sensor_name_node : sensors_node)
94 std::string sensor_name = sensor_name_node.as<std::string>();
95 const YAML::Node& sensor = doc[sensor_name];
98 sensor_map[
"name"] = sensor_name;
99 for (YAML::const_iterator sensor_it = sensor.begin(); sensor_it != sensor.end(); ++sensor_it)
101 sensor_map[sensor_it->first.as<std::string>()] = sensor_it->second.as<std::string>();
104 config.push_back(sensor_map);
109 catch (YAML::ParserException& e)
111 throw std::runtime_error(std::string(
"Error parsing sensors yaml: ") + e.what());
151 emitter << YAML::BeginMap;
152 emitter << YAML::Key <<
"sensors";
153 emitter << YAML::BeginSeq;
156 emitter << YAML::Value << sensor_config[
"name"];
158 emitter << YAML::EndSeq;
161 emitter << YAML::Key << sensor_config[
"name"];
162 emitter << YAML::BeginMap;
163 for (
auto& parameter : sensor_config)
165 if (parameter.first ==
"name")
169 emitter << YAML::Key << parameter.first;
170 emitter << YAML::Value << parameter.second;
172 emitter << YAML::EndMap;
174 emitter << YAML::EndMap;