MC Protocol Serial C++ 0.2.3
MC protocol serial library for MCU-oriented environments
Loading...
Searching...
No Matches
posix_serial.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
9
10namespace mcprotocol::serial {
11
24
30 public:
31 PosixSerialPort() = default;
33
36
38 [[nodiscard]] Status open(const PosixSerialConfig& config) noexcept;
40 void close() noexcept;
41
43 [[nodiscard]] bool is_open() const noexcept;
45 [[nodiscard]] std::intptr_t native_handle() const noexcept;
46
48 [[nodiscard]] Status write_all(std::span<const std::byte> bytes) noexcept;
50 [[nodiscard]] Status read_some(
51 std::span<std::byte> buffer,
52 int timeout_ms,
53 std::size_t& out_size) noexcept;
55 [[nodiscard]] Status flush_rx() noexcept;
57 [[nodiscard]] Status drain_tx() noexcept;
59 [[nodiscard]] Status set_rts(bool enabled) noexcept;
60
61 private:
62 std::intptr_t fd_ = -1;
63};
64
65} // namespace mcprotocol::serial
Minimal blocking host-side serial-port wrapper used by the CLI tools.
Status write_all(std::span< const std::byte > bytes) noexcept
Writes the entire byte range before returning.
PosixSerialPort & operator=(const PosixSerialPort &)=delete
Status drain_tx() noexcept
Waits until queued TX data has physically drained.
Status read_some(std::span< std::byte > buffer, int timeout_ms, std::size_t &out_size) noexcept
Reads up to buffer.size() bytes with a timeout.
bool is_open() const noexcept
Returns whether the serial port is currently open.
PosixSerialPort(const PosixSerialPort &)=delete
Status open(const PosixSerialConfig &config) noexcept
Opens and configures the serial port.
Status set_rts(bool enabled) noexcept
Sets the RTS line when the underlying driver supports it.
void close() noexcept
Closes the serial port if it is open.
Status flush_rx() noexcept
Drops unread RX data that is already buffered by the driver.
std::intptr_t native_handle() const noexcept
Returns the native handle value, or -1 when closed.
Host-side serial-port configuration used by PosixSerialPort.
Result object returned by most public APIs.
Definition status.hpp:26