mavtables  0.2.1
MAVLink router and firewall.
SerialInterface.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 SERIALINTERFACE_HPP_
19 #define SERIALINTERFACE_HPP_
20 
21 
22 #include <chrono>
23 #include <memory>
24 
25 #include "Connection.hpp"
26 #include "ConnectionPool.hpp"
27 #include "Interface.hpp"
28 #include "PacketParser.hpp"
29 #include "SerialPort.hpp"
30 
31 
32 /** A serial port interface.
33  *
34  * An interface (for sending and receiving packets) implementing the serial
35  * port protocol.
36  */
37 class SerialInterface : public Interface
38 {
39  public:
41  std::unique_ptr<SerialPort> port,
42  std::shared_ptr<ConnectionPool> connection_pool,
43  std::unique_ptr<Connection> connection);
44  // LCOV_EXCL_START
45  ~SerialInterface() = default;
46  // LCOV_EXCL_STOP
47  void send_packet(const std::chrono::nanoseconds &timeout) final;
48  void receive_packet(const std::chrono::nanoseconds &timeout) final;
49 
50  protected:
51  std::ostream &print_(std::ostream &os) const final;
52 
53  private:
54  // Variables.
55  std::unique_ptr<SerialPort> port_;
56  std::shared_ptr<ConnectionPool> connection_pool_;
57  std::shared_ptr<Connection> connection_;
58  PacketParser parser_;
59 };
60 
61 
62 #endif // SERIALINTERFACE_HPP_
void receive_packet(const std::chrono::nanoseconds &timeout) final
void send_packet(const std::chrono::nanoseconds &timeout) final
std::ostream & print_(std::ostream &os) const final
~SerialInterface()=default
SerialInterface(std::unique_ptr< SerialPort > port, std::shared_ptr< ConnectionPool > connection_pool, std::unique_ptr< Connection > connection)