serial.h
Go to the documentation of this file.
1 
9 /*
10  * libmavconn
11  * Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
12  *
13  * This file is part of the mavros package and subject to the license terms
14  * in the top-level LICENSE file of the mavros repository.
15  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
16  */
17 
18 #pragma once
19 
20 #include <atomic>
21 #include <boost/asio.hpp>
22 #include <mavconn/interface.h>
23 #include <mavconn/msgbuffer.h>
24 
25 namespace mavconn {
30  public std::enable_shared_from_this<MAVConnSerial> {
31 public:
32  static constexpr auto DEFAULT_DEVICE = "/dev/ttyACM0";
33  static constexpr auto DEFAULT_BAUDRATE = 57600;
34 
41  MAVConnSerial(uint8_t system_id = 1, uint8_t component_id = MAV_COMP_ID_UDP_BRIDGE,
42  std::string device = DEFAULT_DEVICE, unsigned baudrate = DEFAULT_BAUDRATE, bool hwflow = false);
43  virtual ~MAVConnSerial();
44 
45  void close() override;
46 
47  void send_message(const mavlink::mavlink_message_t *message) override;
48  void send_message(const mavlink::Message &message, const uint8_t source_compid) override;
49  void send_bytes(const uint8_t *bytes, size_t length) override;
50 
51  inline bool is_open() override {
52  return serial_dev.is_open();
53  }
54 
55 private:
56  boost::asio::io_service io_service;
57  std::thread io_thread;
58  boost::asio::serial_port serial_dev;
59 
60  std::atomic<bool> tx_in_progress;
61  std::deque<MsgBuffer> tx_q;
62  std::array<uint8_t, MsgBuffer::MAX_SIZE> rx_buf;
63  std::recursive_mutex mutex;
64 
65  void do_read();
66  void do_write(bool check_tx_state);
67 };
68 } // namespace mavconn
virtual ~MAVConnSerial()
Definition: serial.cpp:122
boost::asio::io_service io_service
Definition: serial.h:56
std::thread io_thread
Definition: serial.h:57
static constexpr auto MAV_COMP_ID_UDP_BRIDGE
Same as mavlink::common::MAV_COMPONENT::COMP_ID_UDP_BRIDGE.
Definition: interface.h:45
std::array< uint8_t, MsgBuffer::MAX_SIZE > rx_buf
Definition: serial.h:62
void close() override
Close connection.
Definition: serial.cpp:127
Generic mavlink interface.
Definition: interface.h:97
MAVConn class interface.
void send_bytes(const uint8_t *bytes, size_t length) override
Send raw bytes (for some quirks)
Definition: serial.cpp:147
MAVConn message buffer class (internal)
static constexpr auto DEFAULT_DEVICE
Definition: serial.h:32
boost::asio::serial_port serial_dev
Definition: serial.h:58
std::deque< MsgBuffer > tx_q
Definition: serial.h:61
static constexpr auto DEFAULT_BAUDRATE
Definition: serial.h:33
bool is_open() override
Definition: serial.h:51
std::atomic< bool > tx_in_progress
Definition: serial.h:60
MAVConnSerial(uint8_t system_id=1, uint8_t component_id=MAV_COMP_ID_UDP_BRIDGE, std::string device=DEFAULT_DEVICE, unsigned baudrate=DEFAULT_BAUDRATE, bool hwflow=false)
Definition: serial.cpp:40
Serial interface.
Definition: serial.h:29
void send_message(const mavlink::mavlink_message_t *message) override
Send message (mavlink_message_t)
void do_write(bool check_tx_state)
Definition: serial.cpp:224
std::recursive_mutex mutex
Definition: serial.h:63


libmavconn
Author(s): Vladimir Ermakov
autogenerated on Tue Jun 1 2021 02:36:21