Execute directly from ATCommand
This commit is contained in:
parent
178fbaa791
commit
6cf3e1dbe5
@ -168,17 +168,17 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
|||||||
|
|
||||||
pub trait ATCommand: Send + Sync {
|
pub trait ATCommand: Send + Sync {
|
||||||
type Response: core::fmt::Debug;
|
type Response: core::fmt::Debug;
|
||||||
fn execute(&self) -> ConstructedATCommand;
|
fn execute(&self, at_commands: &mut ATCommands) -> String;
|
||||||
fn parse_response(text: String) -> Self::Response;
|
fn parse_response(text: String) -> Self::Response;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SimpleATCommand: Send + Sync {
|
pub trait SimpleATCommand: Send + Sync {
|
||||||
fn execute(&self) -> ConstructedATCommand;
|
fn execute(&self, at_commands: &mut ATCommands) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ATCommand> SimpleATCommand for T {
|
impl<T: ATCommand> SimpleATCommand for T {
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
self.execute()
|
self.execute(at_commands)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ pub struct StubATCommand(());
|
|||||||
impl ATCommand for StubATCommand {
|
impl ATCommand for StubATCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, _: &mut ATCommands) -> String {
|
||||||
panic!("Should never be called")
|
panic!("Should never be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,8 +201,8 @@ pub struct ATInformationCommand;
|
|||||||
impl ATCommand for ATInformationCommand {
|
impl ATCommand for ATInformationCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single("ATI".to_string())
|
at_commands.raw_command("ATI".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -215,8 +215,8 @@ pub struct EnterPinCommand(pub String);
|
|||||||
impl ATCommand for EnterPinCommand {
|
impl ATCommand for EnterPinCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single(format!("AT+CPIN={}", self.0))
|
at_commands.raw_command(format!("AT+CPIN={}", self.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -229,8 +229,8 @@ pub struct CheckPinCommand;
|
|||||||
impl ATCommand for CheckPinCommand {
|
impl ATCommand for CheckPinCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single("AT+CPIN?".to_string())
|
at_commands.raw_command("AT+CPIN?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -249,8 +249,8 @@ pub struct SelectSMSFormatCommand(pub SMSFormat);
|
|||||||
impl ATCommand for SelectSMSFormatCommand {
|
impl ATCommand for SelectSMSFormatCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single(format!("AT+CMGF={}", self.0 as u8))
|
at_commands.raw_command(format!("AT+CMGF={}", self.0 as u8))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -263,8 +263,8 @@ pub struct CheckSMSFormatCommand;
|
|||||||
impl ATCommand for CheckSMSFormatCommand {
|
impl ATCommand for CheckSMSFormatCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single("AT+CMGF?".to_string())
|
at_commands.raw_command("AT+CMGF?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -277,8 +277,8 @@ pub struct ListTECharacterSetsCommand;
|
|||||||
impl ATCommand for ListTECharacterSetsCommand {
|
impl ATCommand for ListTECharacterSetsCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single("AT+CSCS=?".to_string())
|
at_commands.raw_command("AT+CSCS=?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -310,8 +310,8 @@ pub struct SetTECharsetCommand(pub TECharset);
|
|||||||
impl ATCommand for SetTECharsetCommand {
|
impl ATCommand for SetTECharsetCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::Single(format!("AT+CSCS=\"{}\"", self.0.into_str()))
|
at_commands.raw_command(format!("AT+CSCS=\"{}\"", self.0.into_str()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(text: String) -> Self::Response {
|
fn parse_response(text: String) -> Self::Response {
|
||||||
@ -328,8 +328,8 @@ pub struct SendSMSCommand {
|
|||||||
impl ATCommand for SendSMSCommand {
|
impl ATCommand for SendSMSCommand {
|
||||||
type Response = String;
|
type Response = String;
|
||||||
|
|
||||||
fn execute(&self) -> ConstructedATCommand {
|
fn execute(&self, at_commands: &mut ATCommands) -> String {
|
||||||
ConstructedATCommand::AddInfo(
|
at_commands.raw_two_part_command(
|
||||||
format!("AT+CMGS=\"{}\"", self.destination),
|
format!("AT+CMGS=\"{}\"", self.destination),
|
||||||
self.message.clone(),
|
self.message.clone(),
|
||||||
)
|
)
|
||||||
|
|||||||
11
src/main.rs
11
src/main.rs
@ -228,12 +228,7 @@ fn thread_2_main(
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(command) = unsafe { async_io.clone().check_at_command() } {
|
if let Some(command) = unsafe { async_io.clone().check_at_command() } {
|
||||||
let response = match command.execute() {
|
let response = command.execute(&mut at_commands);
|
||||||
async_io::ConstructedATCommand::Single(cmd) => at_commands.raw_command(cmd),
|
|
||||||
async_io::ConstructedATCommand::AddInfo(cmd, add) => {
|
|
||||||
at_commands.raw_two_part_command(cmd, add)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
unsafe { async_io.set_at_response(response) };
|
unsafe { async_io.set_at_response(response) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +256,10 @@ fn thread_2_main(
|
|||||||
delay.delay_millis(5);
|
delay.delay_millis(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if buttons_pressed.len() > 0 {
|
||||||
|
log::info!("{:?}", buttons_pressed)
|
||||||
|
}
|
||||||
|
|
||||||
async_io.keypad.handle_presses(buttons_pressed);
|
async_io.keypad.handle_presses(buttons_pressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user