From 6cf3e1dbe5707b51a9131ccbc6dc9df84296c38b Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 30 May 2026 17:37:10 +0300 Subject: [PATCH] Execute directly from ATCommand --- src/at_commands.rs | 42 +++++++++++++++++++++--------------------- src/main.rs | 11 +++++------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/at_commands.rs b/src/at_commands.rs index 35564d3..101d724 100644 --- a/src/at_commands.rs +++ b/src/at_commands.rs @@ -168,17 +168,17 @@ impl<'a, 'd> ATCommands<'a, 'd> { pub trait ATCommand: Send + Sync { type Response: core::fmt::Debug; - fn execute(&self) -> ConstructedATCommand; + fn execute(&self, at_commands: &mut ATCommands) -> String; fn parse_response(text: String) -> Self::Response; } pub trait SimpleATCommand: Send + Sync { - fn execute(&self) -> ConstructedATCommand; + fn execute(&self, at_commands: &mut ATCommands) -> String; } impl SimpleATCommand for T { - fn execute(&self) -> ConstructedATCommand { - self.execute() + fn execute(&self, at_commands: &mut ATCommands) -> String { + self.execute(at_commands) } } @@ -187,7 +187,7 @@ pub struct StubATCommand(()); impl ATCommand for StubATCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { + fn execute(&self, _: &mut ATCommands) -> String { panic!("Should never be called") } @@ -201,8 +201,8 @@ pub struct ATInformationCommand; impl ATCommand for ATInformationCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single("ATI".to_string()) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command("ATI".to_string()) } fn parse_response(text: String) -> Self::Response { @@ -215,8 +215,8 @@ pub struct EnterPinCommand(pub String); impl ATCommand for EnterPinCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single(format!("AT+CPIN={}", self.0)) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command(format!("AT+CPIN={}", self.0)) } fn parse_response(text: String) -> Self::Response { @@ -229,8 +229,8 @@ pub struct CheckPinCommand; impl ATCommand for CheckPinCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single("AT+CPIN?".to_string()) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command("AT+CPIN?".to_string()) } fn parse_response(text: String) -> Self::Response { @@ -249,8 +249,8 @@ pub struct SelectSMSFormatCommand(pub SMSFormat); impl ATCommand for SelectSMSFormatCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single(format!("AT+CMGF={}", self.0 as u8)) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command(format!("AT+CMGF={}", self.0 as u8)) } fn parse_response(text: String) -> Self::Response { @@ -263,8 +263,8 @@ pub struct CheckSMSFormatCommand; impl ATCommand for CheckSMSFormatCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single("AT+CMGF?".to_string()) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command("AT+CMGF?".to_string()) } fn parse_response(text: String) -> Self::Response { @@ -277,8 +277,8 @@ pub struct ListTECharacterSetsCommand; impl ATCommand for ListTECharacterSetsCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single("AT+CSCS=?".to_string()) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command("AT+CSCS=?".to_string()) } fn parse_response(text: String) -> Self::Response { @@ -310,8 +310,8 @@ pub struct SetTECharsetCommand(pub TECharset); impl ATCommand for SetTECharsetCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::Single(format!("AT+CSCS=\"{}\"", self.0.into_str())) + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_command(format!("AT+CSCS=\"{}\"", self.0.into_str())) } fn parse_response(text: String) -> Self::Response { @@ -328,8 +328,8 @@ pub struct SendSMSCommand { impl ATCommand for SendSMSCommand { type Response = String; - fn execute(&self) -> ConstructedATCommand { - ConstructedATCommand::AddInfo( + fn execute(&self, at_commands: &mut ATCommands) -> String { + at_commands.raw_two_part_command( format!("AT+CMGS=\"{}\"", self.destination), self.message.clone(), ) diff --git a/src/main.rs b/src/main.rs index d6f7198..ee9b505 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,12 +228,7 @@ fn thread_2_main( loop { if let Some(command) = unsafe { async_io.clone().check_at_command() } { - let response = match command.execute() { - async_io::ConstructedATCommand::Single(cmd) => at_commands.raw_command(cmd), - async_io::ConstructedATCommand::AddInfo(cmd, add) => { - at_commands.raw_two_part_command(cmd, add) - } - }; + let response = command.execute(&mut at_commands); unsafe { async_io.set_at_response(response) }; } @@ -261,6 +256,10 @@ fn thread_2_main( delay.delay_millis(5); } + if buttons_pressed.len() > 0 { + log::info!("{:?}", buttons_pressed) + } + async_io.keypad.handle_presses(buttons_pressed); } }