udp.h
Go to the documentation of this file.
00001 
00009 /*
00010  * libmavconn
00011  * Copyright 2013,2014,2015 Vladimir Ermakov, All rights reserved.
00012  *
00013  * This file is part of the mavros package and subject to the license terms
00014  * in the top-level LICENSE file of the mavros repository.
00015  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
00016  */
00017 
00018 #pragma once
00019 
00020 #include <list>
00021 #include <atomic>
00022 #include <boost/asio.hpp>
00023 #include <mavconn/interface.h>
00024 #include <mavconn/msgbuffer.h>
00025 
00026 namespace mavconn {
00027 
00033 class MAVConnUDP : public MAVConnInterface {
00034 public:
00041         MAVConnUDP(uint8_t system_id = 1, uint8_t component_id = MAV_COMP_ID_UDP_BRIDGE,
00042                         std::string bind_host = "localhost", unsigned short bind_port = 14555,
00043                         std::string remote_host = "", unsigned short remote_port = 14550);
00044         ~MAVConnUDP();
00045 
00046         void close();
00047 
00048         using MAVConnInterface::send_message;
00049         void send_message(const mavlink_message_t *message, uint8_t sysid, uint8_t compid);
00050         void send_bytes(const uint8_t *bytes, size_t length);
00051 
00052         inline bool is_open() { return socket.is_open(); };
00053 
00054 private:
00055         boost::asio::io_service io_service;
00056         std::unique_ptr<boost::asio::io_service::work> io_work;
00057         std::thread io_thread;
00058 
00059         std::atomic<bool> remote_exists;
00060         boost::asio::ip::udp::socket socket;
00061         boost::asio::ip::udp::endpoint remote_ep;
00062         boost::asio::ip::udp::endpoint last_remote_ep;
00063         boost::asio::ip::udp::endpoint bind_ep;
00064 
00065         std::atomic<bool> tx_in_progress;
00066         std::list<MsgBuffer*> tx_q;
00067         uint8_t rx_buf[MsgBuffer::MAX_SIZE];
00068         std::recursive_mutex mutex;
00069 
00070         void do_recvfrom();
00071         void async_receive_end(boost::system::error_code, size_t bytes_transferred);
00072         void do_sendto(bool check_tx_state);
00073         void async_sendto_end(boost::system::error_code, size_t bytes_transferred);
00074 };
00075 
00076 }; // namespace mavconn
00077 


libmavconn
Author(s): Vladimir Ermakov
autogenerated on Sat Jun 8 2019 19:55:13