serial.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 
00031 class MAVConnSerial : public MAVConnInterface {
00032 public:
00039         MAVConnSerial(uint8_t system_id = 1, uint8_t component_id = MAV_COMP_ID_UDP_BRIDGE,
00040                         std::string device = "/dev/ttyACM0", unsigned baudrate = 57600);
00041         ~MAVConnSerial();
00042 
00043         void close();
00044 
00045         using MAVConnInterface::send_message;
00046         void send_message(const mavlink_message_t *message, uint8_t sysid, uint8_t compid);
00047         void send_bytes(const uint8_t *bytes, size_t length);
00048 
00049         inline bool is_open() { return serial_dev.is_open(); };
00050 
00051 private:
00052         boost::asio::io_service io_service;
00053         std::thread io_thread;
00054         boost::asio::serial_port serial_dev;
00055 
00056         std::atomic<bool> tx_in_progress;
00057         std::list<MsgBuffer*> tx_q;
00058         uint8_t rx_buf[MsgBuffer::MAX_SIZE];
00059         std::recursive_mutex mutex;
00060 
00061         void do_read();
00062         void async_read_end(boost::system::error_code, size_t bytes_transferred);
00063         void do_write(bool check_tx_state);
00064         void async_write_end(boost::system::error_code, size_t bytes_transferred);
00065 };
00066 
00067 }; // namespace mavconn
00068 


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