mavtables
0.2.1
MAVLink router and firewall.
|
#include <UnixSerialPort.hpp>
Public Types | |
enum | Parity { NONE, ODD, EVEN, MARK, SPACE } |
enum | Feature { DEFAULT = 0, FLOW_CONTROL = 1 << 0 } |
Public Member Functions | |
UnixSerialPort (std::string device, unsigned long baud_rate=9600, SerialPort::Feature features=SerialPort::DEFAULT, std::unique_ptr< UnixSyscalls > syscalls=std::make_unique< UnixSyscalls >()) | |
virtual | ~UnixSerialPort () |
virtual std::vector< uint8_t > | read (const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero()) final |
virtual void | write (const std::vector< uint8_t > &data) final |
virtual void | read (std::back_insert_iterator< std::vector< uint8_t >> it, const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero()) |
virtual void | write (std::vector< uint8_t >::const_iterator first, std::vector< uint8_t >::const_iterator last) |
Protected Member Functions | |
std::ostream & | print_ (std::ostream &os) const final |
A unix serial port.
Definition at line 34 of file UnixSerialPort.hpp.
|
inherited |
Feature bitflags.
Enumerator | |
---|---|
DEFAULT | No special features. |
FLOW_CONTROL | Enable flow control. |
Definition at line 59 of file SerialPort.hpp.
|
inherited |
Parity options.
Enumerator | |
---|---|
NONE | No parity. |
ODD | Odd parity, must have odd number of set bits. |
EVEN | Even parity, must have even number of set bits. |
MARK | Fill parity bit with 1. |
SPACE | Fill parity bit with 0. |
Definition at line 49 of file SerialPort.hpp.
UnixSerialPort::UnixSerialPort | ( | std::string | device, |
unsigned long | baud_rate = 9600 , |
||
SerialPort::Feature | features = SerialPort::DEFAULT , |
||
std::unique_ptr< UnixSyscalls > | syscalls = std::make_unique<UnixSyscalls>() |
||
) |
Construct a serial port.
device | The string representing the serial port. For example "/dev/ttyUSB0". |
baud_rate | The baud rate in bits per second, the default value is 9600 bps. |
features | A bitflag of the features to enable, default is to not enable any features. See SerialPort::Feature for flags. |
syscalls | The object to use for unix system calls. It is default constructed to the production implementation. This argument is only used for testing. |
std::invalid_argument | if the baud rate is not supported. |
std::system_error | if a system call produces an error. |
Definition at line 47 of file UnixSerialPort.cpp.
|
virtual |
The serial port destructor.
Closes the underlying file descriptor of the serial port device.
Definition at line 64 of file UnixSerialPort.cpp.
|
finalprotectedvirtual |
Print the serial port to the given output stream.
os | The output stream to print to. |
Example:
os | The output stream to print to. |
Reimplemented from SerialPort.
Definition at line 360 of file UnixSerialPort.cpp.
References SerialPort::FLOW_CONTROL.
|
finalvirtual |
Read data from the serial port.
timeout
is not guaranteed to be up to nanosecond precision, the actual precision is up to the operating system's implementation but is guaranteed to have at least millisecond precision.timeout | How long to wait for data to arrive on the serial port if there is not already data to read. The default is to not wait. |
std::system_error | if a system call produces an error. |
Reimplemented from SerialPort.
Definition at line 77 of file UnixSerialPort.cpp.
|
virtualinherited |
Read data from the serial port.
timeout
is not guaranteed to be up to nanosecond precision, the actual precision is up to the operating system's implementation but is guaranteed to have at least millisecond precision.it | A back insert iterator to read bytes into. |
timeout | How long to wait for data to arrive on the serial port if there is not already data to read. The default is to not wait. |
Definition at line 65 of file SerialPort.cpp.
References SerialPort::read().
|
finalvirtual |
Write data to the serial port (blocking write).
data | The bytes to send. |
std::system_error | if a system call produces an error. |
PartialSendError | if it fails to write all the data it is given. |
Reimplemented from SerialPort.
Definition at line 118 of file UnixSerialPort.cpp.
|
virtualinherited |
Write data to the serial port (blocking write).
first | Iterator to first byte in range to send. |
last | Iterator to one past the last byte to send. |
Definition at line 89 of file SerialPort.cpp.
References SerialPort::write().