FDO2 Driver 1.0.0
API reference
Loading...
Searching...
No Matches
Functions
fdo2::detail Namespace Reference

Functions

bool AppendCmd (char *buf, std::size_t cap, std::string_view cmd) noexcept
 
uint16_t Crc16Modbus (const char *data, std::size_t len) noexcept
 CRC-16/MODBUS (CRC-16-IBM, reflected polynomial 0xA001, initial value 0xFFFF, no final XOR).
 
DriverError VerifyAndStripCrc (char *line, bool require) noexcept
 Verify and remove the optional CRC suffix of a reply line (CR already removed).
 
void StripOptionalModbusCrcSuffix (char *line) noexcept
 
template<typename UartT >
DriverError ReadAsciiLine (UartT &uart, char *buf, std::size_t cap, uint32_t timeout_ms, bool require_crc=false) noexcept
 
const char * SkipWs (const char *p) noexcept
 
DriverError Tokenize (const char *line, char *store, std::size_t store_cap, const char *tokens[], std::size_t max_tokens, std::size_t *out_count) noexcept
 
bool IsDecimalToken (const char *s, bool allow_minus) noexcept
 True when s is an optional '-' followed by one or more decimal digits and nothing else.
 
int32_t ParseI32 (const char *s, bool *ok) noexcept
 Parse a signed 32-bit decimal (data sheet §4.1 value range). ok is set (not accumulated).
 
uint32_t ParseU32 (const char *s, bool *ok) noexcept
 Parse an unsigned 32-bit decimal (no sign). ok is set (not accumulated).
 
uint64_t ParseU64 (const char *s, bool *ok) noexcept
 Parse an unsigned 64-bit decimal (no sign; #IDNR). ok is set (not accumulated).
 
int32_t FieldI32 (const char *s, bool &all_ok) noexcept
 Parse one field of a reply; all_ok is cleared if it is invalid and never set back to true.
 
uint32_t FieldU32 (const char *s, bool &all_ok) noexcept
 Parse one field of a reply; all_ok is cleared if it is invalid and never set back to true.
 
bool IsErroHeader (const char *tok0) noexcept
 

Function Documentation

◆ AppendCmd()

bool fdo2::detail::AppendCmd ( char *  buf,
std::size_t  cap,
std::string_view  cmd 
)
inlinenoexcept

◆ Crc16Modbus()

uint16_t fdo2::detail::Crc16Modbus ( const char *  data,
std::size_t  len 
)
inlinenoexcept

CRC-16/MODBUS (CRC-16-IBM, reflected polynomial 0xA001, initial value 0xFFFF, no final XOR).

Data sheet §4.2: the checksum the module appends with #CRCE 1, computed over the reply from its first character up to, not including, the :. Check value: "123456789" -> 0x4B37.

◆ FieldI32()

int32_t fdo2::detail::FieldI32 ( const char *  s,
bool &  all_ok 
)
inlinenoexcept

Parse one field of a reply; all_ok is cleared if it is invalid and never set back to true.

◆ FieldU32()

uint32_t fdo2::detail::FieldU32 ( const char *  s,
bool &  all_ok 
)
inlinenoexcept

Parse one field of a reply; all_ok is cleared if it is invalid and never set back to true.

◆ IsDecimalToken()

bool fdo2::detail::IsDecimalToken ( const char *  s,
bool  allow_minus 
)
inlinenoexcept

True when s is an optional '-' followed by one or more decimal digits and nothing else.

◆ IsErroHeader()

bool fdo2::detail::IsErroHeader ( const char *  tok0)
inlinenoexcept

◆ ParseI32()

int32_t fdo2::detail::ParseI32 ( const char *  s,
bool *  ok 
)
inlinenoexcept

Parse a signed 32-bit decimal (data sheet §4.1 value range). ok is set (not accumulated).

◆ ParseU32()

uint32_t fdo2::detail::ParseU32 ( const char *  s,
bool *  ok 
)
inlinenoexcept

Parse an unsigned 32-bit decimal (no sign). ok is set (not accumulated).

◆ ParseU64()

uint64_t fdo2::detail::ParseU64 ( const char *  s,
bool *  ok 
)
inlinenoexcept

Parse an unsigned 64-bit decimal (no sign; #IDNR). ok is set (not accumulated).

◆ ReadAsciiLine()

template<typename UartT >
DriverError fdo2::detail::ReadAsciiLine ( UartT &  uart,
char *  buf,
std::size_t  cap,
uint32_t  timeout_ms,
bool  require_crc = false 
)
inlinenoexcept

◆ SkipWs()

const char * fdo2::detail::SkipWs ( const char *  p)
inlinenoexcept

◆ StripOptionalModbusCrcSuffix()

void fdo2::detail::StripOptionalModbusCrcSuffix ( char *  line)
inlinenoexcept
Deprecated:
Strips a CRC suffix without checking it; use VerifyAndStripCrc().

◆ Tokenize()

DriverError fdo2::detail::Tokenize ( const char *  line,
char *  store,
std::size_t  store_cap,
const char *  tokens[],
std::size_t  max_tokens,
std::size_t *  out_count 
)
inlinenoexcept

◆ VerifyAndStripCrc()

DriverError fdo2::detail::VerifyAndStripCrc ( char *  line,
bool  require 
)
inlinenoexcept

Verify and remove the optional CRC suffix of a reply line (CR already removed).

Data sheet §4.2: with #CRCE 1 every reply ends in ": C" before the CR, where C is the CRC-16 as a decimal ASCII string, computed over every byte before the : (spaces included). Replies never contain : otherwise, so a : marks the suffix. On success the line is cut at the :.

Parameters
requireWhen true, a line without the suffix is rejected (module known to have #CRCE 1).
Returns
None (no suffix and not required, or suffix valid); CrcMismatch (checksum differs, or required and missing); ProtocolError (a : not followed by a decimal 0..65535).