12 : configPath(configPath)
25 syntax.
endOfMessage = node[
"end_of_message"].as<std::string>();
26 syntax.
endOfFrame = node[
"end_of_frame"].as<std::string>();
27 syntax.
textMsgPrefix = node[
"text_msg_prefix"].as<std::string>();
30 node[
"channel_group_msg_prefix"].as<std::string>();
31 syntax.
cmdErrorPrefix = node[
"cmd_error_prefix"].as<std::string>();
32 syntax.
genErrorPrefix = node[
"gen_error_prefix"].as<std::string>();
33 syntax.
optionsPrefix = node[
"options_prefix"].as<std::string>();
34 const YAML::Node& errorAsciiNode = node[
"grp_errors_ascii"];
35 if (errorAsciiNode.IsSequence() && errorAsciiNode.size() > 0)
37 for (
auto item : errorAsciiNode)
42 const YAML::Node& errorBinaryNode = node[
"grp_errors_binary"];
43 if (errorBinaryNode.IsSequence() && errorBinaryNode.size() > 0)
45 for (
auto item : errorBinaryNode)
48 if (item.IsSequence() && item.size() > 0)
51 std::unordered_set<unsigned int> errorSet;
52 for (
auto item2 : item)
56 errorSet.insert(item2.as<
unsigned int>());
61 type = item2.as<std::string>();
74 serialParams.
baudRate = node[
"baudrate"].as<
unsigned int>();
75 serialParams.
deviceTag = node[
"device_tag"].as<std::string>();
76 serialParams.
serialTimeout = node[
"serial_timeout"].as<
unsigned int>();
77 serialParams.
maxLineLength = node[
"max_line_length"].as<
unsigned int>();
79 node[
"serial_devices_folder"].as<std::string>();
85 std::unordered_map<std::string, std::shared_ptr<Channel>>&
channels)
88 ch.
chName = node[
"ch_name"].as<std::string>();
89 ch.
dataType = node[
"datatype"].as<std::string>();
92 if (node[
"conversion_factor"].IsScalar() &&
93 !node[
"conversion_factor"].IsNull())
97 channels.insert(std::make_pair(ch.
chName, std::make_shared<Channel>(ch)));
102 const YAML::Node& node,
103 std::unordered_map<std::string, std::shared_ptr<CommandOptions>>&
options)
106 cmdOpt.
optName = node[
"name"].as<std::string>();
107 cmdOpt.
optHasParams = node[
"opt_has_params"].as<
bool>();
109 cmdOpt.
addsRespToGrps = node[
"adds_response_to_groups"].as<
bool>();
110 if (node[
"opt"].IsScalar() && !node[
"opt"].IsNull())
112 cmdOpt.
opt = node[
"opt"].as<std::string>();
114 if (node[
"response"].IsScalar() && !node[
"response"].IsNull())
116 cmdOpt.
response = node[
"response"].as<std::string>();
118 const YAML::Node& paramsNode = node[
"params"];
119 if (paramsNode.IsSequence() && paramsNode.size() > 0)
121 for (
auto item : paramsNode)
123 std::string param = item.as<std::string>();
124 std::vector<std::string> split;
125 boost::split(split, param, boost::is_any_of(
":"));
126 std::string type = split[0];
127 std::string name = split[1];
128 cmdOpt.
params.push_back(std::make_pair(name, type));
132 std::make_pair(cmdOpt.
optName, std::make_shared<CommandOptions>(cmdOpt)));
139 cmd.
name = node[
"cmd_name"].as<std::string>();
142 cmd.
respHasParams = node[
"response_contains_params"].as<
bool>();
143 if (node[
"command"].IsScalar() && !node[
"command"].IsNull())
145 cmd.
cmd = node[
"command"].as<std::string>();
147 if (node[
"response"].IsScalar() && !node[
"response"].IsNull())
149 cmd.
response = node[
"response"].as<std::string>();
151 const YAML::Node& paramsNode = node[
"params"];
152 if (paramsNode.IsSequence() && paramsNode.size() > 0)
154 for (
auto item : paramsNode)
156 std::string param = item.as<std::string>();
157 std::vector<std::string> split;
158 boost::split(split, param, boost::is_any_of(
":"));
159 std::string type = split[0];
160 std::string name = split[1];
161 cmd.
params.push_back(std::make_pair(name, type));
173 grp.
grpNumber = node[
"grp_nr"].as<
unsigned int>();
174 if (node[
"name"].IsScalar() && !node[
"name"].IsNull())
176 grp.
grpName = node[
"name"].as<std::string>();
180 grp.
grpName =
"Unspecified Group";
182 const YAML::Node& channelNode = node[
"channels"];
183 if (channelNode.IsSequence() && channelNode.size() > 0)
185 for (
auto item : channelNode)
187 std::string channelName = item.as<std::string>();
192 const YAML::Node& optionsNode = node[
"options"];
193 if (optionsNode.IsSequence() && optionsNode.size() > 0)
195 for (
auto item : optionsNode)
197 std::string option = item.as<std::string>();
198 std::string name =
"";
199 std::string params =
"";
200 if (option.find(
':') != std::string::npos)
202 std::vector<std::string> split;
203 boost::split(split, option, boost::is_any_of(
":"));
215 std::string encoding = node[
"encoding"].as<std::string>();
228 YAML::Node interfaceYaml =
229 YAML::LoadFile(
configPath +
"serial_interface_config.yml");
235 YAML::Node syntaxYaml = YAML::LoadFile(
configPath +
"general_syntax.yml");
241 YAML::Node channelsYaml = YAML::LoadFile(
configPath +
"channels.yml");
243 for (
auto node : channelsYaml)
251 YAML::Node commandOpt = YAML::LoadFile(
configPath +
"command_options.yml");
253 for (
auto node : commandOpt)
261 YAML::Node commandsYaml = YAML::LoadFile(
configPath +
"commands.yml");
263 for (
auto node : commandsYaml)
271 YAML::Node groupsYaml = YAML::LoadFile(
configPath +
"sensor_groups.yml");
273 for (
auto node : groupsYaml)
281 return std::make_shared<Syntax>(
syntax);
283 const std::shared_ptr<SerialInterfaceParams>
286 return std::make_shared<SerialInterfaceParams>(
serialParams);
289 const std::unordered_map<std::string, std::shared_ptr<Command>>&
295 const std::unordered_map<unsigned char, std::shared_ptr<SensorGroup>>&
static const std::string ENCODING_B64
Header file for the CommunicationConfig class.
std::vector< std::pair< std::shared_ptr< CommandOptions >, std::string > > options
unsigned int serialTimeout
CommunicationConfig()
CommunicationConfig default constructor.
std::unordered_map< std::string, std::shared_ptr< Command > > commands
void insertSensorGroup(const YAML::Node &node)
Parses SensorGroup parameters from a YAML::Node and inserts a new SensorGroup object into the SensorG...
std::unordered_map< std::string, std::unordered_set< unsigned int > > grpErrorsBinary
The Channel class serves as a data struct to store sensor channel parameter.
The Syntax class serves as a data struct to provide information about important symbols for the commu...
void readSensorGroups()
Parses all SensorGroup definitions from file.
friend void operator>>(const YAML::Node &node, Syntax &syntax)
Assing operator for YAML::Node to Syntax object.
std::string textMsgPrefix
The SensorGroupParameter class serves as a data struct to configure SensorGroup objects.
The SensorGroup class builds the syntactic template for its specific command that results from the se...
void readOptions()
Parses all CommandOptions definitions from file.
void insertCommand(const YAML::Node &node)
Parses Command parameters from a YAML::Node and inserts a new Command object into the Command map...
std::string answerOnCmdPrefix
void readGeneralSyntax()
Parses Syntax defnition from file.
std::string genErrorPrefix
std::string optionsPrefix
std::string channelGrpMsgPrefix
void readChannels()
Parses all Channel defnitions from file.
void readSerialInterfaceConfig()
Parses serial interface coniguration from file.
The CommandOptions class serves as a data struct to inform Command objects about all modifiers that c...
std::unordered_map< std::string, std::shared_ptr< CommandOptions > > options
unsigned int maxLineLength
const std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > & getSensorGroups() const
SensorGroup map object getter.
The SerialInterfaceParams class serves as a data struct to configure the setup of a serial connection...
static const std::string ENCODING_ASCII
static const std::string ENCODING_HEX
const std::shared_ptr< SerialInterfaceParams > getSerialInterfaceParams() const
SerialInterfaceParams object getter.
std::vector< std::shared_ptr< Channel > > channels
std::vector< std::pair< std::string, std::string > > params
std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > sensorGroups
std::unordered_map< std::string, std::shared_ptr< Channel > > channels
std::unordered_set< std::string > grpErrorsAscii
std::string serialDevicesFolder
The CommandParams class serves as a data struct to configure Command objects.
const std::shared_ptr< Syntax > getSyntax() const
Syntax object getter.
std::vector< std::pair< std::string, std::string > > params
SerialInterfaceParams serialParams
The Command class builds the syntactic template for a specific command defined in a CommandParams str...
void readCommands()
Parses all Command definitions from file.
std::string cmdErrorPrefix
const std::unordered_map< std::string, std::shared_ptr< Command > > & getCommands() const
Command map getter.