63 #if 0 // debugging and unittest
64 class SickScanParseUtilUnittest
67 SickScanParseUtilUnittest()
73 std::string sopas_reply =
"sRA LMPscancfg \\x00\\x00\\x03\\x20\\x00\\x01\\x00\\x00\\x09\\xc4\\x00\\x00\\x00\\x00\\x00\\x36\\xee\\x80\\x00\\x00\\x09\\xc4\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x09\\xc4\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x09\\xc4\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00";
76 std::cerr <<
"## ERROR SickScanParseUtil::SopasToLMPscancfg failed: " << scancfg.
print() << std::endl;
78 std::cout <<
"SickScanParseUtil::SopasToLMPscancfg success: " << scancfg.
print() << std::endl;
79 std::string sopas_cmd;
81 std::cerr <<
"## ERROR SickScanParseUtil::LMPscancfgToSopas failed: \"" << sopas_cmd <<
"\"" << std::endl;
83 std::cout <<
"SickScanParseUtil::LMPscancfgToSopas success: \"" << sopas_cmd <<
"\"" << std::endl;
86 static SickScanParseUtilUnittest selftester = SickScanParseUtilUnittest();
87 #endif // debugging and unittest
92 while(angle_rad > angle_max)
93 angle_rad -= (2 * M_PI);
94 while(angle_rad < angle_min)
95 angle_rad += (2 * M_PI);
102 std::istringstream config_stream(pose_xyz_rpy_str);
103 std::string config_arg;
104 std::vector<float> config_values;
105 while (getline(config_stream, config_arg,
','))
109 std::string::size_type n = 0;
110 while ((n = config_arg.find(
'\\', n)) != std::string::npos)
111 config_arg.replace( n, 1,
"");
114 float arg_value = std::stof(config_arg);
115 config_values.push_back(arg_value);
117 catch(
const std::exception& e)
119 ROS_ERROR_STREAM(
"## ERROR sick_scan_xd::parsePose(): parse error in string \"" << pose_xyz_rpy_str <<
"\", arg=\"" << config_arg <<
"\", exception " << e.what());
122 return config_values;
125 template<
typename T>
static bool convertBin(
const std::string& sopas_string,
size_t& offset, T& value)
128 if (sopas_string.size() >= offset + 4 *
sizeof(value))
130 for (
int byte_cnt = 0; byte_cnt <
sizeof(value); byte_cnt++)
132 std::string hex_str = sopas_string.substr(offset + 4 * byte_cnt + 2, 2);
133 unsigned long cur_byte = std::stoul(hex_str,
nullptr, 16);
134 value = (value << 8) | (cur_byte & 0xFF);
136 offset += 4 *
sizeof(value);
141 ROS_WARN_STREAM(
"## ERROR in SickScanParseUtil::convertBin(\"" << sopas_string <<
"\", offset=" << offset <<
", sizeof(value)=" <<
sizeof(value) <<
"): value not readable, reached end of string");
149 for (
int byte_cnt = (
int)
sizeof(value) - 1; byte_cnt >= 0; byte_cnt--)
151 s <<
"\\x" << std::setfill(
'0') << std::setw(2) << std::hex << ((value >> 8 * byte_cnt) & 0xFF);
158 std::stringstream scancfg_msg;
160 for (
int sector_cnt = 0; sector_cnt <
sector_cfg.size(); sector_cnt++)
162 scancfg_msg <<
", angular_resolution[" << sector_cnt <<
"]=" <<
sector_cfg[sector_cnt].angular_resolution
163 <<
", start_angle[" << sector_cnt <<
"]=" <<
sector_cfg[sector_cnt].start_angle
164 <<
", stop_angle[" << sector_cnt <<
"]=" <<
sector_cfg[sector_cnt].stop_angle;
166 return scancfg_msg.str();
179 std::vector<std::string> sopas_reply_ids = {
"sRA LMPscancfg " ,
"sAN mLMPsetscancfg " };
180 if (strncmp(sopas_reply.data(), sopas_reply_ids[0].data(), sopas_reply_ids[0].size()) == 0)
182 offset = sopas_reply_ids[0].size();
184 else if (strncmp(sopas_reply.data(), sopas_reply_ids[1].data(), sopas_reply_ids[1].size()) == 0)
187 offset = sopas_reply_ids[1].size();
188 uint8_t status_code = 0;
190 if (status_code != 0)
191 ROS_WARN_STREAM(
"SickScanParseUtil::SopasToLMPscancfg(): status code " << (uint32_t)(status_code) <<
" in reply: \"" << sopas_reply <<
"\" indicates an ERROR");
195 ROS_WARN_STREAM(
"## ERROR in SickScanParseUtil::SopasToLMPscancfg: \"" << sopas_reply <<
"\" not supported");
200 int max_sector_cnt = 4;
202 for (
int sector_cnt = 0; success ==
true && sector_cnt < max_sector_cnt && offset < sopas_reply.length(); sector_cnt++)
212 ROS_WARN_STREAM(
"## ERROR in LMPscancfg reply: \"" << sopas_reply <<
"\"");
213 ROS_WARN_STREAM(
"## SickScanParseUtil::SopasToLMPscancfg(): convertBin() failed with " << scancfg.
print());
232 std::stringstream sopas_hex;
233 sopas_hex <<
"\x02sMN mLMPsetscancfg ";
236 for (
int sector_cnt = 0; sector_cnt < scancfg.
sector_cfg.size(); sector_cnt++)
243 sopas_cmd = sopas_hex.str();