FDO2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
fdo2_types.hpp
Go to the documentation of this file.
1
13#ifndef FDO2_TYPES_HPP
14#define FDO2_TYPES_HPP
15
16#include <algorithm>
17#include <array>
18#include <cstddef>
19#include <cstdint>
20
21#include "fdo2_detail.hpp"
22#include "fdo2_version.h"
23
25namespace fdo2 {
26
39enum class [[nodiscard]] Error : uint8_t {
40 // Base set: the same names and values in every driver of the org (standards/driver.md).
41 Ok = 0,
42 NotInitialized = 1,
43 InvalidArgument = 2,
44 Bus = 3,
45 Timeout = 4,
47 Crc = 6,
48 Busy = 7,
49 DeviceFault = 8,
50 Unsupported = 9,
51 // Chip-specific values start at 16; each one is returned by some call (tests/test_errors.cpp).
52 DeviceError = 16,
53 InvalidReply = 17,
54 EchoMismatch = 18,
55 SensorFault = 19,
56 OutOfRange = 20,
58 NotPermitted = 22,
59 StateUnknown = 23,
60 BroadcastActive = 24,
61 NotReady = 25,
62};
63
69constexpr const char* ToString(Error error) noexcept {
70 switch (error) {
71 case Error::Ok:
72 return "Ok";
74 return "NotInitialized";
76 return "InvalidArgument";
77 case Error::Bus:
78 return "Bus";
79 case Error::Timeout:
80 return "Timeout";
82 return "DeviceIdMismatch";
83 case Error::Crc:
84 return "Crc";
85 case Error::Busy:
86 return "Busy";
88 return "DeviceFault";
90 return "Unsupported";
92 return "DeviceError";
94 return "InvalidReply";
96 return "EchoMismatch";
98 return "SensorFault";
100 return "OutOfRange";
102 return "CalibrationRejected";
104 return "NotPermitted";
106 return "StateUnknown";
108 return "BroadcastActive";
109 case Error::NotReady:
110 return "NotReady";
111 default:
112 break;
113 }
114 return "Unknown";
115}
116
124template <typename T>
125struct [[nodiscard]] Result {
126 T value{};
127 Error error{Error::Ok};
128
130 [[nodiscard]] constexpr bool ok() const noexcept {
131 return error == Error::Ok;
132 }
134 constexpr explicit operator bool() const noexcept {
135 return ok();
136 }
137
143 static constexpr Result Success(T v) noexcept {
144 return {v, Error::Ok};
145 }
151 static constexpr Result Failure(Error e) noexcept {
152 return {T{}, e};
153 }
154};
155
157template <>
158struct [[nodiscard]] Result<void> {
159 Error error{Error::Ok};
160
162 [[nodiscard]] constexpr bool ok() const noexcept {
163 return error == Error::Ok;
164 }
166 constexpr explicit operator bool() const noexcept {
167 return ok();
168 }
169
171 static constexpr Result Success() noexcept {
172 return {Error::Ok};
173 }
179 static constexpr Result Failure(Error e) noexcept {
180 return {e};
181 }
182};
183
185enum class LogLevel : uint8_t {
186 Error = 0,
187 Warning,
188 Info,
189 Debug,
190};
191
193enum class Family : uint8_t {
194 Fdo2G2 = 0,
195 Fdo2 = 1,
196};
197
199enum class CrcMode : uint8_t {
200 Auto = 0,
201 Off = 1,
202 Required = 2,
203};
204
206enum class StatusPolicy : uint8_t {
207 Datasheet = 0,
208 Documented =
209 1,
210};
211
213enum class BroadcastPolicy : uint8_t {
214 Refuse = 0,
215 Stream = 1,
216 Disable = 2,
217};
218
220enum class Quality : uint8_t {
221 Good = 0,
222 Warning = 1,
223 Degraded = 2,
224 Invalid = 3,
225};
226
228enum class OperationKind : uint8_t {
229 None = 0,
230 Initialize,
231 Version,
232 UniqueId,
234 MeasureRaw,
235 Identify,
240 SetCrc,
244};
245
247enum class State : uint8_t {
248 Uninitialized = 0,
249 PoweringUp,
250 Idle,
251 Waiting,
252 Streaming,
253 Draining,
255};
256
257namespace detail {
259template <>
260struct EnumLast<Family> {
261 static constexpr Family kValue = Family::Fdo2;
262};
264template <>
265struct EnumLast<CrcMode> {
266 static constexpr CrcMode kValue = CrcMode::Required;
267};
269template <>
270struct EnumLast<StatusPolicy> {
271 static constexpr StatusPolicy kValue = StatusPolicy::Documented;
272};
274template <>
275struct EnumLast<BroadcastPolicy> {
276 static constexpr BroadcastPolicy kValue = BroadcastPolicy::Disable;
277};
278} // namespace detail
279
284struct Status {
285 uint32_t word{0};
286
288 [[nodiscard]] constexpr bool AmplificationReduced() const noexcept {
289 return has(kBit0);
290 }
292 [[nodiscard]] constexpr bool SignalTooLow() const noexcept {
293 return has(kBit1);
294 }
296 [[nodiscard]] constexpr bool SignalTooHigh() const noexcept {
297 return has(kBit2);
298 }
300 [[nodiscard]] constexpr bool ReferenceTooLow() const noexcept {
301 return has(kBit3);
302 }
304 [[nodiscard]] constexpr bool ReferenceTooHigh() const noexcept {
305 return has(kBit4);
306 }
308 [[nodiscard]] constexpr bool TemperatureSensorFailed() const noexcept {
309 return has(kBit5);
310 }
312 [[nodiscard]] constexpr bool HumidityHigh() const noexcept {
313 return has(kBit7);
314 }
316 [[nodiscard]] constexpr bool PressureSensorFailed() const noexcept {
317 return has(kBit9);
318 }
320 [[nodiscard]] constexpr bool HumiditySensorFailed() const noexcept {
321 return has(kBit10);
322 }
324 [[nodiscard]] constexpr bool AnyFatal() const noexcept {
325 return (word & 0x3EU) != 0U;
326 }
328 [[nodiscard]] constexpr bool UndefinedBits() const noexcept {
329 return (word & ~0x6BFU) != 0U;
330 }
332 [[nodiscard]] constexpr Quality Classify() const noexcept {
333 if (AnyFatal() || UndefinedBits()) {
334 return Quality::Invalid;
335 }
336 if ((word & 0x680U) != 0U) {
337 return Quality::Degraded;
338 }
339 return (word == 0U) ? Quality::Good : Quality::Warning;
340 }
341
342private:
343 static constexpr uint32_t kBit0{0x1U};
344 static constexpr uint32_t kBit1{0x2U};
345 static constexpr uint32_t kBit2{0x4U};
346 static constexpr uint32_t kBit3{0x8U};
347 static constexpr uint32_t kBit4{0x10U};
348 static constexpr uint32_t kBit5{0x20U};
349 static constexpr uint32_t kBit7{0x80U};
350 static constexpr uint32_t kBit9{0x200U};
351 static constexpr uint32_t kBit10{0x400U};
352 [[nodiscard]] constexpr bool has(uint32_t mask) const noexcept {
353 return (word & mask) != 0U;
354 }
355};
356
365
367struct Raw {
369 int32_t dphi_mdeg{0};
370 int32_t signal_uv{0};
371 int32_t ambient_uv{0};
372 int32_t pressure_ubar{0};
373 int32_t humidity_mpct{0};
374};
375
377struct Version {
378 int32_t device_id{0};
379 int32_t channels{0};
380 int32_t firmware{0};
381 int32_t sensors{0};
382};
383
386 bool user_memory{false};
387 bool broadcast{false};
388 bool crc_persistent{false};
389 bool calibration_error{false};
390 bool set_mode{false};
391 bool status_bit0{false};
392 bool temp_flag_reliable{false};
393};
394
404
406struct Counters {
407 uint32_t transactions{0};
408 uint32_t retries{0};
409 uint32_t timeouts{0};
410 uint32_t crc_errors{0};
411 uint32_t invalid_replies{0};
412 uint32_t device_errors{0};
413 uint32_t stale_lines{0};
414 uint32_t broadcast_lines{0};
415 uint32_t flash_writes{0};
416 uint32_t bytes_discarded{0};
417};
418
420inline constexpr int32_t kMinFirmware = 328;
422inline constexpr int32_t kFirmwareBroadcast = 341;
424inline constexpr int32_t kFirmwareStatusBit0 = 329;
426inline constexpr int32_t kFirmwareCalibrationError = 351;
428inline constexpr int32_t kFirmwareTempFlag = 354;
430inline constexpr int32_t kFirmwareG2 = 355;
432inline constexpr int32_t kDeviceId = 8;
434inline constexpr int32_t kChannels = 1;
436inline constexpr int32_t kSensorOxygen = 1;
438inline constexpr uint32_t kUserMemoryWords = 64;
440inline constexpr uint32_t kBroadcastMinMs = 100;
442inline constexpr uint32_t kBroadcastMaxMs = 10'000;
444inline constexpr uint32_t kMaxMeasurementMode = 4;
446inline constexpr uint32_t kWarmUpSeconds = 180;
447
454constexpr Capabilities CapabilitiesFor(Family family, int32_t firmware) noexcept {
455 Capabilities c{};
456 if (firmware < kMinFirmware) {
457 return c;
458 }
459 c.user_memory = true;
460 c.status_bit0 = firmware >= kFirmwareStatusBit0;
461 c.broadcast = firmware >= kFirmwareBroadcast;
462 c.crc_persistent = firmware >= kFirmwareBroadcast;
463 c.calibration_error = firmware >= kFirmwareCalibrationError;
464 c.temp_flag_reliable = firmware >= kFirmwareTempFlag;
465 c.set_mode = (family == Family::Fdo2G2) && (firmware >= kFirmwareG2);
466 return c;
467}
468
474constexpr bool HasNoiseErratum(int32_t firmware) noexcept {
475 return (firmware >= kFirmwareTempFlag) && (firmware <= 356);
476}
477
479inline constexpr std::array<uint32_t, 11> kBaudRates = {1200, 2400, 4800, 9600, 14400, 19200,
480 28800, 38400, 56000, 57600, 115200};
481
483inline constexpr uint32_t kDefaultBaud = 19'200;
484
490constexpr bool IsSupportedBaud(uint32_t baud) noexcept {
491 return std::ranges::find(kBaudRates, baud) != kBaudRates.end();
492}
493
500constexpr uint32_t AirtimeUs(uint32_t chars, uint32_t baud) noexcept {
501 if (baud == 0U) {
502 return 0U;
503 }
504 const uint64_t bits = static_cast<uint64_t>(chars) * 10U;
505 const uint64_t us = ((bits * 1'000'000U) + baud - 1U) / baud;
506 return static_cast<uint32_t>((us > 0xFFFF'FFFFU) ? 0xFFFF'FFFFU : us);
507}
508
516struct Config {
518 uint32_t baud{19'200};
519 uint32_t power_up_ms{1500};
521 uint32_t command_ms{100};
523 uint32_t measurement_ms{300};
524 uint32_t calibration_ms{10'000};
525 uint32_t flash_ms{2000};
526 uint32_t logo_ms{1100};
527 uint32_t margin_ms{50};
528 uint32_t power_off_ms{500};
529 uint8_t retries{1};
532 bool strict_spacing{true};
533 bool ignore_lf{true};
534 bool erro_without_crc{true};
539 uint8_t max_flash_writes{8};
541 uint16_t min_steady_s{300};
542 int32_t o2_min_mhpa{-5000};
543 int32_t o2_max_mhpa{2'100'000};
544 int32_t temp_min_mc{-20'000};
545 int32_t temp_max_mc{70'000};
546 int32_t pressure_min_ubar{250'000};
547 int32_t pressure_max_ubar{1'200'000};
548 int32_t humidity_max_mpct{100'000};
551 uint8_t cal_window_pct{20};
553 int32_t cal_window_min_mhpa{5000};
554};
555
557inline constexpr uint32_t kPowerUpMsMin = 1000;
558inline constexpr uint32_t kPowerUpMsMax = 30'000;
559inline constexpr uint32_t kCommandMsMin = 10;
560inline constexpr uint32_t kCommandMsMax = 5000;
561inline constexpr uint32_t kMeasurementMsMin = 50;
562inline constexpr uint32_t kMeasurementMsMax = 5000;
563inline constexpr uint32_t kCalibrationMsMin = 10'000;
564inline constexpr uint32_t kCalibrationMsMax = 60'000;
565inline constexpr uint32_t kFlashMsMin = 100;
566inline constexpr uint32_t kFlashMsMax = 30'000;
567inline constexpr uint32_t kLogoMsMin = 100;
568inline constexpr uint32_t kLogoMsMax = 10'000;
569inline constexpr uint32_t kMarginMsMax = 1000;
570inline constexpr uint32_t kPowerOffMsMin = 10;
571inline constexpr uint32_t kPowerOffMsMax = 10'000;
572inline constexpr uint8_t kRetriesMax = 3;
573inline constexpr uint32_t kBroadcastListenMsMax =
574 12'000;
575inline constexpr uint8_t kFlashBudgetMax = 64;
576inline constexpr uint16_t kMinSteadyMax = 3600;
577inline constexpr uint8_t kCalWindowPctMax = 100;
578inline constexpr int32_t kCalWindowMinMhpaMin = 1000;
579inline constexpr int32_t kCalWindowMinMhpaMax = 50'000;
582inline constexpr int32_t kCalHighMinMhpa = 10'000;
584inline constexpr int32_t kCalHighMaxMhpa = 2'000'000;
585
586namespace detail {
588constexpr bool InWindowI32(int32_t value, int32_t low, int32_t high) noexcept {
589 return (value >= low) && (value <= high);
590}
591
593constexpr bool InRange(uint32_t value, uint32_t low, uint32_t high) noexcept {
594 return (value >= low) && (value <= high);
595}
596
598constexpr bool ConfigEnumsValid(const Config& config) noexcept {
599 return IsEnumerator(config.family) && IsEnumerator(config.crc) &&
600 IsEnumerator(config.status_policy) && IsEnumerator(config.broadcast);
601}
602
604constexpr bool ConfigTimesValid(const Config& config) noexcept {
605 return IsSupportedBaud(config.baud) &&
606 InRange(config.power_up_ms, kPowerUpMsMin, kPowerUpMsMax) &&
607 InRange(config.command_ms, kCommandMsMin, kCommandMsMax) &&
610 InRange(config.flash_ms, kFlashMsMin, kFlashMsMax) &&
611 InRange(config.logo_ms, kLogoMsMin, kLogoMsMax) && (config.margin_ms <= kMarginMsMax) &&
612 InRange(config.power_off_ms, kPowerOffMsMin, kPowerOffMsMax) &&
614}
615
617constexpr bool ConfigLimitsValid(const Config& config) noexcept {
618 return (config.retries <= kRetriesMax) && (config.max_flash_writes >= 1U) &&
619 (config.max_flash_writes <= kFlashBudgetMax) && (config.min_steady_s <= kMinSteadyMax) &&
620 (config.cal_window_pct >= 1U) && (config.cal_window_pct <= kCalWindowPctMax) &&
622}
623
626constexpr bool ConfigWindowsValid(const Config& config) noexcept {
627 const bool reference_ok = (config.pressure_reference_ubar == 0) ||
628 ((config.pressure_reference_ubar >= config.pressure_min_ubar) &&
629 (config.pressure_reference_ubar <= config.pressure_max_ubar));
630 return (config.o2_min_mhpa < config.o2_max_mhpa) && (config.o2_min_mhpa <= 0) &&
631 (config.temp_min_mc < config.temp_max_mc) &&
632 (config.pressure_min_ubar < config.pressure_max_ubar) && (config.pressure_min_ubar > 0) &&
633 (config.humidity_max_mpct > 0) && reference_ok;
634}
635} // namespace detail
636
649constexpr Error Validate(const Config& config) noexcept {
650 const bool valid = detail::ConfigEnumsValid(config) && detail::ConfigTimesValid(config) &&
651 detail::ConfigLimitsValid(config) && detail::ConfigWindowsValid(config);
652 return valid ? Error::Ok : Error::InvalidArgument;
653}
654
655// The defaults are valid, proved at build time (KB-CPP20-012).
656static_assert(Validate(Config{}) == Error::Ok);
657static_assert(CapabilitiesFor(Family::Fdo2G2, 357).set_mode);
658static_assert(!CapabilitiesFor(Family::Fdo2, 357).set_mode);
659namespace detail {
660static_assert(AirtimeUs(1_u32, 19'200_u32) == 521_u32);
661} // namespace detail
662
667void ConfigIsInvalid() noexcept;
668
677public:
682 consteval explicit CheckedConfig(const Config& config) noexcept : config_(config) {
683 if (Validate(config) != Error::Ok) {
685 }
686 }
688 [[nodiscard]] constexpr const Config& Get() const& noexcept {
689 return config_;
690 }
692 void Get() const&& = delete;
693
694private:
695 Config config_;
696};
697
709constexpr Result<int32_t> VolumePercentMilli(int32_t o2_mhpa, int32_t pressure_ubar) noexcept {
710 if (pressure_ubar <= 0) {
712 }
713 const auto num = static_cast<int64_t>(o2_mhpa) * 100'000;
714 const auto den = static_cast<int64_t>(pressure_ubar);
715 const int64_t half = den / 2;
716 const int64_t q = (num >= 0) ? ((num + half) / den) : -(((-num) + half) / den);
717 if ((q > INT32_MAX) || (q < INT32_MIN)) {
719 }
720 return Result<int32_t>::Success(static_cast<int32_t>(q));
721}
722
724inline constexpr uint32_t kDryAirO2Ppm = 209'500;
725
733constexpr Result<int32_t> AirO2Mhpa(int32_t pressure_ubar, uint32_t fraction_ppm) noexcept {
734 if ((pressure_ubar <= 0) || (fraction_ppm == 0U) || (fraction_ppm > 1'000'000U)) {
736 }
737 const int64_t num = static_cast<int64_t>(pressure_ubar) * static_cast<int64_t>(fraction_ppm);
738 return Result<int32_t>::Success(static_cast<int32_t>((num + 500'000) / 1'000'000));
739}
740
746constexpr Result<int32_t> AirO2Mhpa(int32_t pressure_ubar) noexcept {
747 return AirO2Mhpa(pressure_ubar, kDryAirO2Ppm);
748}
749
756constexpr int32_t AmbientLoadMv(const Raw& raw) noexcept {
757 return static_cast<int32_t>((static_cast<int64_t>(raw.ambient_uv) + raw.signal_uv) / 1000);
758}
759
761constexpr const char* GetDriverVersion() noexcept {
762 return FDO2_VERSION_STRING;
763}
765constexpr uint32_t GetDriverVersionMajor() noexcept {
766 return FDO2_VERSION_MAJOR;
767}
769constexpr uint32_t GetDriverVersionMinor() noexcept {
770 return FDO2_VERSION_MINOR;
771}
773constexpr uint32_t GetDriverVersionPatch() noexcept {
774 return FDO2_VERSION_PATCH;
775}
776
779} // namespace fdo2
780
781#endif // FDO2_TYPES_HPP
A configuration proven valid at build time.
Definition fdo2_types.hpp:676
constexpr const Config & Get() const &noexcept
Definition fdo2_types.hpp:688
consteval CheckedConfig(const Config &config) noexcept
Check config at build time.
Definition fdo2_types.hpp:682
void Get() const &&=delete
Not on a temporary: the reference would dangle (KB-CPP20-044).
Compile-time helpers of the FDO2 driver: typed integer literals, exact hook matching,...
@ Ok
The line follows the grammar (and its CRC matches when present).
constexpr uint32_t kBroadcastMaxMs
Longest broadcast interval, milliseconds.
Definition fdo2_types.hpp:442
constexpr bool HasNoiseErratum(int32_t firmware) noexcept
Whether a firmware revision shows the noise erratum (datasheet G2 6.1, G1 6.4).
Definition fdo2_types.hpp:474
constexpr uint32_t kDefaultBaud
The rate after every power-up.
Definition fdo2_types.hpp:483
constexpr uint32_t kBroadcastMinMs
Shortest and longest broadcast interval, milliseconds (#BCST).
Definition fdo2_types.hpp:440
constexpr const char * GetDriverVersion() noexcept
Definition fdo2_types.hpp:761
constexpr int32_t kCalHighMaxMhpa
Highest standard #CAHI accepts: the maximum measuring range, 2000 hPa (2, not specified).
Definition fdo2_types.hpp:584
Family
The module generation the driver talks to (datasheet 1.1; ambiguity A-3).
Definition fdo2_types.hpp:193
constexpr uint32_t kCalibrationMsMax
Largest Config::calibration_ms, ms.
Definition fdo2_types.hpp:564
constexpr int32_t kDeviceId
First revision of the FDO2 (the device id of both families).
Definition fdo2_types.hpp:432
constexpr uint8_t kRetriesMax
Largest Config::retries.
Definition fdo2_types.hpp:572
constexpr uint16_t kMinSteadyMax
Largest Config::min_steady_s, s.
Definition fdo2_types.hpp:576
constexpr uint32_t kCommandMsMax
Largest Config::command_ms, ms.
Definition fdo2_types.hpp:560
constexpr int32_t kSensorOxygen
#VERS sensor mask bit: oxygen.
Definition fdo2_types.hpp:436
constexpr uint32_t kPowerUpMsMin
Bounds of the Config fields, shared by Validate() and the docs.
Definition fdo2_types.hpp:557
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition fdo2_types.hpp:769
constexpr int32_t kCalWindowMinMhpaMin
Smallest Config::cal_window_min_mhpa.
Definition fdo2_types.hpp:578
constexpr uint32_t kWarmUpSeconds
Warm-up after power-up, seconds (datasheet 2, Specifications).
Definition fdo2_types.hpp:446
constexpr int32_t AmbientLoadMv(const Raw &raw) noexcept
Sum of ambient light and signal intensity in millivolts, for the 2000 mV advice (datasheet 4....
Definition fdo2_types.hpp:756
State
The driver's state machine (docs/non-blocking.md).
Definition fdo2_types.hpp:247
constexpr Capabilities CapabilitiesFor(Family family, int32_t firmware) noexcept
What a firmware revision offers.
Definition fdo2_types.hpp:454
constexpr int32_t kFirmwareTempFlag
First revision whose temperature-sensor failure sets status bit 5.
Definition fdo2_types.hpp:428
constexpr int32_t kCalWindowMinMhpaMax
Definition fdo2_types.hpp:579
constexpr uint32_t AirtimeUs(uint32_t chars, uint32_t baud) noexcept
Time to send chars characters, 10 bits each at 8N1.
Definition fdo2_types.hpp:500
constexpr uint32_t kFlashMsMax
Largest Config::flash_ms, ms.
Definition fdo2_types.hpp:566
constexpr int32_t kFirmwareCalibrationError
First revision with #ERRO -60.
Definition fdo2_types.hpp:426
constexpr uint32_t kPowerOffMsMin
Smallest Config::power_off_ms, ms.
Definition fdo2_types.hpp:570
constexpr uint32_t kMeasurementMsMax
Largest Config::measurement_ms, ms.
Definition fdo2_types.hpp:562
CrcMode
Whether replies carry the CRC-16 suffix (datasheet 4.2).
Definition fdo2_types.hpp:199
constexpr uint8_t kFlashBudgetMax
Largest Config::max_flash_writes.
Definition fdo2_types.hpp:575
constexpr int32_t kFirmwareStatusBit0
First revision with status bit 0.
Definition fdo2_types.hpp:424
BroadcastPolicy
What start-up does when the module streams #MRAW lines (datasheet 4.3, #BCST).
Definition fdo2_types.hpp:213
constexpr int32_t kFirmwareG2
First revision of the FDO2-G2 (the first with #SETM).
Definition fdo2_types.hpp:430
constexpr uint32_t kDryAirO2Ppm
Fraction of oxygen in dry air, parts per million (standard dry air, assumption A-10).
Definition fdo2_types.hpp:724
OperationKind
The operation the driver has in flight.
Definition fdo2_types.hpp:228
constexpr uint32_t kLogoMsMin
Smallest Config::logo_ms, ms.
Definition fdo2_types.hpp:567
constexpr int32_t kChannels
Number of oxygen channels.
Definition fdo2_types.hpp:434
constexpr Result< int32_t > AirO2Mhpa(int32_t pressure_ubar, uint32_t fraction_ppm) noexcept
The pO2 of dry air at a pressure, for a one-point calibration (A-10).
Definition fdo2_types.hpp:733
constexpr uint8_t kCalWindowPctMax
Largest Config::cal_window_pct.
Definition fdo2_types.hpp:577
constexpr uint32_t kBroadcastListenMsMax
Largest Config::broadcast_listen_ms, ms (covers the longest interval).
Definition fdo2_types.hpp:573
constexpr int32_t kCalHighMinMhpa
Definition fdo2_types.hpp:582
constexpr uint32_t kMarginMsMax
Largest Config::margin_ms, ms.
Definition fdo2_types.hpp:569
constexpr uint32_t kCommandMsMin
Smallest Config::command_ms, ms.
Definition fdo2_types.hpp:559
constexpr uint32_t kPowerUpMsMax
Largest Config::power_up_ms, ms.
Definition fdo2_types.hpp:558
constexpr bool IsSupportedBaud(uint32_t baud) noexcept
Whether baud is one of the eleven rates.
Definition fdo2_types.hpp:490
LogLevel
Severity passed to the optional Log() hook.
Definition fdo2_types.hpp:185
constexpr uint32_t kPowerOffMsMax
Largest Config::power_off_ms, ms.
Definition fdo2_types.hpp:571
constexpr uint32_t kFlashMsMin
Smallest Config::flash_ms, ms.
Definition fdo2_types.hpp:565
constexpr int32_t kMinFirmware
Lowest firmware revision any document covers: 3.28 (datasheet G1, 5).
Definition fdo2_types.hpp:420
constexpr std::array< uint32_t, 11 > kBaudRates
The baud rates #BAUD accepts, ascending (datasheet 4.3, #BAUD).
Definition fdo2_types.hpp:479
constexpr int32_t kFirmwareBroadcast
First revision with the #BCST command, the persistent #CRCE and the broadcast bug fix 3....
Definition fdo2_types.hpp:422
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition fdo2_types.hpp:39
constexpr Result< int32_t > VolumePercentMilli(int32_t o2_mhpa, int32_t pressure_ubar) noexcept
The oxygen content in volume percent of the gas at the membrane (datasheet 2, p. 6): 100 x pO2 / p,...
Definition fdo2_types.hpp:709
constexpr uint32_t kMeasurementMsMin
Smallest Config::measurement_ms, ms.
Definition fdo2_types.hpp:561
constexpr uint32_t kCalibrationMsMin
Smallest Config::calibration_ms, ms.
Definition fdo2_types.hpp:563
void ConfigIsInvalid() noexcept
Reached only when a CheckedConfig is built from an invalid configuration: it is never defined,...
constexpr uint32_t kMaxMeasurementMode
Highest #SETM mode.
Definition fdo2_types.hpp:444
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition fdo2_types.hpp:69
Quality
How far a reading can be trusted, from the status word.
Definition fdo2_types.hpp:220
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition fdo2_types.hpp:773
constexpr uint32_t kLogoMsMax
Largest Config::logo_ms, ms.
Definition fdo2_types.hpp:568
StatusPolicy
What a status word other than 0 or 1 does (datasheet 4.3, ambiguity A-1).
Definition fdo2_types.hpp:206
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the module (zero port traffic).
Definition fdo2_types.hpp:649
constexpr uint32_t kUserMemoryWords
Words of user memory (#RDUM, #WRUM).
Definition fdo2_types.hpp:438
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition fdo2_types.hpp:765
@ Fdo2G2
FDO2-G2, the current module (firmware 3.55 and later); #SETM is documented.
@ Fdo2
FDO2, the legacy module (firmware 3.28 to 3.55); no #SETM in its data sheet.
@ Draining
Discarding input after a failed read, so a late reply is never taken.
@ Waiting
An operation is waiting for its reply.
@ Streaming
The module sends #MRAW lines by itself.
@ PoweringUp
Waiting power_up_ms before the first command.
@ Idle
Ready for a call.
@ Uninitialized
Nothing started, or Deinitialize() ran.
@ Auto
Learn from the first #VERS reply: a suffix means CRC is on.
@ Required
Every reply must carry a valid suffix (except #ERRO with erro_without_crc).
@ Off
Never expect a suffix: a reply with one is InvalidReply.
@ Disable
Send #BCST 0 (a flash write: needs allow_persistent_writes).
@ Refuse
Fail with BroadcastActive; the driver stays uninitialised.
@ Stream
Go to the Streaming state and decode the frames.
@ Initialize
BeginInitialize() and its #VERS and #IDNR steps.
@ None
Nothing pending.
@ SetMeasurementMode
#SETM.
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised, reset.
@ Debug
Detail for bring-up.
@ SensorFault
The status word was rejected by the StatusPolicy (4.3, #MOXY).
@ StateUnknown
A flash write or baud change ended without a confirmed echo.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ OutOfRange
A decoded value is outside the plausibility window of the Config.
@ DeviceIdMismatch
#VERS is not an FDO2 with an oxygen sensor: wrong device or wiring.
@ Crc
The CRC-16 of a reply did not match (datasheet 4.2).
@ Bus
A port hook returned false.
@ CalibrationRejected
#ERRO -60: the calibration is outside the expected range.
@ InvalidReply
A line the protocol grammar refuses (bytes, header, tokens, number).
@ BroadcastActive
The module streams #MRAW lines and the call needs it silent.
@ DeviceFault
#ERRO with a code the datasheet calls potentially fatal (4.4).
@ NotInitialized
EnsureInitialized() has not succeeded, or Deinitialize() ran since.
@ EchoMismatch
The header or an echoed value differs from what was sent (4.2).
@ Ok
The call succeeded.
@ Unsupported
The hook, firmware revision or family does not offer this call.
@ NotPermitted
A flash-writing call without consent, or over the write budget.
@ DeviceError
#ERRO -1, -21, -22 or -23: the module could not do it.
@ Timeout
No complete reply within the deadline (datasheet 4.1, 4.3).
@ Busy
An operation is pending, draining or the module streams.
@ NotReady
Warming up: a calibration needs a settled sensor (datasheet 2).
@ Warning
S = 1: detector amplification reduced, the reading is valid.
@ Invalid
A fatal bit (1 to 5) or an undefined bit.
@ Degraded
No fatal or undefined bit; bit 7, 9 or 10 set.
@ Documented
Only fatal and undefined bits are SensorFault; bits 7, 9, 10 are Degraded.
@ Datasheet
"S should always be 0 or 1": any other word is SensorFault.
The FDO2 driver: everything it declares lives here; internals in detail.
Definition fdo2.hpp:33
What the firmware revision offers (derived from datasheet 5; CapabilitiesFor).
Definition fdo2_types.hpp:385
bool user_memory
#RDUM, #WRUM.
Definition fdo2_types.hpp:386
bool status_bit0
Status bit 0 exists.
Definition fdo2_types.hpp:391
bool set_mode
#SETM (FDO2-G2 only).
Definition fdo2_types.hpp:390
bool temp_flag_reliable
Status bit 5 is set on a temperature sensor failure.
Definition fdo2_types.hpp:392
bool calibration_error
#ERRO -60 for an out-of-range calibration.
Definition fdo2_types.hpp:389
bool crc_persistent
#CRCE is stored in flash (before: lost at power cycle).
Definition fdo2_types.hpp:388
bool broadcast
#BCST.
Definition fdo2_types.hpp:387
Everything the driver needs from the application, with the datasheet defaults.
Definition fdo2_types.hpp:516
bool allow_persistent_writes
Definition fdo2_types.hpp:538
BroadcastPolicy broadcast
Start-up on a streaming module.
Definition fdo2_types.hpp:535
int32_t pressure_max_ubar
Plausible P, upper bound (sensor 1100 mbar).
Definition fdo2_types.hpp:547
StatusPolicy status_policy
Status acceptance (A-1).
Definition fdo2_types.hpp:531
Family family
Decides whether #SETM is attempted (A-3).
Definition fdo2_types.hpp:517
uint32_t power_off_ms
Off time of PowerCycle(), 10 to 10000.
Definition fdo2_types.hpp:528
uint32_t margin_ms
Added to every deadline, 0 to 1000.
Definition fdo2_types.hpp:527
int32_t pressure_reference_ubar
0: use the module's pressure; else the caller's.
Definition fdo2_types.hpp:549
uint32_t logo_ms
Allowance of #LOGO, 100 to 10000 (A-6).
Definition fdo2_types.hpp:526
uint8_t cal_window_pct
Definition fdo2_types.hpp:551
uint32_t power_up_ms
Wait after power before #VERS, 1000 to 30000 (A-4).
Definition fdo2_types.hpp:519
uint8_t retries
Extra attempts of an idempotent read, 0 to 3.
Definition fdo2_types.hpp:529
bool erro_without_crc
Accept #ERRO without CRC while CRC is on (A-12).
Definition fdo2_types.hpp:534
uint32_t measurement_ms
Definition fdo2_types.hpp:523
int32_t o2_min_mhpa
Plausible O, lower bound (10^-3 hPa).
Definition fdo2_types.hpp:542
uint32_t flash_ms
Allowance of #CRCE #SETM #BCST #WRUM, 100 to 30000 (A-7).
Definition fdo2_types.hpp:525
int32_t temp_max_mc
Plausible T, upper bound (spec 60 degC).
Definition fdo2_types.hpp:545
CrcMode crc
Expectation for the CRC suffix.
Definition fdo2_types.hpp:530
int32_t o2_max_mhpa
Plausible O, upper bound (spec 0 to 2000 hPa).
Definition fdo2_types.hpp:543
int32_t cal_window_min_mhpa
Definition fdo2_types.hpp:553
uint32_t broadcast_listen_ms
Passive listen at start-up, 0 (off) to 12000.
Definition fdo2_types.hpp:536
uint32_t calibration_ms
Allowance of #CALO and #CAHI, 10000 to 60000 (4.3).
Definition fdo2_types.hpp:524
uint8_t max_flash_writes
Flash-writing calls per driver lifetime, 1 to 64.
Definition fdo2_types.hpp:539
int32_t humidity_max_mpct
Plausible H, upper bound (100 RH).
Definition fdo2_types.hpp:548
bool strict_spacing
Exactly one space between tokens (A-11).
Definition fdo2_types.hpp:532
uint16_t min_steady_s
Definition fdo2_types.hpp:541
uint32_t baud
The rate the module runs at now; used for airtime.
Definition fdo2_types.hpp:518
int32_t temp_min_mc
Plausible T, lower bound (10^-3 degC; spec -10 degC).
Definition fdo2_types.hpp:544
int32_t pressure_min_ubar
Plausible P, lower bound (sensor 300 mbar).
Definition fdo2_types.hpp:546
bool ignore_lf
A LF at the start of a line is dropped.
Definition fdo2_types.hpp:533
uint32_t command_ms
Definition fdo2_types.hpp:521
Counters of what happened on the line; they only grow (docs/non-blocking.md).
Definition fdo2_types.hpp:406
uint32_t timeouts
Replies that did not complete in time.
Definition fdo2_types.hpp:409
uint32_t invalid_replies
Lines the grammar refused.
Definition fdo2_types.hpp:411
uint32_t transactions
Command lines written.
Definition fdo2_types.hpp:407
uint32_t device_errors
#ERRO replies.
Definition fdo2_types.hpp:412
uint32_t broadcast_lines
#MRAW lines received without asking.
Definition fdo2_types.hpp:414
uint32_t retries
Extra attempts of an idempotent read.
Definition fdo2_types.hpp:408
uint32_t crc_errors
Replies with a wrong CRC.
Definition fdo2_types.hpp:410
uint32_t flash_writes
Flash-writing commands sent.
Definition fdo2_types.hpp:415
uint32_t stale_lines
Complete lines of another command, dropped.
Definition fdo2_types.hpp:413
uint32_t bytes_discarded
Bytes dropped while resynchronising or draining.
Definition fdo2_types.hpp:416
Who the module is: #VERS, #IDNR, the family and what follows from the firmware.
Definition fdo2_types.hpp:396
uint64_t unique_id
#IDNR, unsigned 64 bit, not the serial number.
Definition fdo2_types.hpp:398
Family family
From Config::family.
Definition fdo2_types.hpp:399
bool noise_erratum
Firmware affected by the 8 to 15 degC noise erratum (informational).
Definition fdo2_types.hpp:400
Capabilities caps
CapabilitiesFor(family, firmware), with -26 learning applied.
Definition fdo2_types.hpp:402
Version version
The #VERS reply.
Definition fdo2_types.hpp:397
#MOXY result: oxygen partial pressure, temperature and status.
Definition fdo2_types.hpp:358
int32_t o2_mhpa
Oxygen partial pressure, 10^-3 hPa (typ. 0 to 210 hPa).
Definition fdo2_types.hpp:359
int32_t temperature_mc
Module temperature, 10^-3 degC (typ. 0 to 50 degC).
Definition fdo2_types.hpp:360
Quality quality
status.Classify(), kept for the caller.
Definition fdo2_types.hpp:362
bool warming_up
Less than 3 minutes since power-up (datasheet 2): reduced accuracy.
Definition fdo2_types.hpp:363
Status status
The status word of this measurement.
Definition fdo2_types.hpp:361
#MRAW result: the Oxygen fields plus the raw values.
Definition fdo2_types.hpp:367
int32_t signal_uv
Signal intensity of the oxygen sensor, microvolt.
Definition fdo2_types.hpp:370
Oxygen oxygen
O, T and S.
Definition fdo2_types.hpp:368
int32_t humidity_mpct
Relative humidity inside the housing, 10^-3 RH.
Definition fdo2_types.hpp:373
int32_t pressure_ubar
Pressure at the back side of the module, microbar.
Definition fdo2_types.hpp:372
int32_t ambient_uv
Ambient light, microvolt.
Definition fdo2_types.hpp:371
int32_t dphi_mdeg
Phase shift dphi, 10^-3 degree (typ. 5 to 60 degrees).
Definition fdo2_types.hpp:369
constexpr bool ok() const noexcept
Definition fdo2_types.hpp:162
static constexpr Result Success() noexcept
Definition fdo2_types.hpp:171
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition fdo2_types.hpp:179
The value of a call, or why there is none.
Definition fdo2_types.hpp:125
static constexpr Result Success(T v) noexcept
A successful result.
Definition fdo2_types.hpp:143
constexpr bool ok() const noexcept
Definition fdo2_types.hpp:130
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition fdo2_types.hpp:151
The status word S of #MOXY and #MRAW, decoded (datasheet 4.3, #MOXY). Pure functions of the word; the...
Definition fdo2_types.hpp:284
constexpr bool PressureSensorFailed() const noexcept
Definition fdo2_types.hpp:316
constexpr bool HumidityHigh() const noexcept
Definition fdo2_types.hpp:312
constexpr bool AmplificationReduced() const noexcept
Definition fdo2_types.hpp:288
uint32_t word
The unsigned 32 bit status word as the module sent it.
Definition fdo2_types.hpp:285
constexpr bool HumiditySensorFailed() const noexcept
Definition fdo2_types.hpp:320
constexpr bool UndefinedBits() const noexcept
Definition fdo2_types.hpp:328
constexpr bool AnyFatal() const noexcept
Definition fdo2_types.hpp:324
constexpr Quality Classify() const noexcept
Definition fdo2_types.hpp:332
constexpr bool SignalTooHigh() const noexcept
Definition fdo2_types.hpp:296
constexpr bool ReferenceTooLow() const noexcept
Definition fdo2_types.hpp:300
constexpr bool ReferenceTooHigh() const noexcept
Definition fdo2_types.hpp:304
constexpr bool TemperatureSensorFailed() const noexcept
Definition fdo2_types.hpp:308
constexpr bool SignalTooLow() const noexcept
Definition fdo2_types.hpp:292
#VERS result (datasheet 4.3, #VERS).
Definition fdo2_types.hpp:377
int32_t sensors
S: bit 0 oxygen, 1 temperature, 2 pressure, 3 humidity (15 = all).
Definition fdo2_types.hpp:381
int32_t device_id
D: 8 for every FDO2 and FDO2-G2.
Definition fdo2_types.hpp:378
int32_t channels
N: 1.
Definition fdo2_types.hpp:379
int32_t firmware
R: 100 x major + minor, 357 is firmware 3.57.
Definition fdo2_types.hpp:380