MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SerialBackend.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "StreamBackend.hpp"
4
5#include <asio/serial_port.hpp>
6
7namespace MayaFlux::Core {
8
9/**
10 * @struct SerialTransport
11 * @brief StreamBackend policy for serial ports
12 *
13 * An endpoint opens the device named by remote_path with the line setup in
14 * EndpointInfo::serial. The port opens synchronously, so open_endpoint returns 0
15 * for a port that cannot be opened, unless the backend reconnects, in which case
16 * the endpoint waits in RECONNECTING until the device appears. AUTO framing is
17 * NONE: each read is delivered as one message and a send writes its payload as
18 * it is.
19 *
20 * Baud rates outside asio's table go through the platform: termios2 on Linux and
21 * IOSSIOSPEED on macOS, and Windows accepts any value. DTR and RTS are driven
22 * after the open, which asserts both, so a board that restarts on DTR sees the
23 * open itself. The endpoint then stays OPENING for settle_ms before any read, and
24 * input received before it opens is discarded.
25 */
27 using Stream = asio::serial_port;
29
30 static constexpr bool listens = false;
33 static constexpr std::string_view label = "Serial";
34 static constexpr std::string_view name = "Serial (Asio)";
35
36 static asio::error_code open(Stream& port, const EndpointInfo& info);
37 static std::chrono::milliseconds settle_time(const EndpointInfo& info);
38 static void ready(Stream& port, const EndpointInfo& info);
39 static bool set_control_lines(Stream& port, std::optional<bool> dtr, std::optional<bool> rts);
40 static bool send_break(Stream& port);
41 static std::string describe(const EndpointInfo& info);
42 static std::string peer_label(const EndpointInfo& info);
43};
44
45/**
46 * @class SerialBackend
47 * @brief Byte stream transport over serial ports via standalone Asio
48 *
49 * One serial device path is one endpoint, with the connection model, outbox,
50 * reconnection and state callbacks of StreamBackend, plus DTR, RTS and break
51 * through INetworkBackend. See SerialTransport for how a port is opened.
52 *
53 * @code
54 * EndpointInfo port;
55 * port.transport = NetworkTransport::SERIAL;
56 * port.remote_path = "/dev/ttyACM0";
57 * port.serial.baud_rate = 31250;
58 * port.serial.dtr_on_open = false;
59 * auto id = serial.open_endpoint(port);
60 * @endcode
61 */
63
64#ifdef MAYAFLUX_EXPORTS
65extern template class StreamBackend<SerialTransport>;
66#else
67extern template class MAYAFLUX_API StreamBackend<SerialTransport>;
68#endif
69
70} // namespace MayaFlux::Core
Connection-oriented reliable message transport over an Asio stream protocol.
NetworkTransport
Identifies the transport protocol a backend implements.
StreamBackend< SerialTransport > SerialBackend
FramingPolicy
How messages are delimited on the wire.
Describes one logical send/receive endpoint managed by a backend.
Configuration for the serial port transport backend.
static constexpr bool listens
static constexpr FramingPolicy automatic_framing
static constexpr std::string_view label
static std::string peer_label(const EndpointInfo &info)
static std::chrono::milliseconds settle_time(const EndpointInfo &info)
static constexpr std::string_view name
static asio::error_code open(Stream &port, const EndpointInfo &info)
static void ready(Stream &port, const EndpointInfo &info)
static bool set_control_lines(Stream &port, std::optional< bool > dtr, std::optional< bool > rts)
static bool send_break(Stream &port)
static std::string describe(const EndpointInfo &info)
StreamBackend policy for serial ports.