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

PT Calibration Manager. More...

#include <PTCalibration.hpp>

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

Public Member Functions

 PTCalibrationManager (bool auto_load=true)
 ~PTCalibrationManager ()=default
bool load_from_json (const std::string &json_path, bool merge_missing_only=false)
 Load calibration from JSON file (from calibration GUI).
bool load_from_csv (const std::string &csv_path)
 Load calibration from CSV file (from DiabloAvionics).
bool load_calibration ()
 Auto-load calibration from default paths Default: factory CSV first, then newest GUI JSON overlays every channel it lists (fixes CSV PT6≠GN2 ch6).
const PTCalibrationCoeffs * get_calibration (uint8_t channel_id) const
 Get calibration coefficients for a sensor channel.
bool is_calibrated (uint8_t channel_id) const
 Check if a channel has calibration.
double calculate_pressure (uint8_t channel_id, int32_t adc_code) const
 Calculate calibrated pressure for a channel.
size_t get_calibrated_count () const
 Get number of calibrated channels.
void set_calibration (uint8_t channel_id, const PTCalibrationCoeffs &coeffs)
 Set/replace the cubic coefficients for a logical channel at runtime.
void clear_calibration (uint8_t channel_id)
 Remove any cubic for a logical channel, so is_calibrated() returns false again.

Static Public Member Functions

static void set_default_paths (const std::string &json_dir, const std::string &csv_path)
 Set default calibration file paths.

Private Member Functions

bool parse_json_file (const std::string &json_path)
bool parse_csv_file (const std::string &csv_path)
std::string find_latest_json_file (const std::string &json_dir) const

Private Attributes

std::map< uint8_t, PTCalibrationCoeffs > calibrations_

Static Private Attributes

static std::string default_json_dir_ = "scripts/calibration/calibrations"
static std::string default_csv_path_

Detailed Description

PT Calibration Manager.

Loads and manages PT calibration coefficients from JSON or CSV files. Provides calibrated pressure values for sensor channels.

Definition at line 67 of file PTCalibration.hpp.

Constructor & Destructor Documentation

◆ PTCalibrationManager()

fsw::calibration::PTCalibrationManager::PTCalibrationManager ( bool auto_load = true)
explicit

Definition at line 88 of file PTCalibration.cpp.

References load_calibration().

◆ ~PTCalibrationManager()

fsw::calibration::PTCalibrationManager::~PTCalibrationManager ( )
default

Member Function Documentation

◆ calculate_pressure()

double fsw::calibration::PTCalibrationManager::calculate_pressure ( uint8_t channel_id,
int32_t adc_code ) const

Calculate calibrated pressure for a channel.

Parameters
channel_idSensor channel ID
adc_codeRaw ADC code
Returns
Calibrated pressure in PSI, or 0.0 if not calibrated

Definition at line 313 of file PTCalibration.cpp.

References get_calibration(), and p.

Referenced by invert_abort_psi_to_adc(), and main().

◆ clear_calibration()

void fsw::calibration::PTCalibrationManager::clear_calibration ( uint8_t channel_id)

Remove any cubic for a logical channel, so is_calibrated() returns false again.

Used by the calibration service's "clear" so a cleared/uncalibrated cubic sensor streams nothing (0) rather than reverting to a factory/baseline curve.

Definition at line 309 of file PTCalibration.cpp.

References calibrations_.

Referenced by main().

◆ find_latest_json_file()

std::string fsw::calibration::PTCalibrationManager::find_latest_json_file ( const std::string & json_dir) const
private

◆ get_calibrated_count()

size_t fsw::calibration::PTCalibrationManager::get_calibrated_count ( ) const
inline

Get number of calibrated channels.

Definition at line 124 of file PTCalibration.hpp.

References calibrations_.

Referenced by main().

◆ get_calibration()

const PTCalibrationCoeffs * fsw::calibration::PTCalibrationManager::get_calibration ( uint8_t channel_id) const

Get calibration coefficients for a sensor channel.

Parameters
channel_idSensor channel ID (1-indexed)
Returns
Calibration coefficients if available, nullptr otherwise

Definition at line 293 of file PTCalibration.cpp.

References calibrations_.

Referenced by calculate_pressure().

◆ is_calibrated()

bool fsw::calibration::PTCalibrationManager::is_calibrated ( uint8_t channel_id) const

Check if a channel has calibration.

Parameters
channel_idSensor channel ID
Returns
true if calibrated

Definition at line 301 of file PTCalibration.cpp.

References calibrations_.

Referenced by invert_abort_psi_to_adc(), and main().

◆ load_calibration()

bool fsw::calibration::PTCalibrationManager::load_calibration ( )

Auto-load calibration from default paths Default: factory CSV first, then newest GUI JSON overlays every channel it lists (fixes CSV PT6≠GN2 ch6).

CAL_PT_JSON_MISSING_ONLY=1 — JSON only fills gaps (legacy). CAL_PT_JSON_FIRST=1 — JSON only, then CSV.

Returns
true if any calibration was loaded

Definition at line 94 of file PTCalibration.cpp.

References calibrations_, default_csv_path_, default_json_dir_, fs::exists(), find_latest_json_file(), load_from_csv(), and load_from_json().

Referenced by main(), and PTCalibrationManager().

◆ load_from_csv()

bool fsw::calibration::PTCalibrationManager::load_from_csv ( const std::string & csv_path)

Load calibration from CSV file (from DiabloAvionics).

Parameters
csv_pathPath to CSV calibration file
Returns
true if loaded successfully

Definition at line 212 of file PTCalibration.cpp.

References calibrations_, and end().

Referenced by load_calibration().

◆ load_from_json()

bool fsw::calibration::PTCalibrationManager::load_from_json ( const std::string & json_path,
bool merge_missing_only = false )

Load calibration from JSON file (from calibration GUI).

Parameters
json_pathPath to JSON calibration file
merge_missing_onlyIf true, only add channels not already present after CSV; if false, every channel in JSON overwrites the same logical key (GUI per-connector calibration).
Returns
true if at least one channel was loaded/merged

Definition at line 166 of file PTCalibration.cpp.

References calibrations_, ch(), and is_number.

Referenced by load_calibration().

◆ parse_csv_file()

bool fsw::calibration::PTCalibrationManager::parse_csv_file ( const std::string & csv_path)
private

◆ parse_json_file()

bool fsw::calibration::PTCalibrationManager::parse_json_file ( const std::string & json_path)
private

◆ set_calibration()

void fsw::calibration::PTCalibrationManager::set_calibration ( uint8_t channel_id,
const PTCalibrationCoeffs & coeffs )

Set/replace the cubic coefficients for a logical channel at runtime.

Used by the calibration service when an operator builds a cubic live from captured reference points — the new fit takes effect immediately on the streaming path (which evaluates these coefficients per packet).

Parameters
channel_idis the logical calibration channel (pt_logical_calibration_channel), not a board-local connector.

Definition at line 305 of file PTCalibration.cpp.

References calibrations_.

Referenced by main().

◆ set_default_paths()

void fsw::calibration::PTCalibrationManager::set_default_paths ( const std::string & json_dir,
const std::string & csv_path )
static

Set default calibration file paths.

Definition at line 357 of file PTCalibration.cpp.

References default_csv_path_, and default_json_dir_.

Referenced by main().

Member Data Documentation

◆ calibrations_

std::map<uint8_t, PTCalibrationCoeffs> fsw::calibration::PTCalibrationManager::calibrations_
private

◆ default_csv_path_

std::string fsw::calibration::PTCalibrationManager::default_csv_path_
staticprivate
Initial value:
=
"external/DiabloAvionics/PT_Board/Calibration/PT Calibration Attempt 2026-02-04_test2.csv"

Definition at line 157 of file PTCalibration.hpp.

Referenced by load_calibration(), and set_default_paths().

◆ default_json_dir_

std::string fsw::calibration::PTCalibrationManager::default_json_dir_ = "scripts/calibration/calibrations"
staticprivate

Definition at line 156 of file PTCalibration.hpp.

Referenced by load_calibration(), and set_default_paths().


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