STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
SensorAssignment.hpp
Go to the documentation of this file.
1#ifndef DAQ_SENSOR_ASSIGNMENT_HPP
2#define DAQ_SENSOR_ASSIGNMENT_HPP
3
4#include <cstdint>
5#include <functional>
6#include <map>
7#include <optional>
8#include <string>
9#include <vector>
10
11namespace fsw {
12namespace config {
13
14/**
15 * @brief System state (GSE or Flight)
16 */
17enum class SystemState {
18 GSE, // Ground Support Equipment
19 FLIGHT // Flight/rocket system
20};
21
22/**
23 * @brief Sensor types
24 */
25enum class SensorType {
26 PT, // Pressure Transducer
27 TC, // Thermocouple
28 RTD, // RTD Temperature Sensor
29 LC, // Load Cell
30 ACTUATOR // Actuator/Valve
31};
32
33/**
34 * @brief Pressure sensor specifications
35 */
37 std::string sensor_id; // Unique identifier (e.g., "PT_HP", "PT_LP")
38 std::string name; // Human-readable name
39 std::string description; // Description
40 uint16_t max_pressure_psi; // Maximum pressure rating (PSI)
41 SystemState system_state; // GSE or FLIGHT
42 std::string location; // Physical location
43 std::string purpose; // Purpose (e.g., "High pressure", "Fuel upstream")
44};
45
46/**
47 * @brief Sensor assignment to board
48 */
50 std::string sensor_id; // Sensor identifier
51 uint8_t board_id; // Board ID (0-255)
52 uint8_t channel_id; // Channel ID on board (0-indexed)
53 SensorType sensor_type; // Type of sensor
54 SystemState system_state; // GSE or FLIGHT
55 bool is_active; // Whether sensor is currently active
56 std::string board_ip; // Board IP address (assigned by FSW)
57 uint16_t board_port; // Board port (default 5005)
58 uint16_t message_id; // Message ID (like FSW: 0, 1, 2, etc.) - converted to packet_id when
59 // serializing
60 std::string location; // Physical location (e.g., "chamber", "COPV", "LOX_tank")
61 std::string purpose; // Purpose/description
62};
63
64/**
65 * @brief Board configuration (assigned by FSW)
66 */
68 uint8_t board_id; // Board ID (0-255)
69 std::string board_ip; // Assigned IP address
70 uint16_t board_port; // Communication port
71 std::string mac_address; // Board MAC address
72 SensorType primary_sensor_type; // Primary sensor type on board
73 std::vector<SensorAssignment> sensors; // Assigned sensors
74 SystemState system_state; // GSE or FLIGHT
75 bool is_configured; // Whether board has been configured
76 std::string firmware_version; // Board firmware version
77};
78
79/**
80 * @brief Sensor Assignment Manager
81 *
82 * Manages sensor-to-board assignments, IP assignment from FSW,
83 * and configuration distribution to boards.
84 */
86public:
89
90 /**
91 * @brief Load sensor definitions from config
92 */
93 bool load_sensor_definitions(const std::string& config_path);
94
95 /**
96 * @brief Set a static IP for a board from loaded configuration
97 * @param board_id Board identifier
98 * @param ip The IP address configured for this board
99 */
100 void set_static_board_ip(uint8_t board_id, const std::string& ip);
101
102 /**
103 * @brief Assign IP address to board (called by FSW)
104 * If a static IP was set for this board_id, it will be used regardless of MAC/source_ip.
105 * @param board_id Board identifier
106 * @param mac_address Board MAC address
107 * @param system_state GSE or FLIGHT
108 * @param source_ip IP address from which the heartbeat was received
109 * @return Assigned IP address
110 */
111 std::string assign_board_ip(uint8_t board_id, const std::string& mac_address,
112 SystemState system_state, const std::string& source_ip = "");
113
114 /**
115 * @brief Assign sensors to board (called by FSW)
116 * @param board_id Board identifier
117 * @param sensor_ids List of sensor IDs to assign
118 * @param start_channel Starting channel ID on board
119 * @return true if assignment successful
120 */
121 bool assign_sensors_to_board(uint8_t board_id, const std::vector<std::string>& sensor_ids,
122 uint8_t start_channel = 0);
123
124 /**
125 * @brief Get board configuration for sending to board
126 * @param board_id Board identifier
127 * @return Board configuration packet data
128 */
129 std::vector<uint8_t> generate_board_config_packet(uint8_t board_id) const;
130
131 /**
132 * @brief Get sensor assignment for a sensor ID
133 */
134 std::optional<SensorAssignment> get_sensor_assignment(const std::string& sensor_id) const;
135
136 /**
137 * @brief Get all sensors for a board
138 */
139 std::vector<SensorAssignment> get_board_sensors(uint8_t board_id) const;
140
141 /**
142 * @brief Get all sensors for a system state
143 */
144 std::vector<SensorAssignment> get_system_sensors(SystemState state) const;
145
146 /**
147 * @brief Get board configuration
148 */
149 std::optional<BoardConfiguration> get_board_config(uint8_t board_id) const;
150
151 /**
152 * @brief Update board configuration from received packet
153 */
154 bool update_board_config_from_packet(uint8_t board_id, const uint8_t* data, size_t size);
155
156 /**
157 * @brief Load assignments from config file
158 */
159 bool load_assignments_from_config(const std::string& config_path);
160
161 /**
162 * @brief Get all pressure sensor specs
163 */
164 const std::map<std::string, PressureSensorSpec>& get_pressure_sensor_specs() const {
166 }
167
168 /**
169 * @brief Register callback for board configuration updates
170 */
172 std::function<void(uint8_t, const BoardConfiguration&)> callback);
173
174private:
175 // Sensor definitions
176 std::map<std::string, PressureSensorSpec> pressure_sensor_specs_;
177
178 // Board configurations
179 std::map<uint8_t, BoardConfiguration> board_configs_;
180
181 // Static IPs loaded from config.toml
182 std::map<uint8_t, std::string> static_board_ips_;
183
184 // Sensor assignments (sensor_id -> assignment)
185 std::map<std::string, SensorAssignment> sensor_assignments_;
186
187 // IP assignment ranges
188 std::string gse_base_ip_;
189 std::string flight_base_ip_;
194
195 // Callbacks
196 std::vector<std::function<void(uint8_t, const BoardConfiguration&)>> config_callbacks_;
197
198 // Helper methods
199 std::string calculate_ip_from_mac(const std::string& mac_address, SystemState state) const;
200 SensorType sensor_type_from_string(const std::string& type_str) const;
201 std::string sensor_type_to_string(SensorType type) const;
202};
203
204} // namespace config
205} // namespace fsw
206
207#endif // DAQ_SENSOR_ASSIGNMENT_HPP
std::string sensor_type_to_string(SensorType type) const
const std::map< std::string, PressureSensorSpec > & get_pressure_sensor_specs() const
Get all pressure sensor specs.
bool load_assignments_from_config(const std::string &config_path)
Load assignments from config file.
std::string assign_board_ip(uint8_t board_id, const std::string &mac_address, SystemState system_state, const std::string &source_ip="")
Assign IP address to board (called by FSW) If a static IP was set for this board_id,...
bool update_board_config_from_packet(uint8_t board_id, const uint8_t *data, size_t size)
Update board configuration from received packet.
std::vector< uint8_t > generate_board_config_packet(uint8_t board_id) const
Get board configuration for sending to board.
bool load_sensor_definitions(const std::string &config_path)
Load sensor definitions from config.
SensorType sensor_type_from_string(const std::string &type_str) const
void register_config_update_callback(std::function< void(uint8_t, const BoardConfiguration &)> callback)
Register callback for board configuration updates.
void set_static_board_ip(uint8_t board_id, const std::string &ip)
Set a static IP for a board from loaded configuration.
std::optional< BoardConfiguration > get_board_config(uint8_t board_id) const
Get board configuration.
std::vector< std::function< void(uint8_t, const BoardConfiguration &)> > config_callbacks_
std::map< uint8_t, std::string > static_board_ips_
std::map< std::string, PressureSensorSpec > pressure_sensor_specs_
std::map< std::string, SensorAssignment > sensor_assignments_
std::string calculate_ip_from_mac(const std::string &mac_address, SystemState state) const
std::map< uint8_t, BoardConfiguration > board_configs_
std::vector< SensorAssignment > get_board_sensors(uint8_t board_id) const
Get all sensors for a board.
bool assign_sensors_to_board(uint8_t board_id, const std::vector< std::string > &sensor_ids, uint8_t start_channel=0)
Assign sensors to board (called by FSW).
std::optional< SensorAssignment > get_sensor_assignment(const std::string &sensor_id) const
Get sensor assignment for a sensor ID.
std::vector< SensorAssignment > get_system_sensors(SystemState state) const
Get all sensors for a system state.
static uint8_t board_id
Definition main.cpp:30
static ActuatorControllerState state
Definition main.cpp:57
SystemState
System state (GSE or Flight).
SensorType
Sensor types.
Motorized ball valve position: raw ADC counts -> % open.
Board configuration (assigned by FSW).
std::vector< SensorAssignment > sensors
Pressure sensor specifications.
Sensor assignment to board.