57 bool Start(
const std::string& path);
Transport-neutral CAN frame and the ICanPort interface for port bindings (EspTwaiPort,...
One CAN transport binding.
Definition HfCanPort.h:106
The bus: forwards datagrams between participants.
Definition PipePort.h:46
std::atomic< bool > running_
Definition PipePort.h:73
std::atomic< uint64_t > forwarded_
Definition PipePort.h:74
std::atomic< std::size_t > participants_
Definition PipePort.h:75
PipeHub & operator=(const PipeHub &)=delete
int listen_fd_
Definition PipePort.h:70
bool Start(const std::string &path)
Listen at path (an existing socket file is replaced) and start the hub thread.
Definition PipePort.cpp:157
void Stop()
Stop the thread, close every connection and remove the socket file.
Definition PipePort.cpp:183
int wake_[2]
Definition PipePort.h:71
~PipeHub()
Definition PipePort.cpp:155
uint64_t Forwarded() const noexcept
Datagrams forwarded so far (each counted once per receiver).
Definition PipePort.h:62
std::size_t Participants() const noexcept
Definition PipePort.h:63
void Loop()
Definition PipePort.cpp:197
std::string path_
Definition PipePort.h:69
static constexpr std::size_t kMaxBacklog
Definition PipePort.h:49
bool Running() const noexcept
Definition PipePort.h:60
PipeHub(const PipeHub &)=delete
std::thread thread_
Definition PipePort.h:72
ICanPort over a PipeHub.
Definition PipePort.h:79
void Close()
Stop the I/O thread and disconnect (and stop a hub this port started).
Definition PipePort.cpp:356
std::thread io_
Definition PipePort.h:120
int fd_
Definition PipePort.h:118
PortStatus Status() const override
Error counters and state.
Definition PipePort.cpp:422
PipePort & operator=(const PipePort &)=delete
void IoLoop()
Definition PipePort.cpp:436
bool Open()
Connect (starting a hub if allowed and needed) and start the I/O thread.
Definition PipePort.cpp:337
bool IsOpen() const noexcept
Definition PipePort.h:97
int wake_[2]
Definition PipePort.h:119
bool RxBackpressure() const override
The pipe bus never drops: a refused frame is held and offered again.
Definition PipePort.h:108
bool Deliver(const CanFrame &f)
Definition PipePort.cpp:431
std::unique_ptr< PipeHub > hub_
Definition PipePort.h:117
TxDoneSink tx_sink_
Definition PipePort.h:135
void Wake() const
Definition PipePort.cpp:373
bool HostsHub() const noexcept
True when this port started the hub it uses.
Definition PipePort.h:99
std::atomic< bool > run_
Definition PipePort.h:121
bool Connect()
Definition PipePort.cpp:307
uint16_t seq_
Definition PipePort.h:139
uint32_t epoch_
Definition PipePort.h:140
PortCaps Caps() const override
Static capabilities.
Definition PipePort.cpp:379
void SetTxDoneSink(TxDoneSink sink, void *ctx) override
Install the TX-done sink. Ports without a TX-done event ignore it.
Definition PipePort.cpp:416
std::mutex tx_mu_
Definition PipePort.h:125
void * tx_ctx_
Definition PipePort.h:136
void * rx_ctx_
Definition PipePort.h:134
std::atomic< bool > connected_
Definition PipePort.h:122
PipePort(const PipePort &)=delete
bool tx_was_full_
Definition PipePort.h:129
~PipePort() override
Definition PipePort.cpp:305
bool Recover() override
Request bus-off recovery; false when not possible now.
Definition PipePort.cpp:429
std::vector< CanFrame > tx_ring_
Definition PipePort.h:126
std::size_t tx_head_
Definition PipePort.h:127
std::size_t tx_count_
Definition PipePort.h:128
std::atomic< uint32_t > tx_queue_full_
Definition PipePort.h:138
void SetRxSink(RxSink sink, void *ctx) override
Install the RX sink (nullptr detaches).
Definition PipePort.cpp:410
std::mutex sink_mu_
Definition PipePort.h:132
RxSink rx_sink_
Definition PipePort.h:133
Options opt_
Definition PipePort.h:116
TxResult Send(const CanFrame &frame) override
Queue frame without blocking.
Definition PipePort.cpp:389
Definition EspTwaiPort.cpp:12
TxResult
Result of a non-blocking ICanPort::Send.
Definition HfCanPort.h:85
bool(*)(void *ctx, const CanFrame &frame) RxSink
RX sink; may run in ISR context (copy and return). Returns false if it could not take the frame.
Definition HfCanPort.h:101
void(*)(void *ctx) TxDoneSink
TX-done sink: the port has room again; may run in ISR context.
Definition HfCanPort.h:103
One CAN or CAN FD frame; len is a byte count, never a DLC code.
Definition HfCanPort.h:49
std::size_t tx_queue_frames
Definition PipePort.h:84
bool host_hub_if_absent
start an in-process hub when none answers at path
Definition PipePort.h:83
bool fd
advertise FD frames (64-byte payloads)
Definition PipePort.h:85
std::string path
hub socket path
Definition PipePort.h:82
What a port binding can carry.
Definition HfCanPort.h:76
Error counters and statistics of one port.
Definition HfCanPort.h:91