STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_ball_valve_config.cpp
Go to the documentation of this file.
1// A motorized ball valve board: its own board kind, and actuator roles on it have no polarity.
2
3#include <iostream>
4#include <stdexcept>
5#include <string>
6
7#include "config/Config.hpp"
8
9using namespace fsw::config;
10
11static void require(bool condition, const char* what) {
12 if (!condition)
13 throw std::runtime_error(std::string("Ball valve config assertion failed: ") + what);
14}
15
16static const char* kConfig = R"(
17[boards.act_11]
18type = "ACTUATOR"
19board_id = 11
20active_connectors = [1, 2]
21
22[boards.ball_valve_board]
23type = "BALL_VALVE"
24board_id = 71
25ip = "192.168.2.71"
26active_connectors = [1]
27
28[actuator_roles]
29"Ball Valve NC" = ["NC", 1, 71]
30"Ball Valve NO" = ["NO", 1, 71]
31"Actuator NO" = ["NO", 2, 11]
32"Actuator NC" = ["NC", 1, 11]
33)";
34
35int main() {
36 require(kind_of("BALL_VALVE") == ActiveBoardKind::BALL_VALVE, "kind_of(BALL_VALVE)");
37 require(kind_of("ACTUATOR") == ActiveBoardKind::ACTUATOR, "kind_of(ACTUATOR) unchanged");
38
39 const Config cfg = load_from_string(kConfig);
40
41 // A ball valve role is pass-through on the wire whatever its first element says.
42 require(cfg.actuator_roles.at("Ball Valve NC").ball_valve, "NC role flagged ball_valve");
43 require(!cfg.actuator_roles.at("Ball Valve NC").is_no, "NC role pass-through");
44 require(cfg.actuator_roles.at("Ball Valve NO").ball_valve, "NO role flagged ball_valve");
45 require(!cfg.actuator_roles.at("Ball Valve NO").is_no,
46 "NO on a ball valve forced pass-through");
47
48 // Roles on an ACTUATOR board are untouched.
49 require(!cfg.actuator_roles.at("Actuator NO").ball_valve, "actuator role not a ball valve");
50 require(cfg.actuator_roles.at("Actuator NO").is_no, "actuator NO stays NO");
51 require(!cfg.actuator_roles.at("Actuator NC").is_no, "actuator NC stays NC");
52
53 // Board 71 is slot 1, as is actuator board 11; separate kinds, so both are active and the
54 // ball valve is listed under its own kind.
55 const auto boards = active_boards(cfg);
56 require(boards.at(ActiveBoardKind::BALL_VALVE).size() == 1, "one ball valve board");
57 require(boards.at(ActiveBoardKind::BALL_VALVE)[0].board_id == 71, "ball valve board id");
58 require(boards.at(ActiveBoardKind::BALL_VALVE)[0].board_number == 1, "board 71 is slot 1");
59 require(boards.at(ActiveBoardKind::ACTUATOR).size() == 1, "actuator board still listed");
60
61 std::cout << "Ball valve config passed\n";
62}
std::map< ActiveBoardKind, std::vector< elodin::BoardChannels > > active_boards(const Config &cfg)
Derive the active-board table (enabled boards -> Elodin BoardChannels), with the same slot-collision ...
Definition Config.cpp:468
ActiveBoardKind kind_of(const std::string &type_str)
[boards.
Definition Config.cpp:60
Config load_from_string(const std::string &text)
Parse config from an in-memory TOML string (SequencerService / ActuatorCommander hold it so).
Definition Config.cpp:458
static void require(bool condition, const char *what)
static const uint8_t kConfig[]
Definition test_ubx.c:21