go_pybindings/
command_factory.rs1use std::collections::HashMap;
8
9use pyo3::prelude::*;
10use pyo3::exceptions::PyValueError;
11
12use tof_dataclasses::commands::factory::*;
13
14use crate::{
15 PyTofCommand,
16 PyTriggerConfig,
17 PyTOFEventBuilderConfig,
18 PyDataPublisherConfig,
19 PyTofRunConfig,
20 PyTofRBConfig,
21};
22
23#[pyfunction]
25#[pyo3(name="get_rbratmap_hardcoded")]
26pub fn py_get_rbratmap_hardcoded() -> HashMap::<u8,u8> {
27 get_rbratmap_hardcoded()
28}
29
30#[pyfunction]
32#[pyo3(name="get_ratrbmap_hardcoded")]
33pub fn py_get_ratrbmap_hardcoded() -> HashMap::<u8,(u8,u8)> {
34 get_ratrbmap_hardcoded()
35}
36
37#[pyfunction]
42#[pyo3(name="get_ratpdumap_hardcoded")]
43pub fn py_get_ratpdumap_hardcoded() -> HashMap::<u8,HashMap::<u8,(u8,u8)>> {
44 get_ratpdumap_hardcoded()
45}
46
47#[pyfunction]
53#[pyo3(name="shutdown_rb")]
54pub fn py_shutdown_rb(rb : u8) -> PyResult<PyTofCommand> {
55 let cmd = shutdown_rb(rb).unwrap();
56 Ok(PyTofCommand {
57 command : cmd
58 })
59}
60
61
62#[pyfunction]
65#[pyo3(name="shutdown_all_rbs")]
66pub fn py_shutdown_all_rbs() -> PyResult<PyTofCommand> {
67 let cmd = shutdown_all_rbs().unwrap();
68 let pycmd = PyTofCommand {
69 command : cmd
70 };
71 return Ok(pycmd);
72}
73
74#[pyfunction]
80#[pyo3(name="shutdown_rat")]
81pub fn py_shutdown_rat(rat : u8) -> PyResult<PyTofCommand> {
82 match shutdown_rat(rat) {
83 None => {
84 return Err(PyValueError::new_err(format!("There might not be a RAT{}!", rat)));
85 }
86 Some(cmd) => {
87 let pycmd = PyTofCommand {
88 command : cmd
89 };
90 return Ok(pycmd);
91 }
92 }
93}
94
95#[pyfunction]
105#[pyo3(name="shutdown_ratpair")]
106pub fn py_shutdown_ratpair(pdu : u8, pduchannel : u8) -> PyResult<PyTofCommand> {
107 match shutdown_ratpair(pdu, pduchannel) {
108 None => {
109 return Err(PyValueError::new_err(format!("There might be an issue with the pdu mapping. Can nto find RATs at PDU {} channel {}!", pdu, pduchannel)));
110 }
111 Some(cmd) => {
112 let pycmd = PyTofCommand {
113 command : cmd
114 };
115 return Ok(pycmd);
116 }
117 }
118}
119
120#[pyfunction]
123#[pyo3(name="shutdown_cpu")]
124pub fn py_shutdown_tofcpu() -> PyResult<PyTofCommand> {
125 match shutdown_tofcpu() {
126 None => {
127 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
128 }
129 Some(cmd) => {
130 let pycmd = PyTofCommand {
131 command : cmd
132 };
133 return Ok(pycmd);
134 }
135 }
136}
137
138
139#[pyfunction]
145#[pyo3(name="restart_liftofrb")]
146pub fn py_restart_liftofrb(rbs : Vec<u8>) -> PyResult<PyTofCommand> {
147 match restart_liftofrb(&rbs) {
148 None => {
149 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
150 }
151 Some(cmd) => {
152 let pycmd = PyTofCommand {
153 command : cmd
154 };
155 return Ok(pycmd);
156 }
157 }
158}
159
160#[pyfunction]
163#[pyo3(name="start_run")]
164pub fn py_start_run() -> PyResult<PyTofCommand> {
165 match start_run() {
166 None => {
167 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
168 }
169 Some(cmd) => {
170 let pycmd = PyTofCommand {
171 command : cmd
172 };
173 return Ok(pycmd);
174 }
175 }
176}
177
178#[pyfunction]
180#[pyo3(name="stop_run")]
181pub fn py_stop_run() -> PyResult<PyTofCommand> {
182 match stop_run() {
183 None => {
184 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
185 }
186 Some(cmd) => {
187 let pycmd = PyTofCommand {
188 command : cmd
189 };
190 return Ok(pycmd);
191 }
192 }
193}
194
195#[pyfunction]
204#[pyo3(name="rb_calibration")]
205pub fn py_rb_calibration(pre_run_calibration : bool, send_packets : bool, save_events : bool) -> PyResult<PyTofCommand> {
206 match rb_calibration(pre_run_calibration,send_packets, save_events) {
207 None => {
208 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
209 }
210 Some(cmd) => {
211 let pycmd = PyTofCommand {
212 command : cmd
213 };
214 return Ok(pycmd);
215 }
216 }
217}
218
219
220#[pyfunction]
222#[pyo3(name="change_triggerconfig")]
223pub fn py_change_triggerconfig(cfg : &PyTriggerConfig) -> PyResult<PyTofCommand> {
224 match change_triggerconfig(&cfg.config) {
225 None => {
226 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
227 }
228 Some(cmd) => {
229 let pycmd = PyTofCommand {
230 command : cmd
231 };
232 return Ok(pycmd);
233 }
234 }
235}
236
237
238#[pyfunction]
240#[pyo3(name="change_tofeventbuilderconfig")]
241pub fn py_change_tofeventbuilderconfig(cfg : &PyTOFEventBuilderConfig) -> PyResult<PyTofCommand> {
242 match change_tofeventbuilderconfig(&cfg.config) {
243 None => {
244 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
245 }
246 Some(cmd) => {
247 let pycmd = PyTofCommand {
248 command : cmd
249 };
250 return Ok(pycmd);
251 }
252 }
253}
254
255#[pyfunction]
257#[pyo3(name="change_datapublisherconfig")]
258pub fn py_change_datapublisherconfig(cfg : &PyDataPublisherConfig) -> PyResult<PyTofCommand> {
259 match change_datapublisherconfig(&cfg.config) {
260 None => {
261 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
262 }
263 Some(cmd) => {
264 let pycmd = PyTofCommand {
265 command : cmd
266 };
267 return Ok(pycmd);
268 }
269 }
270}
271
272#[pyfunction]
274#[pyo3(name="change_tofrunconfig")]
275pub fn py_change_tofrunconfig(cfg : &PyTofRunConfig) -> PyResult<PyTofCommand> {
276 match change_tofrunconfig(&cfg.config) {
277 None => {
278 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
279 }
280 Some(cmd) => {
281 let pycmd = PyTofCommand {
282 command : cmd
283 };
284 return Ok(pycmd);
285 }
286 }
287}
288
289#[pyfunction]
291#[pyo3(name="change_tofrbconfig")]
292pub fn py_change_tofrbconfig(cfg : &PyTofRBConfig) -> PyResult<PyTofCommand> {
293 match change_tofrbconfig(&cfg.config) {
294 None => {
295 return Err(PyValueError::new_err(format!("You encounterd a dragon \u{1f409}! We don't know what's going on either.")));
296 }
297 Some(cmd) => {
298 let pycmd = PyTofCommand {
299 command : cmd
300 };
301 return Ok(pycmd);
302 }
303 }
304}
305