STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
SensorRouter.hpp
Go to the documentation of this file.
1#ifndef DAQ_SENSOR_ROUTER_HPP
2#define DAQ_SENSOR_ROUTER_HPP
3
4#include <cstdint>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
15
16namespace fsw {
17namespace routing {
18
19/**
20 * @brief Configuration for sensor channel routing
21 */
23 uint8_t channel_id;
24 std::string table_name; // Elodin table name (e.g., "pt_chamber_raw")
25 std::array<uint8_t, 2> table_id; // Elodin table ID
26 std::string sensor_type; // "PT", "TC", "RTD", "LC"
27 std::string location; // Human-readable location (e.g., "chamber", "fuel_inlet")
28};
29
30/**
31 * @brief Routes decoded sensor frames to Elodin tables
32 *
33 * Maps sensor channels to Elodin table IDs based on configuration.
34 * This allows adding/removing sensors without code changes.
35 */
37public:
39 ~SensorRouter() = default;
40
41 /**
42 * @brief Load routing configuration from TOML file
43 * @param config_path Path to TOML configuration file
44 * @return true if loaded successfully
45 */
46 bool load_config(const std::string& config_path);
47
48 /**
49 * @brief Add a sensor channel configuration manually
50 */
52
53 /**
54 * @brief Get table ID for a sensor channel
55 * @param sensor_type "PT", "TC", "RTD", or "LC"
56 * @param channel_id Channel identifier
57 * @return Table ID if found, empty array otherwise
58 */
59 std::array<uint8_t, 2> get_table_id(const std::string& sensor_type, uint8_t channel_id) const;
60
61 /**
62 * @brief Get table name for a sensor channel (for debugging)
63 */
64 std::string get_table_name(const std::string& sensor_type, uint8_t channel_id) const;
65
66 /**
67 * @brief Convert a sensor batch into Elodin messages
68 * @param batch Decoded sensor batch
69 * @return Vector of (table_id, message) pairs ready for publishing
70 */
71 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::RawPTMessage>>
73 uint64_t receive_timestamp_ns) const;
74
75 /**
76 * @brief Convert PT samples to calibrated messages
77 * @param batch Decoded sensor batch
78 * @return Vector of (table_id, calibrated_message) pairs
79 */
80 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::CalibratedPTMessage>>
82 uint64_t receive_timestamp_ns, uint8_t pt_board_slot = 1) const;
83
84 /**
85 * @brief Set PT calibration manager (legacy)
86 */
88 pt_calibration_ = cal_manager;
89 }
90
91 /// Set calibration managers for each sensor type
101
102 // ── Raw routing ────────────────────────────────────────────────────────
103 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::RawTCMessage>>
105 uint64_t receive_timestamp_ns) const;
106
107 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::RawRTDMessage>>
109 uint64_t receive_timestamp_ns) const;
110
111 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::RawLCMessage>>
113 uint64_t receive_timestamp_ns) const;
114
115 // ── Calibrated routing (require SensorCalibrationManager) ─────────────
116 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::CalibratedTCMessage>>
118 uint64_t receive_timestamp_ns) const;
119
120 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::CalibratedRTDMessage>>
122 uint64_t receive_timestamp_ns) const;
123
124 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::CalibratedLCMessage>>
126 uint64_t receive_timestamp_ns) const;
127
128 /**
129 * @brief RTD Pt100 temperature conversion — no calibration manager required.
130 *
131 * Applies Callendar-Van Dusen (Pt100, R0=100Ω, A=3.9083e-3, B=-5.775e-7):
132 * resistance_ohm = raw_resistance_counts * 0.001
133 * T = (-R0*A + sqrt((R0*A)^2 - 4*R0*B*(R0 - R))) / (2*R0*B)
134 *
135 * Outputs CalibratedRTDMessage at packet_id {0x22, 0x10 + channel_id + 1}
136 * (matching the RTD_Cal VTable registered in DatabaseConfig).
137 */
138 std::vector<std::pair<std::array<uint8_t, 2>, comms::messages::sensor::CalibratedRTDMessage>>
140 uint64_t receive_timestamp_ns) const;
141
142private:
143 std::unordered_map<std::string, SensorChannelConfig>
144 channel_map_; // Key: "sensor_type:channel_id"
145
150
151 std::string make_key(const std::string& sensor_type, uint8_t channel_id) const;
152};
153
154} // namespace routing
155} // namespace fsw
156
157#endif // DAQ_SENSOR_ROUTER_HPP
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::RawLCMessage > > route_lc_samples(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::RawRTDMessage > > route_rtd_samples(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
void set_pt_calibration(const calibration::PTCalibrationManager *cal_manager)
Set PT calibration manager (legacy).
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::RawTCMessage > > route_tc_samples(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
std::array< uint8_t, 2 > get_table_id(const std::string &sensor_type, uint8_t channel_id) const
Get table ID for a sensor channel.
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::RawPTMessage > > route_pt_samples(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
Convert a sensor batch into Elodin messages.
void set_tc_calibration(const calibration::SensorCalibrationManager *m)
Set calibration managers for each sensor type.
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::CalibratedPTMessage > > route_pt_samples_calibrated(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns, uint8_t pt_board_slot=1) const
Convert PT samples to calibrated messages.
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::CalibratedRTDMessage > > route_rtd_samples_calibrated(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
const calibration::PTCalibrationManager * pt_calibration_
const calibration::SensorCalibrationManager * tc_calibration_
const calibration::SensorCalibrationManager * rtd_calibration_
std::unordered_map< std::string, SensorChannelConfig > channel_map_
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::CalibratedTCMessage > > route_tc_samples_calibrated(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
std::string get_table_name(const std::string &sensor_type, uint8_t channel_id) const
Get table name for a sensor channel (for debugging).
bool load_config(const std::string &config_path)
Load routing configuration from TOML file.
std::string make_key(const std::string &sensor_type, uint8_t channel_id) const
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::CalibratedRTDMessage > > route_rtd_samples_pt100(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
RTD Pt100 temperature conversion — no calibration manager required.
void set_rtd_calibration(const calibration::SensorCalibrationManager *m)
void add_channel(const SensorChannelConfig &config)
Add a sensor channel configuration manually.
std::vector< std::pair< std::array< uint8_t, 2 >, comms::messages::sensor::CalibratedLCMessage > > route_lc_samples_calibrated(const daq_comms::protocol::SensorBatch &batch, uint64_t receive_timestamp_ns) const
const calibration::SensorCalibrationManager * lc_calibration_
void set_lc_calibration(const calibration::SensorCalibrationManager *m)
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, uint32_t, uint32_t, uint8_t > RawTCMessage
Raw Thermocouple sample message for Elodin CRITICAL: Includes padding bytes to ensure uint32_t fields...
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, float, uint32_t, uint8_t > CalibratedRTDMessage
Calibrated RTD message for Elodin.
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, float, uint32_t, uint8_t > CalibratedLCMessage
Calibrated Load Cell message for Elodin.
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, float, uint32_t, uint8_t > CalibratedTCMessage
Calibrated Thermocouple message for Elodin.
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, uint32_t, uint32_t, uint8_t > RawRTDMessage
Raw RTD sample message for Elodin CRITICAL: Includes padding bytes to ensure uint32_t fields are 4-by...
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, float, uint32_t, uint8_t > CalibratedPTMessage
Calibrated Pressure Transducer message for Elodin.
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, uint32_t, uint32_t, uint8_t > RawLCMessage
Raw Load Cell sample message for Elodin CRITICAL: Includes padding bytes to ensure uint32_t fields ar...
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, uint32_t, uint32_t, uint8_t > RawPTMessage
Raw Pressure Transducer sample message for Elodin.
Motorized ball valve position: raw ADC counts -> % open.
Configuration for sensor channel routing.
std::array< uint8_t, 2 > table_id