Improve parsing
This commit is contained in:
parent
42904cc685
commit
4a38ec9bc3
@ -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<Self::Response, ATParseError> {
|
||||
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<String> {
|
||||
at_commands.raw_command(self, "AT+CMGF?".to_string())
|
||||
}
|
||||
|
||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||
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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user