BASIS 2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
alicat_basis2::ascii Namespace Reference

The ASCII grammar: table, encoder, validator, decoders. More...

Classes

struct  Args
 The arguments of a request before encoding. More...
 
struct  CommandSpec
 One row of the command table (rows C01 to C46). More...
 
struct  FrameRules
 The rules a decoded frame is checked against. More...
 
struct  Token
 One token: where it starts and how long it is. More...
 
struct  Tokens
 The tokens of a line. More...
 
struct  Values
 The numbers of a short reply: ID v1 [v2 ...]. More...
 

Enumerations

enum class  ArgKind : uint8_t {
  ArgKind::None = 0 , ArgKind::Int = 1 , ArgKind::Milli = 2 , ArgKind::Letter = 3 ,
  ArgKind::Star = 4 , ArgKind::Ramp = 5 , ArgKind::IntPair = 6
}
 What a command's argument looks like. More...
 

Functions

constexpr const CommandSpec & Spec (Command c) noexcept
 The row of a command.
 
Result< Request > Make (Command command, char id, const Args &args, bool allow_guarded) noexcept
 Build a request: validate every argument, write the wire bytes.
 
bool IsLegalRequest (std::span< const uint8_t > bytes) noexcept
 Whether bytes is exactly one request of the grammar of M pp.10 to 17: unit ID A to Z, a command with its argument, one CR at the end, only the characters A-Z 0-9 space + - . * @ =.
 
Error Tokenize (std::span< const char > line, Tokens &out) noexcept
 Split a line on runs of spaces.
 
std::span< const char > View (std::span< const char > line, const Token &t) noexcept
 The characters of a token.
 
bool ParseDecimal (std::span< const char > tok, Decimal &out) noexcept
 Parse ‘[+-]? digit{1,12} ( ’.' digit{1,6} )?: no exponent, no hex, nonan`, no leading or trailing point.
 
constexpr char Upper (char c) noexcept
 Upper-case a letter.
 
bool EqualsNoCase (std::span< const char > tok, const char *word) noexcept
 Case-insensitive equality of a token and a word.
 
bool StartsWithId (std::span< const char > line, const Tokens &toks, char id) noexcept
 Whether the first token is exactly one letter equal (any case) to the unit ID.
 
Error DecodeFrame (std::span< const char > line, const FrameRules &rules, Frame &out, FrameLayout &layout_seen) noexcept
 Decode a data frame (C01): ID, three or five numbers, the gas, zero or more flags (M p.10 to 11).
 
Error DecodeData (std::span< const char > line, uint8_t mask, const FrameRules &rules, Frame &out) noexcept
 Decode a DV n reply: ID, then the selected fields in table order (M p.11).
 
Error DecodeValues (std::span< const char > line, char id, uint8_t count, Values &out) noexcept
 Decode ID followed by exactly count numbers.
 
Error DecodeLetter (std::span< const char > line, char id, const char *allowed, char &out) noexcept
 Decode ID x where x is one character out of allowed (case-insensitive).
 
Error DecodeText (std::span< const char > line, char id, Text &out) noexcept
 Decode ID text...: the rest of the line after the ID, truncated to kTextMax characters.
 
Error DecodeGas (std::span< const char > line, char id, Frame &out) noexcept
 Decode a gas reply ID number name (C27, C29).
 
Error DecodeFullScale (std::span< const char > line, char id, FullScale &out) noexcept
 Decode a full-scale reply ID value units (C35).
 
FlowUnit FlowUnitFromLabel (std::span< const char > label) noexcept
 The flow unit of an instrument's label (case-insensitive), Other when it is not one of the twenty.
 
Error DecodeGasList (std::span< const char > line, char id, GasList &out) noexcept
 Decode a gas list ID n name n name ... (C28, A5); sets raw when it does not parse.
 
Error DecodeWindow (std::span< const char > line, char id, uint8_t count, uint32_t &time_ms, Values &out) noexcept
 Decode ID time ... replies of DVAA (two values after the time) and DVAR (four).
 
bool IsErrorToken (std::span< const char > line, char id) noexcept
 Whether a reply line is the error token: ? alone, or ? after the unit ID.
 

Variables

constexpr char kCr = '\r'
 Carriage return, the terminator of every request and reply (M p.10).
 
constexpr std::size_t kCommandRows = 46
 Number of rows of the command table.
 
constexpr int64_t kMilliCap = 999'999'999'999LL
 
constexpr int64_t kMeasureMaxMs = 163'837
 Longest measurement duration in ms the driver sends (derived: 65535 samples of 2.5 ms, A7).
 
constexpr std::array< CommandSpec, kCommandRows > kCommands
 The command table, indexed by Command (data; one row per command of the coverage map).
 
constexpr std::size_t kMaxTokens = 26
 Tokens in a line, at most.
 
constexpr std::size_t kMaxToken = 32
 Longest token, in characters.
 

Detailed Description

The ASCII grammar: table, encoder, validator, decoders.