36 return word_address * 2U;
41[[nodiscard]]
constexpr char ascii_upper(
char value)
noexcept {
42 return (value >=
'a' && value <=
'z') ?
static_cast<char>(value - (
'a' -
'A')) : value;
46 return value ==
'\\' || value ==
'/';
58 for (
char ch : text) {
60 if (ch >=
'0' && ch <=
'9') {
62 }
else if (base == 16 && ch >=
'A' && ch <=
'F') {
64 }
else if (base == 16 && ch >=
'a' && ch <=
'f') {
84 if (text.size() > 2U && text[0] ==
'0' &&
85 (text[1] ==
'x' || text[1] ==
'X')) {
100 "Qualified buffer device must begin with U");
111 separator >= (text.size() - 1U)) {
114 "Qualified buffer device must look like U3E0\\G0 or U3E0\\HG0");
119 module_number > 0xFFFFU) {
122 "Qualified buffer module number must be a 16-bit hexadecimal value");
128 if (suffix.
size() >= 2U &&
139 "Qualified buffer device suffix must start with G or HG");
142 if (suffix.
size() <= prefix_length) {
145 "Qualified buffer device must include a word address");
152 "Qualified buffer device word address is invalid");
158 .word_address = word_address,
168 if (word_length == 0U) {
171 "Qualified buffer read length must be at least 1 word");
173 if (word_length > 960U) {
176 "Qualified buffer read length must be in range 1..960 words");
182 .module_number = device.module_number,
196 "Qualified buffer write values must not be empty");
199 if (out_bytes.size() < required) {
202 "Qualified buffer byte buffer is too small");
207 out_bytes[index * 2U] =
static_cast<std::byte>(value & 0xFFU);
208 out_bytes[index * 2U + 1U] =
static_cast<std::byte>((value >> 8U) & 0xFFU);
225 "Qualified buffer write values must not be empty");
227 if (words.size() > 960U) {
230 "Qualified buffer write length must be in range 1..960 words");
233 const Status encode_status =
235 if (!encode_status.
ok()) {
236 return encode_status;
241 .module_number = device.module_number,
242 .bytes = byte_storage.
first(out_byte_count),
251 if ((bytes.size() % 2U) != 0U) {
254 "Qualified buffer byte payload must contain an even number of bytes");
257 if (out_words.size() < word_count) {
260 "Qualified buffer word output buffer is too small");
263 for (
std::size_t index = 0; index < word_count; ++index) {
264 const auto low =
static_cast<std::uint8_t>(bytes[index * 2U]);
265 const auto high =
static_cast<std::uint8_t>(bytes[index * 2U + 1U]);
266 out_words[index] =
static_cast<std::uint16_t>(low | (high << 8U));
constexpr size_type size() const noexcept
constexpr span first(size_type count) const noexcept
constexpr string_view substr(size_type pos, size_type count=npos) const noexcept
static constexpr size_type npos
constexpr size_type size() const noexcept
constexpr bool empty() const noexcept
bool parse_u32_chars(std::string_view text, int base, std::uint32_t &out_value) noexcept
constexpr char ascii_upper(char value) noexcept
constexpr bool is_separator(char value) noexcept
bool parse_u32_auto(std::string_view text, std::uint32_t &out_value) noexcept
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.
Status parse_qualified_buffer_word_device(std::string_view text, QualifiedBufferWordDevice &out_device) noexcept
Parses a helper qualified device string such as U3E0\\G10 or U3E0\\HG20.
Status encode_qualified_buffer_word_values(std::span< const std::uint16_t > words, std::span< std::byte > out_bytes, std::size_t &out_size) noexcept
Encodes helper qualified word values into little-endian module-buffer bytes.
Status make_qualified_buffer_read_words_request(const QualifiedBufferWordDevice &device, std::uint16_t word_length, ModuleBufferReadRequest &out_request) noexcept
Builds a module-buffer read request for a helper qualified word range.
constexpr Status ok_status() noexcept
Returns the default success status.
QualifiedBufferDeviceKind
Qualified buffer-memory family used by helper U... accessors.
constexpr const char * qualified_buffer_kind_name(QualifiedBufferDeviceKind kind) noexcept
Returns "G" or "HG" for the helper device kind.
Status make_qualified_buffer_write_words_request(const QualifiedBufferWordDevice &device, std::span< const std::uint16_t > words, std::span< std::byte > byte_storage, ModuleBufferWriteRequest &out_request, std::size_t &out_byte_count) noexcept
Builds a module-buffer write request for helper qualified word access.
constexpr std::uint32_t qualified_buffer_word_to_byte_address(std::uint32_t word_address) noexcept
Converts a qualified word address to the corresponding module-buffer byte address.
Status decode_qualified_buffer_word_values(std::span< const std::byte > bytes, std::span< std::uint16_t > out_words) noexcept
Decodes little-endian module-buffer bytes into helper qualified word values.
Module-buffer byte read request (0601 helper path).
std::uint32_t start_address
Starting module-buffer byte address.
Module-buffer byte write request (1601 helper path).
std::uint32_t start_address
Starting module-buffer byte address.
Parsed U...\\G... or U...\\HG... qualified word device.
QualifiedBufferDeviceKind kind
std::uint32_t word_address
std::uint16_t module_number
Result object returned by most public APIs.
constexpr bool ok() const noexcept
Public request, response, configuration, and callback types for the serial MC protocol library.