STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
SensorTables.cpp
Go to the documentation of this file.
2
3#include "t7/T7Stream.hpp"
4
5namespace fsw {
6namespace config {
7
8std::string board_key_of(const BoardConfig& b) {
9 return b.section.rfind("boards.", 0) == 0 ? b.section.substr(7) : b.section;
10}
11
12namespace {
13
14/** Fill in the derived half of a ref once board/role/channel are known. */
15PtRoleRef makeRef(const BoardConfig& b, std::string board_key, std::string role, int channel) {
17 r.board = &b;
18 r.board_key = std::move(board_key);
19 r.role = std::move(role);
20 r.channel = channel;
21 r.board_number = b.slot();
22 r.table_hi = 0x20;
23 r.table_lo = static_cast<uint8_t>((r.board_number - 1) * 0x20 + 0x10 + channel);
24 return r;
25}
26
27/** The boards a PT role can live on. Mirrors the abort-threshold walk's filter exactly. */
29 return b.type == "PT" && b.enabled && b.board_id > 0;
30}
31
32/** A PT input on a LabJack T7: calibration_service publishes it on the T7 calibrated table in the
33 * same CalibratedPTMessage layout as an ESP32 PT, so a reader cannot tell them apart. */
36 r.t7 = &b;
37 r.board_key = b.section.rfind("boards.", 0) == 0 ? b.section.substr(7) : b.section;
38 r.role = c.role;
39 r.channel = c.ain;
40 r.board_number = b.slot();
41 const auto id = fsw::t7::calibrated_table_id(r.board_number, static_cast<uint8_t>(c.ain));
42 r.table_hi = id[0];
43 r.table_lo = id[1];
44 return r;
45}
46
47/** Every PT input t7_bridge will actually stream. It refuses to start on any T7 config error, so
48 * then there are none: a script naming one is refused at load rather than waiting on silence. */
49std::vector<PtRoleRef> t7PtRefs(const Config& cfg) {
50 std::vector<PtRoleRef> out;
51 if (!cfg.t7_errors.empty())
52 return out;
53 for (const auto& b : cfg.t7_boards) {
54 if (!b.enabled || b.board_id <= 0)
55 continue;
56 for (const auto& c : b.channels)
57 if (c.kind == "PT" && !c.role.empty())
58 out.push_back(makeT7Ref(b, c));
59 }
60 return out;
61}
62
63} // namespace
64
65std::vector<PtRoleRef> pt_role_tables(const Config& cfg) {
66 std::vector<PtRoleRef> out;
67 for (const auto& b : cfg.boards) {
68 if (!usablePtBoard(b))
69 continue;
70 const std::string board_key = board_key_of(b);
71 const auto* roles = cfg.sensor_roles_for("sensor_roles_" + board_key);
72 if (roles == nullptr)
73 continue;
74 for (const auto& [role, channel] : *roles)
75 out.push_back(makeRef(b, board_key, role, channel));
76 }
77 for (auto& r : t7PtRefs(cfg))
78 out.push_back(std::move(r));
79 return out;
80}
81
82std::optional<PtRoleRef> find_pt_role(const Config& cfg, const std::string& role) {
83 for (const auto& b : cfg.boards) {
84 if (!usablePtBoard(b))
85 continue;
86 const std::string board_key = board_key_of(b);
87 const auto* roles = cfg.sensor_roles_for("sensor_roles_" + board_key);
88 if (roles == nullptr)
89 continue;
90 auto it = roles->find(role);
91 if (it == roles->end())
92 continue; // not on this board — keep looking
93 return makeRef(b, board_key, role, it->second);
94 }
95 for (auto& r : t7PtRefs(cfg))
96 if (r.role == role)
97 return r;
98 return std::nullopt;
99}
100
101} // namespace config
102} // namespace fsw
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
Definition json.hpp:13878
bool usablePtBoard(const BoardConfig &b)
The boards a PT role can live on.
PtRoleRef makeT7Ref(const T7Board &b, const T7Channel &c)
A PT input on a LabJack T7: calibration_service publishes it on the T7 calibrated table in the same C...
PtRoleRef makeRef(const BoardConfig &b, std::string board_key, std::string role, int channel)
Fill in the derived half of a ref once board/role/channel are known.
std::vector< PtRoleRef > t7PtRefs(const Config &cfg)
Every PT input t7_bridge will actually stream.
std::optional< PtRoleRef > find_pt_role(const Config &cfg, const std::string &role)
Resolve one role by its canonical config name.
std::string board_key_of(const BoardConfig &b)
The board's section name minus a leading "boards.", e.g.
std::vector< PtRoleRef > pt_role_tables(const Config &cfg)
Every PT sensor role declared by an enabled PT board, in board-declaration order, then every PT input...
std::array< uint8_t, 2 > calibrated_table_id(uint8_t slot, uint8_t ain)
Calibrated table for one AIN: table_id + 0x10, e.g.
Definition T7Stream.cpp:30
Motorized ball valve position: raw ADC counts -> % open.
The whole parsed config.toml, restricted to what C++ consumes.
Definition Config.hpp:264
Where a named PT sensor role lives: which board, which channel, and which Elodin table its calibrated...
One streamed analog input.
Definition T7Config.hpp:37
int ain
AIN number on the device, 0-13.
Definition T7Config.hpp:38
std::string role
Sensor name, e.g. "LOX Tank" — what the GUI calls it.
Definition T7Config.hpp:40
static boot_report_t r