10#define kDefaultName "ttyS0"
12constexpr auto kDefaultName =
"COM1";
18 enum class Parity { kNone, kOdd, kEven };
20 enum class NumStopBits { kOne, kTwo };
47 friend bool operator<=(
const PortInfo& lhs,
const PortInfo& rhs) {
return !(rhs < lhs); }
48 friend bool operator>(
const PortInfo& lhs,
const PortInfo& rhs) {
return rhs < lhs; }
49 friend bool operator>=(
const PortInfo& lhs,
const PortInfo& rhs) {
return !(lhs < rhs); }
104 std::string parity_string;
108 parity_string =
"none";
111 parity_string =
"odd";
114 parity_string =
"even";
118 <<
"Name: " << obj.
port_name << std::endl
119 <<
"Baud rate: " << obj.
baud_rate << std::endl
120 <<
"Parity: " << parity_string << std::endl
121 <<
"Number of stop bits: " << (obj.
num_stop_bits == NumStopBits::kOne ?
"one" :
"two") << std::endl
123 <<
"Timeout [s]: " << obj.
timeout_s << std::endl
129 using IoException = std::runtime_error;
Holds information about a port.
Definition types.h:24
PortInfo(const std::string &long_name, const std::string &short_name)
Constructor initializing info.
Definition types.h:30
friend bool operator<(const PortInfo &lhs, const PortInfo &rhs)
Overloaded relational operators that allow sorting PortInfo objects by their short name.
Definition types.h:46
std::string short_name
short_name Short name of the port (e.g. "COM1" or "/dev/ttyS0")
Definition types.h:34
PortInfo()=default
Default constructor.
friend std::ostream & operator<<(std::ostream &os, const PortInfo &obj)
Overloaded stream output operator to display port information.
Definition types.h:36
std::string long_name
The long name of the port (same as short name on Linux)
Definition types.h:32
Describes the settings of a port.
Definition types.h:54
NumStopBits num_stop_bits
Number of stop bits.
Definition types.h:78
friend std::ostream & operator<<(std::ostream &os, const Settings &obj)
Overloaded stream output operator.
Definition types.h:102
Parity parity
Parity.
Definition types.h:76
unsigned long timeout_s
Timeout in seconds.
Definition types.h:82
bool hardware_flow_control
Hardware flow control.
Definition types.h:80
int baud_rate
Baud rate.
Definition types.h:74
Settings()=default
Default constructor.
unsigned long timeout_ms
Timeout in milliseconds.
Definition types.h:84
friend bool operator==(const Settings &lhs, const Settings &rhs)
Overloaded equality operator.
Definition types.h:86
Settings(const std::string &port_name, const int baud_rate, const Parity parity, const NumStopBits num_stop_bits, const bool hardware_flow_control, const unsigned long timeout_s, const unsigned long timeout_ms)
Constructor initializing the settings.
Definition types.h:65
friend bool operator!=(const Settings &lhs, const Settings &rhs)
Overloaded inequality operator.
Definition types.h:97
std::string port_name
Name of the port.
Definition types.h:72