MC Protocol Serial C++ 0.2.3
MC protocol serial library for MCU-oriented environments
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6
8
10
20
21namespace mcprotocol::serial {
22
26#ifndef MCPROTOCOL_SERIAL_MAX_REQUEST_FRAME_BYTES
27#define MCPROTOCOL_SERIAL_MAX_REQUEST_FRAME_BYTES 4096U
28#endif
29
30#ifndef MCPROTOCOL_SERIAL_MAX_RESPONSE_FRAME_BYTES
31#define MCPROTOCOL_SERIAL_MAX_RESPONSE_FRAME_BYTES 4096U
32#endif
33
34#ifndef MCPROTOCOL_SERIAL_MAX_REQUEST_DATA_BYTES
35#define MCPROTOCOL_SERIAL_MAX_REQUEST_DATA_BYTES 3500U
36#endif
37
38#ifndef MCPROTOCOL_SERIAL_MAX_BATCH_WORD_POINTS
39#define MCPROTOCOL_SERIAL_MAX_BATCH_WORD_POINTS 960U
40#endif
41
42#ifndef MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_ASCII
43#define MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_ASCII 7904U
44#endif
45
46#ifndef MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_BINARY
47#define MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_BINARY 3584U
48#endif
49
50#ifndef MCPROTOCOL_SERIAL_MAX_RANDOM_ACCESS_ITEMS
51#define MCPROTOCOL_SERIAL_MAX_RANDOM_ACCESS_ITEMS 192U
52#endif
53
54#ifndef MCPROTOCOL_SERIAL_MAX_MULTI_BLOCK_COUNT
55#define MCPROTOCOL_SERIAL_MAX_MULTI_BLOCK_COUNT 120U
56#endif
57
58#ifndef MCPROTOCOL_SERIAL_MAX_MONITOR_ITEMS
59#define MCPROTOCOL_SERIAL_MAX_MONITOR_ITEMS 192U
60#endif
61
62#ifndef MCPROTOCOL_SERIAL_MAX_LOOPBACK_BYTES
63#define MCPROTOCOL_SERIAL_MAX_LOOPBACK_BYTES 960U
64#endif
65
66#ifndef MCPROTOCOL_SERIAL_ENABLE_RANDOM_COMMANDS
67#define MCPROTOCOL_SERIAL_ENABLE_RANDOM_COMMANDS 1
68#endif
69
70#ifndef MCPROTOCOL_SERIAL_ENABLE_MULTI_BLOCK_COMMANDS
71#define MCPROTOCOL_SERIAL_ENABLE_MULTI_BLOCK_COMMANDS 1
72#endif
73
74#ifndef MCPROTOCOL_SERIAL_ENABLE_MONITOR_COMMANDS
75#define MCPROTOCOL_SERIAL_ENABLE_MONITOR_COMMANDS 1
76#endif
77
78#ifndef MCPROTOCOL_SERIAL_ENABLE_HOST_BUFFER_COMMANDS
79#define MCPROTOCOL_SERIAL_ENABLE_HOST_BUFFER_COMMANDS 1
80#endif
81
82#ifndef MCPROTOCOL_SERIAL_ENABLE_MODULE_BUFFER_COMMANDS
83#define MCPROTOCOL_SERIAL_ENABLE_MODULE_BUFFER_COMMANDS 1
84#endif
85
86#ifndef MCPROTOCOL_SERIAL_ENABLE_CPU_MODEL_COMMANDS
87#define MCPROTOCOL_SERIAL_ENABLE_CPU_MODEL_COMMANDS 1
88#endif
89
90#ifndef MCPROTOCOL_SERIAL_ENABLE_LOOPBACK_COMMANDS
91#define MCPROTOCOL_SERIAL_ENABLE_LOOPBACK_COMMANDS 1
92#endif
93
94#ifndef MCPROTOCOL_SERIAL_ENABLE_ASCII_MODE
95#define MCPROTOCOL_SERIAL_ENABLE_ASCII_MODE 1
96#endif
97
98#ifndef MCPROTOCOL_SERIAL_ENABLE_BINARY_MODE
99#define MCPROTOCOL_SERIAL_ENABLE_BINARY_MODE 1
100#endif
101
102#ifndef MCPROTOCOL_SERIAL_ENABLE_FRAME_C4
103#define MCPROTOCOL_SERIAL_ENABLE_FRAME_C4 1
104#endif
105
106#ifndef MCPROTOCOL_SERIAL_ENABLE_FRAME_C3
107#define MCPROTOCOL_SERIAL_ENABLE_FRAME_C3 1
108#endif
109
110#ifndef MCPROTOCOL_SERIAL_ENABLE_FRAME_C2
111#define MCPROTOCOL_SERIAL_ENABLE_FRAME_C2 1
112#endif
113
114#ifndef MCPROTOCOL_SERIAL_ENABLE_FRAME_C1
115#define MCPROTOCOL_SERIAL_ENABLE_FRAME_C1 1
116#endif
117
118#ifndef MCPROTOCOL_SERIAL_ENABLE_FRAME_E1
119#define MCPROTOCOL_SERIAL_ENABLE_FRAME_E1 1
120#endif
122
145
149 C4,
151 C3,
153 C2,
155 C1,
157 E1
158};
159
161enum class CodeMode : std::uint8_t {
163 Ascii,
165 Binary
166};
167
171 Format1,
173 Format2,
175 Format3,
177 Format4
178};
179
182 IQ_R,
183 IQ_L,
184 Q_L,
185 QnA,
186 A
187};
188
196
199 X,
200 Y,
201 M,
202 L,
203 SM,
204 F,
205 V,
206 B,
207 D,
208 SD,
209 W,
210 TS,
211 TC,
212 TN,
213 STS,
214 STC,
215 STN,
216 CS,
217 CC,
218 CN,
219 SB,
220 SW,
221 S,
222 DX,
223 DY,
224 LTS,
225 LTC,
226 LTN,
227 LSTS,
228 LSTC,
229 LSTN,
230 LCS,
231 LCC,
232 LCN,
233 LZ,
234 Z,
235 R,
236 RD,
237 ZR,
238 G,
239 HG
240};
241
243enum class BitValue : std::uint8_t {
244 Off = 0,
245 On = 1
246};
247
250 DoNotExecuteForcibly = 0x0001,
251 ExecuteForcibly = 0x0003
252};
253
256 DoNotClear = 0x00,
258 AllClear = 0x02
259};
260
263 ReceivedSide = 0x00,
264 X1A = 0x01,
265 X1B = 0x02
266};
267
276};
277
290
314
344
354
365
375
383
391
400
410
418
426
434
442
449
459
465
475
483
493
499
513
519
534
543
551
561
571
577
588
598
606
616
627
637
641 void (*on_tx_begin)(void* user) = nullptr;
643 void (*on_tx_end)(void* user) = nullptr;
645 void* user = nullptr;
646};
647
651using CompletionHandler = void (*)(void* user, Status status);
653
654} // namespace mcprotocol::serial
RemoteOperationMode
Conflict-handling mode for remote RUN / PAUSE.
Definition types.hpp:249
ResponseType
Decoded PLC response class before command-specific parsing.
Definition types.hpp:269
@ SuccessData
Successful response carrying payload bytes.
@ SuccessNoData
Successful response carrying no payload bytes.
DeviceCode
Device-family identifier used by the request codecs.
Definition types.hpp:198
RouteKind
Route layout inside the request header.
Definition types.hpp:190
@ MultidropStation
Multidrop route where the destination station number is encoded in the frame.
@ HostStation
Host-station route with fixed station=0, network=0, and pc=FF.
FrameKind
MC protocol frame family used on the serial link.
Definition types.hpp:147
@ C1
Legacy ASCII serial frame with its own command naming and routing rules.
@ C3
Shorter ASCII serial frame that reuses the C4 payload codec.
@ E1
Legacy frame family used by chapter-18 style command layouts.
@ C4
Chapter-8/10/11/13 oriented serial frame with the fullest feature coverage in this repository.
@ C2
Smallest ASCII serial frame supported by this repository.
GlobalSignalTarget
C24 global-signal selector used by command 1618.
Definition types.hpp:262
BitValue
Logical single-bit value used by bit read/write APIs.
Definition types.hpp:243
constexpr std::size_t kMaxUserFrameRegistrationBytes
Definition types.hpp:143
constexpr std::size_t kMaxMonitorItems
Definition types.hpp:139
constexpr std::size_t kMaxRandomAccessItems
Definition types.hpp:135
constexpr std::size_t kMaxRequestFrameBytes
Definition types.hpp:123
constexpr std::size_t kMaxRequestDataBytes
Definition types.hpp:127
CodeMode
Request/response payload encoding.
Definition types.hpp:161
@ Binary
Compact binary command data and response data.
@ Ascii
Text-encoded command data and response data.
AsciiFormat
ASCII formatting variant for C4 / C3 / C2 serial frames.
Definition types.hpp:169
@ Format1
ENQ/STX/ETX layout without CR/LF.
@ Format4
CR/LF terminated layout often used by host-facing bring-up tools.
@ Format3
STX-only layout commonly used on serial MC links.
@ Format2
Format1 plus a 1-byte block number used for request/response pairing on 2C/3C/4C.
constexpr std::size_t kMaxBatchBitPointsAscii
Definition types.hpp:131
constexpr std::size_t kMaxBatchBitPointsBinary
Definition types.hpp:133
PlcSeries
PLC family selection used for subcommand and device-layout differences.
Definition types.hpp:181
constexpr std::size_t kMaxLoopbackBytes
Definition types.hpp:141
constexpr std::size_t kCpuModelNameLength
Definition types.hpp:144
constexpr std::size_t kMaxMultiBlockCount
Definition types.hpp:137
constexpr std::size_t kMaxBatchWordPoints
Definition types.hpp:129
constexpr std::size_t kMaxResponseFrameBytes
Definition types.hpp:125
void(*)(void *user, Status status) CompletionHandler
Completion callback used by the async client.
Definition types.hpp:651
RemoteRunClearMode
Clear scope applied during remote RUN initialization.
Definition types.hpp:255
Contiguous bit-read request (0401 bit path).
Definition types.hpp:377
std::uint16_t points
Number of bit points to read starting at head_device.
Definition types.hpp:381
DeviceAddress head_device
First bit device in the contiguous range.
Definition types.hpp:379
std::uint16_t points
Number of points to read starting at head_device.
Definition types.hpp:373
DeviceAddress head_device
First device in the contiguous range.
Definition types.hpp:371
Contiguous bit-write request (1401 bit path).
Definition types.hpp:393
DeviceAddress head_device
First bit device in the contiguous write range.
Definition types.hpp:395
std::span< const BitValue > bits
Caller-owned bit data to write starting at head_device.
Definition types.hpp:397
Contiguous word-write request (1401).
Definition types.hpp:385
std::span< const std::uint16_t > words
Caller-owned word data to write starting at head_device.
Definition types.hpp:389
DeviceAddress head_device
First device in the contiguous write range.
Definition types.hpp:387
std::uint16_t model_code
Raw model code returned by the target.
Definition types.hpp:635
std::array< char, kCpuModelNameLength+1 > model_name
Null-terminated CPU model name with trailing spaces already trimmed by the parser.
Definition types.hpp:633
Device code plus numeric address.
Definition types.hpp:348
std::uint32_t number
Numeric index inside the selected device family.
Definition types.hpp:352
DeviceCode code
Device family such as D, M, X, LTN, or LZ.
Definition types.hpp:350
Extended file-register address using block number plus R word number.
Definition types.hpp:359
std::uint16_t block_number
Extended file-register block number.
Definition types.hpp:361
std::uint16_t word_number
Word number inside the selected block.
Definition types.hpp:363
std::uint16_t points
Number of words to read from the file-register range.
Definition types.hpp:408
ExtendedFileRegisterAddress head_device
First block-addressed file-register word to read.
Definition types.hpp:406
Extended file-register batch write (EW on 1C ACPU-common, chapter-18 block path on 1E).
Definition types.hpp:420
ExtendedFileRegisterAddress head_device
First block-addressed file-register word to write.
Definition types.hpp:422
std::span< const std::uint16_t > words
Caller-owned word data to write starting at head_device.
Definition types.hpp:424
Direct extended file-register batch read (NR on 1C QnA-common, chapter-18 direct path on 1E).
Definition types.hpp:412
std::uint16_t points
Number of words to read from the direct file-register range.
Definition types.hpp:416
std::uint32_t head_device_number
NR/NW direct address on 1C or the chapter-18 direct R address on 1E.
Definition types.hpp:414
Direct extended file-register batch write (NW on 1C QnA-common, chapter-18 direct path on 1E).
Definition types.hpp:428
std::uint32_t head_device_number
NR/NW direct address on 1C or the chapter-18 direct R address on 1E.
Definition types.hpp:430
std::span< const std::uint16_t > words
Caller-owned word data to write starting at head_device_number.
Definition types.hpp:432
Extended file-register monitor registration (EM on 1C, chapter-18 on 1E).
Definition types.hpp:444
std::span< const ExtendedFileRegisterAddress > items
Sparse list of block-addressed file-register items to register for monitoring.
Definition types.hpp:446
One item inside extended file-register random write (ET on 1C, chapter-18 on 1E).
Definition types.hpp:436
std::uint16_t value
One word written to device.
Definition types.hpp:440
ExtendedFileRegisterAddress device
Target extended file-register address.
Definition types.hpp:438
C24 global-signal ON/OFF request (1618).
Definition types.hpp:579
GlobalSignalTarget target
Which global signal destination should be controlled.
Definition types.hpp:581
bool turn_on
true for ON, false for OFF.
Definition types.hpp:583
std::uint8_t station_no
Station number encoded in the 1618 specification word.
Definition types.hpp:585
std::uint32_t start_address
Starting host-buffer word address.
Definition types.hpp:594
std::uint16_t word_length
Number of words to read.
Definition types.hpp:596
Host-buffer write request (1613).
Definition types.hpp:600
std::uint32_t start_address
Starting host-buffer word address.
Definition types.hpp:602
std::span< const std::uint16_t > words
Caller-owned words written sequentially from start_address.
Definition types.hpp:604
Module-buffer byte read request (0601 helper path).
Definition types.hpp:608
std::uint16_t bytes
Number of bytes to read.
Definition types.hpp:612
std::uint32_t start_address
Starting module-buffer byte address.
Definition types.hpp:610
std::uint16_t module_number
Module number used by the addressed special-function module.
Definition types.hpp:614
Module-buffer byte write request (1601 helper path).
Definition types.hpp:618
std::uint16_t module_number
Module number used by the addressed special-function module.
Definition types.hpp:622
std::span< const std::byte > bytes
Caller-owned raw bytes written starting at start_address.
Definition types.hpp:624
std::uint32_t start_address
Starting module-buffer byte address.
Definition types.hpp:620
std::span< const RandomReadItem > items
Sparse list of word/dword items to register for a later 0802 read.
Definition types.hpp:540
Parsed layout description for one block returned by parse_multi_block_read_response().
Definition types.hpp:521
std::uint16_t points
Point count copied from the original request.
Definition types.hpp:527
DeviceAddress head_device
Block head device copied from the original request.
Definition types.hpp:525
bool bit_block
Block kind copied from the original request.
Definition types.hpp:523
std::uint16_t data_offset
Offset into the aggregate output storage returned by the parser.
Definition types.hpp:529
std::uint16_t data_count
Number of entries contributed by this block to the aggregate output storage.
Definition types.hpp:531
One block inside native multi-block read (0406).
Definition types.hpp:485
bool bit_block
true for bit blocks, false for word blocks.
Definition types.hpp:491
DeviceAddress head_device
First device in this contiguous block.
Definition types.hpp:487
std::uint16_t points
Number of points in this block.
Definition types.hpp:489
Native multi-block read request composed of multiple contiguous blocks.
Definition types.hpp:495
std::span< const MultiBlockReadBlock > blocks
Ordered block list encoded into the native multi-block read request.
Definition types.hpp:497
One block inside native multi-block write (1406).
Definition types.hpp:501
std::uint16_t points
Point count for this block.
Definition types.hpp:505
std::span< const std::uint16_t > words
Caller-owned word data for word blocks.
Definition types.hpp:509
bool bit_block
true when bits is used, false when words is used.
Definition types.hpp:507
std::span< const BitValue > bits
Caller-owned bit data for bit blocks.
Definition types.hpp:511
DeviceAddress head_device
First device in this contiguous block.
Definition types.hpp:503
Native multi-block write request composed of multiple contiguous blocks.
Definition types.hpp:515
std::span< const MultiBlockWriteBlock > blocks
Ordered block list encoded into the native multi-block write request.
Definition types.hpp:517
Top-level protocol configuration shared by codecs and client requests.
Definition types.hpp:323
bool sum_check_enabled
Enables or disables the ASCII/binary sum-check where that frame family supports it.
Definition types.hpp:338
AsciiFormat ascii_format
Selected ASCII framing flavor when code_mode == CodeMode::Ascii.
Definition types.hpp:329
RouteConfig route
Route header fields used for every encoded request.
Definition types.hpp:340
PlcSeries target_series
PLC family used for device and subcommand differences.
Definition types.hpp:336
CodeMode code_mode
Selected payload encoding inside the frame.
Definition types.hpp:327
FrameKind frame_kind
Selected serial frame family.
Definition types.hpp:325
TimeoutConfig timeout
Request timeout policy used by the async client and stream decoder.
Definition types.hpp:342
bool double_word
true when the item should be encoded as a double-word device access.
Definition types.hpp:457
DeviceAddress device
Target device address for this sparse item.
Definition types.hpp:455
Native random-read request made of sparse word/dword items.
Definition types.hpp:461
std::span< const RandomReadItem > items
Sparse word/dword items encoded in the native random-read request.
Definition types.hpp:463
One bit item inside native random write (1402 bit path).
Definition types.hpp:477
DeviceAddress device
Target bit device address for the sparse write.
Definition types.hpp:479
BitValue value
Bit value written to device.
Definition types.hpp:481
One word or double-word item inside native random write (1402 word path).
Definition types.hpp:467
bool double_word
true when the target is encoded as a double-word write item.
Definition types.hpp:473
std::uint32_t value
One word or double-word value to write.
Definition types.hpp:471
DeviceAddress device
Target device address for the sparse write.
Definition types.hpp:469
Route header fields for serial MC requests.
Definition types.hpp:296
std::uint16_t request_destination_module_io_no
Destination I/O number for the target CPU/module in 3C/4C routing.
Definition types.hpp:306
std::uint8_t network_no
Network number used by routed 3C/4C requests.
Definition types.hpp:302
std::uint8_t self_station_no
Self-station number used when self_station_enabled is true.
Definition types.hpp:312
RouteKind kind
Route interpretation used by the selected frame family.
Definition types.hpp:298
bool self_station_enabled
Enables self-station routing on frame families that support it.
Definition types.hpp:310
std::uint8_t request_destination_module_station_no
Destination station number for the target CPU/module in 3C/4C routing.
Definition types.hpp:308
std::uint8_t pc_no
PLC number field used by 3C/4C and legacy frame families.
Definition types.hpp:304
std::uint8_t station_no
Target station number on multidrop serial links.
Definition types.hpp:300
Optional RS-485 callbacks used by the async client around TX start/end.
Definition types.hpp:639
void * user
Opaque user pointer passed back to both callbacks.
Definition types.hpp:645
void(* on_tx_end)(void *user)
Optional callback fired after TX completion or after cleanup on failure/cancel.
Definition types.hpp:643
void(* on_tx_begin)(void *user)
Optional callback fired immediately before the client expects TX to start.
Definition types.hpp:641
Result object returned by most public APIs.
Definition status.hpp:26
Timeout settings used by the frame decoder and async client.
Definition types.hpp:284
std::uint32_t response_timeout_ms
Maximum wait after TX completion before the request is treated as timed out.
Definition types.hpp:286
std::uint32_t inter_byte_timeout_ms
Maximum allowed idle gap between RX bytes once a response has started.
Definition types.hpp:288
User-frame registration-data delete request (1610, subcommand 0001).
Definition types.hpp:573
std::uint16_t frame_no
User-frame number to clear.
Definition types.hpp:575
std::uint16_t frame_no
User-frame number to read, typically in the documented 0x0000..0x03FF or 0x8001..0x801F ranges.
Definition types.hpp:549
User-frame registration-data payload returned by 0610.
Definition types.hpp:553
std::uint16_t registration_data_bytes
Number of valid bytes in registration_data.
Definition types.hpp:555
std::array< std::byte, kMaxUserFrameRegistrationBytes > registration_data
Raw user-frame registration bytes as returned by the target.
Definition types.hpp:559
std::uint16_t frame_bytes
Optional frame-byte count returned by the target for the registered frame data.
Definition types.hpp:557
User-frame registration-data write request (1610, subcommand 0000).
Definition types.hpp:563
std::span< const std::byte > registration_data
Raw user-frame registration bytes to store.
Definition types.hpp:569
std::uint16_t frame_no
User-frame number to overwrite.
Definition types.hpp:565
std::uint16_t frame_bytes
Frame-byte count encoded into the 1610 payload.
Definition types.hpp:567
#define MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_BINARY
Definition types.hpp:47
#define MCPROTOCOL_SERIAL_MAX_MULTI_BLOCK_COUNT
Definition types.hpp:55
#define MCPROTOCOL_SERIAL_MAX_MONITOR_ITEMS
Definition types.hpp:59
#define MCPROTOCOL_SERIAL_MAX_LOOPBACK_BYTES
Definition types.hpp:63
#define MCPROTOCOL_SERIAL_MAX_BATCH_WORD_POINTS
Definition types.hpp:39
#define MCPROTOCOL_SERIAL_MAX_REQUEST_FRAME_BYTES
Definition types.hpp:27
#define MCPROTOCOL_SERIAL_MAX_BATCH_BIT_POINTS_ASCII
Definition types.hpp:43
#define MCPROTOCOL_SERIAL_MAX_RESPONSE_FRAME_BYTES
Definition types.hpp:31
#define MCPROTOCOL_SERIAL_MAX_RANDOM_ACCESS_ITEMS
Definition types.hpp:51
#define MCPROTOCOL_SERIAL_MAX_REQUEST_DATA_BYTES
Definition types.hpp:35