59 #include <jsoncpp/json/json.h> 71 std::vector<std::string> substrings;
73 std::istringstream ss(s);
74 while (std::getline(ss, part, delimiter))
75 substrings.push_back(part);
92 std::vector<std::string> scandatatypes_hex;
93 scandatatypes_hex.reserve(scandatatypes.size());
94 for(
int type_cnt = 0; type_cnt < scandatatypes.size(); type_cnt++)
96 const std::string & scandatatype = scandatatypes[type_cnt];
97 std::stringstream hex_stream;
98 for(
int char_cnt = 0; char_cnt < scandatatype.size(); char_cnt++)
102 hex_stream << std::setfill(
'0') << std::setw(2) << std::hex << (int)(scandatatype[char_cnt] & 0xFF);
104 scandatatypes_hex.push_back(hex_stream.str());
107 std::ifstream json_file(json_filename);
108 if(!json_file.is_open())
110 ROS_WARN_STREAM(
"## WARNING sick_scan::PcapngJsonParser::parseJsonfile: error reading file \"" << json_filename <<
"\".");
113 ROS_INFO_STREAM(
"sick_scan::PcapngJsonParser: parsing file \"" << json_filename <<
"\"...");
114 Json::Reader json_reader;
115 Json::Value json_root;
116 json_reader.parse(json_file, json_root);
119 for (Json::Value::ArrayIndex json_idx = 0; json_idx != json_root.size(); json_idx++)
121 if(json_root[json_idx].isMember(
"_source") && json_root[json_idx][
"_source"].isMember(
"layers") && json_root[json_idx][
"_source"][
"layers"].isMember(
"tcp"))
123 Json::Value & json_tcp = json_root[json_idx][
"_source"][
"layers"][
"tcp"];
124 std::string tcp_timestamp, tcp_payload;
125 if(json_tcp.isMember(
"Timestamps") && json_tcp[
"Timestamps"].isMember(
"tcp.time_relative"))
126 tcp_timestamp = json_tcp[
"Timestamps"][
"tcp.time_relative"].asString();
127 if(json_tcp.isMember(
"tcp.payload"))
128 tcp_payload = json_tcp[
"tcp.payload"].asString();
130 bool type_check_passed = scandatatypes.empty();
131 for(
int type_cnt = 0; type_check_passed ==
false && type_cnt < scandatatypes_hex.size(); type_cnt++)
133 if(tcp_payload.find(scandatatypes_hex[type_cnt]) != std::string::npos)
134 type_check_passed =
true;
136 if(!type_check_passed)
138 if(tcp_timestamp.size() > 0 && tcp_payload.size() > 4)
141 double msg_timestamp = std::stod(tcp_timestamp) + start_time;
142 std::vector<uint8_t> msg_payload;
143 msg_payload.reserve(tcp_payload.size()/3 + 1);
145 std::istringstream payload_stream(tcp_payload);
146 while (std::getline(payload_stream, hexval,
':'))
148 msg_payload.push_back(std::stoul(hexval, 0, 16) & 0xFF);
156 ROS_INFO_STREAM(
"sick_scan::PcapngJsonParser: " << msg_cnt <<
" messages in file \"" << json_filename <<
"\" successfully parsed.");
159 catch(
const std::exception& e)
161 ROS_WARN_STREAM(
"## WARNING sick_scan::PcapngJsonParser::parseJsonfile: exception \"" << e.what() <<
"\" in file \"" << json_filename <<
"\".");
162 std::cerr << e.what() <<
'\n';
class JsonScanData: utility container for binary scandata incl. timestamp
static bool parseJsonfile(const std::string &json_filename, const std::vector< std::string > &scandatatypes, double start_time, std::vector< sick_scan::JsonScanData > &scandata)
Parses a jsonfile and returns a list of binary scandata messages of given type.
#define ROS_WARN_STREAM(args)
#define ROS_INFO_STREAM(args)
static std::vector< std::string > split(const std::string &s, char delimiter)
Splits a comma separated string into its parts.
static sick_scan::SickScanCommonTcp * s