Parse some more commands
This commit is contained in:
parent
e34121d5a6
commit
42904cc685
@ -226,6 +226,7 @@ impl ATResponseParser {
|
||||
self.curr_line = Some(text.to_string());
|
||||
Ok(())
|
||||
} else {
|
||||
self.curr_line = Some(line);
|
||||
Err(ATParseError::InvalidResponse)
|
||||
}
|
||||
}
|
||||
@ -300,10 +301,17 @@ impl ATCommand for ATInformationCommand {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EnterPinResult {
|
||||
Ok,
|
||||
Error,
|
||||
ErrorMessage(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EnterPinCommand(pub String);
|
||||
impl ATCommand for EnterPinCommand {
|
||||
type Response = String;
|
||||
type Response = EnterPinResult;
|
||||
|
||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||
at_commands.raw_command(self, format!("AT+CPIN={}", self.0))
|
||||
@ -312,17 +320,27 @@ impl ATCommand for EnterPinCommand {
|
||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||
while let Some(line) = parser.readline() {
|
||||
if line.starts_with("OK") {
|
||||
return Ok("OK".to_owned());
|
||||
return Ok(EnterPinResult::Ok);
|
||||
} else if line.starts_with("ERROR") {
|
||||
return Ok(EnterPinResult::Error);
|
||||
} else if let Some(status) = line.strip_prefix("+CME ERROR: ") {
|
||||
return Ok(EnterPinResult::ErrorMessage(status.to_string()));
|
||||
}
|
||||
}
|
||||
Err(ATParseError::EOF)
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum CheckPinResult {
|
||||
Ok,
|
||||
Error,
|
||||
ErrorMessage(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CheckPinCommand;
|
||||
impl ATCommand for CheckPinCommand {
|
||||
type Response = String;
|
||||
type Response = CheckPinResult;
|
||||
|
||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||
at_commands.raw_command(self, "AT+CPIN?".to_string())
|
||||
@ -331,13 +349,23 @@ impl ATCommand for CheckPinCommand {
|
||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||
while let Some(line) = parser.readline() {
|
||||
if line.starts_with("OK") {
|
||||
return Ok("OK".to_owned());
|
||||
return Ok(CheckPinResult::Ok);
|
||||
} else if line.starts_with("ERROR") {
|
||||
return Ok(CheckPinResult::Error);
|
||||
} else if let Some(status) = line.strip_prefix("+CME ERROR: ") {
|
||||
return Ok(CheckPinResult::ErrorMessage(status.to_string()));
|
||||
}
|
||||
}
|
||||
Err(ATParseError::EOF)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SelectSMSFormatResult {
|
||||
Ok,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SMSFormat {
|
||||
PDUMode = 0,
|
||||
@ -347,7 +375,7 @@ pub enum SMSFormat {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SelectSMSFormatCommand(pub SMSFormat);
|
||||
impl ATCommand for SelectSMSFormatCommand {
|
||||
type Response = String;
|
||||
type Response = SelectSMSFormatResult;
|
||||
|
||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||
at_commands.raw_command(self, format!("AT+CMGF={}", self.0 as u8))
|
||||
@ -356,7 +384,9 @@ impl ATCommand for SelectSMSFormatCommand {
|
||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||
while let Some(line) = parser.readline() {
|
||||
if line.starts_with("OK") {
|
||||
return Ok("OK".to_owned());
|
||||
return Ok(SelectSMSFormatResult::Ok);
|
||||
} else if line.starts_with("ERROR") {
|
||||
return Ok(SelectSMSFormatResult::Error);
|
||||
}
|
||||
}
|
||||
Err(ATParseError::EOF)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user