STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
DynamicConfigManager.cpp
Go to the documentation of this file.
1#include <fstream>
2#include <iomanip>
3#include <iostream>
4#include <sstream>
5
7
8namespace fsw {
9namespace config {
10
13
14bool DynamicConfigManager::load_base_config(const std::string& config_path) {
15 base_config_path_ = config_path;
16
17 // TODO: Load TOML file using a TOML library
18 // For now, create empty config structure
19 config_["network"] = {};
20 config_["database"] = {};
21 config_["sensors"] = {};
22
23 std::cout << "[DynamicConfig] Loaded base config from: " << config_path << std::endl;
24 return true;
25}
26
27bool DynamicConfigManager::update_with_boards(const std::vector<DiscoveredBoard>& boards) {
28 // Clear existing board configs
29 auto it = config_.begin();
30 while (it != config_.end()) {
31 if (it->first.find("board_") == 0) {
32 it = config_.erase(it);
33 } else {
34 ++it;
35 }
36 }
37
38 // Update sensor counts based on discovered boards
39 std::map<uint8_t, size_t> sensor_counts;
40 std::map<uint8_t, std::vector<uint8_t>> sensor_channels;
41
42 for (const auto& board : boards) {
43 for (const auto& sensor : board.sensors) {
44 sensor_counts[sensor.sensor_type]++;
45 sensor_channels[sensor.sensor_type].push_back(sensor.channel_id);
46 }
47 }
48
49 // Update sensor configuration
50 if (sensor_counts.find(0x01) != sensor_counts.end()) {
51 config_["sensors"]["enable_pt"] = "true";
52 config_["sensors"]["pt_count"] = std::to_string(sensor_counts[0x01]);
53 std::string channels;
54 for (size_t i = 0; i < sensor_channels[0x01].size(); ++i) {
55 if (i > 0)
56 channels += ",";
57 channels += std::to_string(sensor_channels[0x01][i]);
58 }
59 config_["sensors"]["pt_channels"] = channels;
60 }
61
62 if (sensor_counts.find(0x02) != sensor_counts.end()) {
63 config_["sensors"]["enable_tc"] = "true";
64 config_["sensors"]["tc_count"] = std::to_string(sensor_counts[0x02]);
65 std::string channels;
66 for (size_t i = 0; i < sensor_channels[0x02].size(); ++i) {
67 if (i > 0)
68 channels += ",";
69 channels += std::to_string(sensor_channels[0x02][i]);
70 }
71 config_["sensors"]["tc_channels"] = channels;
72 }
73
74 if (sensor_counts.find(0x03) != sensor_counts.end()) {
75 config_["sensors"]["enable_rtd"] = "true";
76 config_["sensors"]["rtd_count"] = std::to_string(sensor_counts[0x03]);
77 std::string channels;
78 for (size_t i = 0; i < sensor_channels[0x03].size(); ++i) {
79 if (i > 0)
80 channels += ",";
81 channels += std::to_string(sensor_channels[0x03][i]);
82 }
83 config_["sensors"]["rtd_channels"] = channels;
84 }
85
86 if (sensor_counts.find(0x04) != sensor_counts.end()) {
87 config_["sensors"]["enable_lc"] = "true";
88 config_["sensors"]["lc_count"] = std::to_string(sensor_counts[0x04]);
89 std::string channels;
90 for (size_t i = 0; i < sensor_channels[0x04].size(); ++i) {
91 if (i > 0)
92 channels += ",";
93 channels += std::to_string(sensor_channels[0x04][i]);
94 }
95 config_["sensors"]["lc_channels"] = channels;
96 }
97
98 // Add board configurations
99 size_t board_idx = 0;
100 for (const auto& board : boards) {
101 std::string board_key = "board_" + std::to_string(board_idx++);
102 config_[board_key]["ip"] = board.current_ip;
103 config_[board_key]["port"] = std::to_string(board.port);
104 config_[board_key]["mac_address"] = board.mac_address;
105 config_[board_key]["board_id"] = "0x" + std::to_string(board.signature.board_id);
106 config_[board_key]["board_type"] = std::to_string(board.signature.board_type);
107 config_[board_key]["max_sensors"] = std::to_string(board.max_sensors);
108 config_[board_key]["active_sensors"] = std::to_string(board.active_sensors);
109 }
110
111 std::cout << "[DynamicConfig] Updated config with " << boards.size() << " boards" << std::endl;
112 return true;
113}
114
115} // namespace config
116} // namespace fsw
static const uint32_t channels[BOARD_ADC_COUNT]
Definition board_adc.c:7
std::map< std::string, std::map< std::string, std::string > > config_
bool load_base_config(const std::string &config_path)
Load base configuration.
bool update_with_boards(const std::vector< DiscoveredBoard > &boards)
Update configuration with discovered boards.
Motorized ball valve position: raw ADC counts -> % open.
std::string board(const std::string &name, const std::string &id, bool enabled=true)