2022-06-16 01:06:32 +02:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
pub struct Command {
|
|
|
|
pub text: String,
|
|
|
|
pub timeout: Duration,
|
2022-06-18 01:39:38 +02:00
|
|
|
pub contains: Option<String>,
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Command {
|
|
|
|
pub fn initgprs() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+SAPBR=3,1,\"Contype\",\"GPRS\"".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn modeminfo() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "ATI".to_string(),
|
|
|
|
timeout: Duration::from_millis(6000),
|
|
|
|
contains: Some("+CIEV".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fwrevision() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+CGMR".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn battery() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+CBC".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn scan() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+COPS=?".to_string(),
|
|
|
|
timeout: Duration::from_millis(60000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn network() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+COPS?".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn signal() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+CSQ".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn checkreg() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+CREG?".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: None,
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn opengprs() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+SAPBR=1,1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getbear() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+SAPBR=2,1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inithttp() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPINIT".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sethttp() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPPARA=\"CID\",1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn checkssl() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+CIPSSL=?".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn enablessl() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPSSL=1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn disablessl() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPSSL=0".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn initurl() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPPARA=\"URL\",\"{}\"".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn doget() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPACTION=0".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("+HTTPACTION".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setcontent() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPPARA=\"CONTENT\",\"{}\"".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn postlen() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPDATA={}5000".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("DOWNLOAD".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dopost() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPACTION=1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("+HTTPACTION".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getdata() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPREAD".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn closehttp() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+HTTPTERM".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn closebear() -> Command {
|
|
|
|
Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
text: "AT+SAPBR=0,1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setapn(apn: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"APN\",\"{}\"", apn),
|
2022-06-18 01:39:38 +02:00
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setuser(user: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"USER\",\"{}\"", user),
|
2022-06-18 01:39:38 +02:00
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setpwd(password: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"PWD\",\"{}\"", password),
|
2022-06-18 01:39:38 +02:00
|
|
|
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()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|