Improve parsing
This commit is contained in:
parent
42904cc685
commit
4a38ec9bc3
@ -332,7 +332,7 @@ impl ATCommand for EnterPinCommand {
|
|||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CheckPinResult {
|
pub enum CheckPinResult {
|
||||||
Ok,
|
Status(String),
|
||||||
Error,
|
Error,
|
||||||
ErrorMessage(String),
|
ErrorMessage(String),
|
||||||
}
|
}
|
||||||
@ -347,10 +347,17 @@ impl ATCommand for CheckPinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
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() {
|
while let Some(line) = parser.readline() {
|
||||||
if line.starts_with("OK") {
|
if line.starts_with("OK") {
|
||||||
return Ok(CheckPinResult::Ok);
|
return Ok(CheckPinResult::Status(status));
|
||||||
} else if line.starts_with("ERROR") {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(line) = parser.readline() {
|
||||||
|
if line.starts_with("ERROR") {
|
||||||
return Ok(CheckPinResult::Error);
|
return Ok(CheckPinResult::Error);
|
||||||
} else if let Some(status) = line.strip_prefix("+CME ERROR: ") {
|
} else if let Some(status) = line.strip_prefix("+CME ERROR: ") {
|
||||||
return Ok(CheckPinResult::ErrorMessage(status.to_string()));
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CheckSMSFormatCommand;
|
pub struct CheckSMSFormatCommand;
|
||||||
impl ATCommand for CheckSMSFormatCommand {
|
impl ATCommand for CheckSMSFormatCommand {
|
||||||
type Response = String;
|
type Response = CheckSMSFormatResult;
|
||||||
|
|
||||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||||
at_commands.raw_command(self, "AT+CMGF?".to_string())
|
at_commands.raw_command(self, "AT+CMGF?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
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() {
|
while let Some(line) = parser.readline() {
|
||||||
if line.starts_with("OK") {
|
if line.starts_with("OK") {
|
||||||
return Ok("OK".to_owned());
|
return Ok(CheckSMSFormatResult::Mode(mode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(line) = parser.readline() {
|
||||||
|
if line.starts_with("ERROR") {
|
||||||
|
return Ok(CheckSMSFormatResult::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ATParseError::EOF)
|
Err(ATParseError::EOF)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user