mavtables  0.2.1
MAVLink router and firewall.
UnixSerialPort.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef UNIXSERIALPORT_HPP_
19 #define UNIXSERIALPORT_HPP_
20 
21 
22 #include <chrono>
23 #include <iterator>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "SerialPort.hpp"
29 #include "UnixSyscalls.hpp"
30 
31 
32 /** A unix serial port.
33  */
34 class UnixSerialPort : public SerialPort
35 {
36  public:
38  std::string device,
39  unsigned long baud_rate = 9600,
41  std::unique_ptr<UnixSyscalls> syscalls =
42  std::make_unique<UnixSyscalls>());
43  virtual ~UnixSerialPort();
44  virtual std::vector<uint8_t> read(
45  const std::chrono::nanoseconds &timeout =
46  std::chrono::nanoseconds::zero()) final;
47  virtual void write(const std::vector<uint8_t> &data) final;
48 
49  protected:
50  std::ostream &print_(std::ostream &os) const final;
51 
52  private:
53  // Variables
54  std::string device_;
55  unsigned long baud_rate_;
56  SerialPort::Feature features_;
57  std::unique_ptr<UnixSyscalls> syscalls_;
58  int port_;
59  // Methods
60  void configure_port_(
61  unsigned long baud_rate, SerialPort::Feature features);
62  void open_port_();
63  std::vector<uint8_t> read_();
64  speed_t speed_constant_(unsigned long baud_rate);
65 };
66 
67 
68 #endif // UNIXSERIALPORT_HPP_
No special features.
Definition: SerialPort.hpp:61
virtual ~UnixSerialPort()
virtual void write(const std::vector< uint8_t > &data) final
virtual std::vector< uint8_t > read(const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero()) final
std::ostream & print_(std::ostream &os) const final
UnixSerialPort(std::string device, unsigned long baud_rate=9600, SerialPort::Feature features=SerialPort::DEFAULT, std::unique_ptr< UnixSyscalls > syscalls=std::make_unique< UnixSyscalls >())