CRC-16, builders, parser, validator.
More...
|
| constexpr uint16_t | alicat_basis2::modbus::Crc16 (std::span< const uint8_t > data) noexcept |
| | Modbus CRC-16 (polynomial 0xA001 reflected, initial value 0xFFFF).
|
| |
| Result< Request > | alicat_basis2::modbus::BuildRead (uint8_t address, uint16_t first, uint16_t count) noexcept |
| | Build a function 3 request.
|
| |
| Result< Request > | alicat_basis2::modbus::BuildWriteSingle (uint8_t address, uint16_t target, uint16_t value) noexcept |
| | Build a function 6 request (one register).
|
| |
| Result< Request > | alicat_basis2::modbus::BuildWriteMultiple (uint8_t address, uint16_t target, uint32_t value) noexcept |
| | Build a function 16 request for a two-register item (32-bit value, high register first).
|
| |
| bool | alicat_basis2::modbus::IsLegalModbusRequest (std::span< const uint8_t > bytes) noexcept |
| | Whether bytes is exactly one request the driver may send: a valid CRC, an address 1 to 247, function 3 on readable registers, function 6 or 16 on writable registers with a legal value.
|
| |
| std::size_t | alicat_basis2::modbus::ReplyLength (std::span< const char > bytes) noexcept |
| | How long the reply frame is, as far as the bytes received so far tell.
|
| |
| Error | alicat_basis2::modbus::ParseResponse (std::span< const char > frame, uint8_t request_address, uint8_t request_function, std::span< const uint8_t > request_bytes, Response &out) noexcept |
| | Parse and validate a response frame.
|
| |
|
|
constexpr uint8_t | alicat_basis2::modbus::kReadHolding = 3 |
| | Function code: read holding registers.
|
| |
|
constexpr uint8_t | alicat_basis2::modbus::kWriteSingle = 6 |
| | Function code: write single register.
|
| |
|
constexpr uint8_t | alicat_basis2::modbus::kWriteMultiple = 16 |
| | Function code: write multiple registers.
|
| |
CRC-16, builders, parser, validator.
◆ BuildRead()
| Result< Request > alicat_basis2::modbus::BuildRead |
( |
uint8_t |
address, |
|
|
uint16_t |
first, |
|
|
uint16_t |
count |
|
) |
| |
|
inlinenoexcept |
Build a function 3 request.
- Parameters
-
| address | Modbus address, 1 to 247. |
| first | First register. |
| count | Number of registers, 1 to reg::kMaxRead, all on readable registers of the table. |
- Returns
- The request, or
InvalidArgument (nothing is formed).
◆ BuildWriteMultiple()
| Result< Request > alicat_basis2::modbus::BuildWriteMultiple |
( |
uint8_t |
address, |
|
|
uint16_t |
target, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinenoexcept |
Build a function 16 request for a two-register item (32-bit value, high register first).
- Parameters
-
| address | Modbus address, 1 to 247. |
| target | The first register of a writable two-register row. |
| value | The combined 32-bit value, within the row's range. |
- Returns
- The request, or
InvalidArgument.
◆ BuildWriteSingle()
| Result< Request > alicat_basis2::modbus::BuildWriteSingle |
( |
uint8_t |
address, |
|
|
uint16_t |
target, |
|
|
uint16_t |
value |
|
) |
| |
|
inlinenoexcept |
Build a function 6 request (one register).
- Parameters
-
| address | Modbus address, 1 to 247. |
| target | The register, a writable one-register row of the table. |
| value | The value, within the row's range, or exactly its magic number. |
- Returns
- The request, or
InvalidArgument.
◆ Crc16()
| constexpr uint16_t alicat_basis2::modbus::Crc16 |
( |
std::span< const uint8_t > |
data | ) |
|
|
constexprnoexcept |
Modbus CRC-16 (polynomial 0xA001 reflected, initial value 0xFFFF).
- Parameters
-
- Returns
- The CRC; it is sent low byte first.
◆ IsLegalModbusRequest()
| bool alicat_basis2::modbus::IsLegalModbusRequest |
( |
std::span< const uint8_t > |
bytes | ) |
|
|
inlinenoexcept |
Whether bytes is exactly one request the driver may send: a valid CRC, an address 1 to 247, function 3 on readable registers, function 6 or 16 on writable registers with a legal value.
Independent of the builders: it parses the bytes back and checks them against the register table.
- Parameters
-
| bytes | The candidate wire bytes. |
- Returns
- true when legal.
◆ ParseResponse()
| Error alicat_basis2::modbus::ParseResponse |
( |
std::span< const char > |
frame, |
|
|
uint8_t |
request_address, |
|
|
uint8_t |
request_function, |
|
|
std::span< const uint8_t > |
request_bytes, |
|
|
Response & |
out |
|
) |
| |
|
inlinenoexcept |
Parse and validate a response frame.
- Parameters
-
| frame | The received bytes. |
| request_address | The address that was sent to. |
| request_function | The function code that was sent. |
| request_bytes | The request that was sent: the echo of a write is checked against it. |
| out | The response; untouched on failure except exception of a Rejected reply. |
- Returns
Ok, BadReply (too short, wrong length, wrong byte count, wrong function), Crc, DeviceIdMismatch (another address) or Rejected (an exception reply; the code is in out.exception).
◆ ReplyLength()
| std::size_t alicat_basis2::modbus::ReplyLength |
( |
std::span< const char > |
bytes | ) |
|
|
inlinenoexcept |
How long the reply frame is, as far as the bytes received so far tell.
- Parameters
-
- Returns
- The full length (5 for an exception reply,
5 + byte count for function 3, 8 for 6 and 16), or 0 while it is not known yet; kMaxLine + 1 for a function code the driver never sends.