STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
fsw::calibration::CubicCalibrationStore Class Reference

Owns the per-channel captured points and the fitted cubic for the calibration service. More...

#include <CubicCalibrationStore.hpp>

Collaboration diagram for fsw::calibration::CubicCalibrationStore:
[legend]

Public Member Functions

 CubicCalibrationStore (std::string file_path)
void register_channel (uint16_t uid, uint8_t board_id, uint8_t connector, uint8_t logical_ch, const std::string &role, const std::string &active_model="cubic", SensorKind kind=SensorKind::PT, const std::string &raw_unit="adc")
 Attach/refresh identity + role + streaming model for a uid (idempotent; call at startup).
CubicFit add_point (uint16_t uid, double adc, double psi)
 Append a capture point (raw ADC, reference PSI), cap history, and re-fit.
void note_capture (uint16_t uid, const CaptureQuality &q)
 Record how the last capture on this uid went, for the UI to show.
void set_fit_curve (uint16_t uid, const std::vector< std::pair< double, double > > &curve)
 Replace a robust uid's display fit-curve (sampled predict_pressure_psi points).
void clear_channel (uint16_t uid)
 Drop all points, fit, and fit-curve for a uid (channel goes back to PENDING).
const CubicFit * fit_for (uint16_t uid) const
const CubicChannel * channel (uint16_t uid) const
std::vector< uint16_t > uids () const
bool save () const
 Atomically write the JSON record (temp + rename).
size_t load ()
 Load the JSON record, resume points, and re-fit each channel.
bool load_failed () const
 True when load() could not read an existing file, so every curve here is a fallback rather than the operator's.

Static Public Member Functions

static CubicFit compute_fit (const std::vector< CubicPoint > &pts, int max_degree=3)
 Least-squares polynomial of degree min(max_degree, n - 1) over pts.

Static Public Attributes

static constexpr size_t kMaxPoints = 20

Private Member Functions

std::string serialize () const

Static Private Member Functions

static void refit (CubicChannel &ch)
 Recompute fit_cubic / fit_linear / fit / status from ch.points per ch.active_model.

Private Attributes

std::mutex mutex_
std::string file_path_
bool load_failed_ = false
 Set when load() could not read an existing file.
std::map< uint16_t, CubicChannel > channels_

Detailed Description

Owns the per-channel captured points and the fitted cubic for the calibration service.

Thread-safe. Persists atomically to a single JSON file that is:

  • re-loadable by this class on restart (resume points, re-fit), and
  • backward-compatible with the existing calibration_polynomials/poly_coeffs loaders (logical-channel-keyed) so the file doubles as the factory-cubic overlay the service loads. Those maps are PT-only; load cells get lc_-prefixed equivalents, because the two share a logical-channel space (see SensorKind). The service is the sole writer; the Node backend only reads the file to serve the UI.

Definition at line 161 of file CubicCalibrationStore.hpp.

Constructor & Destructor Documentation

◆ CubicCalibrationStore()

fsw::calibration::CubicCalibrationStore::CubicCalibrationStore ( std::string file_path)
explicit

Definition at line 32 of file CubicCalibrationStore.cpp.

References file_path_.

Member Function Documentation

◆ add_point()

◆ channel()

◆ clear_channel()

void fsw::calibration::CubicCalibrationStore::clear_channel ( uint16_t uid)

Drop all points, fit, and fit-curve for a uid (channel goes back to PENDING).

Definition at line 203 of file CubicCalibrationStore.cpp.

References channels_, lock, and mutex_.

Referenced by main().

◆ compute_fit()

CubicFit fsw::calibration::CubicCalibrationStore::compute_fit ( const std::vector< CubicPoint > & pts,
int max_degree = 3 )
static

◆ fit_for()

◆ load()

◆ load_failed()

bool fsw::calibration::CubicCalibrationStore::load_failed ( ) const
inline

True when load() could not read an existing file, so every curve here is a fallback rather than the operator's.

Callers that DERIVE from a curve (the LC tare recompute) must skip rather than persist a number computed against one.

Definition at line 201 of file CubicCalibrationStore.hpp.

References load_failed_, lock, and mutex_.

Referenced by main().

◆ note_capture()

void fsw::calibration::CubicCalibrationStore::note_capture ( uint16_t uid,
const CaptureQuality & q )

Record how the last capture on this uid went, for the UI to show.

Definition at line 188 of file CubicCalibrationStore.cpp.

References channels_, lock, and mutex_.

Referenced by main().

◆ refit()

void fsw::calibration::CubicCalibrationStore::refit ( CubicChannel & ch)
staticprivate

Recompute fit_cubic / fit_linear / fit / status from ch.points per ch.active_model.

Caller holds mutex_. Robust channels are left to their own branch (no fit).

Definition at line 61 of file CubicCalibrationStore.cpp.

References ch(), and compute_fit().

Referenced by add_point(), load(), and register_channel().

◆ register_channel()

void fsw::calibration::CubicCalibrationStore::register_channel ( uint16_t uid,
uint8_t board_id,
uint8_t connector,
uint8_t logical_ch,
const std::string & role,
const std::string & active_model = "cubic",
SensorKind kind = SensorKind::PT,
const std::string & raw_unit = "adc" )

Attach/refresh identity + role + streaming model for a uid (idempotent; call at startup).

active_model is the config truth ("cubic"|"robust"|"linear"|"physics"); it takes precedence over a value restored from disk by load(). A channel that already holds points is re-fitted when its model changes, so switching cubic <-> linear in config needs no recapture.

Definition at line 36 of file CubicCalibrationStore.cpp.

References board_id, ch(), channels_, lock, mutex_, and refit().

Referenced by anonymous_namespace{test_lc_linear_fit.cpp}::a_model_change_refits_without_a_capture(), anonymous_namespace{test_cubic_store_namespace.cpp}::add_point_rejects_unknown_uid(), anonymous_namespace{test_lc_linear_fit.cpp}::both_fits_are_serialized(), anonymous_namespace{test_lc_linear_fit.cpp}::cubic_model_is_unchanged(), disabled_board_orphan_is_not_applied(), anonymous_namespace{test_lc_linear_fit.cpp}::fill(), anonymous_namespace{test_cubic_store_namespace.cpp}::kind_round_trip(), anonymous_namespace{test_cubic_store_namespace.cpp}::legacy_file_without_kind(), anonymous_namespace{test_lc_linear_fit.cpp}::linear_needs_two_points(), anonymous_namespace{test_cubic_store_namespace.cpp}::logical_1_collision(), main(), anonymous_namespace{test_cubic_store_namespace.cpp}::pt_lc_logical_collision(), anonymous_namespace{test_cubic_store_namespace.cpp}::recovery_regenerates_overwritten_pt_curve(), removed_board_does_not_win_the_logical_map(), role_moved_to_t7_keeps_its_unit(), and t7_role_follows_within_t7().

◆ save()

◆ serialize()

◆ set_fit_curve()

void fsw::calibration::CubicCalibrationStore::set_fit_curve ( uint16_t uid,
const std::vector< std::pair< double, double > > & curve )

Replace a robust uid's display fit-curve (sampled predict_pressure_psi points).

Definition at line 195 of file CubicCalibrationStore.cpp.

References channels_, lock, and mutex_.

Referenced by main().

◆ uids()

std::vector< uint16_t > fsw::calibration::CubicCalibrationStore::uids ( ) const

Member Data Documentation

◆ channels_

std::map<uint16_t, CubicChannel> fsw::calibration::CubicCalibrationStore::channels_
private

◆ file_path_

std::string fsw::calibration::CubicCalibrationStore::file_path_
private

Definition at line 210 of file CubicCalibrationStore.hpp.

Referenced by CubicCalibrationStore(), load(), and save().

◆ kMaxPoints

size_t fsw::calibration::CubicCalibrationStore::kMaxPoints = 20
staticconstexpr

Definition at line 206 of file CubicCalibrationStore.hpp.

Referenced by add_point(), and load().

◆ load_failed_

bool fsw::calibration::CubicCalibrationStore::load_failed_ = false
private

Set when load() could not read an existing file.

Blocks save(), so an unreadable store is never replaced by the empty one we fell back to.

Definition at line 213 of file CubicCalibrationStore.hpp.

Referenced by load(), load_failed(), and save().

◆ mutex_

std::mutex fsw::calibration::CubicCalibrationStore::mutex_
mutableprivate

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