63 #include <boost/algorithm/string.hpp> 72 "sINVALID",
"sRN",
"sRA",
"sMN",
"sAN",
"sMA",
"sWN",
"sWA",
"sEN",
"sEA",
"sSN",
"sFA" 80 {
"", sINVALID}, {
"sINVALID", sINVALID}, {
"sRN", sRN}, {
"sRA", sRA}, {
"sMN", sMN}, {
"sAN", sAN}, {
"sMA", sMA}, {
"sWN", sWN}, {
"sWA", sWA}, {
"sEN", sEN}, {
"sEA", sEA}, {
"sSN", sSN}, {
"sFA", sFA}
101 const std::string & command_name,
const std::vector<std::string> & parameter)
103 sick_scan::SickLocColaTelegramMsg cola_telegram;
104 cola_telegram.header.stamp =
ROS::now();
105 cola_telegram.command_type = command_type;
106 cola_telegram.command_name = command_name;
107 cola_telegram.parameter = parameter;
108 return cola_telegram;
133 std::string cola_ascii_cmd;
145 std::vector<std::string> cola_parts;
146 boost::split(cola_parts, cola_ascii_cmd, boost::algorithm::is_space());
147 if(cola_parts.size() < 2)
149 ROS_WARN_STREAM(
"## ERROR Parse error in ColaParser::decodeColaTelegram(\"" << cola_ascii_cmd <<
"\"): to few arguments, at least command_type and command_name required");
156 ROS_WARN_STREAM(
"## ERROR Parse error in ColaParser::decodeColaTelegram(\"" << cola_ascii_cmd <<
"\"): invalid command_type \"" << cola_parts[0] <<
"\"");
160 if(cola_parts[1].empty())
162 ROS_WARN_STREAM(
"## ERROR Parse error in ColaParser::decodeColaTelegram(\"" << cola_ascii_cmd <<
"\"): invalid command_name \"" << cola_parts[1] <<
"\"");
166 sick_scan::SickLocColaTelegramMsg cola_telegram =
createColaTelegram(command_type, cola_parts[1]);
167 if(cola_parts.size() > 2)
169 cola_telegram.parameter.reserve(cola_parts.size() - 2);
170 for(
size_t n = 2; n < cola_parts.size(); n++)
171 cola_telegram.parameter.push_back(cola_parts[n]);
173 return cola_telegram;
186 cola_ascii.reserve(64*1024);
190 cola_ascii += cola_telegram.command_name;
191 for(
size_t n = 0; n < cola_telegram.parameter.size(); n++)
193 if( n == 0 || parameter_is_ascii)
195 cola_ascii += cola_telegram.parameter[n];
209 const std::vector<std::string> & parameter,
bool parameter_is_ascii)
233 std::map<std::string, sick_scan::ColaParser::COLA_SOPAS_COMMAND>::const_iterator iter_command_type =
s_command_type_map.find(sopas_command);
250 base = ((cola_arg.find_first_of(
"+-") != std::string::npos) ? 10 : 16);
251 return std::stoi(cola_arg, 0, base);
253 catch(
const std::exception & exc)
255 ROS_WARN_STREAM(
"## ERROR ColaParser::convertColaArg(" << cola_arg <<
") failed, exception " << exc.what());
257 return default_value;
272 base = ((cola_arg.find_first_of(
"+-") != std::string::npos) ? 10 : 16);
273 return (uint32_t)std::stoul(cola_arg, 0, base);
275 catch(
const std::exception & exc)
277 ROS_WARN_STREAM(
"## ERROR ColaParser::convertColaArg(" << cola_arg <<
") failed, exception " << exc.what());
279 return default_value;
static std::vector< uint8_t > encodeColaTelegram(const sick_scan::SickLocColaTelegramMsg &cola_telegram, bool parameter_is_ascii=true)
Encodes and returns a Cola Binary telegram from ros message SickLocColaTelegramMsg.
static sick_scan::SickLocColaTelegramMsg decodeColaTelegram(const std::vector< uint8_t > &cola_binary)
Decodes and returns a Cola message of type SickLocColaTelegramMsg from a Cola-Binary telegram...
static const std::string s_cola_ascii_end_tag
All Cola-ACSII telegrams start with s_cola_ascii_start_tag := "<ETX>" ("End of TeXt") ...
static const std::string s_command_type_string[MAX_COLA_COMMAND_NUMBER]
static table to convert COLA_SOPAS_COMMAND to string, f.e. s_command_type_string[sRN]:="sRN", s_command_type_string[sRA]:="sRA" and so on
enum sick_scan::ColaParser::COLA_SOPAS_COMMAND_ENUM COLA_SOPAS_COMMAND
Enumeration of SOPAS commands in cola telegrams: The command_type in SickLocColaTelegramMsg is one of...
uninitialized, command_type should never have this value)
Number of possible COLA_SOPAS_COMMANDs incl. invalid command.
#define ROS_WARN_STREAM(args)
static std::string convertSopasCommand(COLA_SOPAS_COMMAND command_type)
Converts and returns a COLA_SOPAS_COMMAND to string. Example: convertSopasCommand(sMN) returns "sMN"...
static int32_t convertColaArg(const std::string &cola_arg, int base=10, int32_t default_value=0)
static sick_scan::SickLocColaTelegramMsg createColaTelegram(const COLA_SOPAS_COMMAND &command_type, const std::string &command_name, const std::vector< std::string > ¶meter=std::vector< std::string >())
Creates and returns a Cola telegram (type SickLocColaTelegramMsg).
static std::string ConvertColaAscii(const std::vector< uint8_t > &cola_telegram)
Converts and returns a Cola-ASCII telegram to string.
static const std::string s_cola_ascii_start_tag
All Cola-ACSII telegrams start with s_cola_ascii_start_tag := "<STX>" ("Start of TeXt") ...
static bool convertColaResponseBool(const std::string &cola_response_arg, bool default_value)
static const std::map< std::string, COLA_SOPAS_COMMAND > s_command_type_map
static map to convert COLA_SOPAS_COMMANDs from string to enum, f.e. s_command_type_map["sRN"]:=sRN, s_command_type_map["sRA"]:=sRA and so on