connect to gprs and check if attached
This commit is contained in:
parent
1cb8a90caf
commit
94b9ce312f
3 changed files with 189 additions and 122 deletions
168
src/command.rs
168
src/command.rs
|
@ -3,215 +3,231 @@ use std::time::Duration;
|
|||
pub struct Command {
|
||||
pub text: String,
|
||||
pub timeout: Duration,
|
||||
pub ends_with: Option<String>,
|
||||
pub contains: Option<String>,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn initgprs() -> Command {
|
||||
Command {
|
||||
text: "AT+SAPBR=3,1,\"Contype\",\"GPRS\"".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+SAPBR=3,1,\"Contype\",\"GPRS\"".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modeminfo() -> Command {
|
||||
Command {
|
||||
text: "ATI".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "ATI".to_string(),
|
||||
timeout: Duration::from_millis(6000),
|
||||
contains: Some("+CIEV".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fwrevision() -> Command {
|
||||
Command {
|
||||
text: "AT+CGMR".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+CGMR".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn battery() -> Command {
|
||||
Command {
|
||||
text: "AT+CBC".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+CBC".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scan() -> Command {
|
||||
Command {
|
||||
text: "AT+COPS=?".to_owned(),
|
||||
timeout: Duration::from_millis(60),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+COPS=?".to_string(),
|
||||
timeout: Duration::from_millis(60000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn network() -> Command {
|
||||
Command {
|
||||
text: "AT+COPS?".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+COPS?".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signal() -> Command {
|
||||
Command {
|
||||
text: "AT+CSQ".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+CSQ".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn checkreg() -> Command {
|
||||
Command {
|
||||
text: "AT+CREG?".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: None,
|
||||
text: "AT+CREG?".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opengprs() -> Command {
|
||||
Command {
|
||||
text: "AT+SAPBR=1,1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+SAPBR=1,1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getbear() -> Command {
|
||||
Command {
|
||||
text: "AT+SAPBR=2,1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+SAPBR=2,1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inithttp() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPINIT".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPINIT".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sethttp() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPPARA=\"CID\",1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPPARA=\"CID\",1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn checkssl() -> Command {
|
||||
Command {
|
||||
text: "AT+CIPSSL=?".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+CIPSSL=?".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enablessl() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPSSL=1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPSSL=1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disablessl() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPSSL=0".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPSSL=0".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initurl() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPPARA=\"URL\",\"{}\"".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPPARA=\"URL\",\"{}\"".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn doget() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPACTION=0".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("+HTTPACTION".to_owned()),
|
||||
text: "AT+HTTPACTION=0".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("+HTTPACTION".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setcontent() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPPARA=\"CONTENT\",\"{}\"".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPPARA=\"CONTENT\",\"{}\"".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn postlen() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPDATA={}5000".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("DOWNLOAD".to_owned()),
|
||||
text: "AT+HTTPDATA={}5000".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("DOWNLOAD".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dopost() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPACTION=1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("+HTTPACTION".to_owned()),
|
||||
text: "AT+HTTPACTION=1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("+HTTPACTION".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getdata() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPREAD".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPREAD".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn closehttp() -> Command {
|
||||
Command {
|
||||
text: "AT+HTTPTERM".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+HTTPTERM".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn closebear() -> Command {
|
||||
Command {
|
||||
text: "AT+SAPBR=0,1".to_owned(),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
text: "AT+SAPBR=0,1".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setapn(apn: &str) -> Command {
|
||||
Command {
|
||||
text: format!("AT+SAPBR=3,1,\"APN\",\"{}\"", apn),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setuser(user: &str) -> Command {
|
||||
Command {
|
||||
text: format!("AT+SAPBR=3,1,\"USER\",\"{}\"", user),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setpwd(password: &str) -> Command {
|
||||
Command {
|
||||
text: format!("AT+SAPBR=3,1,\"PWD\",\"{}\"", password),
|
||||
timeout: Duration::from_millis(3),
|
||||
ends_with: Some("OK".to_owned()),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn probe() -> Command {
|
||||
Command {
|
||||
text: "AT".to_string(),
|
||||
timeout: Duration::from_millis(3000),
|
||||
contains: Some("+CIEV".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_gprs_attached() -> Command {
|
||||
Command {
|
||||
text: "AT+CGATT?".to_string(),
|
||||
timeout: Duration::from_millis(1000),
|
||||
contains: Some("OK".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue