diff --git a/src/pf_driver/config/r2000_params.yaml b/src/pf_driver/config/r2000_params.yaml index 7896b7c..807046d 100644 --- a/src/pf_driver/config/r2000_params.yaml +++ b/src/pf_driver/config/r2000_params.yaml @@ -2,7 +2,7 @@ pf_r2000: ros__parameters: transport: "udp" scanner_ip: "10.0.10.9" - # port: "3000" # optional + # port: 3000 # optional device: "R2000" start_angle: -1800000 max_num_points_scan: 0 diff --git a/src/pf_driver/config/r2300_params.yaml b/src/pf_driver/config/r2300_params.yaml index d7b65a2..ca317a6 100644 --- a/src/pf_driver/config/r2300_params.yaml +++ b/src/pf_driver/config/r2300_params.yaml @@ -2,7 +2,7 @@ pf_r2300: ros__parameters: transport: "udp" scanner_ip: "169.254.235.110" - # port: "3000" # optional + # port: 3000 # optional start_angle: -450000 max_num_points_scan: 0 packet_type: "C1" diff --git a/src/pf_driver/config/r2300_single_layer_params.yaml b/src/pf_driver/config/r2300_single_layer_params.yaml index 48758a2..3a905a9 100644 --- a/src/pf_driver/config/r2300_single_layer_params.yaml +++ b/src/pf_driver/config/r2300_single_layer_params.yaml @@ -2,7 +2,7 @@ pf_r2300: ros__parameters: transport: "udp" scanner_ip: "169.254.235.110" - # port: "3000" # optional + # port: 3000 # optional start_angle: -450000 max_num_points_scan: 0 packet_type: "C1" diff --git a/src/pf_driver/include/pf_driver/communication/transport.h b/src/pf_driver/include/pf_driver/communication/transport.h index ba94c00..e69f9b1 100644 --- a/src/pf_driver/include/pf_driver/communication/transport.h +++ b/src/pf_driver/include/pf_driver/communication/transport.h @@ -32,12 +32,12 @@ class Transport { } - void set_port(std::string port) + void set_port(int port) { - port_ = std::move(port); + port_ = port; } - std::string get_port() + int get_port() { return port_; } @@ -65,7 +65,7 @@ class Transport protected: std::string address_; std::string host_ip_; - std::string port_; + int port_; bool is_connected_; transport_type type_; std::shared_ptr io_service_; diff --git a/src/pf_driver/include/pf_driver/communication/udp_transport.h b/src/pf_driver/include/pf_driver/communication/udp_transport.h index 0089271..5dbe5cd 100644 --- a/src/pf_driver/include/pf_driver/communication/udp_transport.h +++ b/src/pf_driver/include/pf_driver/communication/udp_transport.h @@ -19,7 +19,7 @@ class UDPTransport : public Transport { public: - UDPTransport(std::string address, std::string port = "0"); + UDPTransport(std::string address, int port = 0); ~UDPTransport(); diff --git a/src/pf_driver/include/pf_driver/pf/handle_info.h b/src/pf_driver/include/pf_driver/pf/handle_info.h index 78fab46..e335c04 100644 --- a/src/pf_driver/include/pf_driver/pf/handle_info.h +++ b/src/pf_driver/include/pf_driver/pf/handle_info.h @@ -9,7 +9,7 @@ struct HandleInfo int handle_type; std::string hostname; - std::string port; + int actual_port; std::string handle; std::string endpoint; }; diff --git a/src/pf_driver/include/pf_driver/pf/http_helpers/curl_resource.h b/src/pf_driver/include/pf_driver/pf/http_helpers/curl_resource.h index ff7cfc7..9ebca15 100644 --- a/src/pf_driver/include/pf_driver/pf/http_helpers/curl_resource.h +++ b/src/pf_driver/include/pf_driver/pf/http_helpers/curl_resource.h @@ -20,7 +20,7 @@ #include #include -#include "pf_driver/pf/http_helpers/param_map_type.h" +#include "pf_driver/pf/http_helpers/param_vector_type.h" #include "pf_driver/pf/http_helpers/param_type.h" class CurlResource @@ -32,7 +32,7 @@ class CurlResource void append_query(const std::initializer_list& list, bool do_encoding = false); - void append_query(const param_map_type& params, bool do_encoding = false); + void append_query(const param_vector_type& params, bool do_encoding = false); void get(Json::Value& json_resp); diff --git a/src/pf_driver/include/pf_driver/pf/http_helpers/http_interface.h b/src/pf_driver/include/pf_driver/pf/http_helpers/http_interface.h index 542bd50..fbd17cc 100644 --- a/src/pf_driver/include/pf_driver/pf/http_helpers/http_interface.h +++ b/src/pf_driver/include/pf_driver/pf/http_helpers/http_interface.h @@ -17,7 +17,7 @@ #include #include "pf_driver/pf/http_helpers/param_type.h" -#include "pf_driver/pf/http_helpers/param_map_type.h" +#include "pf_driver/pf/http_helpers/param_vector_type.h" class CurlResource; @@ -29,7 +29,7 @@ class HTTPInterface const Json::Value get(const std::string& command, const std::initializer_list& list = std::initializer_list()); - const Json::Value get(const std::string& command, const param_map_type& params = param_map_type()); + const Json::Value get(const std::string& command, const param_vector_type& params = param_vector_type()); private: const Json::Value get_(CurlResource& res); diff --git a/src/pf_driver/include/pf_driver/pf/http_helpers/param_map_type.h b/src/pf_driver/include/pf_driver/pf/http_helpers/param_vector_type.h similarity index 86% rename from src/pf_driver/include/pf_driver/pf/http_helpers/param_map_type.h rename to src/pf_driver/include/pf_driver/pf/http_helpers/param_vector_type.h index a71c85e..d3df1e3 100644 --- a/src/pf_driver/include/pf_driver/pf/http_helpers/param_map_type.h +++ b/src/pf_driver/include/pf_driver/pf/http_helpers/param_vector_type.h @@ -14,7 +14,7 @@ #pragma once -#include -#include +#include +#include "param_type.h" -using param_map_type = std::map; +using param_vector_type = std::vector; diff --git a/src/pf_driver/include/pf_driver/pf/pfsdp_base.h b/src/pf_driver/include/pf_driver/pf/pfsdp_base.h index 8152f9a..6314945 100644 --- a/src/pf_driver/include/pf_driver/pf/pfsdp_base.h +++ b/src/pf_driver/include/pf_driver/pf/pfsdp_base.h @@ -24,7 +24,7 @@ #include "pf_driver/pf/http_helpers/http_interface.h" #include "pf_driver/pf/http_helpers/param_type.h" -#include "pf_driver/pf/http_helpers/param_map_type.h" +#include "pf_driver/pf/http_helpers/param_vector_type.h" #include "pf_driver/pf/handle_info.h" #include "pf_driver/pf/scan_config.h" #include "pf_driver/pf/scan_parameters.h" @@ -45,7 +45,7 @@ class PFSDPBase const std::initializer_list& query); const std::map get_request(const std::string& command, const std::vector& json_keys = std::vector(), - const param_map_type& query = param_map_type()); + const param_vector_type& query = param_vector_type()); bool get_request_bool(const std::string& command, const std::vector& json_keys = std::vector(), @@ -100,7 +100,7 @@ class PFSDPBase std::string get_parameter_str(const std::string& param); - void request_handle_tcp(); + void request_handle_tcp(int port = 0); virtual void request_handle_udp(); diff --git a/src/pf_driver/include/pf_driver/pf/scan_config.h b/src/pf_driver/include/pf_driver/pf/scan_config.h index 2500b73..b423f6d 100644 --- a/src/pf_driver/include/pf_driver/pf/scan_config.h +++ b/src/pf_driver/include/pf_driver/pf/scan_config.h @@ -10,6 +10,7 @@ struct ScanConfig int start_angle = 0; uint max_num_points_scan = 0; uint skip_scans = 0; + uint port = 0; // void print() // { diff --git a/src/pf_driver/src/communication/tcp_transport.cpp b/src/pf_driver/src/communication/tcp_transport.cpp index e7a94c3..3909b97 100644 --- a/src/pf_driver/src/communication/tcp_transport.cpp +++ b/src/pf_driver/src/communication/tcp_transport.cpp @@ -26,7 +26,7 @@ bool TCPTransport::connect() try { tcp::resolver resolver(*io_service_); - tcp::resolver::query query(address_, port_); + tcp::resolver::query query(address_, std::to_string(port_)); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; diff --git a/src/pf_driver/src/communication/udp_transport.cpp b/src/pf_driver/src/communication/udp_transport.cpp index f6e6390..7b47422 100644 --- a/src/pf_driver/src/communication/udp_transport.cpp +++ b/src/pf_driver/src/communication/udp_transport.cpp @@ -9,10 +9,10 @@ using boost::asio::ip::udp; auto udp_logger = rclcpp::get_logger("transport"); -UDPTransport::UDPTransport(std::string address, std::string port) : Transport(address, transport_type::udp) +UDPTransport::UDPTransport(std::string address, int port) : Transport(address, transport_type::udp) { io_service_ = std::make_shared(); - udp::endpoint local_endpoint = udp::endpoint(boost::asio::ip::address_v4::from_string("0.0.0.0"), stoi(port)); + udp::endpoint local_endpoint = udp::endpoint(boost::asio::ip::address_v4::from_string("0.0.0.0"), port); socket_ = std::make_unique(*io_service_, local_endpoint); timer_ = std::make_shared(*io_service_.get()); @@ -27,7 +27,7 @@ bool UDPTransport::connect() { udp::endpoint udp_endpoint = udp::endpoint(boost::asio::ip::address::from_string(address_), 0); socket_->connect(udp_endpoint); - port_ = std::to_string(socket_->local_endpoint().port()); + port_ = socket_->local_endpoint().port(); host_ip_ = socket_->local_endpoint().address().to_string(); is_connected_ = true; diff --git a/src/pf_driver/src/pf/http_helpers/curl_resource.cpp b/src/pf_driver/src/pf/http_helpers/curl_resource.cpp index 96fd8ec..705a3d0 100644 --- a/src/pf_driver/src/pf/http_helpers/curl_resource.cpp +++ b/src/pf_driver/src/pf/http_helpers/curl_resource.cpp @@ -23,7 +23,7 @@ void CurlResource::append_query(const std::initializer_list& list, b url_.pop_back(); } -void CurlResource::append_query(const param_map_type& params, bool do_encoding) +void CurlResource::append_query(const param_vector_type& params, bool do_encoding) { url_ += "?"; for (const auto& p : params) diff --git a/src/pf_driver/src/pf/http_helpers/http_interface.cpp b/src/pf_driver/src/pf/http_helpers/http_interface.cpp index 7a4ce4c..9472f9b 100644 --- a/src/pf_driver/src/pf/http_helpers/http_interface.cpp +++ b/src/pf_driver/src/pf/http_helpers/http_interface.cpp @@ -15,7 +15,7 @@ const Json::Value HTTPInterface::get(const std::string& command, const std::init return get_(res); } -const Json::Value HTTPInterface::get(const std::string& command, const param_map_type& params) +const Json::Value HTTPInterface::get(const std::string& command, const param_vector_type& params) { CurlResource res(host); res.append_path(base_path); diff --git a/src/pf_driver/src/pf/pf_interface.cpp b/src/pf_driver/src/pf/pf_interface.cpp index ee87aad..6acf9d2 100644 --- a/src/pf_driver/src/pf/pf_interface.cpp +++ b/src/pf_driver/src/pf/pf_interface.cpp @@ -75,7 +75,7 @@ bool PFInterface::init(std::shared_ptr info, std::shared_ptrhandle_type == HandleInfo::HANDLE_TYPE_UDP) { - transport_ = std::make_unique(info->hostname, info->port); + transport_ = std::make_unique(info->hostname, config->port); if (!transport_->connect()) { RCLCPP_ERROR(node_->get_logger(), "Unable to establish UDP connection"); @@ -83,16 +83,16 @@ bool PFInterface::init(std::shared_ptr info, std::shared_ptrendpoint = transport_->get_host_ip(); - info->port = transport_->get_port(); + info->actual_port = transport_->get_port(); protocol_interface_->request_handle_udp(); } else if (info->handle_type == HandleInfo::HANDLE_TYPE_TCP) { transport_ = std::make_unique(info->hostname); - protocol_interface_->request_handle_tcp(); + protocol_interface_->request_handle_tcp(config->port); // if initially port was not set, request_handle sets it // set the updated port in transport - transport_->set_port(info_->port); + transport_->set_port(info->actual_port); if (!transport_->connect()) { RCLCPP_ERROR(node_->get_logger(), "Unable to establish TCP connection"); diff --git a/src/pf_driver/src/pf/pfsdp_base.cpp b/src/pf_driver/src/pf/pfsdp_base.cpp index 52a76d3..73fb0e7 100644 --- a/src/pf_driver/src/pf/pfsdp_base.cpp +++ b/src/pf_driver/src/pf/pfsdp_base.cpp @@ -62,12 +62,12 @@ const std::map PFSDPBase::get_request(const std::strin const std::vector& json_keys, const std::initializer_list& query) { - return get_request(command, json_keys, param_map_type(query.begin(), query.end())); + return get_request(command, json_keys, param_vector_type(query.begin(), query.end())); } const std::map PFSDPBase::get_request(const std::string& command, const std::vector& json_keys, - const param_map_type& query) + const param_vector_type& query) { Json::Value json_resp = http_interface->get(command, query); @@ -254,29 +254,29 @@ std::string PFSDPBase::get_parameter_str(const std::string& param) return resp[param]; } -void PFSDPBase::request_handle_tcp() +void PFSDPBase::request_handle_tcp(int port) { - param_map_type query; + param_vector_type query; if (!config_->packet_type.empty()) { - query["packet_type"] = config_->packet_type; + query.push_back(KV("packet_type", packet_type)); } - if (info_->port.compare("0") != 0) + if (port != 0) { - query["port"] = info_->port; + query.push_back(KV("port", port)); } auto resp = get_request("request_handle_tcp", { "handle", "port" }, query); info_->handle = resp["handle"]; - info_->port = resp["port"]; + info_->actual_port = parser_utils::to_long(resp["port"]); } -void PFSDPBase::request_handle_udp() +void PFSDPBase::request_handle_udp(const std::string& packet_type) { - param_map_type query = { KV("address", info_->endpoint), KV("port", info_->port) }; + param_vector_type query = { KV("address", info_->endpoint), KV("port", info_->actual_port) }; if (!config_->packet_type.empty()) { - query["packet_type"] = config_->packet_type; + query.push_back(KV("packet_type", config_->packet_type)); } auto resp = get_request("request_handle_udp", { "handle", "port" }, query); info_->handle = resp["handle"]; @@ -298,23 +298,23 @@ void PFSDPBase::get_scanoutput_config(const std::string& handle) bool PFSDPBase::update_scanoutput_config() { - param_map_type query = { KV("handle", info_->handle) }; + param_vector_type query = { KV("handle", info_->handle) }; - query.insert(KV("start_angle", config_->start_angle)); + query.push_back(KV("start_angle", config_->start_angle)); if (!config_->packet_type.empty()) { - query.insert(KV("packet_type", config_->packet_type)); + query.push_back(KV("packet_type", config_->packet_type)); } - query.insert(KV("max_num_points_scan", config_->max_num_points_scan)); - query.insert(KV("skip_scans", config_->skip_scans)); + query.push_back(KV("max_num_points_scan", config_->max_num_points_scan)); + query.push_back(KV("skip_scans", config_->skip_scans)); if (config_->watchdogtimeout != 0) { - query.insert(KV("watchdogtimeout", config_->watchdogtimeout)); + query.push_back(KV("watchdogtimeout", config_->watchdogtimeout)); } if (config_->watchdog == false) { /* Force watchdog off. Otherwise (if watchdog==true), use scanner default */ - query.insert(KV("watchdog", "off")); + query.push_back(KV("watchdog", "off")); } auto resp = get_request("set_scanoutput_config", { "" }, query); @@ -395,7 +395,7 @@ bool PFSDPBase::reconfig_callback_impl(const std::vector& par } else if (parameter.get_name() == "port") { - info_->port = parameter.value_to_string(); + config_->port = parameter.as_int(); } else if (parameter.get_name() == "transport") { diff --git a/src/pf_driver/src/ros/ros_main.cpp b/src/pf_driver/src/ros/ros_main.cpp index a198d67..b5b75da 100644 --- a/src/pf_driver/src/ros/ros_main.cpp +++ b/src/pf_driver/src/ros/ros_main.cpp @@ -16,7 +16,6 @@ int main(int argc, char* argv[]) std::string device; std::string transport_str; std::string scanner_ip; - std::string port("0"); /* 0 means: automatic */ std::string topic("/scan"); std::string frame_id("scanner_link"); std::string packet_type; /* empty means: use scanner default */ @@ -55,7 +54,7 @@ int main(int argc, char* argv[]) node->declare_parameter("port", port); } node->get_parameter("port", port); - RCLCPP_INFO(node->get_logger(), "port: %s", port.c_str()); + RCLCPP_INFO(node->get_logger(), "port: %d", port); if (!node->has_parameter("start_angle")) { @@ -143,9 +142,11 @@ int main(int argc, char* argv[]) info->handle_type = transport_str == "udp" ? HandleInfo::HANDLE_TYPE_UDP : HandleInfo::HANDLE_TYPE_TCP; info->hostname = node->get_parameter("scanner_ip").get_parameter_value().get(); - info->port = node->get_parameter("port").get_parameter_value().get(); + info->actual_port = -1; std::shared_ptr config = std::make_shared(); + + config->port = node->get_parameter("port").get_parameter_value().get(); config->start_angle = node->get_parameter("start_angle").get_parameter_value().get(); config->max_num_points_scan = node->get_parameter("max_num_points_scan").get_parameter_value().get(); config->skip_scans = node->get_parameter("skip_scans").get_parameter_value().get(); diff --git a/src/pf_driver/tests/pipeline.cpp b/src/pf_driver/tests/pipeline.cpp index b37ef57..a691314 100644 --- a/src/pf_driver/tests/pipeline.cpp +++ b/src/pf_driver/tests/pipeline.cpp @@ -49,7 +49,7 @@ TEST(PFPipeline_TestSuite, testPipelineReadWrite) bool net_fail = false; std::unique_ptr transport = std::make_unique("127.0.0.1"); - transport->set_port("1234"); + transport->set_port(1234); if (transport->connect()) {