|
Alicat BASIS-2 Driver 1.0.0
API reference
|
Modbus-RTU framing and CRC-16 helpers used by the BASIS-2 driver. More...
#include <array>#include <cstdint>#include <cstddef>#include "alicat_basis2_registers.hpp"#include "alicat_basis2_types.hpp"Go to the source code of this file.
Namespaces | |
| namespace | alicat_basis2 |
| namespace | alicat_basis2::modbus |
Functions | |
| uint16_t | alicat_basis2::modbus::Crc16 (const uint8_t *data, std::size_t length) noexcept |
| Compute the Modbus-RTU CRC-16 over a byte buffer. | |
| std::size_t | alicat_basis2::modbus::AppendCrc (uint8_t *frame, std::size_t length) noexcept |
Append the CRC-16 to frame[length..length+1] and return new length. | |
| bool | alicat_basis2::modbus::CheckCrc (const uint8_t *frame, std::size_t length) noexcept |
Verify the CRC at frame[length-2..length-1] matches the body. | |
| std::size_t | alicat_basis2::modbus::BuildReadHolding (uint8_t unit_addr, uint16_t reg_addr, uint16_t reg_count, uint8_t *out, std::size_t out_capacity) noexcept |
| Build a Function-03 (Read Holding Registers) request. | |
| std::size_t | alicat_basis2::modbus::BuildWriteSingle (uint8_t unit_addr, uint16_t reg_addr, uint16_t value, uint8_t *out, std::size_t out_capacity) noexcept |
| Build a Function-06 (Write Single Register) request. | |
| std::size_t | alicat_basis2::modbus::BuildWriteMultiple (uint8_t unit_addr, uint16_t reg_addr, const uint16_t *regs, uint8_t count, uint8_t *out, std::size_t out_capacity) noexcept |
| Build a Function-16 (Write Multiple Registers) request. | |
| constexpr uint32_t | alicat_basis2::modbus::InterFrameGapUs (uint32_t bps) noexcept |
| Minimum idle time t3.5 between two Modbus-RTU frames, in microseconds. | |
| constexpr uint32_t | alicat_basis2::modbus::InterFrameGapMs (uint32_t bps) noexcept |
InterFrameGapUs(bps) rounded up to whole milliseconds (for UartInterface::delay_ms()). | |
| bool | alicat_basis2::modbus::IsExceptionReply (const uint8_t *frame, std::size_t length) noexcept |
| DriverError | alicat_basis2::modbus::ParseException (const uint8_t *frame, std::size_t length, uint8_t expected_addr, uint8_t expected_fn, uint8_t *code) noexcept |
| Parse a 5-byte exception reply (Modbus Application Protocol V1.1b3, section 7). | |
| DriverError | alicat_basis2::modbus::ParseReadHolding (const uint8_t *frame, std::size_t length, uint8_t expected_addr, uint8_t expected_count, uint16_t *regs) noexcept |
Parse a Function-03 response into regs[]. | |
| DriverError | alicat_basis2::modbus::ParseWriteSingleEcho (const uint8_t *frame, std::size_t length, const uint8_t *request, std::size_t req_len) noexcept |
| Validate the echo of a Function-06 (Write Single) request against the just-sent request. | |
| DriverError | alicat_basis2::modbus::ParseWriteMultipleEcho (const uint8_t *frame, std::size_t length, uint8_t expected_addr, uint16_t expected_reg_addr, uint16_t expected_count) noexcept |
| Validate the response of a Function-16 (Write Multiple) request. | |
Variables | |
| constexpr uint32_t | alicat_basis2::modbus::kRtuBitsPerChar = 11 |
| Bits per RTU character used for the timing: start + 8 data + parity/stop + stop (section 2.5.1). | |
| constexpr uint32_t | alicat_basis2::modbus::kFixedGapAboveBps = 19200 |
| Above this baud rate the spec fixes t3.5 at 1750 us instead of 3.5 character times. | |
| constexpr uint32_t | alicat_basis2::modbus::kFixedGapUs = 1750 |
| The fixed t3.5 used above 19200 baud, in microseconds. | |
| constexpr std::size_t | alicat_basis2::modbus::kExceptionFrameLength = 5 |
| Length of a Modbus-RTU exception reply: address, function | 0x80, exception code, CRC-16. | |
| constexpr std::size_t | alicat_basis2::modbus::kReplyHeaderLength = 3 |
| Number of reply bytes a receiver reads before it can tell an exception reply (bit 7 of the function code set) from a normal one: address, function code, and one more byte. | |
Modbus-RTU framing and CRC-16 helpers used by the BASIS-2 driver.
Implements only the three function codes BASIS-2 supports: 03 — Read Holding Registers 06 — Write Single Register 16 — Write Multiple Registers plus the canonical Modbus CRC-16 (polynomial 0xA001, init 0xFFFF, LSB first) defined by the Modbus-RTU specification.
All routines are pure / constexpr-friendly, allocation-free, and operate on plain uint8_t* byte buffers so the implementation can be reused on any MCU without the STL.