Skip to content

Commit

Permalink
upgrade core and finalize att tester (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ authored Dec 17, 2024
1 parent f6a31f5 commit 1972029
Show file tree
Hide file tree
Showing 19 changed files with 609 additions and 449 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": true,
"rust-analyzer.linkedProjects": [
"Cargo.toml",
],
"rust-analyzer.showUnlinkedFileNotification": false,
}
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["lib", "cdylib"]

[dependencies]
# Core
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.8" }
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.9" }
# Main async framework for the platform
tokio = { version = "1.40.0", features = ["full"] }
# Json serialization & deserialization
Expand All @@ -26,15 +26,15 @@ rand = "0.8.5"
# This level is configured separately for release and debug builds.
tracing = { version = "0.1", features = [
"max_level_trace",
"release_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.8" }
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.9" }


[features]
Expand Down
21 changes: 11 additions & 10 deletions src/virtual_instrument/producer.rs → src/attribute_tester.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
pub mod device;
use panduza_platform_core::{DriverOperations, Producer};
use super::device::ViDevice;

pub struct Vi {}
#[derive(Default)]
pub struct Package {}

impl Vi {
pub fn new() -> Box<Vi> {
Box::new(Vi {})
impl Package {
pub fn boxed(self) -> Box<Self> {
Box::new(self)
}
}

impl Producer for Vi {
impl Producer for Package {
fn manufacturer(&self) -> String {
"panduza".to_string()
"vi".to_string()
}

fn model(&self) -> String {
"VI".to_string()
"attribute_tester".to_string()
}

fn description(&self) -> String {
"Virtual Instrument interface".to_string()
"Virtual Instrument to test attributes and classes".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(ViDevice::new()));
return Ok(Box::new(device::Device::new()));
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
// mod datatype;
mod string_ro_wo;
mod string_rw;
mod bool_ro_wo;
mod enum_ro_wo;
mod json_ro_wo;
mod number_ro_wo;
mod si_ro_wo;
mod string_ro_wo;

use async_trait::async_trait;
use panduza_platform_core::{DriverOperations, Error, Instance};
use std::time::Duration;
use tokio::time::sleep;

#[derive(Default)]
///
///
///
pub struct ViDevice {}
pub struct Device {}

impl ViDevice {
///
impl Device {
/// Constructor
///
pub fn new() -> Self {
ViDevice {}
Device {}
}
}

#[async_trait]
impl DriverOperations for ViDevice {
impl DriverOperations for Device {
///
///
///
async fn mount(&mut self, instance: Instance) -> Result<(), Error> {

string_ro_wo::mount(instance.clone()).await?;
string_rw::mount(instance.clone()).await?;
bool_ro_wo::mount(instance.clone()).await?;
enum_ro_wo::mount(instance.clone()).await?;
json_ro_wo::mount(instance.clone()).await?;
number_ro_wo::mount(instance.clone()).await?;
si_ro_wo::mount(instance.clone()).await?;

Ok(())
}
///
Expand Down
88 changes: 88 additions & 0 deletions src/attribute_tester/device/bool_ro_wo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use panduza_platform_core::{
log_info, spawn_on_command, BooleanAttServer, Container, Error, Instance,
};

///
///
///
pub async fn mount(mut instance: Instance) -> Result<(), Error> {
//
// Create interface
let mut class = instance.create_class("boolean").finish().await;

//
//
let att_boolean_ro = class
.create_attribute("boolean_ro")
.with_ro()
.with_info(r#"read command"#)
.finish_as_boolean()
.await?;
att_boolean_ro.set(false).await?;

//
//
let att_boolean_wo = class
.create_attribute("boolean_wo")
.with_wo()
.with_info(r#"write command"#)
.finish_as_boolean()
.await?;

//
//
let att_boolean_wo_2 = att_boolean_wo.clone();
spawn_on_command!(
"on_command",
instance,
att_boolean_wo_2,
on_command(att_boolean_ro.clone(), att_boolean_wo_2.clone())
);

//
//
let att_boolean_rw = class
.create_attribute("boolean_rw")
.with_wo()
.with_info(r#"read write command"#)
.finish_as_boolean()
.await?;
att_boolean_rw.set(false).await?;

//
//
let att_boolean_rw_2 = att_boolean_rw.clone();
spawn_on_command!(
"on_command => boolean_rw",
instance,
att_boolean_rw_2,
on_command_rw(att_boolean_rw_2.clone())
);

Ok(())
}

///
///
///
async fn on_command(
att_boolean_ro: BooleanAttServer,
mut att_boolean_wo: BooleanAttServer,
) -> Result<(), Error> {
while let Some(command) = att_boolean_wo.pop_cmd().await {
log_info!(att_boolean_wo.logger(), "command recieved - {:?}", command);
att_boolean_ro.set(command).await?;
}
Ok(())
}

///
///
///
async fn on_command_rw(mut att_boolean_rw: BooleanAttServer) -> Result<(), Error> {
while let Some(command) = att_boolean_rw.pop_cmd().await {
log_info!(att_boolean_rw.logger(), "command recieved - {:?}", command);
att_boolean_rw.set(command).await?;
}
Ok(())
}
118 changes: 118 additions & 0 deletions src/attribute_tester/device/enum_ro_wo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use panduza_platform_core::{
log_error, log_info, spawn_on_command, Container, EnumAttServer, Error, Instance,
};

///
///
///
pub async fn mount(mut instance: Instance) -> Result<(), Error> {
//
// Create interface
let mut class = instance.create_class("enum").finish().await;

//
// Some of the first contributors (sorted by alphabetic order)
let choices = vec![
"Adel".to_string(),
"Antoine".to_string(),
"Bryan".to_string(),
"Damien".to_string(),
"Edmundo".to_string(),
"Florian".to_string(),
"Lucas".to_string(),
"Rethusan".to_string(),
"Valentin".to_string(),
"Xavier".to_string(),
];

//
//
let att_enum_ro = class
.create_attribute("enum_ro")
.with_ro()
.with_info(r#"read command"#)
.finish_as_enum(choices.clone())
.await?;
att_enum_ro.set(choices.get(0).unwrap().clone()).await?;

//
//
let att_enum_wo = class
.create_attribute("enum_wo")
.with_wo()
.with_info(r#"write command"#)
.finish_as_enum(choices.clone())
.await?;

//
//
let att_enum_wo_2 = att_enum_wo.clone();
spawn_on_command!(
"on_command",
instance,
att_enum_wo_2,
on_command(att_enum_ro.clone(), att_enum_wo_2.clone())
);

//
//
let att_enum_rw = class
.create_attribute("enum_rw")
.with_wo()
.with_info(r#"read write command"#)
.finish_as_enum(choices.clone())
.await?;
att_enum_rw.set(choices.get(0).unwrap().clone()).await?;

//
//
let att_enum_rw_2 = att_enum_rw.clone();
spawn_on_command!(
"on_command => enum_rw",
instance,
att_enum_rw_2,
on_command_rw(att_enum_rw_2.clone())
);

Ok(())
}

///
///
///
async fn on_command(
att_enum_ro: EnumAttServer,
mut att_enum_wo: EnumAttServer,
) -> Result<(), Error> {
while let Some(command) = att_enum_wo.pop_cmd().await {
match command {
Ok(c) => {
log_info!(att_enum_ro.logger(), "command recieved - {:?}", c);
att_enum_ro.set(c).await?;
}
Err(e) => {
log_error!(att_enum_ro.logger(), "command recieved err - {:?}", e);
}
}
}

Ok(())
}

///
///
///
async fn on_command_rw(mut att_enum_rw: EnumAttServer) -> Result<(), Error> {
while let Some(command) = att_enum_rw.pop_cmd().await {
match command {
Ok(c) => {
log_info!(att_enum_rw.logger(), "command recieved - {:?}", c);
att_enum_rw.set(c).await?;
}
Err(e) => {
log_error!(att_enum_rw.logger(), "command recieved err - {:?}", e);
}
}
}
Ok(())
}
Loading

0 comments on commit 1972029

Please sign in to comment.