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 {
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn modem_info() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn fw_revision() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn check_reg() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn gprs_init() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+SAPBR=3,1,\"Contype\",\"GPRS\"".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gprs_open() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn gprs_set_apn(apn: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"APN\",\"{}\"", apn),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gprs_set_user(user: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"USER\",\"{}\"", user),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gprs_set_pwd(password: &str) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+SAPBR=3,1,\"PWD\",\"{}\"", password),
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn get_local_ip_addr() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: "AT+CIFSR".to_string(),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn ping(domain: &str) -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: format!("AT+CIPPING=\"{}\"", domain),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_init() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: "AT+HTTPINIT".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn http_set() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+HTTPPARA=\"CID\",1".to_string(),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_enable_ssl() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_disable_ssl() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_init_url() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_get() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_set_content() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_post_len() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_post() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn http_get_data() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn probe() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: "AT".to_string(),
|
2022-06-18 01:39:38 +02:00
|
|
|
timeout: Duration::from_millis(3000),
|
2022-06-19 00:33:32 +02:00
|
|
|
contains: Some("+CIEV".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_gprs_attached() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+CGATT?".to_string(),
|
|
|
|
timeout: Duration::from_millis(1000),
|
2022-06-18 01:39:38 +02:00
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 00:28:25 +02:00
|
|
|
pub fn tcp_ssl_set(enabled: bool) -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-24 00:28:25 +02:00
|
|
|
text: format!("AT+CIPSSL={}", if enabled { 1 } else { 0 }),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn tcp_ssl_enable() -> Command {
|
2022-06-16 01:06:32 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: "AT+CIPSSL=1".to_string(),
|
2022-06-18 01:39:38 +02:00
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn tcp_ssl_check() -> Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: "AT+CIPSSL=?".to_string(),
|
2022-06-18 01:39:38 +02:00
|
|
|
timeout: Duration::from_millis(3000),
|
2022-06-19 00:33:32 +02:00
|
|
|
contains: Some("OK".to_string()),
|
2022-06-18 01:39:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:33:32 +02:00
|
|
|
pub fn tcp_connect(addr: &str, port: u16) -> Command {
|
2022-06-18 01:39:38 +02:00
|
|
|
Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
text: format!("AT+CIPSTART=\"TCP\",\"{}\",\"{}\"", addr, port),
|
|
|
|
timeout: Duration::from_millis(5000),
|
|
|
|
contains: Some("CONNECT OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 03:07:07 +02:00
|
|
|
pub fn tcp_send_size(size: usize) -> Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
Command {
|
|
|
|
text: format!("AT+CIPSEND={}", size),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 00:03:44 +02:00
|
|
|
pub fn tcp_transparent_mode() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+CIPMODE=1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tcp_exit_data_mode() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "ATO".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("CLOSED".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 03:07:07 +02:00
|
|
|
pub fn tcp_send() -> Command {
|
2022-06-19 00:33:32 +02:00
|
|
|
Command {
|
2022-06-19 03:07:07 +02:00
|
|
|
text: "AT+CIPSEND".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some(">".to_string()),
|
2022-06-19 00:33:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tcp_set_quick_mode(quick_mode: bool) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+CIPQSEND={}", quick_mode as u8),
|
|
|
|
timeout: Duration::from_millis(3000),
|
2022-06-18 01:39:38 +02:00
|
|
|
contains: Some("OK".to_string()),
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-21 02:30:00 +02:00
|
|
|
|
|
|
|
pub fn tcp_receive(size: usize) -> Command {
|
|
|
|
Command {
|
|
|
|
text: format!("AT+CIPRXGET=2,{}", size),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 00:28:25 +02:00
|
|
|
pub fn tcp_receive_reply_len() -> Command {
|
2022-06-21 02:30:00 +02:00
|
|
|
Command {
|
|
|
|
text: "AT+CIPRXGET=4".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tcp_set_manual_receive() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+CIPRXGET=1".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tcp_close() -> Command {
|
|
|
|
Command {
|
|
|
|
text: "AT+CIPCLOSE=0".to_string(),
|
|
|
|
timeout: Duration::from_millis(3000),
|
|
|
|
contains: Some("CLOSE OK".to_string()),
|
|
|
|
}
|
|
|
|
}
|
2022-06-16 01:06:32 +02:00
|
|
|
}
|