25#ifndef COMPONENT_HANDLER_SFM_HANDLER_H_
26#define COMPONENT_HANDLER_SFM_HANDLER_H_
33#include "base/BaseI2c.h"
34#include "core/hf-core-drivers/external/hf-sfm-flow-meter-driver/inc/sfm.hpp"
59 bool Write(std::uint8_t addr7,
const std::uint8_t* data, std::size_t len)
noexcept;
60 bool Read(std::uint8_t addr7, std::uint8_t* out, std::size_t len)
noexcept;
61 void DelayMs(std::uint32_t ms)
noexcept;
110 RtosMutex* bus_mutex =
nullptr)
noexcept;
141 [[nodiscard]]
bool SupportsGas(sfm::Gas gas)
const noexcept;
155 sfm::DriverResult<
void>
Start(sfm::Gas gas) noexcept;
161 sfm::DriverResult<void>
Stop() noexcept;
180 sfm::DriverResult<sfm::Measurement>
DecodeFrame(const std::uint8_t frame[9]) noexcept;
189 [[nodiscard]] sfm::Gas
ActiveGas() const noexcept;
193 [[nodiscard]]
bool Measuring() const noexcept;
197 std::uint32_t frames{0};
198 std::uint32_t no_data{0};
199 std::uint32_t crc_errors{0};
200 std::uint32_t bus_errors{0};
202 [[nodiscard]] Counters
GetCounters() const noexcept;
CRTP transport bridging sfm::I2cInterface to a BaseI2c device.
Definition SfmHandler.h:53
bool Write(std::uint8_t addr7, const std::uint8_t *data, std::size_t len) noexcept
Definition SfmHandler.cpp:28
void DelayMs(std::uint32_t ms) noexcept
Definition SfmHandler.cpp:63
std::uint8_t tx_scratch_[8]
Definition SfmHandler.h:70
bool EnsureInitialized() noexcept
Definition SfmHandler.cpp:70
std::uint8_t rx_scratch_[18]
Definition SfmHandler.h:71
bool Read(std::uint8_t addr7, std::uint8_t *out, std::size_t len) noexcept
Definition SfmHandler.cpp:49
BaseI2c & i2c_device_
Definition SfmHandler.h:69
std::uint8_t DeviceAddress() const noexcept
Address configured on the bound BaseI2c device.
Definition SfmHandler.cpp:24
Handler wrapping one SF06 flow meter on a BaseI2c device.
Definition SfmHandler.h:99
sfm::Family Family() const noexcept
Part family (from the identifier once probed).
Definition SfmHandler.cpp:244
SfmHandlerConfig config_
Definition SfmHandler.h:207
sfm::DriverResult< float > ReadTemperature() noexcept
SFx6000: flow-chip temperature while measuring (NotSupported on SF06).
Definition SfmHandler.cpp:225
SfmHandler(SfmHandler &&)=delete
SfmHandler & operator=(SfmHandler &&)=delete
void Invalidate() noexcept
Forget the cached identity: the next EnsureInitialized() (or Start) reads the product identifier agai...
Definition SfmHandler.h:130
const sfm::ProductInfo & Identity() const noexcept
Cached identity (zeroed until probe succeeds).
Definition SfmHandler.h:138
std::atomic< std::uint32_t > bus_errors_
Definition SfmHandler.h:217
sfm::DriverResult< void > ConfigureAveraging(std::uint16_t window) noexcept
Change the averaging window while measuring (0 = average-until-read).
Definition SfmHandler.cpp:201
sfm::DriverResult< sfm::Measurement > ReadMeasurement() noexcept
Read one flow / temperature / status frame (NoData when no fresh sample).
Definition SfmHandler.cpp:183
sfm::ProductInfo identity_
Definition SfmHandler.h:211
sfm::Driver< HalI2cSfmComm > DriverType
Definition SfmHandler.h:101
SfmHandler(const SfmHandler &)=delete
std::atomic< std::uint32_t > no_data_
Definition SfmHandler.h:215
sfm::DriverResult< sfm::Measurement > DecodeFrame(const std::uint8_t frame[9]) noexcept
Decode a 9-byte frame fetched by an interrupt / DMA reader with the active family and scaling; counts...
Definition SfmHandler.cpp:233
bool Measuring() const noexcept
True while a continuous measurement is running.
Definition SfmHandler.cpp:250
sfm::Gas ActiveGas() const noexcept
Gas selected by the last successful Start().
Definition SfmHandler.cpp:246
std::atomic< std::uint32_t > crc_errors_
Definition SfmHandler.h:216
std::uint8_t Address() const noexcept
7-bit address of the bound device.
Definition SfmHandler.h:186
std::atomic< bool > initialized_
Definition SfmHandler.h:212
RtosMutex * bus_mutex_
Definition SfmHandler.h:220
std::atomic< std::uint32_t > frames_
Definition SfmHandler.h:214
bool EnsureInitializedLocked() noexcept
Definition SfmHandler.cpp:93
Counters GetCounters() const noexcept
Definition SfmHandler.cpp:252
sfm::DriverResult< void > UpdateConcentration(std::uint16_t o2_permille) noexcept
Update the O2 fraction of a running mixture table.
Definition SfmHandler.cpp:213
bool EnsureInitialized() noexcept
Probe the device: optional soft reset, stop any running measurement, read product identifier + serial...
Definition SfmHandler.cpp:85
sfm::DriverResult< void > Start() noexcept
Start(config.default_gas).
Definition SfmHandler.h:158
std::unique_ptr< DriverType > driver_
Definition SfmHandler.h:209
SfmHandler & operator=(const SfmHandler &)=delete
sfm::DriverResult< void > Stop() noexcept
Stop continuous measurement (idle).
Definition SfmHandler.cpp:175
sfm::Scaling ActiveScaling() const noexcept
Scale / offset / unit captured at Start().
Definition SfmHandler.cpp:248
bool IsPresent() const noexcept
True once EnsureInitialized() has succeeded.
Definition SfmHandler.h:133
float FullScaleSlm() const noexcept
Full-scale flow of the probed variant [slm] (0 when unknown).
Definition SfmHandler.cpp:136
bool SupportsGas(sfm::Gas gas) const noexcept
Whether the probed variant carries a factory table for gas.
Definition SfmHandler.cpp:132
HalI2cSfmComm comm_
Definition SfmHandler.h:208
RtosMutex private_mutex_
Definition SfmHandler.h:219
Diagnostics counters since construction.
Definition SfmHandler.h:196
Construction-time configuration for one SF06 flow meter.
Definition SfmHandler.h:79
std::uint16_t averaging_window
On-sensor averaging: 0 = average-until-read, 1…128 = fixed-N.
Definition SfmHandler.h:85
bool soft_reset_on_init
Issue a general-call soft reset during bring-up when the bus supports it.
Definition SfmHandler.h:87
std::uint16_t o2_permille
O2 volume fraction (‰) for mixture tables.
Definition SfmHandler.h:83
sfm::Gas default_gas
Gas table requested at Start() when the caller passes none.
Definition SfmHandler.h:81
std::uint8_t device_index
Logical index for diagnostics.
Definition SfmHandler.h:89