16 std::shared_ptr<Syntax>
syntax)
36 std::vector<std::string> channels;
38 channelMap = std::unordered_map<std::string, std::shared_ptr<Channel>>();
39 for (std::shared_ptr<Channel> ch : channelList)
41 channels.push_back(ch->chName);
42 channelMap.insert(std::make_pair(ch->chName, ch));
50 for (
auto option : sensorParams.
options)
54 for (
auto param : option.first->params)
60 std::vector<std::string> optionSplit;
61 boost::split(optionSplit, option.first->opt, boost::is_any_of(
" ="));
62 std::vector<std::string> splitParamValues;
63 if (option.second.find(
',') != std::string::npos)
65 boost::split(splitParamValues, option.second, boost::is_any_of(
","));
69 splitParamValues.push_back(option.second);
73 for (std::string optString : optionSplit)
75 if (optString.at(0) ==
'$')
77 std::string paramName = optString.substr(1, std::string::npos);
81 if (valueCounter >= splitParamValues.size())
86 paramName, splitParamValues[valueCounter]);
91 if (option.first->addsRespToGrps)
93 std::vector<std::string> split;
94 boost::split(split, option.first->response, boost::is_any_of(
" "));
95 for (std::string s : split)
99 std::string paramName = s.substr(1, std::string::npos);
100 optionVariableList.push_back(paramName);
101 optionValues.insertParameter(
120 std::vector<std::string> split;
121 boost::split(split, response, boost::is_any_of(
" | "));
123 for (std::string s : split)
125 s.erase(boost::remove_if(s, boost::is_any_of(
" | ")), s.end());
131 if (
syntax->grpErrorsAscii.find(s) !=
syntax->grpErrorsAscii.end() &&
137 " had a faulty value!\n Error Code: " + s);
171 response, byteIndex, byteIndex + typeSize - 1, typeSize, isSigned);
173 if (
syntax->grpErrorsBinary.find(type) !=
syntax->grpErrorsBinary.end())
177 if (
syntax->grpErrorsBinary[type].find(tempValue) !=
178 syntax->grpErrorsBinary[type].end())
182 " had a faulty value!\n Error Code: " +
183 std::to_string(tempValue));
187 std::string val = std::to_string(tempValue);
189 byteIndex += typeSize;
209 std::string& command)
const 216 const std::string& response)
const 229 out = std::numeric_limits<double>::quiet_NaN();
234 if (type.compare(
"int8_t") == 0)
237 throw std::invalid_argument(
"Parameter typename \"" + type +
238 "\" doesn't match given variable type!");
241 out = value *
channelMap.at(name)->conversionFactor;
243 else if (type.compare(
"uint8_t") == 0)
246 throw std::invalid_argument(
"Parameter typename \"" + type +
247 "\" doesn't match given variable type!");
250 out = value *
channelMap.at(name)->conversionFactor;
252 else if (type.compare(
"int16_t") == 0)
255 throw std::invalid_argument(
"Parameter typename \"" + type +
256 "\" doesn't match given variable type!");
259 out = value *
channelMap.at(name)->conversionFactor;
261 else if (type.compare(
"uint16_t") == 0)
264 throw std::invalid_argument(
"Parameter typename \"" + type +
265 "\" doesn't match given variable type!");
266 unsigned short value;
268 out = value *
channelMap.at(name)->conversionFactor;
270 else if (type.compare(
"int32_t") == 0)
273 throw std::invalid_argument(
"Parameter typename \"" + type +
274 "\" doesn't match given variable type!");
277 out = value *
channelMap.at(name)->conversionFactor;
279 else if (type.compare(
"uint32_t") == 0)
282 throw std::invalid_argument(
"Parameter typename \"" + type +
283 "\" doesn't match given variable type!");
286 out = value *
channelMap.at(name)->conversionFactor;
288 else if (type.compare(
"int64_t") == 0)
291 throw std::invalid_argument(
"Parameter typename \"" + type +
292 "\" doesn't match given variable type!");
295 out = value *
channelMap.at(name)->conversionFactor;
297 else if (type.compare(
"uint64_t") == 0)
300 throw std::invalid_argument(
"Parameter typename \"" + type +
301 "\" doesn't match given variable type!");
304 out = value *
channelMap.at(name)->conversionFactor;
306 else if (type.compare(
"float32_t") == 0)
309 throw std::invalid_argument(
"Parameter typename \"" + type +
310 "\" doesn't match given variable type!");
313 out = value *
channelMap.at(name)->conversionFactor;
315 else if (type.compare(
"float64_t") == 0)
318 throw std::invalid_argument(
"Parameter typename \"" + type +
319 "\" doesn't match given variable type!");
322 out = value *
channelMap.at(name)->conversionFactor;
static const std::string ENCODING_B64
SensorGroup()
SensorGroup default constructor.
std::vector< std::pair< std::shared_ptr< CommandOptions >, std::string > > options
const bool verifyResponseOnComand(Command &cmd, const std::string &response) const
Verfy the response on a constructed set sensor group command.
boost::function< void(SensorGroup *)> responseCallback
valueErrorCallbackPtr valueError
The Parameter::ParameterMap class provides a map functionality for Parameter::Parameter objects conta...
const bool isParamInMap(const std::string &name) const
Is a parameter with the given name contained within this map?.
void registerErrorCallback(valueErrorCallbackPtr valueError)
Register a value error function pointer to handle value errors during communication.
The SensorGroupParameter class serves as a data struct to configure SensorGroup objects.
std::shared_ptr< Syntax > syntax
Header file for the SensorGroup class.
std::vector< std::shared_ptr< Channel > > channelList
std::vector< std::string > optionsList
const bool verifyResponse(const Parameter::ParameterMap &inputParams, const std::string &responseOrig, Parameter::ParameterMap &outputParams)
Verifies a given response based on the internal template given all necessary input parameter values...
responseCallback callbackFunction
const bool getChannelValueConverted(const std::string &name, double &value) const
Get a received converted value from a certain channel.
std::unordered_map< std::string, std::shared_ptr< Channel > > channelMap
void insertParameter(const std::string &name, const std::string &type, const T &value, const bool isValid=true)
Insert a new parameter in this map, with the given name, type and value.
static const std::string ENCODING_ASCII
static const std::string ENCODING_HEX
const std::shared_ptr< Parameter > & getParameter(const std::string &name) const
std::vector< std::shared_ptr< Channel > > channels
Parameter::ParameterMap cmdInputParams
Parameter::ParameterMap optionValues
void setParameterValueAsString(const std::string &name, const std::string &input, const bool isValid=true)
Set the value of a parameter in this map with the given name from a string.
void createSensorGroupCommand(Command &cmd, std::string &command) const
Get the generated sensor group command, that can be used to register this sensor group on the serial ...
const std::string & getName() const
Get the name of this sensor group.
std::vector< std::string > optionVariableList
std::string responseEncoding
Parameter::ParameterMap channelValues
void setResponseCallback(responseCallback callbackFunction)
Register a sensor group callback.
The Command class builds the syntactic template for a specific command defined in a CommandParams str...
long base64_decode(const std::string &in, const unsigned int startByteIndex, const unsigned int endByteIndex, const unsigned int size, bool isSigned)
Function decodes a Base64 string and returns the decoded string (or only parts of it) up to a maximum...
void processResponse(const std::string &response)
Parses an incoming sensor group message, extracts contained values and calls the registered sensor gr...
boost::function< void(const std::string &)> valueErrorCallbackPtr
void parseResponse(const std::string &response)
Parse a received sensor channel message and extract channel values, i.e. convert encoded data to "pro...
void generateCommand(const Parameter::ParameterMap &inputParams, std::string &out)
Generates a command string from the internal template given all necessary parameter values...
void getParameterValue(const std::string &name, T &value) const
Get the value of a parameter in this map with the given name.