FDO2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
fdo2_protocol.hpp
Go to the documentation of this file.
1
17#ifndef FDO2_PROTOCOL_HPP
18#define FDO2_PROTOCOL_HPP
19
20#include <algorithm>
21#include <array>
22#include <bit>
23#include <cstddef>
24#include <cstdint>
25#include <span>
26#include <type_traits>
27#include <utility>
28
29#include "fdo2_types.hpp"
30
31namespace fdo2 {
32
41inline constexpr std::size_t kMaxLineLength = 800;
43inline constexpr std::size_t kMaxCommandLength = 800;
45inline constexpr std::size_t kMaxValues = 66;
47inline constexpr uint32_t kMaxStale = 4;
48
50enum class Command : uint8_t {
51 Vers = 0,
52 Idnr,
53 Moxy,
54 Mraw,
55 Logo,
56 Crce,
57 Rdum,
58 Wrum,
59 Baud,
60 Calo,
61 Cahi,
62 Bcst,
63 Setm,
64};
65
66namespace detail {
68template <>
69struct EnumLast<Command> {
70 static constexpr Command kValue = Command::Setm;
71};
72} // namespace detail
73
79constexpr const char* HeaderOf(Command command) noexcept {
80 switch (command) {
81 case Command::Vers:
82 return "VERS";
83 case Command::Idnr:
84 return "IDNR";
85 case Command::Moxy:
86 return "MOXY";
87 case Command::Mraw:
88 return "MRAW";
89 case Command::Logo:
90 return "LOGO";
91 case Command::Crce:
92 return "CRCE";
93 case Command::Rdum:
94 return "RDUM";
95 case Command::Wrum:
96 return "WRUM";
97 case Command::Baud:
98 return "BAUD";
99 case Command::Calo:
100 return "CALO";
101 case Command::Cahi:
102 return "CAHI";
103 case Command::Bcst:
104 return "BCST";
105 case Command::Setm:
106 return "SETM";
107 default:
108 break;
109 }
110 return "";
111}
112
121template <typename T>
122 requires(std::is_same_v<T, uint8_t> || std::is_same_v<T, char>)
123constexpr uint16_t Crc16Modbus(std::span<const T> data) noexcept {
124 uint32_t crc = 0xFFFFU;
125 for (const T item : data) {
126 crc ^=
127 static_cast<uint32_t>(std::bit_cast<uint8_t>(item)); // the byte, not the character's value
128 for (uint32_t bit = 0U; bit < 8U; ++bit) {
129 const bool lsb = (crc & 1U) != 0U;
130 crc >>= 1U;
131 if (lsb) {
132 crc ^= 0xA001U;
133 }
134 }
135 }
136 return static_cast<uint16_t>(crc);
137}
138
139namespace detail {
140
142inline constexpr std::array<char, 10> kDecimalDigits{'0', '1', '2', '3', '4',
143 '5', '6', '7', '8', '9'};
144
146inline constexpr std::array<char, 26> kCapitalLetters{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
147 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
148 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
149
151constexpr bool SameChar(char first, char second) noexcept {
152 return std::array<char, 1>{first} == std::array<char, 1>{second};
153}
154
156template <std::size_t N>
157constexpr bool OneOf(char c, const std::array<char, N>& set) noexcept {
158 return std::find(set.begin(), set.end(), c) != set.end();
159}
160
162constexpr bool PutInt(std::span<char> out, std::size_t& pos, int32_t value) noexcept {
163 std::array<char, 12> digits{};
164 std::size_t n = 0U;
165 const bool neg = value < 0;
166 uint32_t mag = neg ? (0U - static_cast<uint32_t>(value)) : static_cast<uint32_t>(value);
167 do {
168 digits[n] = kDecimalDigits[mag % 10U];
169 ++n;
170 mag /= 10U;
171 } while (mag != 0U);
172 const std::size_t total = n + (neg ? 1U : 0U);
173 if ((pos + total) > out.size()) {
174 return false;
175 }
176 if (neg) {
177 out[pos] = '-';
178 ++pos;
179 }
180 while (n > 0U) {
181 --n;
182 out[pos] = digits[n];
183 ++pos;
184 }
185 return true;
186}
187
189constexpr std::size_t FixedArgCount(Command command) noexcept {
190 switch (command) {
191 case Command::Crce:
192 case Command::Baud:
193 case Command::Cahi:
194 case Command::Bcst:
195 case Command::Setm:
196 return 1U;
197 case Command::Rdum:
198 return 2U;
199 case Command::Vers:
200 case Command::Idnr:
201 case Command::Moxy:
202 case Command::Mraw:
203 case Command::Logo:
204 case Command::Calo:
205 case Command::Wrum:
206 default:
207 break;
208 }
209 return 0U;
210}
211
214constexpr bool OneArgumentValid(Command command, int32_t value) noexcept {
215 switch (command) {
216 case Command::Crce:
217 return (value == 0) || (value == 1);
218 case Command::Baud:
219 return (value > 0) && IsSupportedBaud(static_cast<uint32_t>(value));
220 case Command::Cahi:
221 return value != 0;
222 case Command::Bcst:
223 return (value == 0) || (std::cmp_greater_equal(value, kBroadcastMinMs) &&
224 std::cmp_less_equal(value, kBroadcastMaxMs));
225 case Command::Setm:
226 return (value >= 0) && std::cmp_less_equal(value, kMaxMeasurementMode);
227 case Command::Vers:
228 case Command::Idnr:
229 case Command::Moxy:
230 case Command::Mraw:
231 case Command::Logo:
232 case Command::Rdum:
233 case Command::Wrum:
234 case Command::Calo:
235 default:
236 break;
237 }
238 return false;
239}
240
242constexpr bool UserMemoryArgumentsValid(bool is_write, std::span<const int32_t> args) noexcept {
243 if (args.size() < 2U) {
244 return false;
245 }
246 const int64_t first = args[0];
247 const int64_t count = args[1];
248 const bool span_ok =
249 (first >= 0) && (first <= 63) && (count >= 1) && (count <= 64) && ((first + count) <= 64);
250 const bool length_ok =
251 is_write ? (static_cast<int64_t>(args.size()) == (count + 2)) : (args.size() == 2U);
252 return span_ok && length_ok;
253}
254
256constexpr bool ArgumentsValid(Command command, std::span<const int32_t> args) noexcept {
257 switch (command) {
258 case Command::Crce:
259 case Command::Baud:
260 case Command::Cahi:
261 case Command::Bcst:
262 case Command::Setm:
263 return (args.size() == 1U) && OneArgumentValid(command, args[0]);
264 case Command::Rdum:
265 case Command::Wrum:
266 return UserMemoryArgumentsValid(command == Command::Wrum, args);
267 case Command::Vers:
268 case Command::Idnr:
269 case Command::Moxy:
270 case Command::Mraw:
271 case Command::Logo:
272 case Command::Calo:
273 default:
274 break;
275 }
276 return args.empty();
277}
278
279} // namespace detail
280
294constexpr std::size_t EncodeCommand(Command command, std::span<const int32_t> args,
295 std::span<char> out) noexcept {
296 if (!detail::IsEnumerator(command) || !detail::ArgumentsValid(command, args)) {
297 return 0U;
298 }
299 const char* header = HeaderOf(command);
300 std::size_t pos = 0U;
301 if (out.size() < 6U) {
302 return 0U;
303 }
304 out[pos] = '#';
305 ++pos;
306 for (std::size_t i = 0U; i < 4U; ++i) {
307 out[pos] = header[i];
308 ++pos;
309 }
310 for (const int32_t value : args) {
311 if ((pos >= out.size()) || (pos >= (kMaxCommandLength - 1U))) {
312 return 0U;
313 }
314 out[pos] = ' ';
315 ++pos;
316 if (!detail::PutInt(out, pos, value)) {
317 return 0U;
318 }
319 }
320 if (pos >= out.size()) {
321 return 0U;
322 }
323 out[pos] = '\r';
324 ++pos;
325 return pos;
326}
327
329enum class PushResult : uint8_t {
330 Pending = 0,
331 Line,
332 Bad,
333};
334
345public:
347 constexpr LineAssembler() noexcept = default;
348
353 constexpr void Reset(bool ignore_lf) noexcept {
354 len_ = 0U;
355 discarding_ = false;
356 ready_ = false;
357 ignore_lf_ = ignore_lf;
358 }
359
365 constexpr PushResult PushByte(uint8_t byte) noexcept {
366 if (ready_) {
367 ready_ = false;
368 len_ = 0U;
369 }
370 if (byte == 0x0DU) {
371 return endOfLine();
372 }
373 if (discarding_) {
374 ++discarded_;
375 return PushResult::Pending;
376 }
377 if ((byte == 0x0AU) && ignore_lf_ && (len_ == 0U)) {
378 return PushResult::Pending;
379 }
380 if ((byte < 0x20U) || (byte > 0x7EU) || (len_ >= (kMaxLineLength - 1U))) {
381 discarded_ += static_cast<uint32_t>(len_) + 1U;
382 len_ = 0U;
383 discarding_ = true;
384 return PushResult::Bad;
385 }
386 buf_[len_] = std::bit_cast<char>(byte);
387 ++len_;
388 return PushResult::Pending;
389 }
390
392 [[nodiscard]] constexpr std::span<const char> Line() const noexcept {
393 return std::span<const char>{buf_}.first(len_);
394 }
397 [[nodiscard]] constexpr uint32_t TakeDiscarded() noexcept {
398 const uint32_t n = discarded_;
399 discarded_ = 0U;
400 return n;
401 }
403 [[nodiscard]] constexpr bool Discarding() const noexcept {
404 return discarding_;
405 }
407 [[nodiscard]] constexpr std::size_t Pending() const noexcept {
408 return len_;
409 }
410
411private:
412 constexpr PushResult endOfLine() noexcept {
413 if (discarding_) {
414 discarding_ = false;
415 return PushResult::Pending;
416 }
417 if (len_ == 0U) {
418 return PushResult::Pending;
419 }
420 ready_ = true;
421 return PushResult::Line;
422 }
423
424 std::array<char, kMaxLineLength> buf_{};
425 std::size_t len_{0};
426 uint32_t discarded_{0};
427 bool discarding_{false};
428 bool ready_{false};
429 bool ignore_lf_{true};
430};
431
433enum class ParseStatus : uint8_t {
434 Ok = 0,
435 BadCrc,
436 Malformed,
437};
438
441 bool crc_required{false};
442 bool crc_forbidden{false};
443 bool strict_spacing{true};
445 true};
446};
447
451 bool known{false};
452 bool erro{false};
453 bool crc_present{false};
455 std::size_t count{0};
456 int32_t error_code{0};
457 uint64_t big{0};
458 std::array<int64_t, kMaxValues> values{};
459};
460
461namespace detail {
462
465constexpr bool ParseNumber(std::span<const char> token, bool& negative, uint64_t& mag) noexcept {
466 std::size_t i = 0U;
467 negative = false;
468 mag = 0U;
469 if (token.empty()) {
470 return false;
471 }
472 if (SameChar(token[0], '-')) {
473 negative = true;
474 i = 1U;
475 }
476 const std::size_t digits = token.size() - i;
477 if ((digits == 0U) || (digits > 20U)) {
478 return false;
479 }
480 if (SameChar(token[i], '0') && ((digits > 1U) || negative)) {
481 return false;
482 }
483 for (; i < token.size(); ++i) {
484 const auto* const found = std::find(kDecimalDigits.begin(), kDecimalDigits.end(), token[i]);
485 if (found == kDecimalDigits.end()) {
486 return false;
487 }
488 const auto d =
489 static_cast<uint64_t>(found - kDecimalDigits.begin()); // the digit's value is its place
490 if (mag > ((0xFFFF'FFFF'FFFF'FFFFULL - d) / 10U)) {
491 return false;
492 }
493 mag = (mag * 10U) + d;
494 }
495 return true;
496}
497
499enum class ValueKind : uint8_t { Int32, UInt32, UInt64 };
500
503constexpr ValueKind FieldOf(Command command, std::size_t index) noexcept {
504 if (command == Command::Idnr) {
505 return ValueKind::UInt64;
506 }
507 if (((command == Command::Moxy) || (command == Command::Mraw)) && (index == 2U)) {
508 return ValueKind::UInt32;
509 }
510 return ValueKind::Int32;
511}
512
514constexpr bool ConvertValue(ValueKind kind, std::span<const char> token, int64_t& out,
515 uint64_t& big) noexcept {
516 bool neg = false;
517 uint64_t mag = 0U;
518 if (!ParseNumber(token, neg, mag)) {
519 return false;
520 }
521 switch (kind) {
522 case ValueKind::UInt64:
523 big = mag;
524 out = 0;
525 return !neg;
526 case ValueKind::UInt32:
527 out = static_cast<int64_t>(mag);
528 return !neg && (mag <= 0xFFFF'FFFFULL);
529 case ValueKind::Int32:
530 if (neg) {
531 out = (mag <= 2'147'483'648ULL) ? -static_cast<int64_t>(mag) : 0;
532 return mag <= 2'147'483'648ULL;
533 }
534 out = static_cast<int64_t>(mag);
535 return mag <= 2'147'483'647ULL;
536 default:
537 break;
538 }
539 return false;
540}
541
543constexpr bool FindCommand(std::span<const char> letters, Command& out) noexcept {
544 if (letters.size() < 4U) {
545 return false;
546 }
547 for (uint8_t i = 0U; i <= static_cast<uint8_t>(Command::Setm); ++i) {
548 const auto candidate = static_cast<Command>(i);
549 const char* header = HeaderOf(candidate);
550 if (SameChar(letters[0], header[0]) && SameChar(letters[1], header[1]) &&
551 SameChar(letters[2], header[2]) && SameChar(letters[3], header[3])) {
552 out = candidate;
553 return true;
554 }
555 }
556 return false;
557}
558
560constexpr bool ParseValues(std::span<const char> rest, bool strict, Command command, bool erro,
561 ParsedLine& out) noexcept {
562 std::size_t pos = 0U;
563 while (pos < rest.size()) {
564 if (!SameChar(rest[pos], ' ')) {
565 return false;
566 }
567 ++pos;
568 if (!strict) {
569 while ((pos < rest.size()) && (SameChar(rest[pos], ' '))) {
570 ++pos;
571 }
572 if (pos >= rest.size()) {
573 break;
574 }
575 }
576 std::size_t end = pos;
577 while ((end < rest.size()) && (!SameChar(rest[end], ' '))) {
578 ++end;
579 }
580 if ((end == pos) || (out.count >= kMaxValues)) {
581 return false;
582 }
583 const std::span<const char> token = rest.subspan(pos, end - pos);
584 int64_t value = 0;
585 const ValueKind kind = erro ? ValueKind::Int32 : FieldOf(command, out.count);
586 if (!ConvertValue(kind, token, value, out.big)) {
587 return false;
588 }
589 out.values[out.count] = value;
590 ++out.count;
591 pos = end;
592 }
593 return true;
594}
595
597constexpr ParseStatus SplitCrc(std::span<const char> line, std::span<const char>& body,
598 bool& suffix, uint32_t& crc) noexcept {
599 body = line;
600 suffix = false;
601 std::size_t colon = line.size();
602 for (std::size_t i = 0U; i < line.size(); ++i) {
603 if (SameChar(line[i], ':')) {
604 colon = i;
605 }
606 }
607 if (colon == line.size()) {
608 return ParseStatus::Ok;
609 }
610 // `colon + 2` must lie inside the line before the digit count is taken: the count is unsigned.
611 if (((colon + 2U) >= line.size()) || (!SameChar(line[colon + 1U], ' '))) {
613 }
614 const std::size_t digits = line.size() - colon - 2U;
615 if (digits > 5U) {
617 }
618 uint64_t mag = 0U;
619 bool neg = false;
620 if (!ParseNumber(line.subspan(colon + 2U), neg, mag) || neg || (mag > 0xFFFFU)) {
622 }
623 body = line.first(colon);
624 suffix = true;
625 crc = static_cast<uint32_t>(mag);
626 return ParseStatus::Ok;
627}
628
630constexpr ParseStatus CheckCrc(std::span<const char> body, bool suffix, uint32_t crc, bool is_erro,
631 const ParseOptions& options) noexcept {
632 if (suffix && options.crc_forbidden) {
634 }
635 if (suffix && (Crc16Modbus(body) != static_cast<uint16_t>(crc))) {
636 return ParseStatus::BadCrc;
637 }
638 if (!suffix && options.crc_required && !(is_erro && options.erro_without_crc)) {
639 return ParseStatus::BadCrc;
640 }
641 return ParseStatus::Ok;
642}
643
645constexpr bool TakeErrorCode(ParsedLine& line) noexcept {
646 if ((line.count != 1U) || (line.values[0] >= 0)) {
647 return false;
648 }
649 line.error_code = static_cast<int32_t>(line.values[0]);
650 return true;
651}
652
654constexpr bool IsErroHeader(std::span<const char> body) noexcept {
655 return (body.size() >= 5U) && (SameChar(body[0], '#')) && (SameChar(body[1], 'E')) &&
656 (SameChar(body[2], 'R')) && (SameChar(body[3], 'R')) && (SameChar(body[4], 'O'));
657}
658
660constexpr bool HasHeader(std::span<const char> body) noexcept {
661 if ((body.size() < 5U) || (!SameChar(body[0], '#'))) {
662 return false;
663 }
664 for (std::size_t i = 1U; i < 5U; ++i) {
665 if (!OneOf(body[i], kCapitalLetters)) {
666 return false;
667 }
668 }
669 return (body.size() == 5U) || (SameChar(body[5], ' '));
670}
671} // namespace detail
672
687constexpr ParsedLine ParseLine(std::span<const char> line, const ParseOptions& options) noexcept {
688 ParsedLine out{};
689 std::span<const char> body{};
690 bool suffix = false;
691 uint32_t crc = 0U;
692 if (detail::SplitCrc(line, body, suffix, crc) != ParseStatus::Ok) {
693 return out;
694 }
695 const bool is_erro = detail::IsErroHeader(body);
696 const ParseStatus crc_status = detail::CheckCrc(body, suffix, crc, is_erro, options);
697 if (crc_status != ParseStatus::Ok) {
698 out.status = crc_status;
699 return out;
700 }
701 if (!detail::HasHeader(body)) {
702 return out;
703 }
704 out.crc_present = suffix;
705 out.erro = is_erro;
706 out.known = is_erro || detail::FindCommand(body.subspan(1U, 4U), out.command);
707 if (!out.known) {
708 out.status = ParseStatus::Ok;
709 return out;
710 }
711 const bool strict = options.strict_spacing || is_erro;
712 if (!detail::ParseValues(body.subspan(5U), strict, out.command, is_erro, out)) {
713 out.count = 0U;
714 return out;
715 }
716 if (is_erro && !detail::TakeErrorCode(out)) {
717 out.count = 0U;
718 return out;
719 }
720 out.status = ParseStatus::Ok;
721 return out;
722}
723
730constexpr std::size_t ExpectedCount(Command command, std::span<const int32_t> args) noexcept {
731 switch (command) {
732 case Command::Vers:
733 return 4U;
734 case Command::Idnr:
735 return 1U;
736 case Command::Moxy:
737 return 3U;
738 case Command::Mraw:
739 return 8U;
740 case Command::Crce:
741 case Command::Baud:
742 case Command::Cahi:
743 case Command::Bcst:
744 case Command::Setm:
745 return 1U;
746 case Command::Rdum:
747 case Command::Wrum:
748 return (args.size() >= 2U) ? (2U + static_cast<std::size_t>(args[1])) : 0U;
749 case Command::Logo:
750 case Command::Calo:
751 default:
752 break;
753 }
754 return 0U;
755}
756
764constexpr bool VerifyEcho(Command command, std::span<const int32_t> args,
765 const ParsedLine& reply) noexcept {
766 if (!reply.known || reply.erro || (reply.command != command)) {
767 return false;
768 }
769 const std::size_t echoed = args.size();
770 if ((command == Command::Vers) || (command == Command::Idnr) || (command == Command::Moxy) ||
771 (command == Command::Mraw)) {
772 return true;
773 }
774 if (reply.count < echoed) {
775 return false;
776 }
777 for (std::size_t i = 0U; i < echoed; ++i) {
778 if (reply.values[i] != static_cast<int64_t>(args[i])) {
779 return false;
780 }
781 }
782 return true;
783}
784
792constexpr uint32_t MaxReplyChars(Command command, uint32_t words) noexcept {
793 switch (command) {
794 case Command::Vers:
795 return 48U;
796 case Command::Idnr:
797 return 40U;
798 case Command::Moxy:
799 return 56U;
800 case Command::Mraw:
801 return 120U;
802 case Command::Rdum:
803 case Command::Wrum:
804 return 32U + (12U * words);
805 case Command::Logo:
806 case Command::Crce:
807 case Command::Baud:
808 case Command::Calo:
809 case Command::Cahi:
810 case Command::Bcst:
811 case Command::Setm:
812 default:
813 break;
814 }
815 return 40U;
816}
817
820} // namespace fdo2
821
822#endif // FDO2_PROTOCOL_HPP
Collects the bytes of a reply into lines, one byte at a time (datasheet 4.1: one CR ends a reply).
Definition fdo2_protocol.hpp:344
constexpr uint32_t TakeDiscarded() noexcept
Definition fdo2_protocol.hpp:397
constexpr void Reset(bool ignore_lf) noexcept
Drop the partial line and the discard state.
Definition fdo2_protocol.hpp:353
constexpr std::span< const char > Line() const noexcept
Definition fdo2_protocol.hpp:392
constexpr bool Discarding() const noexcept
Definition fdo2_protocol.hpp:403
constexpr std::size_t Pending() const noexcept
Definition fdo2_protocol.hpp:407
constexpr LineAssembler() noexcept=default
An empty assembler that ignores a leading LF.
constexpr PushResult PushByte(uint8_t byte) noexcept
Feed one byte.
Definition fdo2_protocol.hpp:365
Public types of the FDO2 driver: errors, Result<T>, the status word, measurements,...
constexpr const char * HeaderOf(Command command) noexcept
The four header letters of a command, without the #.
Definition fdo2_protocol.hpp:79
ParseStatus
The outcome class of ParseLine().
Definition fdo2_protocol.hpp:433
constexpr std::size_t kMaxValues
Most values a reply holds: #RDUM R N and 64 words.
Definition fdo2_protocol.hpp:45
constexpr std::size_t kMaxLineLength
Definition fdo2_protocol.hpp:41
PushResult
What LineAssembler::PushByte() did with a byte.
Definition fdo2_protocol.hpp:329
constexpr std::size_t ExpectedCount(Command command, std::span< const int32_t > args) noexcept
How many values the reply to a command holds (datasheet 4.3).
Definition fdo2_protocol.hpp:730
constexpr uint32_t 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 (de...
Definition fdo2_protocol.hpp:792
constexpr ParsedLine ParseLine(std::span< const char > line, const ParseOptions &options) noexcept
Parse one reply line (without its CR) under the grammar of datasheet 4.
Definition fdo2_protocol.hpp:687
constexpr std::size_t 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,...
Definition fdo2_protocol.hpp:294
Command
The thirteen commands of the module (datasheet 4.3).
Definition fdo2_protocol.hpp:50
constexpr uint16_t Crc16Modbus(std::span< const T > data) noexcept
The CRC-16/MODBUS of a byte or character string (polynomial 0xA001 reflected, start 0xFFFF),...
Definition fdo2_protocol.hpp:123
constexpr uint32_t kMaxStale
Complete lines of another command dropped per transaction before the reply is InvalidReply.
Definition fdo2_protocol.hpp:47
constexpr bool 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.
Definition fdo2_protocol.hpp:764
constexpr std::size_t kMaxCommandLength
Longest command line the driver sends (#WRUM 0 64 and 64 values), including the CR.
Definition fdo2_protocol.hpp:43
@ Malformed
The line breaks the grammar.
@ BadCrc
A CRC suffix is wrong, or required and missing.
@ Ok
The line follows the grammar (and its CRC matches when present).
@ 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.
@ Bcst
#BCST T
@ Crce
#CRCE K
@ Baud
#BAUD R
@ Cahi
#CAHI P
@ Rdum
#RDUM R N
@ Setm
#SETM M
@ Wrum
#WRUM R N Y1 ... YN
constexpr uint32_t kBroadcastMaxMs
Longest broadcast interval, milliseconds.
Definition fdo2_types.hpp:442
constexpr uint32_t kBroadcastMinMs
Shortest and longest broadcast interval, milliseconds (#BCST).
Definition fdo2_types.hpp:440
constexpr bool IsSupportedBaud(uint32_t baud) noexcept
Whether baud is one of the eleven rates.
Definition fdo2_types.hpp:490
constexpr uint32_t kMaxMeasurementMode
Highest #SETM mode.
Definition fdo2_types.hpp:444
The FDO2 driver: everything it declares lives here; internals in detail.
Definition fdo2.hpp:33
How ParseLine() treats the CRC and the spacing (from the Config).
Definition fdo2_protocol.hpp:440
bool strict_spacing
Exactly one space between tokens, none leading or trailing.
Definition fdo2_protocol.hpp:443
bool crc_forbidden
A suffix is Malformed (CrcMode::Off).
Definition fdo2_protocol.hpp:442
bool crc_required
A suffix must be present (except #ERRO with erro_without_crc).
Definition fdo2_protocol.hpp:441
bool erro_without_crc
An #ERRO line without a suffix is accepted while CRC is required.
Definition fdo2_protocol.hpp:444
A parsed reply line.
Definition fdo2_protocol.hpp:449
std::size_t count
Values parsed (for Idnr: 1, in big).
Definition fdo2_protocol.hpp:455
Command command
The header, when known and not erro.
Definition fdo2_protocol.hpp:454
bool known
The header is one of the thirteen (or #ERRO).
Definition fdo2_protocol.hpp:451
bool erro
The line is #ERRO E.
Definition fdo2_protocol.hpp:452
int32_t error_code
E of #ERRO.
Definition fdo2_protocol.hpp:456
bool crc_present
A CRC suffix was present and valid.
Definition fdo2_protocol.hpp:453
std::array< int64_t, kMaxValues > values
The values, signed 32 bit or unsigned 32 bit.
Definition fdo2_protocol.hpp:458
uint64_t big
The #IDNR value.
Definition fdo2_protocol.hpp:457
ParseStatus status
Whether the line is valid.
Definition fdo2_protocol.hpp:450