diff --git a/src/at_commands.rs b/src/at_commands.rs index 492cde0..4404cce 100644 --- a/src/at_commands.rs +++ b/src/at_commands.rs @@ -332,7 +332,7 @@ impl ATCommand for EnterPinCommand { } #[derive(Debug)] pub enum CheckPinResult { - Ok, + Status(String), Error, ErrorMessage(String), } @@ -347,10 +347,17 @@ impl ATCommand for CheckPinCommand { } fn parse_response(parser: &mut ATResponseParser) -> Result { + if let Ok(_) = parser.expect("+CPIN: ".to_string()) { + let status = parser.readline().unwrap(); + while let Some(line) = parser.readline() { + if line.starts_with("OK") { + return Ok(CheckPinResult::Status(status)); + } + } + } + while let Some(line) = parser.readline() { - if line.starts_with("OK") { - return Ok(CheckPinResult::Ok); - } else if line.starts_with("ERROR") { + 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())); @@ -393,19 +400,34 @@ impl ATCommand for SelectSMSFormatCommand { } } +#[derive(Debug)] +pub enum CheckSMSFormatResult { + Mode(String), + Error, +} + #[derive(Debug, Clone)] pub struct CheckSMSFormatCommand; impl ATCommand for CheckSMSFormatCommand { - type Response = String; + type Response = CheckSMSFormatResult; fn execute(&self, at_commands: &mut ATCommands) -> Vec { at_commands.raw_command(self, "AT+CMGF?".to_string()) } fn parse_response(parser: &mut ATResponseParser) -> Result { + if let Ok(_) = parser.expect("+CMGF: ".to_string()) { + let mode = parser.readline().unwrap(); + while let Some(line) = parser.readline() { + if line.starts_with("OK") { + return Ok(CheckSMSFormatResult::Mode(mode)); + } + } + } + while let Some(line) = parser.readline() { - if line.starts_with("OK") { - return Ok("OK".to_owned()); + if line.starts_with("ERROR") { + return Ok(CheckSMSFormatResult::Error); } } Err(ATParseError::EOF)