Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
StreamTransport.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_STREAMTRANSPORT_HXX_
36#define _OPENLCB_STREAMTRANSPORT_HXX_
37
39#include "utils/Queue.hxx"
40
41#include <inttypes.h>
42
43namespace openlcb
44{
45
46class StreamSender;
47class IfCan;
48class If;
49
52{
53public:
57 StreamTransport(If *iface);
58
61
66 {
67 int ret = -1;
68 for (int i = 0; i < MAX_SEND_STREAM_ID && ret < 0; ++i)
69 {
70 if ((inUseSendStreamIds_ & (1u << nextSendStreamId_)) == 0)
71 {
74 }
76 {
78 }
79 }
80 return ret & 0xFF;
81 }
82
85 void release_send_stream_id(uint8_t stream_id)
86 {
87 inUseSendStreamIds_ &= ~(1u << stream_id);
88 }
89
99
104 {
105 return nextReceiveStreamId_++;
106 }
107
108protected:
111
112private:
114 static constexpr uint8_t MAX_SEND_STREAM_ID = 26;
117 unsigned inUseSendStreamIds_ : 27;
119 unsigned nextSendStreamId_ : 5;
120
121protected:
123 uint8_t nextReceiveStreamId_{0x50};
124};
125
128{
129public:
134 StreamTransportCan(IfCan *iface, unsigned num_senders);
135
138};
139
140} // namespace openlcb
141
142#endif // _OPENLCB_STREAMTRANSPORT_HXX_
Base class of everything with a virtual destructor.
Strongly typed queue class with asynchronous access.
Definition Queue.hxx:406
Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard.
Definition IfCan.hxx:65
Abstract class representing an OpenLCB Interface.
Definition If.hxx:185
CAN-specific implementation of the stream transport interface.
Collects the objects needed to support streams on an OpenLCB interface.
uint8_t nextReceiveStreamId_
Stream ID to be given out to the next stream receiver that we create.
static constexpr uint8_t MAX_SEND_STREAM_ID
Largest stream ID we will be using for transmit stream's local IDs.
TypedQAsync< StreamSender > * sender_allocator()
Stream sender flows.
unsigned nextSendStreamId_
Index of the next bit to check in the inUseSendStreamIds_.
TypedQAsync< StreamSender > senders_
Stream Sender objects.
void release_send_stream_id(uint8_t stream_id)
unsigned inUseSendStreamIds_
Bits are 1 if the respective stream ID is in use (for transmit streams).