Skip to content

Commit

Permalink
Trigger (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ authored Dec 23, 2024
1 parent 87c514d commit 4ad2d77
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 12 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "pza-plugin-vi"
edition = "2021"
version = "0.1.1"
version = "0.1.2"

[lib]
path = "src/lib.rs"
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
Expand All @@ -20,22 +20,19 @@ 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.
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
Expand Down
6 changes: 3 additions & 3 deletions src/attribute_tester/device/si_ro_wo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand All @@ -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?;

//
Expand All @@ -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?;

Expand Down
34 changes: 34 additions & 0 deletions src/daq.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
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<Box<dyn DriverOperations>, panduza_platform_core::Error> {
return Ok(Box::new(Device::default()));
}
}
38 changes: 38 additions & 0 deletions src/daq/device.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/daq/device/random_si_reader.rs
Original file line number Diff line number Diff line change
@@ -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<Mutex<Self>> {
Arc::new(Mutex::new(self))
}
}

#[async_trait]
impl SiDataReader for RandomSiReader {
async fn read_data(&mut self, _channel: usize) -> Result<f64, Error> {
let mut rng = rand::thread_rng();
let random_value: f64 = rng.gen_range(0.0..0xffff as f64);
Ok(random_value)
}
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Producer>> {
let mut producers: Vec<Box<dyn Producer>> = vec![];
producers.push(repl::Package::default().boxed());
producers.push(daq::Package::default().boxed());
producers.push(attribute_tester::Package::default().boxed());
return producers;
}
Expand Down
2 changes: 0 additions & 2 deletions src/repl/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
///
Expand Down

0 comments on commit 4ad2d77

Please sign in to comment.