Commit 1bb98f77 authored by Lorenz Meier's avatar Lorenz Meier
Browse files

Cleaner network API, make sure we read all bytes on that port!

parent d8ac825e
......@@ -173,14 +173,14 @@ class GazeboMavlinkInterface : public ModelPlugin {
mavlink::msgs::HilGps hil_gps_msg_;
int _fd;
struct sockaddr_in _srcaddr;
struct sockaddr_in _myaddr; ///< The locally bound address
struct sockaddr_in _srcaddr; ///< SITL instance
socklen_t _addrlen;
unsigned char _buf[200];
unsigned char _buf[65535];
struct pollfd fds[1];
struct sockaddr_in _srcaddr_2;
socklen_t _addrlen_2;
struct sockaddr_in _srcaddr_2; ///< MAVROS
//so we dont have to do extra callbacks
double optflow_xgyro;
......
......@@ -122,6 +122,17 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
return;
}
memset((char *)&_myaddr, 0, sizeof(_myaddr));
_myaddr.sin_family = AF_INET;
_myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
// Let the OS pick the port
_myaddr.sin_port = htons(0);
if (bind(_fd, (struct sockaddr *)&_myaddr, sizeof(_myaddr)) < 0) {
printf("bind failed\n");
return;
}
_srcaddr.sin_family = AF_INET;
_srcaddr.sin_addr.s_addr = htonl(INADDR_ANY);
_srcaddr.sin_port = htons(UDP_PORT);
......@@ -132,8 +143,6 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
_addrlen = sizeof(_srcaddr);
_addrlen_2 = sizeof(_srcaddr_2);
fds[0].fd = _fd;
fds[0].events = POLLIN;
}
......@@ -421,7 +430,7 @@ void GazeboMavlinkInterface::pollForMAVLinkMessages()
if (len > 0) {
mavlink_message_t msg;
mavlink_status_t status;
for (int i = 0; i < len; ++i)
for (unsigned i = 0; i < len; ++i)
{
if (mavlink_parse_char(MAVLINK_COMM_0, _buf[i], &msg, &status))
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment