19 config_socket_ = std::make_unique<daq_comms::transport::UDPSocket>(bind_address, bind_port);
22 std::cerr <<
"[FSWConfig] Failed to create UDP socket: " <<
config_socket_->last_error()
30 std::cout <<
"[FSWConfig] Initialized FSW configuration manager" << std::endl;
31 std::cout <<
"[FSWConfig] System state: "
38 const daq::BoardHeartbeatPacket& body,
39 const std::string& source_ip,
40 const std::string& mac_address) {
47 std::string assigned_ip =
52 if (board_config && board_config->sensors.empty()) {
54 std::vector<std::string> sensor_ids;
60 sensor_ids = {
"PT_HP",
"PT_LP"};
63 sensor_ids = {
"PT_FUP",
"PT_FDP"};
66 sensor_ids = {
"PT_OUP",
"PT_ODP"};
75 sensor_ids = {
"PT_OF"};
78 sensor_ids = {
"PT_FF"};
81 sensor_ids = {
"PT_HPF",
"PT_MPF",
"PT_LPF"};
88 if (!sensor_ids.empty()) {
90 std::cout <<
"[FSWConfig] Auto-assigned " << sensor_ids.size() <<
" sensors to board "
111 uint8_t start_channel) {
125 std::cerr <<
"[FSWConfig] Board " << (int)
board_id <<
" not found" << std::endl;
131 if (packet.empty()) {
132 std::cerr <<
"[FSWConfig] Failed to generate config packet for board " << (int)
board_id
138 std::cout <<
"[FSWConfig] SENSOR_CONFIG packet for board " <<
static_cast<int>(
board_id)
139 <<
" len=" << packet.size() <<
" bytes: ";
140 std::ios_base::fmtflags f(std::cout.flags());
141 for (
size_t i = 0; i < packet.size(); ++i) {
142 std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill(
'0')
143 <<
static_cast<int>(packet[i]);
144 if (i + 1 < packet.size()) {
149 std::cout << std::dec << std::setfill(
' ') << std::endl;
157 ssize_t sent = board_socket.
send(packet.data(), packet.size());
159 if (sent !=
static_cast<ssize_t
>(packet.size())) {
160 std::cerr <<
"[FSWConfig] Failed to send config to board " << (int)
board_id <<
" at "
161 << board_config->board_ip <<
":" << board_config->board_port << std::endl;
166 std::cout <<
"[FSWConfig] Sent configuration to board " << (int)
board_id <<
" ("
167 << board_config->board_ip <<
":" << board_config->board_port <<
")" << std::endl;
185 std::cout <<
"[FSWConfig] System state changed to: "
196 const std::string& source_ip)
const {
203 if (source_ip.find(
"192.168.2.") == 0) {
205 }
else if (source_ip.find(
"192.168.3.") == 0) {
UDP socket implementation.
ssize_t send(const uint8_t *data, size_t size) override
Send data through the socket.
std::string process_board_heartbeat(const daq::PacketHeader &header, const daq::BoardHeartbeatPacket &body, const std::string &source_ip, const std::string &mac_address)
Process board heartbeat and assign IP if needed.
config::SensorAssignmentManager assignment_manager_
void set_board_static_ip(uint8_t board_id, const std::string &ip)
Configure static board IP address loaded from config.toml.
std::map< uint8_t, bool > boards_configured_
bool send_config_to_board(uint8_t board_id)
Send configuration packet to board.
void send_configs_to_all_boards()
Send configuration to all configured boards.
config::SystemState current_state_
config::SystemState infer_system_state(uint8_t board_id, const std::string &source_ip) const
std::string bind_address_
Local address board config packets are sent from — the same NIC this manager listens on.
void set_system_state(config::SystemState state)
Set system state (GSE or FLIGHT).
bool initialize(const std::string &bind_address, uint16_t bind_port)
Initialize FSW config manager.
bool assign_sensors(uint8_t board_id, const std::vector< std::string > &sensor_ids, uint8_t start_channel=0)
Assign sensors to a board.
std::unique_ptr< daq_comms::transport::UDPSocket > config_socket_
static ActuatorControllerState state
SystemState
System state (GSE or Flight).
Motorized ball valve position: raw ADC counts -> % open.