1use pyo3::exceptions;
2use pyo3::prelude::*;
3use pyo3::wrap_pymodule;
4
5pub(crate) mod controller;
6pub(crate) mod transfer; #[pymodule]
9#[pyo3(name = "deimos")]
10fn deimos<'py>(_py: Python, m: &Bound<'py, PyModule>) -> PyResult<()> {
11 m.add_class::<controller::Controller>()?;
12 m.add_class::<crate::Overflow>()?;
13 m.add_class::<crate::RunHandle>()?;
14 m.add_class::<crate::Snapshot>()?;
15 m.add_class::<crate::LoopMethod>()?;
16 m.add_class::<crate::LossOfContactPolicy>()?;
17 m.add_class::<crate::Termination>()?;
18
19 #[pymodule]
20 #[pyo3(name = "calc")]
21 mod calc_ {
22 #[pymodule_export]
23 pub use crate::calc::{
24 Affine, Butter2, Constant, InverseAffine, Pid, Polynomial, RtdPt100, SequenceMachine,
25 Sin, TcKtype,
26 };
27 }
28
29 m.add_wrapped(wrap_pymodule!(calc_))?;
30
31 #[pymodule]
32 #[pyo3(name = "peripheral")]
33 mod peripheral_ {
34 #[pymodule_export]
35 pub use crate::peripheral::{
36 AnalogIRev2, AnalogIRev3, AnalogIRev4, DeimosDaqRev5, DeimosDaqRev6, HootlDriver,
37 HootlPeripheral, HootlRunHandle, HootlTransport,
38 };
39 }
40
41 m.add_wrapped(wrap_pymodule!(peripheral_))?;
42
43 #[pymodule]
44 #[pyo3(name = "socket")]
45 mod socket_ {
46 #[cfg(unix)]
47 #[pymodule_export]
48 pub use crate::socket::unix::UnixSocket;
49 #[pymodule_export]
50 pub use crate::socket::{thread_channel::ThreadChannelSocket, udp::UdpSocket};
51 }
52
53 m.add_wrapped(wrap_pymodule!(socket_))?;
54
55 #[pymodule]
56 #[pyo3(name = "dispatcher")]
57 mod dispatcher_ {
58 #[pymodule_export]
59 pub use crate::dispatcher::{
60 ChannelFilter, CsvDispatcher, DataFrameDispatcher, DataFrameHandle,
61 DecimationDispatcher, LatestValueDispatcher, LowPassDispatcher, TimescaleDbDispatcher,
62 };
63 }
64
65 m.add_wrapped(wrap_pymodule!(dispatcher_))?;
66
67 Ok(())
68}
69
70#[derive(Debug)]
71#[allow(dead_code)]
72pub(crate) enum BackendErr {
73 InvalidPathErr { msg: String },
74 RunErr { msg: String },
75 InvalidPeripheralErr { msg: String },
76 InvalidCalcErr { msg: String },
77 InvalidDispatcherErr { msg: String },
78 InvalidSocketErr { msg: String },
79}
80
81impl From<BackendErr> for PyErr {
82 fn from(val: BackendErr) -> Self {
83 match &val {
84 BackendErr::InvalidPathErr { msg: _ } => {
85 exceptions::PyValueError::new_err(format!("{:#?}", val))
86 }
87 BackendErr::RunErr { msg: _ } => exceptions::PyIOError::new_err(format!("{:#?}", val)),
88 BackendErr::InvalidPeripheralErr { msg: _ } => {
89 exceptions::PyValueError::new_err(format!("{:#?}", val))
90 }
91 BackendErr::InvalidCalcErr { msg: _ } => {
92 exceptions::PyValueError::new_err(format!("{:#?}", val))
93 }
94 BackendErr::InvalidDispatcherErr { msg: _ } => {
95 exceptions::PyValueError::new_err(format!("{:#?}", val))
96 }
97 BackendErr::InvalidSocketErr { msg: _ } => {
98 exceptions::PyValueError::new_err(format!("{:#?}", val))
99 }
100 }
101 }
102}