FDO2 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions | Variables
fdo2_types.hpp File Reference

Public types of the FDO2 driver: errors, Result<T>, the status word, measurements, configuration, firmware capabilities and the pure conversions. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include "fdo2_detail.hpp"
#include "fdo2_version.h"

Go to the source code of this file.

Classes

struct  fdo2::Result< T >
 The value of a call, or why there is none. More...
 
struct  fdo2::Result< void >
 The result of a call that returns no value. More...
 
struct  fdo2::Status
 The status word S of #MOXY and #MRAW, decoded (datasheet 4.3, #MOXY). Pure functions of the word; the word is kept whole. More...
 
struct  fdo2::Oxygen
 #MOXY result: oxygen partial pressure, temperature and status. More...
 
struct  fdo2::Raw
 #MRAW result: the Oxygen fields plus the raw values. More...
 
struct  fdo2::Version
 #VERS result (datasheet 4.3, #VERS). More...
 
struct  fdo2::Capabilities
 What the firmware revision offers (derived from datasheet 5; CapabilitiesFor). More...
 
struct  fdo2::Identity
 Who the module is: #VERS, #IDNR, the family and what follows from the firmware. More...
 
struct  fdo2::Counters
 Counters of what happened on the line; they only grow (docs/non-blocking.md). More...
 
struct  fdo2::Config
 Everything the driver needs from the application, with the datasheet defaults. More...
 
class  fdo2::CheckedConfig
 A configuration proven valid at build time. More...
 

Namespaces

namespace  fdo2
 The FDO2 driver: everything it declares lives here; internals in detail.
 

Enumerations

enum class  fdo2::Error : uint8_t {
  fdo2::Error::Ok = 0 , fdo2::Error::NotInitialized = 1 , fdo2::Error::InvalidArgument = 2 , fdo2::Error::Bus = 3 ,
  fdo2::Error::Timeout = 4 , fdo2::Error::DeviceIdMismatch = 5 , fdo2::Error::Crc = 6 , fdo2::Error::Busy = 7 ,
  fdo2::Error::DeviceFault = 8 , fdo2::Error::Unsupported = 9 , fdo2::Error::DeviceError = 16 , fdo2::Error::InvalidReply = 17 ,
  fdo2::Error::EchoMismatch = 18 , fdo2::Error::SensorFault = 19 , fdo2::Error::OutOfRange = 20 , fdo2::Error::CalibrationRejected = 21 ,
  fdo2::Error::NotPermitted = 22 , fdo2::Error::StateUnknown = 23 , fdo2::Error::BroadcastActive = 24 , fdo2::Error::NotReady = 25
}
 Why a call failed. Every call of the driver returns one of these in its Result. More...
 
enum class  fdo2::LogLevel : uint8_t { fdo2::LogLevel::Error = 0 , fdo2::LogLevel::Warning , fdo2::LogLevel::Info , fdo2::LogLevel::Debug }
 Severity passed to the optional Log() hook. More...
 
enum class  fdo2::Family : uint8_t { fdo2::Family::Fdo2G2 = 0 , fdo2::Family::Fdo2 = 1 }
 The module generation the driver talks to (datasheet 1.1; ambiguity A-3). More...
 
enum class  fdo2::CrcMode : uint8_t { fdo2::CrcMode::Auto = 0 , fdo2::CrcMode::Off = 1 , fdo2::CrcMode::Required = 2 }
 Whether replies carry the CRC-16 suffix (datasheet 4.2). More...
 
enum class  fdo2::StatusPolicy : uint8_t { fdo2::StatusPolicy::Datasheet = 0 , fdo2::StatusPolicy::Documented }
 What a status word other than 0 or 1 does (datasheet 4.3, ambiguity A-1). More...
 
enum class  fdo2::BroadcastPolicy : uint8_t { fdo2::BroadcastPolicy::Refuse = 0 , fdo2::BroadcastPolicy::Stream = 1 , fdo2::BroadcastPolicy::Disable = 2 }
 What start-up does when the module streams #MRAW lines (datasheet 4.3, #BCST). More...
 
enum class  fdo2::Quality : uint8_t { fdo2::Quality::Good = 0 , fdo2::Quality::Warning = 1 , fdo2::Quality::Degraded = 2 , fdo2::Quality::Invalid = 3 }
 How far a reading can be trusted, from the status word. More...
 
enum class  fdo2::OperationKind : uint8_t {
  fdo2::OperationKind::None = 0 , fdo2::OperationKind::Initialize , fdo2::OperationKind::Version , fdo2::OperationKind::UniqueId ,
  fdo2::OperationKind::MeasureOxygen , fdo2::OperationKind::MeasureRaw , fdo2::OperationKind::Identify , fdo2::OperationKind::ReadUserMemory ,
  fdo2::OperationKind::WriteUserMemory , fdo2::OperationKind::CalibrateZero , fdo2::OperationKind::CalibrateHigh , fdo2::OperationKind::SetCrc ,
  fdo2::OperationKind::SetMeasurementMode , fdo2::OperationKind::SetBroadcast , fdo2::OperationKind::SetBaudRate
}
 The operation the driver has in flight. More...
 
enum class  fdo2::State : uint8_t {
  fdo2::State::Uninitialized = 0 , fdo2::State::PoweringUp , fdo2::State::Idle , fdo2::State::Waiting ,
  fdo2::State::Streaming , fdo2::State::Draining , fdo2::State::StateUnknown
}
 The driver's state machine (docs/non-blocking.md). More...
 

Functions

constexpr const char * fdo2::ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr Capabilities fdo2::CapabilitiesFor (Family family, int32_t firmware) noexcept
 What a firmware revision offers.
 
constexpr bool fdo2::HasNoiseErratum (int32_t firmware) noexcept
 Whether a firmware revision shows the noise erratum (datasheet G2 6.1, G1 6.4).
 
constexpr bool fdo2::IsSupportedBaud (uint32_t baud) noexcept
 Whether baud is one of the eleven rates.
 
constexpr uint32_t fdo2::AirtimeUs (uint32_t chars, uint32_t baud) noexcept
 Time to send chars characters, 10 bits each at 8N1.
 
constexpr Error fdo2::Validate (const Config &config) noexcept
 Check a configuration without touching the module (zero port traffic).
 
void fdo2::ConfigIsInvalid () noexcept
 Reached only when a CheckedConfig is built from an invalid configuration: it is never defined, so the build fails and names it (KB-CPP20-013).
 
constexpr Result< int32_t > fdo2::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, in 10^-3 percent, rounded half up.
 
constexpr Result< int32_t > fdo2::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).
 
constexpr Result< int32_t > fdo2::AirO2Mhpa (int32_t pressure_ubar) noexcept
 AirO2Mhpa() for standard dry air.
 
constexpr int32_t fdo2::AmbientLoadMv (const Raw &raw) noexcept
 Sum of ambient light and signal intensity in millivolts, for the 2000 mV advice (datasheet 4.3, #MRAW, ambient light).
 
constexpr const char * fdo2::GetDriverVersion () noexcept
 
constexpr uint32_t fdo2::GetDriverVersionMajor () noexcept
 
constexpr uint32_t fdo2::GetDriverVersionMinor () noexcept
 
constexpr uint32_t fdo2::GetDriverVersionPatch () noexcept
 

Variables

constexpr int32_t fdo2::kMinFirmware = 328
 Lowest firmware revision any document covers: 3.28 (datasheet G1, 5).
 
constexpr int32_t fdo2::kFirmwareBroadcast = 341
 First revision with the #BCST command, the persistent #CRCE and the broadcast bug fix 3.53.
 
constexpr int32_t fdo2::kFirmwareStatusBit0 = 329
 First revision with status bit 0.
 
constexpr int32_t fdo2::kFirmwareCalibrationError = 351
 First revision with #ERRO -60.
 
constexpr int32_t fdo2::kFirmwareTempFlag = 354
 First revision whose temperature-sensor failure sets status bit 5.
 
constexpr int32_t fdo2::kFirmwareG2 = 355
 First revision of the FDO2-G2 (the first with #SETM).
 
constexpr int32_t fdo2::kDeviceId = 8
 First revision of the FDO2 (the device id of both families).
 
constexpr int32_t fdo2::kChannels = 1
 Number of oxygen channels.
 
constexpr int32_t fdo2::kSensorOxygen = 1
 #VERS sensor mask bit: oxygen.
 
constexpr uint32_t fdo2::kUserMemoryWords = 64
 Words of user memory (#RDUM, #WRUM).
 
constexpr uint32_t fdo2::kBroadcastMinMs = 100
 Shortest and longest broadcast interval, milliseconds (#BCST).
 
constexpr uint32_t fdo2::kBroadcastMaxMs = 10'000
 Longest broadcast interval, milliseconds.
 
constexpr uint32_t fdo2::kMaxMeasurementMode = 4
 Highest #SETM mode.
 
constexpr uint32_t fdo2::kWarmUpSeconds = 180
 Warm-up after power-up, seconds (datasheet 2, Specifications).
 
constexpr std::array< uint32_t, 11 > fdo2::kBaudRates
 The baud rates #BAUD accepts, ascending (datasheet 4.3, #BAUD).
 
constexpr uint32_t fdo2::kDefaultBaud = 19'200
 The rate after every power-up.
 
constexpr uint32_t fdo2::kPowerUpMsMin = 1000
 Bounds of the Config fields, shared by Validate() and the docs.
 
constexpr uint32_t fdo2::kPowerUpMsMax = 30'000
 Largest Config::power_up_ms, ms.
 
constexpr uint32_t fdo2::kCommandMsMin = 10
 Smallest Config::command_ms, ms.
 
constexpr uint32_t fdo2::kCommandMsMax = 5000
 Largest Config::command_ms, ms.
 
constexpr uint32_t fdo2::kMeasurementMsMin = 50
 Smallest Config::measurement_ms, ms.
 
constexpr uint32_t fdo2::kMeasurementMsMax = 5000
 Largest Config::measurement_ms, ms.
 
constexpr uint32_t fdo2::kCalibrationMsMin = 10'000
 Smallest Config::calibration_ms, ms.
 
constexpr uint32_t fdo2::kCalibrationMsMax = 60'000
 Largest Config::calibration_ms, ms.
 
constexpr uint32_t fdo2::kFlashMsMin = 100
 Smallest Config::flash_ms, ms.
 
constexpr uint32_t fdo2::kFlashMsMax = 30'000
 Largest Config::flash_ms, ms.
 
constexpr uint32_t fdo2::kLogoMsMin = 100
 Smallest Config::logo_ms, ms.
 
constexpr uint32_t fdo2::kLogoMsMax = 10'000
 Largest Config::logo_ms, ms.
 
constexpr uint32_t fdo2::kMarginMsMax = 1000
 Largest Config::margin_ms, ms.
 
constexpr uint32_t fdo2::kPowerOffMsMin = 10
 Smallest Config::power_off_ms, ms.
 
constexpr uint32_t fdo2::kPowerOffMsMax = 10'000
 Largest Config::power_off_ms, ms.
 
constexpr uint8_t fdo2::kRetriesMax = 3
 Largest Config::retries.
 
constexpr uint32_t fdo2::kBroadcastListenMsMax
 Largest Config::broadcast_listen_ms, ms (covers the longest interval).
 
constexpr uint8_t fdo2::kFlashBudgetMax = 64
 Largest Config::max_flash_writes.
 
constexpr uint16_t fdo2::kMinSteadyMax = 3600
 Largest Config::min_steady_s, s.
 
constexpr uint8_t fdo2::kCalWindowPctMax = 100
 Largest Config::cal_window_pct.
 
constexpr int32_t fdo2::kCalWindowMinMhpaMin = 1000
 Smallest Config::cal_window_min_mhpa.
 
constexpr int32_t fdo2::kCalWindowMinMhpaMax = 50'000
 
constexpr int32_t fdo2::kCalHighMinMhpa = 10'000
 
constexpr int32_t fdo2::kCalHighMaxMhpa = 2'000'000
 Highest standard #CAHI accepts: the maximum measuring range, 2000 hPa (2, not specified).
 
constexpr uint32_t fdo2::kDryAirO2Ppm = 209'500
 Fraction of oxygen in dry air, parts per million (standard dry air, assumption A-10).
 

Detailed Description

Public types of the FDO2 driver: errors, Result<T>, the status word, measurements, configuration, firmware capabilities and the pure conversions.

Everything here is plain data and constexpr functions with no platform dependency, so handlers, tests and tools can include it without the driver class. Values keep the units the module reports (datasheet section 4.3): 10^-3 hPa, 10^-3 degC, millidegrees, microvolts, microbar and 10^-3 RH, as integers; the unit is part of each name.