STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
DatabaseConfig.hpp
Go to the documentation of this file.
1#ifndef DAQ_DATABASE_CONFIG_HPP
2#define DAQ_DATABASE_CONFIG_HPP
3
4#include <cstdint>
5#include <string>
6#include <utility>
7#include <vector>
8
9#include "ElodinClient.hpp"
10
11namespace fsw {
12namespace elodin {
13
14/**
15 * @brief Per-board channel info for board-namespaced entity registration.
16 *
17 * board_id: raw board ID from config (e.g. 21, 22, 12, 14)
18 * board_number: Elodin / daq slot = (board_id % 10) with 0 → 10 (e.g. id 12→2, id 10→10)
19 * channels: local connector IDs (1-10) that are active on this board
20 */
22 uint8_t board_id;
23 uint8_t board_number; // board_id % 10
24 std::vector<uint8_t> channels; // local channels (1-10)
25};
26
27/**
28 * @brief Elodin table ids (hi, lo) for the RAW sensor VTables the given boards publish.
29 *
30 * The (type_hi, (board_number-1)*0x20 + channel) encoding is defined by
31 * DatabaseConfig::register_tables(), so it lives here beside it rather than being re-derived by
32 * every subscriber. Built from the boards actually in config — the version this replaced guessed
33 * boards 1-8 x channels 1-10 and subscribed to 480 tables whether they existed or not.
34 */
35std::vector<std::pair<uint8_t, uint8_t>> raw_sensor_tables(
36 const std::vector<BoardChannels>& pt_boards, const std::vector<BoardChannels>& act_boards,
37 const std::vector<BoardChannels>& tc_boards, const std::vector<BoardChannels>& rtd_boards,
38 const std::vector<BoardChannels>& lc_boards, const std::vector<BoardChannels>& enc_boards);
39
40/**
41 * @brief Elodin table ids for the CALIBRATED VTables, matching register_calibrated_tables()
42 * (same encoding as above with a +0x10 channel offset, and ACT at 0x31 rather than 0x30).
43 */
44std::vector<std::pair<uint8_t, uint8_t>> calibrated_sensor_tables(
45 const std::vector<BoardChannels>& pt_boards, const std::vector<BoardChannels>& tc_boards,
46 const std::vector<BoardChannels>& rtd_boards, const std::vector<BoardChannels>& lc_boards,
47 const std::vector<BoardChannels>& enc_boards, const std::vector<BoardChannels>& act_boards);
48
49/**
50 * Ball valve boards (BALL_VALVE) have their own type_hi bytes, so a valve never shares a key with
51 * an ACTUATOR board on the same board_id % 10 slot (board 71 and actuator board 11 are both slot
52 * 1): 0x33 raw position counts BV<n>.CH<m> raw_adc_counts 0x34 calibrated position
53 * BV<n>_Cal.CH<m> position_pct, raw_adc, cal_status 0x35 commanded state BV_CMD.B<n>.CH<m>
54 * actuator_state (0 closed, 1 open) Low bytes follow the other boards: raw/cmd (n-1)*0x20 + m,
55 * calibrated (n-1)*0x20 + 0x10 + m.
56 */
57constexpr uint8_t kBallValveRawHi = 0x33;
58constexpr uint8_t kBallValveCalHi = 0x34;
59constexpr uint8_t kBallValveCmdHi = 0x35;
60
61std::vector<std::pair<uint8_t, uint8_t>> ball_valve_raw_tables(
62 const std::vector<BoardChannels>& bv_boards);
63std::vector<std::pair<uint8_t, uint8_t>> ball_valve_calibrated_tables(
64 const std::vector<BoardChannels>& bv_boards);
65std::vector<std::pair<uint8_t, uint8_t>> ball_valve_cmd_tables(
66 const std::vector<BoardChannels>& bv_boards);
67
68/** Non-sensor tables, named rather than spelled as literals at each use site. */
69constexpr std::pair<uint8_t, uint8_t> kTableSequencerState{0x50, 0x00};
70constexpr std::pair<uint8_t, uint8_t> kTableControllerState{0x43, 0x00};
71constexpr std::pair<uint8_t, uint8_t> kTableCalibrationCommand{0x46, 0x00};
72
73/**
74 * @brief Register sensor table schemas with Elodin database.
75 *
76 * All VTables use board-namespaced entity names (e.g. PT1.CH1, TC1.CH5,
77 * ACT2.CH3). Role names (e.g. "Fuel Upstream") are metadata only — the
78 * frontend maps channel → display name from config.toml at render time.
79 *
80 * Two separate entry points:
81 * - register_tables() → RAW VTables only (called by daq_bridge)
82 * - register_calibrated_tables() → CALIBRATED VTables (called by calibration_service)
83 */
85public:
87 const std::vector<BoardChannels>& boards);
88
89 /**
90 * @brief Register RAW sensor / actuator VTables.
91 *
92 * Each vector lists boards with their local channels.
93 * Entity names: PT<board_number>.CH<n>, ACT<board_number>.CH<n>, etc.
94 */
95 static bool register_tables(ElodinClient& client, const std::vector<BoardChannels>& pt_boards,
96 const std::vector<BoardChannels>& act_boards,
97 const std::vector<BoardChannels>& tc_boards,
98 const std::vector<BoardChannels>& rtd_boards,
99 const std::vector<BoardChannels>& lc_boards,
100 const std::vector<BoardChannels>& enc_boards);
101
102 /**
103 * @brief Register CALIBRATED VTables.
104 *
105 * Entity names: PT<board_number>_Cal.CH<n>, TC<board_number>_Cal.CH<n>, etc.
106 */
107 static bool register_calibrated_tables(ElodinClient& client,
108 const std::vector<BoardChannels>& pt_boards,
109 const std::vector<BoardChannels>& tc_boards,
110 const std::vector<BoardChannels>& rtd_boards,
111 const std::vector<BoardChannels>& lc_boards,
112 const std::vector<BoardChannels>& enc_boards,
113 const std::vector<BoardChannels>& act_boards);
114
115 /**
116 * @brief Register BOARD_HEARTBEAT VTables for specific board IDs.
117 */
118 static bool register_heartbeat_tables(ElodinClient& client,
119 const std::vector<uint8_t>& board_ids);
120
121 /**
122 * @brief Register SELF_TEST VTables for specific board IDs.
123 */
124 static bool register_self_test_tables(ElodinClient& client,
125 const std::vector<uint8_t>& board_ids);
126
127 /**
128 * @brief Register one LabJack T7's RAW VTables (t7_bridge).
129 *
130 * Per AIN: table {0x26, (slot-1)*0x20 + ain}, entity T7<slot>.AIN<ain>, fields timestamp_ns,
131 * channel_id, volts (f32), sample_ts_ms, status — T7RawMessage. With `cjc`, also the
132 * cold-junction table {0x26, (slot-1)*0x20 + 0x0F}, entity T7<slot>.CJC, field
133 * temperature_c (f32) in the same layout.
134 */
135 static bool register_t7_raw_tables(ElodinClient& client, uint8_t slot,
136 const std::vector<uint8_t>& ains, bool cjc);
137
138 /**
139 * @brief Register one LabJack T7's CALIBRATED VTables (calibration_service).
140 *
141 * Per input: table {0x26, (slot-1)*0x20 + 0x10 + ain}, entity T7<slot>_Cal.AIN<ain>, fields
142 * timestamp_ns, channel_id, <cal_field> (f32: pressure_psi / temperature_c / force_kg),
143 * raw_uv (i32: the reading in µV, the "ADC code" calibration works in), cal_status — the
144 * ESP32 calibrated layout.
145 */
146 struct T7Table {
147 uint8_t ain;
148 std::string cal_field;
149 };
150 static bool register_t7_calibrated_tables(ElodinClient& client, uint8_t slot,
151 const std::vector<T7Table>& tables);
152
153 /** @brief Register ball valve RAW position VTables [0x33] (daq_bridge). */
154 static bool register_ball_valve_tables(ElodinClient& client,
155 const std::vector<BoardChannels>& bv_boards);
156
157 /** @brief Register ball valve CALIBRATED position VTables [0x34] (calibration_service). */
159 const std::vector<BoardChannels>& bv_boards);
160
161 /** @brief Register ball valve commanded-state VTables [0x35] (sequencer_service). */
163 const std::vector<BoardChannels>& bv_boards);
164
165 /** @brief Register sequencer/controller and ACT_CMD tables */
166 static bool register_non_sensor_tables(ElodinClient& client,
167 const std::vector<BoardChannels>& act_boards = {});
168};
169
170} // namespace elodin
171} // namespace fsw
172
173#endif // DAQ_DATABASE_CONFIG_HPP
Register sensor table schemas with Elodin database.
static bool register_ball_valve_calibrated_tables(ElodinClient &client, const std::vector< BoardChannels > &bv_boards)
Register ball valve CALIBRATED position VTables [0x34] (calibration_service).
static bool register_calibrated_tables(ElodinClient &client, const std::vector< BoardChannels > &pt_boards, const std::vector< BoardChannels > &tc_boards, const std::vector< BoardChannels > &rtd_boards, const std::vector< BoardChannels > &lc_boards, const std::vector< BoardChannels > &enc_boards, const std::vector< BoardChannels > &act_boards)
Register CALIBRATED VTables.
static bool register_non_sensor_tables(ElodinClient &client, const std::vector< BoardChannels > &act_boards={})
Register sequencer/controller and ACT_CMD tables.
static bool register_environmental_tables(ElodinClient &client, const std::vector< BoardChannels > &boards)
static bool register_heartbeat_tables(ElodinClient &client, const std::vector< uint8_t > &board_ids)
Register BOARD_HEARTBEAT VTables for specific board IDs.
static bool register_tables(ElodinClient &client, const std::vector< BoardChannels > &pt_boards, const std::vector< BoardChannels > &act_boards, const std::vector< BoardChannels > &tc_boards, const std::vector< BoardChannels > &rtd_boards, const std::vector< BoardChannels > &lc_boards, const std::vector< BoardChannels > &enc_boards)
Register RAW sensor / actuator VTables.
static bool register_self_test_tables(ElodinClient &client, const std::vector< uint8_t > &board_ids)
Register SELF_TEST VTables for specific board IDs.
static bool register_ball_valve_cmd_tables(ElodinClient &client, const std::vector< BoardChannels > &bv_boards)
Register ball valve commanded-state VTables [0x35] (sequencer_service).
static bool register_t7_raw_tables(ElodinClient &client, uint8_t slot, const std::vector< uint8_t > &ains, bool cjc)
Register one LabJack T7's RAW VTables (t7_bridge).
static bool register_t7_calibrated_tables(ElodinClient &client, uint8_t slot, const std::vector< T7Table > &tables)
static bool register_ball_valve_tables(ElodinClient &client, const std::vector< BoardChannels > &bv_boards)
Register ball valve RAW position VTables [0x33] (daq_bridge).
Standalone Elodin database client.
std::vector< std::pair< uint8_t, uint8_t > > ball_valve_calibrated_tables(const std::vector< BoardChannels > &bv_boards)
constexpr uint8_t kBallValveCmdHi
constexpr std::pair< uint8_t, uint8_t > kTableCalibrationCommand
constexpr uint8_t kBallValveCalHi
std::vector< std::pair< uint8_t, uint8_t > > ball_valve_cmd_tables(const std::vector< BoardChannels > &bv_boards)
std::vector< std::pair< uint8_t, uint8_t > > raw_sensor_tables(const std::vector< BoardChannels > &pt_boards, const std::vector< BoardChannels > &act_boards, const std::vector< BoardChannels > &tc_boards, const std::vector< BoardChannels > &rtd_boards, const std::vector< BoardChannels > &lc_boards, const std::vector< BoardChannels > &enc_boards)
Elodin table ids (hi, lo) for the RAW sensor VTables the given boards publish.
std::vector< std::pair< uint8_t, uint8_t > > calibrated_sensor_tables(const std::vector< BoardChannels > &pt_boards, const std::vector< BoardChannels > &tc_boards, const std::vector< BoardChannels > &rtd_boards, const std::vector< BoardChannels > &lc_boards, const std::vector< BoardChannels > &enc_boards, const std::vector< BoardChannels > &act_boards)
Elodin table ids for the CALIBRATED VTables, matching register_calibrated_tables() (same encoding as ...
constexpr std::pair< uint8_t, uint8_t > kTableControllerState
constexpr uint8_t kBallValveRawHi
Ball valve boards (BALL_VALVE) have their own type_hi bytes, so a valve never shares a key with an AC...
constexpr std::pair< uint8_t, uint8_t > kTableSequencerState
Non-sensor tables, named rather than spelled as literals at each use site.
std::vector< std::pair< uint8_t, uint8_t > > ball_valve_raw_tables(const std::vector< BoardChannels > &bv_boards)
Motorized ball valve position: raw ADC counts -> % open.
Per-board channel info for board-namespaced entity registration.
std::vector< uint8_t > channels
Register one LabJack T7's CALIBRATED VTables (calibration_service).
static SlugTables tables()
The tables every case validates against.