From 74f4d4251f914ea8e147f07d36cec24e3e3b2ec2 Mon Sep 17 00:00:00 2001 From: XdoctorwhoZ Date: Wed, 4 Dec 2024 12:55:51 +0100 Subject: [PATCH 1/2] update serial driver --- Cargo.toml | 7 ++++++- src/common.rs | 4 +++- src/common/{real => }/control.rs | 0 src/common/{real => }/control/current.rs | 0 src/common/{real => }/control/options.rs | 0 src/common/{real => }/control/options/beep.rs | 0 src/common/{real => }/control/options/lock.rs | 0 src/common/{real => }/control/options/mode.rs | 0 src/common/{real => }/control/options/ocp.rs | 18 ++++++++++++++---- src/common/{real => }/control/options/ovp.rs | 0 src/common/{real => }/control/voltage.rs | 0 src/common/driver.rs | 19 ++++++++++--------- src/common/{real => }/identity.rs | 8 ++++++++ src/common/{real => }/measure.rs | 0 src/common/{real => }/measure/ampermeter.rs | 0 src/common/{real => }/measure/voltmeter.rs | 0 src/common/real.rs | 3 --- src/ka3005p/device.rs | 11 +++++------ src/kd3005p/device.rs | 8 +++++--- src/kd3005p_fake/device.rs | 6 +++--- 20 files changed, 54 insertions(+), 30 deletions(-) rename src/common/{real => }/control.rs (100%) rename src/common/{real => }/control/current.rs (100%) rename src/common/{real => }/control/options.rs (100%) rename src/common/{real => }/control/options/beep.rs (100%) rename src/common/{real => }/control/options/lock.rs (100%) rename src/common/{real => }/control/options/mode.rs (100%) rename src/common/{real => }/control/options/ocp.rs (76%) rename src/common/{real => }/control/options/ovp.rs (100%) rename src/common/{real => }/control/voltage.rs (100%) rename src/common/{real => }/identity.rs (83%) rename src/common/{real => }/measure.rs (100%) rename src/common/{real => }/measure/ampermeter.rs (100%) rename src/common/{real => }/measure/voltmeter.rs (100%) delete mode 100644 src/common/real.rs diff --git a/Cargo.toml b/Cargo.toml index 46d34a6..c49b600 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,14 @@ crate-type = ["lib", "cdylib"] [dependencies] # The panduza core library -panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.5", features = [ +# panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.5", features = [ +# "serial", +# ] } +panduza-platform-core = { path = "C:/Users/xavie/workspace/panduza-platform-core", features = [ "serial", ] } + + # The panduza connectors library # Main async framework for the platform tokio = { version = "1", features = ["full", "tracing"] } diff --git a/src/common.rs b/src/common.rs index 7468133..e459d91 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,3 +1,5 @@ +pub mod control; pub mod driver; pub mod fake; -pub mod real; +pub mod identity; +pub mod measure; diff --git a/src/common/real/control.rs b/src/common/control.rs similarity index 100% rename from src/common/real/control.rs rename to src/common/control.rs diff --git a/src/common/real/control/current.rs b/src/common/control/current.rs similarity index 100% rename from src/common/real/control/current.rs rename to src/common/control/current.rs diff --git a/src/common/real/control/options.rs b/src/common/control/options.rs similarity index 100% rename from src/common/real/control/options.rs rename to src/common/control/options.rs diff --git a/src/common/real/control/options/beep.rs b/src/common/control/options/beep.rs similarity index 100% rename from src/common/real/control/options/beep.rs rename to src/common/control/options/beep.rs diff --git a/src/common/real/control/options/lock.rs b/src/common/control/options/lock.rs similarity index 100% rename from src/common/real/control/options/lock.rs rename to src/common/control/options/lock.rs diff --git a/src/common/real/control/options/mode.rs b/src/common/control/options/mode.rs similarity index 100% rename from src/common/real/control/options/mode.rs rename to src/common/control/options/mode.rs diff --git a/src/common/real/control/options/ocp.rs b/src/common/control/options/ocp.rs similarity index 76% rename from src/common/real/control/options/ocp.rs rename to src/common/control/options/ocp.rs index c3a3d5c..76ef946 100644 --- a/src/common/real/control/options/ocp.rs +++ b/src/common/control/options/ocp.rs @@ -2,13 +2,12 @@ use crate::common::driver::KoradDriver; use panduza_platform_core::protocol::AsciiCmdRespProtocol; use panduza_platform_core::Error; use panduza_platform_core::{ - spawn_on_command, BooleanAttServer, Class, InstanceLogger, Instance, + log_debug, spawn_on_command, BooleanAttServer, Class, Instance, InstanceLogger, }; use std::sync::Arc; use tokio::sync::Mutex; -/// -/// +/// Mount OCP Attribute /// pub async fn mount( mut instance: Instance, @@ -16,7 +15,12 @@ pub async fn mount( driver: Arc>>, ) -> Result<(), Error> { // + // Start logging + let logger = instance.logger.clone(); + log_debug!(logger, "Mounting 'control/options/ocp' class..."); + // + // Mount the attribute let att_voltage = class .create_attribute("ocp") .with_wo() @@ -37,6 +41,10 @@ pub async fn mount( on_command(logger_2.clone(), att_voltage_2.clone(), driver.clone()) ); + // + // + log_debug!(logger, "Mounting 'control/options/ocp' class -> OK"); + // // Function ok Ok(()) @@ -53,7 +61,9 @@ async fn on_command( while let Some(command) = value_value_attr.pop_cmd().await { // // Log - logger.debug(format!("OCP command received '{:?}'", command)); + log_debug!(logger, "OCP command received '{:?}'", command); + // + // driver.lock().await.set_ocp(command).await?; } Ok(()) diff --git a/src/common/real/control/options/ovp.rs b/src/common/control/options/ovp.rs similarity index 100% rename from src/common/real/control/options/ovp.rs rename to src/common/control/options/ovp.rs diff --git a/src/common/real/control/voltage.rs b/src/common/control/voltage.rs similarity index 100% rename from src/common/real/control/voltage.rs rename to src/common/control/voltage.rs diff --git a/src/common/driver.rs b/src/common/driver.rs index 0b72fa4..383a438 100644 --- a/src/common/driver.rs +++ b/src/common/driver.rs @@ -220,16 +220,17 @@ impl KoradDriver { /// /// pub async fn set_ocp(&mut self, value: bool) -> Result<(), Error> { - match value { - true => { - let cmd = "OCP1".to_string(); - self.driver.send(&cmd).await - } - false => { - let cmd = "OCP0".to_string(); - self.driver.send(&cmd).await - } + // + // Prepare command + let mut cmd = "OCP0".to_string(); + if value { + cmd = "OCP1".to_string(); } + + // + // Send + log_trace!(self.logger, "SEND => {:?}", cmd); + self.driver.send(&cmd).await } /// diff --git a/src/common/real/identity.rs b/src/common/identity.rs similarity index 83% rename from src/common/real/identity.rs rename to src/common/identity.rs index 8fc47a7..0462888 100644 --- a/src/common/real/identity.rs +++ b/src/common/identity.rs @@ -11,6 +11,10 @@ pub async fn mount( mut instance: Instance, driver: Arc>>, ) -> Result<(), Error> { + // + // + instance.logger.debug("Mounting 'identity'..."); + // // Create attribute let att_identity = instance @@ -25,5 +29,9 @@ pub async fn mount( let idn = driver.lock().await.get_idn().await?; att_identity.set(idn).await?; + // + // + instance.logger.debug("Mounting 'identity' => OK"); + Ok(()) } diff --git a/src/common/real/measure.rs b/src/common/measure.rs similarity index 100% rename from src/common/real/measure.rs rename to src/common/measure.rs diff --git a/src/common/real/measure/ampermeter.rs b/src/common/measure/ampermeter.rs similarity index 100% rename from src/common/real/measure/ampermeter.rs rename to src/common/measure/ampermeter.rs diff --git a/src/common/real/measure/voltmeter.rs b/src/common/measure/voltmeter.rs similarity index 100% rename from src/common/real/measure/voltmeter.rs rename to src/common/measure/voltmeter.rs diff --git a/src/common/real.rs b/src/common/real.rs deleted file mode 100644 index 380a485..0000000 --- a/src/common/real.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod control; -pub mod identity; -pub mod measure; diff --git a/src/ka3005p/device.rs b/src/ka3005p/device.rs index 79c4b32..b16cf50 100644 --- a/src/ka3005p/device.rs +++ b/src/ka3005p/device.rs @@ -63,8 +63,7 @@ impl KA3005PDevice { SerialSettings::new() .set_port_name_from_json_or_usb_settings(&json_settings, &usb_settings) .map_err(|e| Error::Generic(e.to_string()))? - .set_baudrate(DEVICE_SERIAL_BAUDRATE) - .set_time_lock_duration(Duration::from_millis(300)), // require delay between 2 commands + .set_baudrate(DEVICE_SERIAL_BAUDRATE), ); Ok(()) @@ -83,7 +82,7 @@ impl KA3005PDevice { "Serial Settings not provided".to_string(), ))?; - let driver = SerialTimeLockDriver::open(settings)?; + let driver = SerialTimeLockDriver::open(settings, Duration::from_millis(300))?; let kdriver = KoradDriver::new(driver, instance.logger.clone()); @@ -107,9 +106,9 @@ impl DriverOperations for KA3005PDevice { let driver = self.mount_driver(instance.clone())?; - crate::common::real::identity::mount(instance.clone(), driver.clone()).await?; - crate::common::real::control::mount(instance.clone(), driver.clone()).await?; - crate::common::real::measure::mount(instance.clone(), driver.clone()).await?; + crate::common::identity::mount(instance.clone(), driver.clone()).await?; + crate::common::control::mount(instance.clone(), driver.clone()).await?; + crate::common::measure::mount(instance.clone(), driver.clone()).await?; Ok(()) } diff --git a/src/kd3005p/device.rs b/src/kd3005p/device.rs index 5a2e0ca..82b5805 100644 --- a/src/kd3005p/device.rs +++ b/src/kd3005p/device.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; use crate::common::driver::KoradDriver; use panduza_platform_core::drivers::serial::eol::Driver as SerialEolDriver; +// use panduza_platform_core::drivers::serial::time_lock::Driver as SerialTimeLockDriver; use panduza_platform_core::drivers::serial::Settings as SerialSettings; use panduza_platform_core::drivers::usb::Settings as UsbSettings; use panduza_platform_core::{DriverOperations, Error}; @@ -94,6 +95,7 @@ impl KD3005PDevice { ))?; let driver = SerialEolDriver::open(settings, vec![b'\n'])?; + // let driver = SerialTimeLockDriver::open(settings, Duration::from_millis(300))?; let kdriver = KoradDriver::new(driver, instance.logger.clone()); @@ -121,9 +123,9 @@ impl DriverOperations for KD3005PDevice { let driver = self.mount_driver(instance.clone())?; - crate::common::real::identity::mount(instance.clone(), driver.clone()).await?; - crate::common::real::control::mount(instance.clone(), driver.clone()).await?; - crate::common::real::measure::mount(instance.clone(), driver.clone()).await?; + crate::common::identity::mount(instance.clone(), driver.clone()).await?; + crate::common::control::mount(instance.clone(), driver.clone()).await?; + crate::common::measure::mount(instance.clone(), driver.clone()).await?; // // diff --git a/src/kd3005p_fake/device.rs b/src/kd3005p_fake/device.rs index e358089..92535e4 100644 --- a/src/kd3005p_fake/device.rs +++ b/src/kd3005p_fake/device.rs @@ -40,9 +40,9 @@ impl DriverOperations for KD3005PFakeDevice { async fn mount(&mut self, instance: Instance) -> Result<(), Error> { let driver = self.mount_driver(instance.clone())?; - crate::common::real::identity::mount(instance.clone(), driver.clone()).await?; - crate::common::real::control::mount(instance.clone(), driver.clone()).await?; - crate::common::real::measure::mount(instance.clone(), driver.clone()).await?; + crate::common::identity::mount(instance.clone(), driver.clone()).await?; + crate::common::control::mount(instance.clone(), driver.clone()).await?; + crate::common::measure::mount(instance.clone(), driver.clone()).await?; Ok(()) } From 28d4379b659a93885af5b1cd1114927bf4aacfa2 Mon Sep 17 00:00:00 2001 From: XdoctorwhoZ Date: Wed, 4 Dec 2024 13:14:54 +0100 Subject: [PATCH 2/2] prepare 1.0.5 --- Cargo.toml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c49b600..5daf736 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pza-plugin-korad" edition = "2021" -version = "1.0.4" +version = "1.0.5" [lib] path = "src/lib.rs" @@ -9,14 +9,9 @@ crate-type = ["lib", "cdylib"] [dependencies] # The panduza core library -# panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.5", features = [ -# "serial", -# ] } -panduza-platform-core = { path = "C:/Users/xavie/workspace/panduza-platform-core", features = [ +panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.6", features = [ "serial", ] } - - # The panduza connectors library # Main async framework for the platform tokio = { version = "1", features = ["full", "tracing"] } @@ -29,7 +24,7 @@ futures = "0.3.17" [package.metadata.cargo-post.dependencies] # Only for env paths -panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.5" } +panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.6" } [build-dependencies] #