HardFOC Core
API reference
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SfmHandler Class Reference

Handler wrapping one SF06 flow meter on a BaseI2c device. More...

#include <SfmHandler.h>

Classes

struct  Counters
 Diagnostics counters since construction. More...
 

Public Types

using DriverType = sfm::Driver< HalI2cSfmComm >
 

Public Member Functions

 SfmHandler (BaseI2c &i2c_device, const SfmHandlerConfig &config=SfmHandlerConfig{}, RtosMutex *bus_mutex=nullptr) noexcept
 
 SfmHandler (const SfmHandler &)=delete
 
SfmHandler & operator= (const SfmHandler &)=delete
 
 SfmHandler (SfmHandler &&)=delete
 
SfmHandler & operator= (SfmHandler &&)=delete
 
bool EnsureInitialized () noexcept
 Probe the device: optional soft reset, stop any running measurement, read product identifier + serial. Idempotent.
 
void Invalidate () noexcept
 Forget the cached identity: the next EnsureInitialized() (or Start) reads the product identifier again. For a re-probe after a fault — the part may have been reset, swapped, or identified from a corrupted read.
 
bool IsPresent () const noexcept
 True once EnsureInitialized() has succeeded.
 
const sfm::ProductInfo & Identity () const noexcept
 Cached identity (zeroed until probe succeeds).
 
bool SupportsGas (sfm::Gas gas) const noexcept
 Whether the probed variant carries a factory table for gas.
 
float FullScaleSlm () const noexcept
 Full-scale flow of the probed variant [slm] (0 when unknown).
 
sfm::DriverResult< void > Start (sfm::Gas gas) noexcept
 Start continuous measurement on gas (reads scale/offset first) and apply the configured averaging window.
 
sfm::DriverResult< void > Start () noexcept
 Start(config.default_gas).
 
sfm::DriverResult< void > Stop () noexcept
 Stop continuous measurement (idle).
 
sfm::DriverResult< sfm::Measurement > ReadMeasurement () noexcept
 Read one flow / temperature / status frame (NoData when no fresh sample).
 
sfm::DriverResult< void > ConfigureAveraging (std::uint16_t window) noexcept
 Change the averaging window while measuring (0 = average-until-read).
 
sfm::DriverResult< void > UpdateConcentration (std::uint16_t o2_permille) noexcept
 Update the O2 fraction of a running mixture table.
 
sfm::DriverResult< float > ReadTemperature () noexcept
 SFx6000: flow-chip temperature while measuring (NotSupported on SF06).
 
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 frames and CRC errors.
 
sfm::Family Family () const noexcept
 Part family (from the identifier once probed).
 
std::uint8_t Address () const noexcept
 7-bit address of the bound device.
 
sfm::Gas ActiveGas () const noexcept
 Gas selected by the last successful Start().
 
sfm::Scaling ActiveScaling () const noexcept
 Scale / offset / unit captured at Start().
 
bool Measuring () const noexcept
 True while a continuous measurement is running.
 
Counters GetCounters () const noexcept
 

Private Member Functions

bool EnsureInitializedLocked () noexcept
 

Private Attributes

SfmHandlerConfig config_
 
HalI2cSfmComm comm_
 
std::unique_ptr< DriverType > driver_
 
sfm::ProductInfo identity_ {}
 
std::atomic< bool > initialized_ {false}
 
std::atomic< std::uint32_t > frames_ {0}
 
std::atomic< std::uint32_t > no_data_ {0}
 
std::atomic< std::uint32_t > crc_errors_ {0}
 
std::atomic< std::uint32_t > bus_errors_ {0}
 
RtosMutex private_mutex_
 
RtosMutex * bus_mutex_
 

Detailed Description

Handler wrapping one SF06 flow meter on a BaseI2c device.

Member Typedef Documentation

◆ DriverType

using SfmHandler::DriverType = sfm::Driver<HalI2cSfmComm>

Constructor & Destructor Documentation

◆ SfmHandler() [1/3]

SfmHandler::SfmHandler ( BaseI2c &  i2c_device,
const SfmHandlerConfig &  config = SfmHandlerConfig{},
RtosMutex *  bus_mutex = nullptr 
)
explicitnoexcept
Parameters
i2c_deviceConfigured BaseI2c device (address = sensor address). Must outlive the handler.
configGas / averaging / diagnostics.
bus_mutexOptional shared mutex when several devices share the bus; private when null.

◆ SfmHandler() [2/3]

SfmHandler::SfmHandler ( const SfmHandler &  )
delete

◆ SfmHandler() [3/3]

SfmHandler::SfmHandler ( SfmHandler &&  )
delete

Member Function Documentation

◆ ActiveGas()

sfm::Gas SfmHandler::ActiveGas ( ) const
noexcept

Gas selected by the last successful Start().

◆ ActiveScaling()

sfm::Scaling SfmHandler::ActiveScaling ( ) const
noexcept

Scale / offset / unit captured at Start().

◆ Address()

std::uint8_t SfmHandler::Address ( ) const
inlinenoexcept

7-bit address of the bound device.

◆ ConfigureAveraging()

sfm::DriverResult< void > SfmHandler::ConfigureAveraging ( std::uint16_t  window)
noexcept

Change the averaging window while measuring (0 = average-until-read).

◆ DecodeFrame()

sfm::DriverResult< sfm::Measurement > SfmHandler::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 frames and CRC errors.

Note
No bus access. The caller owns the bus transaction.

◆ EnsureInitialized()

bool SfmHandler::EnsureInitialized ( )
noexcept

Probe the device: optional soft reset, stop any running measurement, read product identifier + serial. Idempotent.

Returns
true when the identifier was read (device present).

◆ EnsureInitializedLocked()

bool SfmHandler::EnsureInitializedLocked ( )
privatenoexcept

◆ Family()

sfm::Family SfmHandler::Family ( ) const
noexcept

Part family (from the identifier once probed).

◆ FullScaleSlm()

float SfmHandler::FullScaleSlm ( ) const
noexcept

Full-scale flow of the probed variant [slm] (0 when unknown).

◆ GetCounters()

SfmHandler::Counters SfmHandler::GetCounters ( ) const
noexcept

◆ Identity()

const sfm::ProductInfo & SfmHandler::Identity ( ) const
inlinenoexcept

Cached identity (zeroed until probe succeeds).

◆ Invalidate()

void SfmHandler::Invalidate ( )
inlinenoexcept

Forget the cached identity: the next EnsureInitialized() (or Start) reads the product identifier again. For a re-probe after a fault — the part may have been reset, swapped, or identified from a corrupted read.

◆ IsPresent()

bool SfmHandler::IsPresent ( ) const
inlinenoexcept

True once EnsureInitialized() has succeeded.

◆ Measuring()

bool SfmHandler::Measuring ( ) const
noexcept

True while a continuous measurement is running.

◆ operator=() [1/2]

SfmHandler & SfmHandler::operator= ( const SfmHandler &  )
delete

◆ operator=() [2/2]

SfmHandler & SfmHandler::operator= ( SfmHandler &&  )
delete

◆ ReadMeasurement()

sfm::DriverResult< sfm::Measurement > SfmHandler::ReadMeasurement ( )
noexcept

Read one flow / temperature / status frame (NoData when no fresh sample).

◆ ReadTemperature()

sfm::DriverResult< float > SfmHandler::ReadTemperature ( )
noexcept

SFx6000: flow-chip temperature while measuring (NotSupported on SF06).

◆ Start() [1/2]

sfm::DriverResult< void > SfmHandler::Start ( )
inlinenoexcept

Start(config.default_gas).

◆ Start() [2/2]

sfm::DriverResult< void > SfmHandler::Start ( sfm::Gas  gas)
noexcept

Start continuous measurement on gas (reads scale/offset first) and apply the configured averaging window.

Returns
Driver result; UnsupportedGas when the variant lacks the table.

◆ Stop()

sfm::DriverResult< void > SfmHandler::Stop ( )
noexcept

Stop continuous measurement (idle).

◆ SupportsGas()

bool SfmHandler::SupportsGas ( sfm::Gas  gas) const
noexcept

Whether the probed variant carries a factory table for gas.

◆ UpdateConcentration()

sfm::DriverResult< void > SfmHandler::UpdateConcentration ( std::uint16_t  o2_permille)
noexcept

Update the O2 fraction of a running mixture table.

Member Data Documentation

◆ bus_errors_

std::atomic<std::uint32_t> SfmHandler::bus_errors_ {0}
private

◆ bus_mutex_

RtosMutex* SfmHandler::bus_mutex_
private

◆ comm_

HalI2cSfmComm SfmHandler::comm_
private

◆ config_

SfmHandlerConfig SfmHandler::config_
private

◆ crc_errors_

std::atomic<std::uint32_t> SfmHandler::crc_errors_ {0}
private

◆ driver_

std::unique_ptr<DriverType> SfmHandler::driver_
private

◆ frames_

std::atomic<std::uint32_t> SfmHandler::frames_ {0}
private

◆ identity_

sfm::ProductInfo SfmHandler::identity_ {}
private

◆ initialized_

std::atomic<bool> SfmHandler::initialized_ {false}
private

◆ no_data_

std::atomic<std::uint32_t> SfmHandler::no_data_ {0}
private

◆ private_mutex_

RtosMutex SfmHandler::private_mutex_
private

The documentation for this class was generated from the following files: