7 std::shared_ptr<ScanParameters> params)
8 : http_interface(new
HTTPInterface(info->hostname,
"cmd")), info_(info), config_(
config), params_(params)
13 const std::vector<std::string>& json_keys,
14 const std::initializer_list<param_type>& query)
20 const std::vector<std::string>& json_keys,
23 const std::string err_code =
"error_code";
24 const std::string err_text =
"error_text";
25 const std::string err_http =
"error_http";
26 std::vector<std::string> keys = { err_code, err_text };
27 keys.insert(keys.end(), json_keys.begin(), json_keys.end());
30 if (!
check_error(json_resp, err_code, err_text, err_http))
32 return std::map<std::string, std::string>();
39 const std::initializer_list<param_type>& query)
51 std::string error_1 =
"Failed to connect to ";
52 std::string error_2 =
"No route to host";
54 if (http_error.find(error_1) != std::string::npos && http_error.find(error_2) != std::string::npos)
62 const std::string& err_text,
const std::string& err_http)
64 const std::string http_error = mp[err_http];
65 const std::string code = mp[err_code];
66 const std::string text = mp[err_text];
74 if (http_error.compare(std::string(
"OK")))
76 std::cerr <<
"HTTP ERROR: " << http_error << std::endl;
89 if (!code.compare(
"--COULD NOT RETRIEVE VALUE--") || !text.compare(
"--COULD NOT RETRIEVE VALUE--"))
91 std::cout <<
"Invalid command or parameter requested." << std::endl;
95 if (code.compare(
"0") || text.compare(
"success"))
97 std::cout <<
"protocol error: " << code <<
" " << text << std::endl;
110 auto resp =
get_request(
"list_parameters", {
"parameters" });
126 get_request(
"release_handle", {
"" }, {
KV(
"handle", handle) });
133 auto resp =
get_request(
"get_protocol_info", {
"protocol_name",
"version_major",
"version_minor",
"commands" });
153 return std::numeric_limits<std::int64_t>::quiet_NaN();
163 return std::numeric_limits<float>::quiet_NaN();
173 return std::string(
"");
181 if (!packet_type.empty())
183 query[
"packet_type"] = packet_type;
187 query[
"packet_type"] =
config_->packet_type;
191 query[
"port"] = port;
193 else if (
info_->port.compare(
"0") != 0)
195 query[
"port"] =
info_->port;
197 auto resp =
get_request(
"request_handle_tcp", {
"handle",
"port" }, query);
199 info_->handle = resp[
"handle"];
200 info_->port = resp[
"port"];
208 if (!packet_type.empty())
210 query[
"packet_type"] = packet_type;
214 query[
"packet_type"] =
config_->packet_type;
216 auto resp =
get_request(
"request_handle_udp", {
"handle",
"port" }, query);
217 info_->handle = resp[
"handle"];
224 {
"start_angle",
"packet_type",
"watchdogtimeout",
"skip_scans",
"watchdog",
"max_num_points_scan" },
225 {
KV(
"handle", handle) });
226 config_->packet_type = resp[
"packet_type"];
229 config_->watchdog = (resp[
"watchdog"] ==
"off") ?
false :
true;
237 KV(
"start_angle",
config.start_angle),
238 KV(
"packet_type",
config.packet_type),
239 KV(
"max_num_points_scan",
config.max_num_points_scan),
240 KV(
"watchdogtimeout",
config.watchdogtimeout),
241 KV(
"skip_scans",
config.skip_scans),
242 KV(
"watchdog",
config.watchdog ?
"on" :
"off") };
243 auto resp =
get_request(
"set_scanoutput_config", {
"" }, query);
256 KV(
"max_num_points_scan",
config_->max_num_points_scan),
257 KV(
"watchdogtimeout",
config_->watchdogtimeout),
259 KV(
"watchdog",
config_->watchdog ?
"on" :
"off") };
260 auto resp =
get_request(
"set_scanoutput_config", {
"" }, query);
275 return get_request_bool(
"stop_scanoutput", {
"" }, { {
"handle", handle } });
280 auto resp =
get_request(
"get_scanoutput_config", {
param }, {
KV(
"handle", handle) });
291 return std::string(
"");
296 return std::string(
"");