Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
StreamDefs.hxx
Go to the documentation of this file.
1
34#ifndef _OPENLCB_STREAMDEFS_HXX_
35#define _OPENLCB_STREAMDEFS_HXX_
36
37#include "openlcb/Defs.hxx"
38
39namespace openlcb
40{
41
44{
46 static constexpr uint16_t MAX_PAYLOAD = 0xffff;
48 static constexpr uint8_t INVALID_STREAM_ID = 0xff;
51 static constexpr uint32_t INVALID_TOTAL_BYTE_COUNT = 0xffffffff;
52
53 enum Flags
54 {
55 FLAG_CARRIES_ID = 0x01,
56 FLAG_REJECT_OUT_OF_ORDER = 0x02,
60 FLAG_TEMPORARY_ERROR = 0x20,
61 FLAG_ACCEPT = 0x80,
62 };
63
64 enum AdditionalFlags
65 {
66 REJECT_INFO_LOGGED = 0x01,
67 REJECT_PERMANENT_INVALID_REQUEST = 0x20,
68 REJECT_PERMANENT_SRC_NOT_PERMITTED = 0x40,
69 REJECT_PERMANENT_STREAMS_NOT_ACCEPTED = 0x80,
70 REJECT_TEMPORARY_BUFFER_FULL = 0x20,
71 REJECT_TEMPORARY_OUT_OF_ORDER = 0x40,
72 };
73
76 static constexpr uint16_t STREAM_ACCEPT = ((uint16_t)FLAG_ACCEPT) << 8;
77
80 static constexpr uint16_t STREAM_ERROR_INVALID_ARGS =
81 (((uint16_t)FLAG_PERMANENT_ERROR) << 8) |
82 REJECT_PERMANENT_INVALID_REQUEST;
83
93 static Payload create_initiate_request(uint16_t max_buffer_size,
94 bool has_ident, uint8_t src_stream_id,
95 uint8_t dst_stream_id = INVALID_STREAM_ID)
96 {
97 Payload p(6, 0);
98 p[0] = max_buffer_size >> 8;
99 p[1] = max_buffer_size & 0xff;
100 p[2] = has_ident ? FLAG_CARRIES_ID : 0;
101 p[3] = 0; // flags
102 p[4] = src_stream_id;
103 p[5] = dst_stream_id;
104 return p;
105 }
106
117 static Payload create_initiate_response(uint16_t max_buffer_size,
118 uint8_t src_stream_id, uint8_t dst_stream_id,
119 uint16_t error_code = STREAM_ACCEPT)
120 {
121 Payload p(6, 0);
122 p[0] = max_buffer_size >> 8;
123 p[1] = max_buffer_size & 0xff;
124 p[2] = error_code >> 8;
125 p[3] = error_code & 0xff;
126 p[4] = src_stream_id;
127 p[5] = dst_stream_id;
128 return p;
129 }
130
139 uint8_t src_stream_id, uint8_t dst_stream_id)
140 {
141 Payload p(2, 0);
142 p[0] = src_stream_id;
143 p[1] = dst_stream_id;
144 return p;
145 }
146
156 static Payload create_close_request(uint8_t src_stream_id,
157 uint8_t dst_stream_id, uint32_t total_bytes = INVALID_TOTAL_BYTE_COUNT)
158 {
159 Payload p(total_bytes != INVALID_TOTAL_BYTE_COUNT ? 6 : 2, 0);
160 p[0] = src_stream_id;
161 p[1] = dst_stream_id;
162 if (total_bytes != INVALID_TOTAL_BYTE_COUNT)
163 {
164 p[2] = (total_bytes >> 24) & 0xff;
165 p[3] = (total_bytes >> 16) & 0xff;
166 p[4] = (total_bytes >> 8) & 0xff;
167 p[5] = (total_bytes >> 0) & 0xff;
168 }
169 return p;
170 }
171};
172
173} // namespace openlcb
174
175#endif // _OPENLCB_STREAMDEFS_HXX_
string Payload
Container that carries the data bytes in an NMRAnet message.
Static constants and helper functions for the OpenLCB streaming protocol.
static constexpr uint16_t STREAM_ACCEPT
This code is sent back in the error code field in the stream initiate reply if the stream is accepted...
static constexpr uint8_t INVALID_STREAM_ID
This value is invalid as a source or destination stream ID.
static Payload create_close_request(uint8_t src_stream_id, uint8_t dst_stream_id, uint32_t total_bytes=INVALID_TOTAL_BYTE_COUNT)
Creates the payload for a stream close message.
static constexpr uint16_t STREAM_ERROR_INVALID_ARGS
This code is sent back in the error code field in the stream initiate reply if the stream is rejected...
static constexpr uint32_t INVALID_TOTAL_BYTE_COUNT
Supply this value to the total byte count in stream close to mark it as invalid.
static Payload create_initiate_response(uint16_t max_buffer_size, uint8_t src_stream_id, uint8_t dst_stream_id, uint16_t error_code=STREAM_ACCEPT)
Creates a Stream Initiate Reply message payload.
static Payload create_initiate_request(uint16_t max_buffer_size, bool has_ident, uint8_t src_stream_id, uint8_t dst_stream_id=INVALID_STREAM_ID)
Creates a Stream Initiate Request message payload.
static constexpr uint16_t MAX_PAYLOAD
Maximum window size for stream send.
static Payload create_data_proceed(uint8_t src_stream_id, uint8_t dst_stream_id)
Creates a Stream Data Proceed message payload.