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());
28 std::map<std::string, std::string> json_resp =
http_interface->get(keys, command, query);
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)
41 std::map<std::string, std::string> resp =
get_request(command, json_keys, 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" });
150 std::map<std::string, std::string> resp =
get_parameter(param);
153 return std::numeric_limits<std::int64_t>::quiet_NaN();
160 std::map<std::string, std::string> resp =
get_parameter(param);
163 return std::numeric_limits<float>::quiet_NaN();
170 std::map<std::string, std::string> resp =
get_parameter(param);
173 return std::string(
"");
181 if (!packet_type.empty())
183 query[
"packet_type"] = packet_type;
187 query[
"packet_type"] =
config_->packet_type;
189 auto resp =
get_request(
"request_handle_tcp", {
"handle",
"port" }, query);
191 info_->handle = resp[
"handle"];
192 info_->port = resp[
"port"];
200 if (!packet_type.empty())
202 query[
"packet_type"] = packet_type;
206 query[
"packet_type"] =
config_->packet_type;
208 auto resp =
get_request(
"request_handle_udp", {
"handle",
"port" }, query);
209 info_->handle = resp[
"handle"];
216 {
"start_angle",
"packet_type",
"watchdogtimeout",
"skip_scans",
"watchdog",
"max_num_points_scan" },
217 {
KV(
"handle", handle) });
218 config_->packet_type = resp[
"packet_type"];
221 config_->watchdog = (resp[
"watchdog"] ==
"off") ?
false :
true;
234 KV(
"watchdog", config.
watchdog ?
"on" :
"off") };
235 auto resp =
get_request(
"set_scanoutput_config", {
"" }, query);
248 KV(
"max_num_points_scan",
config_->max_num_points_scan),
249 KV(
"watchdogtimeout",
config_->watchdogtimeout),
251 KV(
"watchdog",
config_->watchdog ?
"on" :
"off") };
252 auto resp =
get_request(
"set_scanoutput_config", {
"" }, query);
267 return get_request_bool(
"stop_scanoutput", {
"" }, { {
"handle", handle } });
272 auto resp =
get_request(
"get_scanoutput_config", { param }, {
KV(
"handle", handle) });
283 return std::string(
"");
288 return std::string(
"");
float to_float(const std::string &s)
void set_connection_failure_cb(std::function< void()> callback)
const std::vector< std::string > split(const std::string &str, const char delim=';')
bool is_connection_failure(const std::string &http_error)
bool get_request_bool(const std::string &command, const std::vector< std::string > &json_keys=std::vector< std::string >(), const std::initializer_list< param_type > &query=std::initializer_list< param_type >())
const std::map< std::string, std::string > get_request(const std::string &command, const std::vector< std::string > &json_keys, const std::initializer_list< param_type > &query)
virtual void request_handle_udp(const std::string &packet_type="")
std::string protocol_name
virtual std::string get_part()
virtual void setup_param_server()
std::string get_parameter_str(const std::string ¶m)
std::map< std::string, std::string > param_map_type
const std::vector< std::string > list_parameters()
std::map< std::string, std::string > get_parameter(const Ts &... ts)
bool stop_scanoutput(const std::string &handle)
virtual std::string get_product()
PFSDPBase(std::shared_ptr< HandleInfo > info, std::shared_ptr< ScanConfig > config, std::shared_ptr< ScanParameters > params)
bool feed_watchdog(const std::string &handle)
bool check_error(std::map< std::string, std::string > &mp, const std::string &err_code, const std::string &err_text, const std::string &err_http)
std::int64_t get_parameter_int(const std::string ¶m)
std::shared_ptr< HandleInfo > info_
HTTPInterfacePtr http_interface
std::int64_t to_long(const std::string &s)
bool update_scanoutput_config()
float get_parameter_float(const std::string ¶m)
std::function< void()> handle_connection_failure
virtual void get_scanoutput_config(const std::string &handle)
virtual void get_scan_parameters()
bool set_scanoutput_config(const std::string &handle, const ScanConfig &config)
ProtocolInfo get_protocol_info()
std::shared_ptr< ScanConfig > config_
void request_handle_tcp(const std::string &port="", const std::string &packet_type="")
bool release_handle(const std::string &handle)