Skip to main content

cu_flight_controller_export/
python_module.rs

1#![cfg_attr(not(feature = "python-bindings"), no_std)]
2//! App-specific Python bindings for offline log inspection.
3//!
4//! This module demonstrates the intended Copper pattern for typed Python log
5//! access:
6//!
7//! - keep the runtime in Rust
8//! - generate the app-specific CopperList type with `gen_cumsgs!`
9//! - expose a tiny `#[pymodule]` wrapper for offline analysis scripts
10//!
11//! This is not the same thing as running task logic in Python.
12
13#[cfg(feature = "python-bindings")]
14extern crate cu29 as bevy;
15
16#[cfg(feature = "python-bindings")]
17mod messages;
18
19#[cfg(feature = "python-bindings")]
20use cu29::prelude::*;
21#[cfg(feature = "python-bindings")]
22use pyo3::prelude::*;
23#[cfg(feature = "python-bindings")]
24use std::path::Path;
25
26#[cfg(feature = "python-bindings")]
27gen_cumsgs!("copperconfig.ron");
28
29#[cfg(feature = "python-bindings")]
30const EXPECTED_MISSION: &str = "gnss";
31
32#[cfg(feature = "python-bindings")]
33fn ensure_expected_mission(unified_src_path: &str) -> PyResult<()> {
34    cu29_export::assert_unified_log_mission(Path::new(unified_src_path), EXPECTED_MISSION)
35        .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))
36}
37
38#[cfg(feature = "python-bindings")]
39#[pyfunction]
40fn copperlist_iterator_unified(unified_src_path: &str, py: Python<'_>) -> PyResult<Py<PyAny>> {
41    ensure_expected_mission(unified_src_path)?;
42    cu29_export::copperlist_iterator_unified_typed_py::<cumsgs::gnss::CuStampedDataSet>(
43        unified_src_path,
44        py,
45    )
46}
47
48#[cfg(feature = "python-bindings")]
49#[pyfunction]
50fn runtime_lifecycle_iterator_unified(
51    unified_src_path: &str,
52    py: Python<'_>,
53) -> PyResult<Py<PyAny>> {
54    ensure_expected_mission(unified_src_path)?;
55    cu29_export::runtime_lifecycle_iterator_unified_py(unified_src_path, py)
56}
57
58/// The compiled shared object is named `libcu_flight_controller_export.*`.
59#[cfg(feature = "python-bindings")]
60#[pymodule(name = "libcu_flight_controller_export")]
61fn cu_flight_controller_export(m: &Bound<'_, PyModule>) -> PyResult<()> {
62    m.add_function(wrap_pyfunction!(copperlist_iterator_unified, m)?)?;
63    m.add_function(wrap_pyfunction!(runtime_lifecycle_iterator_unified, m)?)?;
64    Ok(())
65}