SRS-control 0.1.4
 
Loading...
Searching...
No Matches
CommandHandlers.cpp
Go to the documentation of this file.
1// #include <array>
2// #include <bitset>
3// #include <numeric>
4// #include <ranges>
5// #include <srs/CommandHandlers.hpp>
6// #include <srs/Control.hpp>
7// #include <vector>
8// #include <srs/CommonDefitions.hpp>
9// #include <fmt/format.h>
10
11// namespace srs
12// {
13// // TODO: why?
14// constexpr auto magic_data_size = 16;
15// constexpr auto INDEX_MAP_BIT_SIZE = 16;
16
17// template <typename T>
18// concept EntryTypeExact = std::same_as<T, EntryType>;
19
20// void acq_on_handler(App& control, DeviceIndex /*indices*/)
21// {
22// const auto data = std::vector<EntryType>{ 0, 15, 1 };
23// control.register_command<MessageMode::write>(data, NULL_ADDRESS);
24// }
25
26// void acq_off_handler(App& control, DeviceIndex /*indices*/)
27// {
28// const auto data = std::vector<EntryType>{ 0, 15, 0 };
29// control.register_command<MessageMode::write>(data, NULL_ADDRESS);
30// }
31
32// void reset_handler(App& control, DeviceIndex /*indices*/)
33// {
34// const auto data = std::vector<EntryType>{ 0, 0xffffffff, 0xffff0001 };
35// control.register_command<MessageMode::write>(data, NULL_ADDRESS);
36// }
37
38// void powercycle_hybrids_handler(App& control, DeviceIndex /*indices*/)
39// {
40// const auto data = std::vector<EntryType>{ 0, 0, 0x37f };
41// control.register_command<MessageMode::write>(data, I2C_ADDRESS);
42// }
43
44// void set_mask_handler(App& control, DeviceIndex /*indices*/)
45// {
46// const auto data = std::vector<EntryType>{ 0, 8, control.get_channel_address() };
47// control.register_command<MessageMode::write>(data);
48// }
49
50// void link_status_handler(App& control, DeviceIndex /*indices*/)
51// {
52// const auto data = std::vector<EntryType>{ 0, 16 };
53// control.register_command<MessageMode::write>(data);
54// }
55
56// inline auto make_reserved_vector(int size)
57// {
58// auto data = std::vector<EntryType>{};
59// data.reserve(size);
60// data.push_back(0);
61// return data;
62// }
63
64// inline void add_config_to_vector(auto& vec, EntryType pos, EntryTypeExact auto entry)
65// {
66// vec.push_back(pos);
67// vec.push_back(entry);
68// }
69
70// void system_register_handler(App& control, DeviceIndex /*indices*/)
71// {
72// auto data = make_reserved_vector(magic_data_size + 1);
73// std::iota(data.begin() + 1, data.end(), 0);
74
75// control.register_command<MessageMode::read>(data);
76// }
77
78// void trigger_acq_constants_handler(App& control, DeviceIndex /*indices*/)
79// {
80// const auto& config = control.get_fec_config();
81
82// constexpr auto data_size = 17;
83// auto data = make_reserved_vector(data_size);
84
85// // TODO: where do these magic numbers come from?
86
87// // NOLINTBEGIN (cppcoreguidelines-avoid-magic-numbers)
88// add_config_to_vector(data, 1, config.debug_data_format);
89// add_config_to_vector(data, 2, config.latency_reset);
90// add_config_to_vector(data, 3, config.latency_data_max);
91// add_config_to_vector(data, 4, config.latency_data_error);
92// add_config_to_vector(data, 9, config.tp_offset_first);
93// add_config_to_vector(data, 10, config.tp_offset);
94// add_config_to_vector(data, 11, config.tp_latency);
95// add_config_to_vector(data, 12, config.tp_number);
96// // NOLINTEND (cppcoreguidelines-avoid-magic-numbers)
97
98// control.register_command<MessageMode::write>(data);
99// }
100
101// void configure_hybrid_handler(App& control, DeviceIndex indices)
102// {
103// auto hybrid_map = std::bitset<INDEX_MAP_BIT_SIZE>{};
104// hybrid_map.set(indices.hybrid);
105
106// const auto& config = control.get_fec_config();
107
108// constexpr auto data_size = 7;
109// auto data = make_reserved_vector(data_size);
110
111// // TODO: Why 3 here?
112// if (config.clock_source == 3)
113// {
114// // TODO: this is not safe
115// const auto test_pulser_config = (config.tp_polarity << 7U) | (config.tp_width << 4U) | config.tp_skew;
116// const auto clock_bunch_counter_config = (config.ckbc_skew << 4U) | config.ckbc;
117// const auto clock_data_config = config.ckdt * 2;
118// // NOLINTBEGIN (cppcoreguidelines-avoid-magic-numbers)
119// add_config_to_vector(data, 2, test_pulser_config);
120// add_config_to_vector(data, 7, clock_bunch_counter_config);
121// add_config_to_vector(data, 5, clock_data_config);
122// }
123// else
124// {
125// add_config_to_vector(data, 2, config.tp_skew);
126// add_config_to_vector(data, 3, config.tp_width);
127// add_config_to_vector(data, 4, config.tp_polarity);
128// // NOLINTEND (cppcoreguidelines-avoid-magic-numbers)
129// }
130// control.register_command<MessageMode::write>(data, static_cast<uint16_t>(hybrid_map.to_ulong()));
131// }
132
133// const CommandsHandlerMap commands_handler_map{ { Commands::acq_on, acq_on_handler },
134// { Commands::acq_off, acq_off_handler },
135// { Commands::configure_hybrid, configure_hybrid_handler },
136// { Commands::link_status, link_status_handler },
137// { Commands::powercycle_hybrids, powercycle_hybrids_handler },
138// // { Commands::read_adc, } ,
139// { Commands::reset, reset_handler },
140// // { Commands::send_config, } ,
141// { Commands::set_mask, set_mask_handler },
142// { Commands::system_registers, system_register_handler },
143// { Commands::trigger_acq_constants, trigger_acq_constants_handler }
144
145// };
146
147// } // namespace srs