Skip to content

Commit

Permalink
Prepare 0.5.2 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ authored Dec 17, 2024
1 parent 2be9fad commit b7f94e2
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 192 deletions.
39 changes: 10 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "panduza-rust-platform"
version = "0.5.1"
version = "0.5.2"
edition = "2021"


[dependencies]

# Main base code for Panduza platform and plugins
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.1.6" }
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", "tracing"] }
#
Expand All @@ -28,27 +27,19 @@ async-trait = "0.1.77"
futures = "0.3.17"
#
serde = { "version" = "1.0.0", features = ["derive"] }

# Json serialization & deserialization
serde_json = "1.0.114"

# Regex management
regex = "1.10.3"

# Bytes array management
bytes = "1.5.0"

# Bitflags
bitflags = "2.5.0"

#
hostname = "0.4.0"

#
chrono = "0.4"


# backtrace = "0.3.61"

# To managed logs in colored format
# colored = { version="2.0.0", optional = true }
colored = "2.0.0"
Expand All @@ -57,18 +48,8 @@ colored = "2.0.0"
# 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_off",
# "max_level_error",
# "max_level_warn",
# "max_level_info",
# "max_level_debug",
"max_level_trace",
# "release_max_level_off",
# "release_max_level_error",
# "release_max_level_warn",
# "release_max_level_info",
# "release_max_level_debug",
"release_max_level_trace",
"release_max_level_debug",
] }

#
Expand All @@ -90,23 +71,23 @@ rust_decimal_macros = "1.35"
# --- BUILT-IN DRIVERS
# crate-type = ["lib"] => because plugins need to be compile as simple lib when built-in
# ---
# Fake devices
pza-plugin-fakes = { git = "https://github.com/Panduza/pza-plugin-fakes", tag = "0.1.1", optional = true }
# Virtual Instruments
pza-plugin-vi = { git = "https://github.com/Panduza/pza-plugin-vi", tag = "0.1.0", optional = true }
# ---
# Korad devices
pza-plugin-korad = { git = "https://github.com/Panduza/pza-plugin-korad", tag = "1.0.5", optional = true }
pza-plugin-korad = { git = "https://github.com/Panduza/pza-plugin-korad", tag = "1.0.6", optional = true }
# ---
# Hameg devices
pza-plugin-hameg = { git = "https://github.com/Panduza/pza-plugin-hameg", tag = "1.0.4", optional = true }
# pza-plugin-hameg = { git = "https://github.com/Panduza/pza-plugin-hameg", tag = "1.0.4", optional = true }


[build-dependencies]
toml = "0.8.19"

# --- FEATURES

[features]

# ---
# Integrate some generic drivers directly into the platform
#
built-in-drivers = ["pza-plugin-korad", "pza-plugin-hameg", "pza-plugin-fakes"]
built-in-drivers = ["pza-plugin-korad", "pza-plugin-vi"]
8 changes: 4 additions & 4 deletions src/built_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use panduza_platform_core::Scanner;
//
pub fn plugin_producers() -> Vec<Box<dyn Producer>> {
let mut producers: Vec<Box<dyn Producer>> = vec![];
producers.extend(pza_plugin_fakes::plugin_producers());
producers.extend(pza_plugin_vi::plugin_producers());
producers.extend(pza_plugin_korad::plugin_producers());
producers.extend(pza_plugin_hameg::plugin_producers());
// producers.extend(pza_plugin_hameg::plugin_producers());
return producers;
}

//
//
pub fn plugin_scanners() -> Vec<Box<dyn Scanner>> {
let mut scanners: Vec<Box<dyn Scanner>> = vec![];
scanners.extend(pza_plugin_fakes::plugin_scanners());
scanners.extend(pza_plugin_vi::plugin_scanners());
scanners.extend(pza_plugin_korad::plugin_scanners());
scanners.extend(pza_plugin_hameg::plugin_scanners());
// scanners.extend(pza_plugin_hameg::plugin_scanners());
return scanners;
}
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
while_true,
improper_ctypes,
non_shorthand_field_patterns,
// no_mangle_generic_items,
// overflowing_literals,
// path_statements,
// patterns_in_fns_without_body,
// unconditional_recursion,
// bad_style,
// dead_code,
// unused,
// unused_allocation,
// unused_comparisons,
// unused_parens,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
unconditional_recursion,
bad_style,
// dead_code,
// unused,
unused_allocation,
unused_comparisons,
unused_parens
)]

#[cfg(feature = "built-in-drivers")]
Expand Down
71 changes: 48 additions & 23 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::underscore_device::store::data::SharedStore;
use crate::underscore_device::UnderscoreDevice;
use futures::FutureExt;
use panduza_platform_core::{
create_task_channel, env, log_debug, Factory, InstanceMonitor, Notification, NotificationGroup,
ProductionOrder, Runtime, Store, TaskReceiver, TaskResult, TaskSender,
create_task_channel, env, log_debug, log_warn, Factory, InstanceMonitor, Notification,
NotificationGroup, ProductionOrder, Runtime, Store, TaskReceiver, TaskResult, TaskSender,
};
use panduza_platform_core::{PlatformLogger, Reactor, ReactorSettings};
use rumqttd::Broker;
Expand Down Expand Up @@ -191,18 +191,30 @@ impl Platform {
_ = signal::ctrl_c() => {
//
// Exit due to user request
self.logger.warn("User ctrl-c, abort requested");
log_warn!(self.logger, "User ctrl-c, abort requested");
self.task_pool.abort_all();
self.must_stop.store(true, Ordering::Relaxed);
self.new_task_notifier.notify_waiters();
},
task = task_receiver.rx.recv() => {
//
// Function to effectily spawn tasks requested by the system
let ah = self.task_pool.spawn(task.unwrap());
self.logger.debug(format!( "New task created ! [{:?}]", ah ));
self.new_task_notifier.notify_waiters();
//
// Manage new task creation requests
//
request = task_receiver.rx.recv() => {
match request {
Some(task) => {
// Function to effectily spawn tasks requested by the system
let ah = self.task_pool.spawn(task.future);
log_debug!(self.logger, "New task created [{:?} => {:?}]", ah.id(), task.name);
self.new_task_notifier.notify_waiters();
},
None => {
log_warn!(self.logger, "Empty Task Request Received !");
}
}
},
//
//
//
request = request_receiver.recv() => {
//
// Manage service requests
Expand Down Expand Up @@ -230,7 +242,7 @@ impl Platform {
self.service_produce_device(order).await;
},
ServiceRequest::StartScanning => {
self.service_start_scanning().await;
self.service_start_scanning(self.scanner_driver.clone()).await;
},
}
},
Expand Down Expand Up @@ -521,7 +533,9 @@ impl Platform {

//
// Start thread
self.task_sender.spawn(runtime.task().boxed()).unwrap();
self.task_sender
.spawn_with_name("platform_runtime", runtime.task().boxed())
.unwrap();
}

/// -------------------------------------------------------------
Expand All @@ -546,7 +560,8 @@ impl Platform {
);

self.task_sender
.spawn(
.spawn_with_name(
"_/fsm",
async move {
device.run_fsm().await;
Ok(())
Expand All @@ -556,7 +571,8 @@ impl Platform {
.unwrap();

self.task_sender
.spawn(
.spawn_with_name(
"_/monitor",
async move {
monitor.run().await;
Ok(())
Expand All @@ -569,13 +585,17 @@ impl Platform {
let n_n = self.notifications.clone();
let n_notifier = self.new_notifications_notifier.clone();
self.task_sender
.spawn(Self::task_process_notifications(info_pack, n_notifier, n_n).boxed())
.spawn_with_name(
"notifications",
Self::task_process_notifications(info_pack, n_notifier, n_n).boxed(),
)
.unwrap();

//
//
self.task_sender
.spawn(
.spawn_with_name(
"scanner_request_processor",
Self::task_process_scanner(
self.scanner_driver.clone(),
self.request_sender.clone(),
Expand Down Expand Up @@ -608,19 +628,24 @@ impl Platform {

/// -------------------------------------------------------------
///
async fn service_start_scanning(&mut self) {
async fn service_start_scanning(&mut self, mut scanner_shared_data: ScannerDriver) {
//
// info
self.logger.info("----- SERVICE : START SCANNING -----");
// self.logger.info(format!("ORDER: {:?}", po));

// #[cfg(feature = "built-in-drivers")]
// for scanner in built_in::plugin_scanners() {
// let result = scanner.scan();
// }
let mut orders = Vec::new();

orders.extend(self.plugin_manager.scan().unwrap());

#[cfg(feature = "built-in-drivers")]
for scanner in built_in::plugin_scanners() {
orders.extend(scanner.scan());
}

log_info!(self.logger, "Found instances : {:?}", orders);

let _res = self.plugin_manager.scan().unwrap();
println!("{:?}", _res);
scanner_shared_data.store_instances(orders).await;
scanner_shared_data.stop_running().await;
}

/// -------------------------------------------------------------
Expand Down
37 changes: 3 additions & 34 deletions src/underscore_device/devices.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, sync::Arc};

use super::pack::InfoPack;
use panduza_platform_core::{log_trace, Error, Instance};
use panduza_platform_core::{log_trace, Container, Error, Instance};
use serde_json::json;
use tokio::sync::Mutex;

Expand All @@ -20,14 +20,14 @@ pub async fn mount(mut instance: Instance, pack: InfoPack) -> Result<(), Error>

//
// state of each devices
let mut interface_devices = instance.create_class("devices").finish();
let mut interface_devices = instance.create_class("devices").finish().await;

// I need to spawn a task to watch if a device status has changed, if yes update
// It is a better design to create a task that will always live here
let pack_clone2 = pack.clone();
let instance_attributes_clone = instance_attributes.clone();
instance
.spawn(async move {
.spawn("devices/watcher", async move {
//
// Clone the notifier from info pack
let device_status_change = pack_clone2.instance_status_change_notifier();
Expand Down Expand Up @@ -68,37 +68,6 @@ pub async fn mount(mut instance: Instance, pack: InfoPack) -> Result<(), Error>
})
.await;

// //
// // Structure of the devices
// let structure_att = instance
// .create_attribute("structure")
// .with_ro()
// .finish_as_json()
// .await?;

// let pack_clone3 = pack.clone();
// instance
// .spawn(async move {
// //
// //
// let structure_change = pack_clone3.instance_structure_change_notifier().await;
// // let pack_clone4 = pack_clone3.clone();

// loop {
// //
// // Wait for next status change
// structure_change.notified().await;
// log_trace!(logger, "structure change notification");

// let structure = pack_clone3.device_structure_as_json_value().await.unwrap();
// log_trace!(logger, "new structure {:?}", structure);

// structure_att.set(structure).await.unwrap();
// }
// // Ok(())
// })
// .await;

//
//
Ok(())
Expand Down
Loading

0 comments on commit b7f94e2

Please sign in to comment.