CRC, encoders, line assembler and parser.
More...
|
| enum class | fdo2::Command : uint8_t {
fdo2::Command::Vers = 0
, fdo2::Command::Idnr
, fdo2::Command::Moxy
, fdo2::Command::Mraw
,
fdo2::Command::Logo
, fdo2::Command::Crce
, fdo2::Command::Rdum
, fdo2::Command::Wrum
,
fdo2::Command::Baud
, fdo2::Command::Calo
, fdo2::Command::Cahi
, fdo2::Command::Bcst
,
fdo2::Command::Setm
} |
| | The thirteen commands of the module (datasheet 4.3). More...
|
| |
| enum class | fdo2::PushResult : uint8_t { fdo2::PushResult::Pending = 0
, fdo2::PushResult::Line
, fdo2::PushResult::Bad
} |
| | What LineAssembler::PushByte() did with a byte. More...
|
| |
| enum class | fdo2::ParseStatus : uint8_t { fdo2::ParseStatus::Ok = 0
, fdo2::ParseStatus::BadCrc
, fdo2::ParseStatus::Malformed
} |
| | The outcome class of ParseLine(). More...
|
| |
|
| constexpr const char * | fdo2::HeaderOf (Command command) noexcept |
| | The four header letters of a command, without the #.
|
| |
template<typename T >
requires (std::is_same_v<T, uint8_t> || std::is_same_v<T, char>) |
| constexpr uint16_t | fdo2::Crc16Modbus (std::span< const T > data) noexcept |
| | The CRC-16/MODBUS of a byte or character string (polynomial 0xA001 reflected, start 0xFFFF), as the module computes it over the reply before the colon (datasheet 4.2). "123456789" gives 0x4B37.
|
| |
| constexpr std::size_t | fdo2::EncodeCommand (Command command, std::span< const int32_t > args, std::span< char > out) noexcept |
| | Encode a command line: #HEAD, each argument as plain decimal with one space before it, and one carriage return (never a LF: datasheet 4.1 allows CR or CR LF, the driver sends CR).
|
| |
| constexpr ParsedLine | fdo2::ParseLine (std::span< const char > line, const ParseOptions &options) noexcept |
| | Parse one reply line (without its CR) under the grammar of datasheet 4.
|
| |
| constexpr std::size_t | fdo2::ExpectedCount (Command command, std::span< const int32_t > args) noexcept |
| | How many values the reply to a command holds (datasheet 4.3).
|
| |
| constexpr bool | fdo2::VerifyEcho (Command command, std::span< const int32_t > args, const ParsedLine &reply) noexcept |
| | The echo check of datasheet 4.2: the header and the echoed arguments equal what was sent.
|
| |
| constexpr uint32_t | fdo2::MaxReplyChars (Command command, uint32_t words) noexcept |
| | The longest reply of a command, in characters including the CR and a CRC suffix, for the deadline (derived from datasheet 4.1 and 4.3: #MRAW with eight 11-character values).
|
| |
|
| constexpr std::size_t | fdo2::kMaxLineLength = 800 |
| |
|
constexpr std::size_t | fdo2::kMaxCommandLength = 800 |
| | Longest command line the driver sends (#WRUM 0 64 and 64 values), including the CR.
|
| |
|
constexpr std::size_t | fdo2::kMaxValues = 66 |
| | Most values a reply holds: #RDUM R N and 64 words.
|
| |
|
constexpr uint32_t | fdo2::kMaxStale = 4 |
| | Complete lines of another command dropped per transaction before the reply is InvalidReply.
|
| |
CRC, encoders, line assembler and parser.
◆ Command
The thirteen commands of the module (datasheet 4.3).
| Enumerator |
|---|
| Vers | #VERS
|
| Idnr | #IDNR
|
| Moxy | #MOXY
|
| Mraw | #MRAW
|
| Logo | #LOGO
|
| Crce | #CRCE K
|
| Rdum | #RDUM R N
|
| Wrum | #WRUM R N Y1 ... YN
|
| Baud | #BAUD R
|
| Calo | #CALO
|
| Cahi | #CAHI P
|
| Bcst | #BCST T
|
| Setm | #SETM M
|
◆ ParseStatus
The outcome class of ParseLine().
| Enumerator |
|---|
| Ok | The line follows the grammar (and its CRC matches when present).
|
| BadCrc | A CRC suffix is wrong, or required and missing.
|
| Malformed | The line breaks the grammar.
|
◆ PushResult
What LineAssembler::PushByte() did with a byte.
| Enumerator |
|---|
| Pending | The line is not complete.
|
| Line | A carriage return completed a line: Line() holds it (without the CR).
|
| Bad | The byte, or the length, broke the grammar; the line is discarded to the next CR.
|
◆ Crc16Modbus()
template<typename T >
requires (std::is_same_v<T, uint8_t> || std::is_same_v<T, char>)
| constexpr uint16_t fdo2::Crc16Modbus |
( |
std::span< const T > |
data | ) |
|
|
constexprnoexcept |
The CRC-16/MODBUS of a byte or character string (polynomial 0xA001 reflected, start 0xFFFF), as the module computes it over the reply before the colon (datasheet 4.2). "123456789" gives 0x4B37.
- Template Parameters
-
- Parameters
-
| data | The bytes or characters (spaces included). |
- Returns
- The CRC.
◆ EncodeCommand()
| constexpr std::size_t fdo2::EncodeCommand |
( |
Command |
command, |
|
|
std::span< const int32_t > |
args, |
|
|
std::span< char > |
out |
|
) |
| |
|
constexprnoexcept |
Encode a command line: #HEAD, each argument as plain decimal with one space before it, and one carriage return (never a LF: datasheet 4.1 allows CR or CR LF, the driver sends CR).
The arguments are range-checked first (R 0 to 63, N 1 to 64, R + N at most 64, a baud rate from the table, #BCST 0 or 100 to 10000, #SETM 0 to 4, #CRCE 0 or 1, #CAHI not 0, and the count of arguments).
- Parameters
-
| command | The command. |
| args | The arguments; for Wrum R, N, Y1 ... YN. |
| out | The buffer; at least kMaxCommandLength bytes fits every command. |
- Returns
- The length written, including the CR; 0 when an argument is invalid or
out is short.
◆ ExpectedCount()
| constexpr std::size_t fdo2::ExpectedCount |
( |
Command |
command, |
|
|
std::span< const int32_t > |
args |
|
) |
| |
|
constexprnoexcept |
How many values the reply to a command holds (datasheet 4.3).
- Parameters
-
| command | The command. |
| args | The arguments that were sent (#RDUM and #WRUM need N). |
- Returns
- The count; for
Rdum and Wrum it is 2 + N.
◆ HeaderOf()
| constexpr const char * fdo2::HeaderOf |
( |
Command |
command | ) |
|
|
constexprnoexcept |
The four header letters of a command, without the #.
- Parameters
-
- Returns
- A string such as
"VERS"; "" for a value that is not an enumerator.
◆ MaxReplyChars()
| constexpr uint32_t fdo2::MaxReplyChars |
( |
Command |
command, |
|
|
uint32_t |
words |
|
) |
| |
|
constexprnoexcept |
The longest reply of a command, in characters including the CR and a CRC suffix, for the deadline (derived from datasheet 4.1 and 4.3: #MRAW with eight 11-character values).
- Parameters
-
| command | The command. |
| words | N of #RDUM/#WRUM, 0 otherwise. |
- Returns
- The bound.
◆ ParseLine()
Parse one reply line (without its CR) under the grammar of datasheet 4.
(1) The CRC suffix : C (when present or required) is checked over every character before the colon. (2) The header is # and four letters A to Z, then the end or a space. (3) Values are separated by exactly one space (strict_spacing), each is 0 or an optional minus and a digit 1 to 9 and digits, in range for its field (S unsigned 32 bit, #IDNR unsigned 64 bit, the rest signed 32 bit). #ERRO is exactly #ERRO E with E negative. The token count is checked by the caller against the command's reply (ExpectedCount()). No allocation, no strtol, no locale.
- Parameters
-
| line | The line, without CR. |
| options | The CRC and spacing rules. |
- Returns
- The parsed line; check
status, then known, erro, command.
◆ VerifyEcho()
| constexpr bool fdo2::VerifyEcho |
( |
Command |
command, |
|
|
std::span< const int32_t > |
args, |
|
|
const ParsedLine & |
reply |
|
) |
| |
|
constexprnoexcept |
The echo check of datasheet 4.2: the header and the echoed arguments equal what was sent.
- Parameters
-
| command | The command that was sent. |
| args | The arguments that were sent. |
| reply | The parsed reply (its header must be command). |
- Returns
- true when the echo matches.
#RDUM echoes R N and then returns data.
◆ kMaxLineLength
| constexpr std::size_t fdo2::kMaxLineLength = 800 |
|
inlineconstexpr |
Longest line, including its carriage return: a line of up to 799 characters is accepted. The longest legitimate reply (#RDUM of 64 words with CRC) has about 790 characters.