mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Protected Member Functions | List of all members
SerialInterface Class Reference

#include <SerialInterface.hpp>

Inheritance diagram for SerialInterface:
Inheritance graph
Collaboration diagram for SerialInterface:
Collaboration graph

Public Member Functions

 SerialInterface (std::unique_ptr< SerialPort > port, std::shared_ptr< ConnectionPool > connection_pool, std::unique_ptr< Connection > connection)
 
 ~SerialInterface ()=default
 
void send_packet (const std::chrono::nanoseconds &timeout) final
 
void receive_packet (const std::chrono::nanoseconds &timeout) final
 

Protected Member Functions

std::ostream & print_ (std::ostream &os) const final
 

Detailed Description

A serial port interface.

An interface (for sending and receiving packets) implementing the serial port protocol.

Definition at line 37 of file SerialInterface.hpp.

Constructor & Destructor Documentation

◆ SerialInterface()

SerialInterface::SerialInterface ( std::unique_ptr< SerialPort port,
std::shared_ptr< ConnectionPool connection_pool,
std::unique_ptr< Connection connection 
)

Construct a serial port interface using a given device.

Parameters
portThe serial port device to communicate over.
connection_poolThe connection pool to use for sending packets the interface has received and to register the connection with.
connectionThe connection to get packets to send packets from. This will be registered with the given ConnectionPool.
Exceptions
std::invalid_argumentif the serial port device pointer is null.
std::invalid_argumentif the connection_pool pointer is null.
std::invalid_argumentif the connection pointer is null.

Definition at line 39 of file SerialInterface.cpp.

◆ ~SerialInterface()

SerialInterface::~SerialInterface ( )
default

Member Function Documentation

◆ print_()

std::ostream & SerialInterface::print_ ( std::ostream &  os) const
finalprotectedvirtual

Print the interface to the given output stream.

Parameters
osThe output stream to print to.
Returns
The output stream.

Example:

serial {
device /dev/ttyUSB0;
baudrate 115200;
flow_control yes;
}
Parameters
osThe output stream to print to.

Implements Interface.

Definition at line 121 of file SerialInterface.cpp.

◆ receive_packet()

void SerialInterface::receive_packet ( const std::chrono::nanoseconds &  timeout)
finalvirtual

Receive a packet on the interface.

Parameters
timeoutThe maximum amount of time to wait for incoming data.

Reads the data in the serial port's receive buffer or waits for up to timeout until data arrives if no data is present in the serial port buffer.

Implements Interface.

Definition at line 86 of file SerialInterface.cpp.

References PacketParser::parse_byte().

Here is the call graph for this function:

◆ send_packet()

void SerialInterface::send_packet ( const std::chrono::nanoseconds &  timeout)
finalvirtual

Send a packet from one of the interface's connections.

Note
Which connection to take this packet from is not defined but it must not starve any one of the Interface's connections.
Parameters
timeoutThe maximum amount of time to wait for a packet to be available for sending.

Writes up to one packet from the contained connection to the serial port.

Implements Interface.

Definition at line 70 of file SerialInterface.cpp.


The documentation for this class was generated from the following files: