From 4ad2d779edb42ab5e2edd5c1916fd807d0045132 Mon Sep 17 00:00:00 2001 From: Xavier RODRIGUEZ Date: Mon, 23 Dec 2024 06:04:32 +0100 Subject: [PATCH] Trigger (#4) --- Cargo.toml | 9 ++---- src/attribute_tester/device/si_ro_wo.rs | 6 ++-- src/daq.rs | 34 ++++++++++++++++++++++ src/daq/device.rs | 38 +++++++++++++++++++++++++ src/daq/device/random_si_reader.rs | 26 +++++++++++++++++ src/lib.rs | 4 ++- src/repl/device.rs | 2 -- 7 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 src/daq.rs create mode 100644 src/daq/device.rs create mode 100644 src/daq/device/random_si_reader.rs diff --git a/Cargo.toml b/Cargo.toml index 5d2668a..2bf9847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pza-plugin-vi" edition = "2021" -version = "0.1.1" +version = "0.1.2" [lib] path = "src/lib.rs" @@ -9,7 +9,7 @@ crate-type = ["lib", "cdylib"] [dependencies] # Core -panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.10" } +panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.2.0" } # Main async framework for the platform tokio = { version = "1.40.0", features = ["full"] } # Json serialization & deserialization @@ -20,7 +20,6 @@ async-trait = "0.1.77" futures = "0.3.17" # rand = "0.8.5" - # Trace instrumentation at disabled levels will be skipped and will not even be present # in the resulting binary unless the verbosity level is specified dynamically. # This level is configured separately for release and debug builds. @@ -28,14 +27,12 @@ tracing = { version = "0.1", features = [ "max_level_trace", "release_max_level_trace", ] } - # tracing-core = { version = "0.1.32" } [package.metadata.cargo-post.dependencies] # Core -panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.10" } - +panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core" } [features] # Enable this if you want to build this driver as a dynamic plugin diff --git a/src/attribute_tester/device/si_ro_wo.rs b/src/attribute_tester/device/si_ro_wo.rs index 081776b..4aacfba 100644 --- a/src/attribute_tester/device/si_ro_wo.rs +++ b/src/attribute_tester/device/si_ro_wo.rs @@ -16,7 +16,7 @@ pub async fn mount(mut instance: Instance) -> Result<(), Error> { .create_attribute("si_ro") .with_ro() .with_info(r#"read command"#) - .finish_as_si("test", 0, 100, 2) + .finish_as_si("test", 0.0, 100.0, 2) .await?; att_si_ro.set_from_f32(0.0).await?; @@ -26,7 +26,7 @@ pub async fn mount(mut instance: Instance) -> Result<(), Error> { .create_attribute("si_wo") .with_wo() .with_info(r#"write command"#) - .finish_as_si("test", 0, 100, 2) + .finish_as_si("test", 0.0, 100.0, 2) .await?; // @@ -45,7 +45,7 @@ pub async fn mount(mut instance: Instance) -> Result<(), Error> { .create_attribute("si_rw") .with_rw() .with_info(r#"read write command"#) - .finish_as_si("test", 0, 100, 2) + .finish_as_si("test", 0.0, 100.0, 2) .await?; att_si_rw.set_from_f32(0.0).await?; diff --git a/src/daq.rs b/src/daq.rs new file mode 100644 index 0000000..a45f41e --- /dev/null +++ b/src/daq.rs @@ -0,0 +1,34 @@ +pub mod device; +use device::Device; +use panduza_platform_core::{DriverOperations, Producer}; + +#[derive(Default)] +pub struct Package {} + +impl Package { + pub fn boxed(self) -> Box { + Box::new(self) + } +} + +impl Producer for Package { + fn manufacturer(&self) -> String { + "vi".to_string() + } + + fn model(&self) -> String { + "daq".to_string() + } + + fn description(&self) -> String { + "Virtual DAQ interface".to_string() + } + + fn props(&self) -> panduza_platform_core::Props { + panduza_platform_core::Props::default() + } + + fn produce(&self) -> Result, panduza_platform_core::Error> { + return Ok(Box::new(Device::default())); + } +} diff --git a/src/daq/device.rs b/src/daq/device.rs new file mode 100644 index 0000000..27a279f --- /dev/null +++ b/src/daq/device.rs @@ -0,0 +1,38 @@ +use async_trait::async_trait; +use panduza_platform_core::{DriverOperations, Error, Instance}; +use std::time::Duration; +use tokio::time::sleep; +mod random_si_reader; + +#[derive(Default)] +/// +/// Device to control PicoHA SSB Board +/// +pub struct Device {} + +#[async_trait] +impl DriverOperations for Device { + /// + /// + /// + async fn mount(&mut self, instance: Instance) -> Result<(), Error> { + let interface = random_si_reader::RandomSiReader::default().into_arc_mutex(); + panduza_platform_core::std::class::acq_si::mount( + "randommeter", + "Pika", + 0.0, + 0xffff as f64, + 4, + instance.clone(), + interface.clone(), + ) + .await?; + Ok(()) + } + /// + /// Easiest way to implement the reboot event + /// + async fn wait_reboot_event(&mut self, mut _device: Instance) { + sleep(Duration::from_secs(5)).await; + } +} diff --git a/src/daq/device/random_si_reader.rs b/src/daq/device/random_si_reader.rs new file mode 100644 index 0000000..a3e4c15 --- /dev/null +++ b/src/daq/device/random_si_reader.rs @@ -0,0 +1,26 @@ +use async_trait::async_trait; +use panduza_platform_core::{std::class::acq_si::SiDataReader, Error}; +use rand::Rng; +use std::sync::Arc; +use tokio::sync::Mutex; + +#[derive(Default)] +/// +/// Simple echo evaluation +/// +pub struct RandomSiReader {} + +impl RandomSiReader { + pub fn into_arc_mutex(self) -> Arc> { + Arc::new(Mutex::new(self)) + } +} + +#[async_trait] +impl SiDataReader for RandomSiReader { + async fn read_data(&mut self, _channel: usize) -> Result { + let mut rng = rand::thread_rng(); + let random_value: f64 = rng.gen_range(0.0..0xffff as f64); + Ok(random_value) + } +} diff --git a/src/lib.rs b/src/lib.rs index 144a522..9b26092 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,14 +5,16 @@ panduza_platform_core::plugin_interface!("vi"); // // Import modules -mod repl; mod attribute_tester; +mod daq; +mod repl; // // Export the producers of the plugin pub fn plugin_producers() -> Vec> { let mut producers: Vec> = vec![]; producers.push(repl::Package::default().boxed()); + producers.push(daq::Package::default().boxed()); producers.push(attribute_tester::Package::default().boxed()); return producers; } diff --git a/src/repl/device.rs b/src/repl/device.rs index c4df507..e476222 100644 --- a/src/repl/device.rs +++ b/src/repl/device.rs @@ -4,14 +4,12 @@ use std::time::Duration; use tokio::time::sleep; mod eval_echo; - #[derive(Default)] /// /// Device to control PicoHA SSB Board /// pub struct Device {} - #[async_trait] impl DriverOperations for Device { ///