76[[nodiscard]]
constexpr char ascii_upper(
char value)
noexcept {
77 return (value >=
'a' && value <=
'z') ?
static_cast<char>(value - (
'a' -
'A')) : value;
82 std::uint32_t& out_value,
88 std::uint32_t value = 0U;
89 for (
char ch : text) {
90 std::uint32_t digit = 0U;
91 if (ch >=
'0' && ch <=
'9') {
92 digit =
static_cast<std::uint32_t
>(ch -
'0');
93 }
else if (base == 16 && ch >=
'A' && ch <=
'F') {
94 digit =
static_cast<std::uint32_t
>(ch -
'A' + 10);
95 }
else if (base == 16 && ch >=
'a' && ch <=
'f') {
96 digit =
static_cast<std::uint32_t
>(ch -
'a' + 10);
101 if (digit >=
static_cast<std::uint32_t
>(base)) {
105 value =
static_cast<std::uint32_t
>(value *
static_cast<std::uint32_t
>(base) + digit);
133 config.target_series = series;
134 config.sum_check_enabled =
true;
136 config.route.station_no = 0x00;
137 config.route.network_no = 0x00;
138 config.route.pc_no = 0xFF;
139 config.route.request_destination_module_io_no = 0x03FF;
140 config.route.request_destination_module_station_no = 0x00;
141 config.route.self_station_enabled =
false;
142 config.route.self_station_no = 0x00;
143 config.timeout.response_timeout_ms = 5000;
144 config.timeout.inter_byte_timeout_ms = 250;
155 config.target_series = series;
156 config.sum_check_enabled =
false;
158 config.route.station_no = 0x00;
159 config.route.network_no = 0x00;
160 config.route.pc_no = 0xFF;
161 config.route.request_destination_module_io_no = 0x03FF;
162 config.route.request_destination_module_station_no = 0x00;
163 config.route.self_station_enabled =
false;
164 config.route.self_station_no = 0x00;
165 config.timeout.response_timeout_ms = 5000;
166 config.timeout.inter_byte_timeout_ms = 250;
220 if (text.size() <= spec.prefix_length) {
224 bool prefix_match =
true;
225 for (std::size_t index = 0; index < spec.prefix_length; ++index) {
227 if (lhs != spec.prefix[index]) {
228 prefix_match =
false;
236 std::uint32_t number = 0;
254 std::uint16_t points,
271 std::uint16_t points,
323 bool double_word =
false) noexcept {
341 bool double_word =
false) noexcept {
380 if (out_items.size() < specs.size()) {
384 for (std::size_t index = 0; index < specs.size(); ++index) {
413 .
items = request.items,
423 if (out_items.size() < specs.size()) {
432 specs[index].double_word);
447 if (out_items.size() < specs.size()) {
constexpr size_type size() const noexcept
constexpr bool is_double_word_device(DeviceCode code) noexcept
bool parse_u32(std::string_view text, std::uint32_t &out_value, int base) noexcept
constexpr char ascii_upper(char value) noexcept
constexpr std::array< DeviceParseSpec, 39 > kDeviceParseSpecs
Status make_random_write_word_items(std::span< const RandomWriteWordSpec > specs, std::span< RandomWriteWordItem > out_items, std::span< const RandomWriteWordItem > &out_item_view) noexcept
Builds sparse random word-write items from string-address specs.
Status make_random_write_word_item(std::string_view device, std::uint32_t value, RandomWriteWordItem &out_item, bool double_word=false) noexcept
Builds one sparse random word-write item from a string address.
constexpr ProtocolConfig make_c4_binary_protocol(PlcSeries series=PlcSeries::Q_L) noexcept
Returns a practical default for Q/L-era Format5 / Binary / C4.
Status make_random_read_request(std::span< const RandomReadSpec > specs, std::span< RandomReadItem > out_items, RandomReadRequest &out_request) noexcept
Builds a sparse random-read request from string-address specs.
Status make_batch_write_words_request(std::string_view head_device, std::span< const std::uint16_t > words, BatchWriteWordsRequest &out_request) noexcept
Builds a contiguous word-write request from a string address such as D100.
Status make_random_write_bit_items(std::span< const RandomWriteBitSpec > specs, std::span< RandomWriteBitItem > out_items, std::span< const RandomWriteBitItem > &out_item_view) noexcept
Builds sparse random bit-write items from string-address specs.
Status make_batch_write_bits_request(std::string_view head_device, std::span< const BitValue > bits, BatchWriteBitsRequest &out_request) noexcept
Builds a contiguous bit-write request from a string address such as M100.
Status make_random_read_item(std::string_view device, RandomReadItem &out_item, bool double_word=false) noexcept
Builds one sparse random-read item from a string address.
Status make_batch_read_words_request(std::string_view head_device, std::uint16_t points, BatchReadWordsRequest &out_request) noexcept
Builds a contiguous word-read request from a string address such as D100.
Status make_batch_read_bits_request(std::string_view head_device, std::uint16_t points, BatchReadBitsRequest &out_request) noexcept
Builds a contiguous bit-read request from a string address such as M100.
Status make_monitor_registration(std::span< const RandomReadSpec > specs, std::span< RandomReadItem > out_items, MonitorRegistration &out_request) noexcept
Builds a sparse monitor registration payload from string-address specs.
Status make_random_write_bit_item(std::string_view device, BitValue value, RandomWriteBitItem &out_item) noexcept
Builds one sparse random bit-write item from a string address.
constexpr ProtocolConfig make_c4_ascii_format4_protocol(PlcSeries series=PlcSeries::Q_L) noexcept
Returns a practical default for Format4 / ASCII / C4.
Status parse_device_address(std::string_view text, DeviceAddress &out_device) noexcept
Parses a plain MC device string such as D100, M100, X10, or B20.
constexpr ProtocolConfig make_c4_ascii_format2_protocol(PlcSeries series=PlcSeries::Q_L) noexcept
Returns a practical default for Format2 / ASCII / C4.
DeviceCode
Device-family identifier used by the request codecs.
@ 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.
@ C4
Chapter-8/10/11/13 oriented serial frame with the fullest feature coverage in this repository.
BitValue
Logical single-bit value used by bit read/write APIs.
constexpr Status make_status(StatusCode code, const char *message, std::uint16_t plc_error_code=0) noexcept
Builds a status value with an optional PLC end code.
@ Binary
Compact binary command data and response data.
@ Ascii
Text-encoded command data and response data.
@ 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.
PlcSeries
PLC family selection used for subcommand and device-layout differences.
constexpr Status ok_status() noexcept
Returns the default success status.
Contiguous bit-read request (0401 bit path).
DeviceAddress head_device
First bit device in the contiguous range.
DeviceAddress head_device
First device in the contiguous range.
Contiguous bit-write request (1401 bit path).
DeviceAddress head_device
First bit device in the contiguous write range.
Contiguous word-write request (1401).
DeviceAddress head_device
First device in the contiguous write range.
Device code plus numeric address.
DeviceCode code
Device family such as D, M, X, LTN, or LZ.
std::span< const RandomReadItem > items
Sparse list of word/dword items to register for a later 0802 read.
Top-level protocol configuration shared by codecs and client requests.
bool sum_check_enabled
Enables or disables the ASCII/binary sum-check where that frame family supports it.
AsciiFormat ascii_format
Selected ASCII framing flavor when code_mode == CodeMode::Ascii.
RouteConfig route
Route header fields used for every encoded request.
FrameKind frame_kind
Selected serial frame family.
std::uint8_t ascii_block_number
DeviceAddress device
Target device address for this sparse item.
Native random-read request made of sparse word/dword items.
std::span< const RandomReadItem > items
Sparse word/dword items encoded in the native random-read request.
One bit item inside native random write (1402 bit path).
DeviceAddress device
Target bit device address for the sparse write.
One word or double-word item inside native random write (1402 word path).
DeviceAddress device
Target device address for the sparse write.
RouteKind kind
Route interpretation used by the selected frame family.
std::uint8_t station_no
Target station number on multidrop serial links.
Result object returned by most public APIs.
constexpr bool ok() const noexcept
String-address spec used to build sparse random-read or monitor requests.
std::string_view device
Plain device string such as D100, LZ0, or LCN10.
bool double_word
true when the target should be encoded as a double-word sparse item.
String-address spec used to build sparse random bit-write items.
BitValue value
Bit value written to device.
std::string_view device
Plain bit-device string such as M100 or X10.
String-address spec used to build sparse random word-write items.
std::string_view device
Plain device string such as D100 or LZ0.
std::uint32_t value
Word or double-word value written to device.
bool double_word
true when the item should be encoded as a double-word sparse write.
std::size_t prefix_length
Public request, response, configuration, and callback types for the serial MC protocol library.