Parse rest of the messages
This commit is contained in:
parent
4a38ec9bc3
commit
fe648fdb88
@ -260,6 +260,12 @@ impl<T: ATCommand> SimpleATCommand for T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SimpleATResponse {
|
||||||
|
Ok,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ATInformation {
|
pub struct ATInformation {
|
||||||
manufacturer: String,
|
manufacturer: String,
|
||||||
@ -367,12 +373,6 @@ impl ATCommand for CheckPinCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum SelectSMSFormatResult {
|
|
||||||
Ok,
|
|
||||||
Error,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum SMSFormat {
|
pub enum SMSFormat {
|
||||||
PDUMode = 0,
|
PDUMode = 0,
|
||||||
@ -382,7 +382,7 @@ pub enum SMSFormat {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SelectSMSFormatCommand(pub SMSFormat);
|
pub struct SelectSMSFormatCommand(pub SMSFormat);
|
||||||
impl ATCommand for SelectSMSFormatCommand {
|
impl ATCommand for SelectSMSFormatCommand {
|
||||||
type Response = SelectSMSFormatResult;
|
type Response = SimpleATResponse;
|
||||||
|
|
||||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||||
at_commands.raw_command(self, format!("AT+CMGF={}", self.0 as u8))
|
at_commands.raw_command(self, format!("AT+CMGF={}", self.0 as u8))
|
||||||
@ -391,9 +391,9 @@ impl ATCommand for SelectSMSFormatCommand {
|
|||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||||
while let Some(line) = parser.readline() {
|
while let Some(line) = parser.readline() {
|
||||||
if line.starts_with("OK") {
|
if line.starts_with("OK") {
|
||||||
return Ok(SelectSMSFormatResult::Ok);
|
return Ok(SimpleATResponse::Ok);
|
||||||
} else if line.starts_with("ERROR") {
|
} else if line.starts_with("ERROR") {
|
||||||
return Ok(SelectSMSFormatResult::Error);
|
return Ok(SimpleATResponse::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ATParseError::EOF)
|
Err(ATParseError::EOF)
|
||||||
@ -434,19 +434,29 @@ impl ATCommand for CheckSMSFormatCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum TECharacterSets {
|
||||||
|
Charsets(Vec<String>),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ListTECharacterSetsCommand;
|
pub struct ListTECharacterSetsCommand;
|
||||||
impl ATCommand for ListTECharacterSetsCommand {
|
impl ATCommand for ListTECharacterSetsCommand {
|
||||||
type Response = String;
|
type Response = TECharacterSets;
|
||||||
|
|
||||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||||
at_commands.raw_command(self, "AT+CSCS=?".to_string())
|
at_commands.raw_command(self, "AT+CSCS=?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||||
|
parser.expect("+CSCS: ".to_owned())?;
|
||||||
|
let result = parser.readline().unwrap();
|
||||||
|
let result = result.strip_prefix("(").unwrap().strip_suffix(")").unwrap();
|
||||||
|
let results = result.split(",").map(|s| s.to_owned()).collect::<Vec<_>>();
|
||||||
|
|
||||||
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(TECharacterSets::Charsets(results));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ATParseError::EOF)
|
Err(ATParseError::EOF)
|
||||||
@ -475,7 +485,7 @@ impl TECharset {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SetTECharsetCommand(pub TECharset);
|
pub struct SetTECharsetCommand(pub TECharset);
|
||||||
impl ATCommand for SetTECharsetCommand {
|
impl ATCommand for SetTECharsetCommand {
|
||||||
type Response = String;
|
type Response = SimpleATResponse;
|
||||||
|
|
||||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||||
at_commands.raw_command(self, format!("AT+CSCS=\"{}\"", self.0.into_str()))
|
at_commands.raw_command(self, format!("AT+CSCS=\"{}\"", self.0.into_str()))
|
||||||
@ -484,13 +494,22 @@ impl ATCommand for SetTECharsetCommand {
|
|||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||||
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(SimpleATResponse::Ok);
|
||||||
|
} else if line.starts_with("ERROR") {
|
||||||
|
return Ok(SimpleATResponse::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ATParseError::EOF)
|
Err(ATParseError::EOF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SendSMSResponse {
|
||||||
|
MessageRefrence(String),
|
||||||
|
Error,
|
||||||
|
ErrorMessage(String),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SendSMSCommand {
|
pub struct SendSMSCommand {
|
||||||
pub destination: String,
|
pub destination: String,
|
||||||
@ -498,7 +517,7 @@ pub struct SendSMSCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ATCommand for SendSMSCommand {
|
impl ATCommand for SendSMSCommand {
|
||||||
type Response = String;
|
type Response = SendSMSResponse;
|
||||||
|
|
||||||
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
fn execute(&self, at_commands: &mut ATCommands) -> Vec<String> {
|
||||||
at_commands.raw_two_part_command(
|
at_commands.raw_two_part_command(
|
||||||
@ -509,11 +528,27 @@ impl ATCommand for SendSMSCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
fn parse_response(parser: &mut ATResponseParser) -> Result<Self::Response, ATParseError> {
|
||||||
while let Some(line) = parser.readline() {
|
// Read first line out
|
||||||
if line.starts_with("OK") {
|
parser.readline();
|
||||||
return Ok("OK".to_owned());
|
|
||||||
|
if let Ok(_) = parser.expect("+CMGS: ".to_owned()) {
|
||||||
|
let result = parser.readline().unwrap();
|
||||||
|
while let Some(line) = parser.readline() {
|
||||||
|
if line.starts_with("OK") {
|
||||||
|
return Ok(SendSMSResponse::MessageRefrence(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Ok(_) = parser.expect("+CMS ERROR:".to_owned()) {
|
||||||
|
let message = parser.readline().unwrap();
|
||||||
|
return Ok(SendSMSResponse::ErrorMessage(message));
|
||||||
|
} else {
|
||||||
|
while let Some(line) = parser.readline() {
|
||||||
|
if line.starts_with("ERROR") {
|
||||||
|
return Ok(SendSMSResponse::Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ATParseError::EOF)
|
Err(ATParseError::EOF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user