-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade core and finalize att tester (#3)
- Loading branch information
1 parent
f6a31f5
commit 1972029
Showing
19 changed files
with
609 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/virtual_instrument/producer.rs → src/attribute_tester.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
18 changes: 7 additions & 11 deletions
18
src/virtual_instrument/device.rs → src/attribute_tester/device.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.