Skip to content

Commit c176058

Browse files
committed
Fixed hard-coded host address
1 parent adff7b9 commit c176058

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

pf_driver/include/pf_driver/communication.hpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Connection
7474
return this->port;
7575
}
7676

77+
const std::string get_host_ip()
78+
{
79+
return this->host_address;
80+
}
81+
7782
void set_port(std::string port)
7883
{
7984
this->port = port;
@@ -117,7 +122,7 @@ class Connection
117122

118123
bool is_connected_;
119124
double last_data_time;
120-
std::string ip_address, port;
125+
std::string ip_address, port, host_address;
121126
};
122127

123128
class TCPConnection : public Connection
@@ -185,9 +190,13 @@ class UDPConnection : public Connection
185190
void connect()
186191
{
187192
udp_socket = new boost::asio::ip::udp::socket(io_service, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), atoi(port.c_str())));
188-
port = std::to_string(udp_socket->local_endpoint().port());
189193
udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string(ip_address), atoi(port.c_str()));
190194

195+
udp_socket->connect(udp_endpoint);
196+
197+
port = std::to_string(udp_socket->local_endpoint().port());
198+
host_address = udp_socket->local_endpoint().address().to_string();
199+
191200
is_connected_ = true;
192201
}
193202

pf_driver/include/pf_driver/hardware_interface.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class HardwareInterface
5252
return connection->get_port();
5353
}
5454

55+
const std::string get_host_ip()
56+
{
57+
return connection->get_host_ip();
58+
}
59+
5560
void set_port(std::string port)
5661
{
5762
connection->set_port(port);

pf_driver/include/pf_driver/pf_interface.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ class PF_Interface : public HardwareInterface<ConnectionType>, public DataParser
217217
std::cerr << "Exception: " << e.what() << std::endl;
218218
return HandleInfo();
219219
}
220-
return protocol_interface->request_handle_udp(HardwareInterface<ConnectionType>::get_port(), 'C', 0);
220+
return protocol_interface->request_handle_udp(HardwareInterface<ConnectionType>::get_host_ip(),
221+
HardwareInterface<ConnectionType>::get_port(), 'C', 0);
221222
}
222223
}
223224

pf_driver/include/pf_driver/pfsdp_protocol.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ class PFSDPBase
171171
return handle_info;
172172
}
173173

174-
HandleInfo request_handle_udp(const std::string port, const char packet_type, const int start_angle)
174+
HandleInfo request_handle_udp(const std::string host_ip, const std::string port, const char packet_type, const int start_angle)
175175
{
176-
auto resp = get_request("request_handle_udp", {"handle", "port"}, {KV("address", "10.0.10.1"), KV("port", port)});
176+
auto resp = get_request("request_handle_udp", {"handle", "port"}, {KV("address", host_ip), KV("port", port)});
177177
HandleInfo handle_info;
178178
handle_info.handle = resp["handle"];
179179
handle_info.port = resp["port"];

0 commit comments

Comments
 (0)