From f960aedd1c601d2735075080be7d21d7ae9f56ba Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Sat, 11 Jul 2026 12:11:50 +0200 Subject: [PATCH 1/2] style(microscpi, macros): apply Rust codestyle leftover issues Signed-off-by: Adrian DC --- microscpi-macros/src/tree.rs | 13 ++++++++----- microscpi/src/commands.rs | 4 ++-- microscpi/src/registers.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/microscpi-macros/src/tree.rs b/microscpi-macros/src/tree.rs index 9f9230b..ce0b706 100644 --- a/microscpi-macros/src/tree.rs +++ b/microscpi-macros/src/tree.rs @@ -28,7 +28,7 @@ impl std::fmt::Display for Error { type NodeId = usize; /// Represents a tree of SCPI commands. -/// +/// /// The tree is used to efficiently look up command handlers based on the parsed command string. /// It maps each component of a command path to the appropriate handler function. pub struct Tree { @@ -37,7 +37,7 @@ pub struct Tree { } /// A node in the SCPI command tree. -/// +/// /// Each node can have: /// - Children nodes representing the next part of a command /// - An optional command handler for when this node is a command endpoint @@ -67,7 +67,7 @@ impl Tree { /// - "STATUS:EVENT?" /// - "STAT:EVENT?" /// - "EVENT?" (since STATUS is optional) - /// + /// /// # Arguments /// * `cmd` - The command definition to insert /// @@ -128,8 +128,11 @@ impl Tree { self.insert_at(node_id, &path[1..], cmd)?; } else { // We've reached the end of the path, register the command here - let node = self.items.get_mut(&id).expect("Node ID must exist in the tree"); - + let node = self + .items + .get_mut(&id) + .expect("Node ID must exist in the tree"); + if cmd.command.is_query() { // This is a query command (ends with '?') if let Some(existing) = &node.query { diff --git a/microscpi/src/commands.rs b/microscpi/src/commands.rs index 2387954..bc56e65 100644 --- a/microscpi/src/commands.rs +++ b/microscpi/src/commands.rs @@ -115,10 +115,10 @@ pub trait StatusCommands: ErrorCommands { let value = self.status_registers().event_status; let mask = self.status_registers().event_status_enable; let result = value.intersection(mask).bits(); - + // Clear the event status register after reading (per SCPI standard) self.status_registers().event_status = EventStatus::empty(); - + Ok(result) } diff --git a/microscpi/src/registers.rs b/microscpi/src/registers.rs index ddfad8b..60bf0ca 100644 --- a/microscpi/src/registers.rs +++ b/microscpi/src/registers.rs @@ -39,8 +39,8 @@ impl Default for StatusRegisters { Self { event_status: EventStatus::POWER_ON, event_status_enable: EventStatus::all(), - status_byte_enable: StatusByte::all() - & !StatusByte::IMPLEMENTOR_DEFINED_1 + status_byte_enable: StatusByte::all() + & !StatusByte::IMPLEMENTOR_DEFINED_1 & !StatusByte::IMPLEMENTOR_DEFINED_0, } } From 2ced81e67012cbbbf7e24ff4bf970225bc56dc0b Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Sat, 11 Jul 2026 12:02:18 +0200 Subject: [PATCH 2/2] feat(commands, error_queue): implement 'SYSTem:ERRor:ALL?' Signed-off-by: Adrian DC --- microscpi-macros/src/lib.rs | 8 ++++++++ microscpi/src/commands.rs | 12 ++++++++++++ microscpi/src/error_queue.rs | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/microscpi-macros/src/lib.rs b/microscpi-macros/src/lib.rs index 9f21bbe..b864dea 100644 --- a/microscpi-macros/src/lib.rs +++ b/microscpi-macros/src/lib.rs @@ -311,6 +311,14 @@ pub fn interface(attr: TokenStream, item: TokenStream) -> TokenStream { handler: CommandHandler::StandardFunction("ErrorCommands::system_error_count"), future: false, }); + + command_set.push(CommandDefinition { + id: None, + args: Vec::new(), + command: Command::try_from("SYSTem:ERRor:ALL?").unwrap(), + handler: CommandHandler::StandardFunction("ErrorCommands::system_error_all"), + future: false, + }); } if config.status_commands { diff --git a/microscpi/src/commands.rs b/microscpi/src/commands.rs index bc56e65..454710a 100644 --- a/microscpi/src/commands.rs +++ b/microscpi/src/commands.rs @@ -30,6 +30,18 @@ pub trait ErrorCommands { Ok((0, "")) } } + + fn system_error_all(&mut self) -> Result, Error> { + let errors = self.error_queue().all(); + if !errors.is_empty() { + Ok(errors + .iter() + .map(|error| (error.number(), (*error).into())) + .collect::>()) + } else { + Ok(vec![(0, "")]) + } + } } impl ErrorHandler for I diff --git a/microscpi/src/error_queue.rs b/microscpi/src/error_queue.rs index cd192e7..432528d 100644 --- a/microscpi/src/error_queue.rs +++ b/microscpi/src/error_queue.rs @@ -15,6 +15,8 @@ pub trait ErrorQueue: Default { /// Get and remove the error in the front of the error queue. If the queue /// is empty, [None] is returned. fn pop_error(&mut self) -> Option; + /// Get all errors list + fn all(&self) -> Vec; /// Clear the error queue. fn clear(&mut self); } @@ -51,6 +53,10 @@ impl ErrorQueue for StaticErrorQueue { self.0.len() } + fn all(&self) -> Vec { + self.0.iter().copied().collect() + } + fn clear(&mut self) { self.0.clear(); }