97 bool open(
const std::string& path);
105 bool send(std::span<const uint8_t> bytes);
112 bool send_framed(std::span<const uint8_t> message);
142 std::atomic<ISerialLink::TimerToken>
timer { 0 };
145 using ReaderList = std::vector<std::pair<ReaderToken, std::shared_ptr<SerialReader>>>;
150 std::shared_ptr<Pending>
take_pending(
const std::shared_ptr<Pending>& only = {});
151 [[nodiscard]]
bool is_pending(
const std::shared_ptr<Pending>& request)
const;
std::function< void(EndpointState previous, EndpointState current)> StateCallback
Memory::SnapshotCell< ReaderList > m_readers
std::vector< std::pair< ReaderToken, std::shared_ptr< SerialReader > > > ReaderList
SerialDevice(SerialDevice &&)=delete
Memory::SnapshotCell< std::shared_ptr< Pending > > m_pending
std::unique_ptr< SerialReader > m_reader
bool send_framed(std::span< const uint8_t > message)
Send one message framed the way the spec reads them.
std::function< bool(Transitive::Protocol::Message message)> ReplyMatcher
SerialDevice & operator=(SerialDevice &&)=delete
uint32_t device_id() const
ISerialLink::StateCallback StateCallback
SerialDeviceStats stats() const
std::function< void(SerialReply how, Transitive::Protocol::Message reply)> ReplyCallback
size_t write_backlog() const
Bytes accepted for sending and not yet sent.
std::shared_ptr< Pending > take_pending(const std::shared_ptr< Pending > &only={})
std::unique_ptr< ISerialLink > m_link
std::atomic< ReaderToken > m_next_token
void handle_chunk(std::span< const uint8_t > chunk)
SerialDevice(uint32_t device_id, SerialSpec spec, std::unique_ptr< ISerialLink > link)
void handle_state(EndpointState previous, EndpointState current)
bool set_control_lines(std::optional< bool > dtr, std::optional< bool > rts)
void set_value_callback(ValueCallback callback)
bool open(const std::string &path)
Open the port at path with the spec's line setup.
SerialDevice & operator=(const SerialDevice &)=delete
std::function< void(const InputValue &)> ValueCallback
SerialDevice(const SerialDevice &)=delete
bool complete_request(Transitive::Protocol::Message frame)
const SerialSpec & spec() const
bool send(std::span< const uint8_t > bytes)
Send bytes as they are.
void set_state_callback(StateCallback callback)
EndpointState state() const
ReaderToken add_reader(SerialSpec spec, uint32_t id, ValueCallback callback)
Read the same bytes a second way.
bool request(std::span< const uint8_t > command, ReplyMatcher matcher, std::chrono::milliseconds timeout, ReplyCallback done)
Send a command and wait for its reply.
void close()
Close the port.
void remove_reader(ReaderToken token)
Stop a reader.
Lock-free cell holding one immutable snapshot of a value, read without blocking.
EndpointState
Observable connection state for an endpoint.
SerialReaderStats SerialDeviceStats
SerialReply
How a request ended.
@ REPLIED
A message the matcher accepted arrived.
@ LINK_LOST
The port left OPEN, or the device was closed, before a reply.
@ TIMED_OUT
Nothing matched within the timeout.
std::span< const uint8_t > Message
One complete message.
std::atomic< ISerialLink::TimerToken > timer
What a reader has seen since it was made.
What a serial device is: its line setup, framing and parsing, as a plain value.