Execute directly from ATCommand

This commit is contained in:
Sofia 2026-05-30 17:37:10 +03:00
parent 178fbaa791
commit 6cf3e1dbe5
2 changed files with 26 additions and 27 deletions

View File

@ -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<T: ATCommand> 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(),
)

View File

@ -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);
}
}