|
HardFOC Core
API reference
|
Thread-safe access layer to one BASIS-2 instrument on a shared bus. More...
#include <AlicatBasis2Handler.h>
Classes | |
| struct | DiscoveredDevice |
| One discovered instrument and the baud rate it was found at. More... | |
Public Types | |
| using | DriverType = alicat_basis2::Driver< HalUartAlicatBasis2Comm > |
| using | HostBaudSetter = std::function< bool(std::uint32_t bps)> |
Callback used by DiscoverAcrossBauds / NormalizeBusBaud to retune the host UART when probing a new baud rate. | |
Public Member Functions | |
| AlicatBasis2Handler (BaseUart &uart, const AlicatBasis2HandlerConfig &config, RtosMutex *bus_mutex=nullptr) noexcept | |
| AlicatBasis2Handler (const AlicatBasis2Handler &)=delete | |
| AlicatBasis2Handler & | operator= (const AlicatBasis2Handler &)=delete |
| bool | EnsureInitialized () noexcept |
Lazy initialisation; reads identity, caches flow_decimals_. | |
| bool | IsInitialized () const noexcept |
| std::uint8_t | Address () const noexcept |
| std::uint8_t | DeviceIndex () const noexcept |
| const alicat_basis2::InstrumentIdentity & | Identity () const noexcept |
Cached identity (filled by EnsureInitialized). | |
| std::uint8_t | FlowDecimals () const noexcept |
| alicat_basis2::DriverResult< alicat_basis2::InstantaneousData > | ReadInstantaneous () noexcept |
| alicat_basis2::DriverResult< alicat_basis2::InstrumentIdentity > | RereadIdentity () noexcept |
| alicat_basis2::DriverResult< void > | Tare () noexcept |
| alicat_basis2::DriverResult< void > | SetGas (alicat_basis2::Gas g) noexcept |
| alicat_basis2::DriverResult< void > | SetSetpoint (float user_units) noexcept |
| alicat_basis2::DriverResult< void > | SetSetpointSource (alicat_basis2::SetpointSource s) noexcept |
| alicat_basis2::DriverResult< void > | SetCommWatchdogMs (std::uint16_t ms) noexcept |
| alicat_basis2::DriverResult< void > | SetMaxSetpointRamp (std::uint32_t pct_per_ms_x_10e7) noexcept |
| alicat_basis2::DriverResult< void > | SetAutotareEnabled (bool enabled) noexcept |
| alicat_basis2::DriverResult< void > | ResetTotalizer () noexcept |
| alicat_basis2::DriverResult< void > | SetTotalizerLimitMode (alicat_basis2::TotalizerLimitMode m) noexcept |
| alicat_basis2::DriverResult< void > | SetTotalizerBatch (std::uint32_t value_scaled) noexcept |
| alicat_basis2::DriverResult< void > | SetFlowAveragingMs (std::uint16_t ms) noexcept |
| alicat_basis2::DriverResult< void > | SetReferenceTemperatureC (float c) noexcept |
| alicat_basis2::DriverResult< void > | ConfigureMeasurementTrigger (std::uint16_t bits) noexcept |
| alicat_basis2::DriverResult< void > | StartMeasurementSamples (std::uint16_t n) noexcept |
| alicat_basis2::DriverResult< alicat_basis2::MeasurementData > | ReadMeasurement () noexcept |
| alicat_basis2::DriverResult< void > | SetModbusAddress (std::uint8_t addr) noexcept |
| alicat_basis2::DriverResult< void > | SetAsciiUnitId (char id) noexcept |
| alicat_basis2::DriverResult< void > | SetBaudRate (alicat_basis2::BaudRate br) noexcept |
| alicat_basis2::DriverResult< void > | FactoryRestore () noexcept |
| alicat_basis2::DriverResult< std::uint8_t > | Discover (std::uint8_t *present_bitmap, std::size_t bitmap_bytes, std::uint16_t probe_timeout_ms=30) noexcept |
| Bus-wide discovery sweep at the current host baud only. | |
| alicat_basis2::DriverResult< std::size_t > | DiscoverAcrossBauds (DiscoveredDevice *out, std::size_t max_devices, const HostBaudSetter &set_host_baud, std::uint16_t probe_timeout_ms=30, std::uint32_t settle_ms=25, const std::uint32_t *baud_list_bps=nullptr, std::size_t baud_list_count=0) noexcept |
| Sweep multiple baud rates, returning every BASIS-2 found on the bus along with the baud rate it answered at. | |
| alicat_basis2::DriverResult< std::size_t > | NormalizeBusBaud (std::uint32_t target_bps, const DiscoveredDevice *devices, std::size_t device_count, const HostBaudSetter &set_host_baud, std::uint8_t *failed_addresses_bitmap=nullptr, std::size_t failed_bitmap_bytes=0, std::uint16_t verify_timeout_ms=100) noexcept |
| Normalise every device on the bus to the same baud rate. | |
| DriverType * | GetDriver () noexcept |
| Direct access to the underlying driver (for advanced use; mutex must be held). | |
Private Member Functions | |
| bool | EnsureInitializedLocked () noexcept |
Private Attributes | |
| AlicatBasis2HandlerConfig | config_ |
| HalUartAlicatBasis2Comm | comm_ |
| std::unique_ptr< DriverType > | driver_ |
| alicat_basis2::InstrumentIdentity | identity_ {} |
| std::uint8_t | flow_decimals_ {3} |
| std::atomic< bool > | initialized_ {false} |
| RtosMutex | private_mutex_ |
| RtosMutex * | bus_mutex_ {&private_mutex_} |
Thread-safe access layer to one BASIS-2 instrument on a shared bus.
EnsureInitialized() lazily probes the instrument and caches identity.BaseUart to every handler that shares the bus. The first handler created with a nullptr mutex pointer creates the shared mutex; subsequent handlers must be constructed with a pointer to that same mutex object so transactions are properly serialised. | using AlicatBasis2Handler::DriverType = alicat_basis2::Driver<HalUartAlicatBasis2Comm> |
| using AlicatBasis2Handler::HostBaudSetter = std::function<bool(std::uint32_t bps)> |
Callback used by DiscoverAcrossBauds / NormalizeBusBaud to retune the host UART when probing a new baud rate.
true if the host UART successfully switched to bps, false to skip that baud entry.BaseUart& (which has no runtime baud setter), so the caller wires in whichever MCU-specific call applies (e.g. EspUart::SetBaudRate(bps)).
|
noexcept |
| uart | Reference to the (already-configured) BaseUart. |
| config | Per-slave configuration. |
| bus_mutex | Optional shared mutex when several handlers share the same bus. Pass nullptr for a private mutex. |
|
delete |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
noexcept |
Bus-wide discovery sweep at the current host baud only.
| [out] | present_bitmap | ≥32-byte bitmap; bit N = address N is alive. |
| bitmap_bytes | Size of present_bitmap (must be ≥32). | |
| probe_timeout_ms | Per-address probe timeout (ms). |
DiscoverAcrossBauds() to also find devices at other baud rates.
|
noexcept |
Sweep multiple baud rates, returning every BASIS-2 found on the bus along with the baud rate it answered at.
For each baud in baud_list the handler:
set_host_baud(baud) to retune the host UART.settle_ms so any stale RX bytes drain.DiscoverPresentAddresses() at that baud.{addr, baud} for every responder that isn't already in out (first-seen-baud wins).When baud_list is nullptr the handler iterates over every value in alicat_basis2::BaudRate (4800/9600/19200/38400/57600/115200).
On exit the host UART is restored to whatever baud was active last — typically you should follow the call with NormalizeBusBaud() (which retunes again) or an explicit set_host_baud(target).
| [out] | out | Destination buffer (caller-allocated). |
| max_devices | Capacity of out in elements. | |
| set_host_baud | Callback that retunes the host UART. | |
| probe_timeout_ms | Per-address timeout passed to the sweep. | |
| settle_ms | Delay after each baud change to let UART glitches subside (default 25 ms). | |
| baud_list_bps | Optional explicit baud-rate list in bits-per-second. nullptr = all six supported rates. | |
| baud_list_count | Number of entries in baud_list_bps. |
out on success; BufferTooSmall if out overflows; transport error if set_host_baud rejects every requested rate.
|
noexcept |
Lazy initialisation; reads identity, caches flow_decimals_.
|
privatenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Direct access to the underlying driver (for advanced use; mutex must be held).
|
inlinenoexcept |
Cached identity (filled by EnsureInitialized).
|
inlinenoexcept |
|
noexcept |
Normalise every device on the bus to the same baud rate.
For every {addr, baud} in devices whose baud != target_bps:
SetBaudRate(target). The device switches immediately — the response may be lost or garbled (datasheet calls this out explicitly), so the operation is logged but never aborts on a single failure.target_bps.failed_addresses (if provided).Devices already at target_bps are skipped (verified only). On exit the host UART is left at target_bps.
| target_bps | Final baud rate everyone should use. | |
| devices | Output of DiscoverAcrossBauds(). | |
| device_count | Length of devices. | |
| set_host_baud | Callback that retunes the host UART. | |
| [out] | failed_addresses | Optional buffer for slaves that could not be normalised; use a 32-byte bitmap. |
| verify_timeout_ms | Per-device verify timeout (ms). |
target_bps (verified by identity read), or transport / parameter error.
|
delete |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |