218 lines
5.5 KiB
Rust
218 lines
5.5 KiB
Rust
|
use std::time::Duration;
|
||
|
|
||
|
pub struct Command {
|
||
|
pub text: String,
|
||
|
pub timeout: Duration,
|
||
|
pub ends_with: 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()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn modeminfo() -> Command {
|
||
|
Command {
|
||
|
text: "ATI".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn fwrevision() -> Command {
|
||
|
Command {
|
||
|
text: "AT+CGMR".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn battery() -> Command {
|
||
|
Command {
|
||
|
text: "AT+CBC".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn scan() -> Command {
|
||
|
Command {
|
||
|
text: "AT+COPS=?".to_owned(),
|
||
|
timeout: Duration::from_millis(60),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn network() -> Command {
|
||
|
Command {
|
||
|
text: "AT+COPS?".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn signal() -> Command {
|
||
|
Command {
|
||
|
text: "AT+CSQ".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn checkreg() -> Command {
|
||
|
Command {
|
||
|
text: "AT+CREG?".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: None,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn opengprs() -> Command {
|
||
|
Command {
|
||
|
text: "AT+SAPBR=1,1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn getbear() -> Command {
|
||
|
Command {
|
||
|
text: "AT+SAPBR=2,1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn inithttp() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPINIT".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn sethttp() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPPARA=\"CID\",1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn checkssl() -> Command {
|
||
|
Command {
|
||
|
text: "AT+CIPSSL=?".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn enablessl() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPSSL=1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn disablessl() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPSSL=0".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn initurl() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPPARA=\"URL\",\"{}\"".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn doget() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPACTION=0".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("+HTTPACTION".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn setcontent() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPPARA=\"CONTENT\",\"{}\"".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn postlen() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPDATA={}5000".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("DOWNLOAD".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn dopost() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPACTION=1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("+HTTPACTION".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn getdata() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPREAD".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn closehttp() -> Command {
|
||
|
Command {
|
||
|
text: "AT+HTTPTERM".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn closebear() -> Command {
|
||
|
Command {
|
||
|
text: "AT+SAPBR=0,1".to_owned(),
|
||
|
timeout: Duration::from_millis(3),
|
||
|
ends_with: Some("OK".to_owned()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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()),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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()),
|
||
|
}
|
||
|
}
|
||
|
}
|