17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-30 23:40:29 +01:00
Files
maszyna/hardware/transport/hardware_transport.h
Hirek193 4e3afdd2a6 hardware protocol v2: sessions, subscriptions and the transport worker
Adds the logical protocol layer on top of the frame codec: session
handshake with negotiated frame size, session scoped symbol handles,
state subscriptions with periodic, on change and deadband filtering,
command events with duplicate protection and continuous controls with
stale update rejection, plus per connection rate limits and diagnostics.

A single worker thread owns all of the blocking transport work and
exchanges finished frames with the simulation thread through short locked
queues, so a stalled, flooding or unplugged controller cannot hold up the
simulation.
2026-09-05 20:30:32 +00:00

48 lines
1.4 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <cstdint>
#include <string>
// transport abstraction of the hardware protocol
// the upper layers only ever see a byte stream, which is what lets the same protocol run over
// serial, tcp or rs-485 without changing message semantics
// every method is called from the hardware worker thread only
namespace hardware
{
class hardware_transport
{
public:
// methods
virtual ~hardware_transport() = default;
virtual bool connected() const = 0;
// tries to establish the link, returns true on success
virtual bool connect() = 0;
virtual void disconnect() = 0;
// non-blocking read, returns the number of bytes placed in the buffer or -1 on error
virtual int read( std::uint8_t *Buffer, std::size_t const Size ) = 0;
// non-blocking write, returns the number of bytes accepted or -1 on error
virtual int write( std::uint8_t const *Data, std::size_t const Size ) = 0;
// human readable transport type, i.e. "Serial"
virtual std::string kind() const = 0;
// human readable endpoint, i.e. "COM4 @ 115200"
virtual std::string endpoint() const = 0;
// last error reported by the underlying device
virtual std::string last_error() const = 0;
};
} // namespace hardware