433 lines
12 KiB
Rust
433 lines
12 KiB
Rust
use std::time::Duration;
|
|
|
|
pub struct Command {
|
|
pub text: String,
|
|
pub timeout: Duration,
|
|
pub contains: Option<String>,
|
|
}
|
|
|
|
impl Command {
|
|
pub fn modem_info() -> Command {
|
|
Command {
|
|
text: "ATI".to_string(),
|
|
timeout: Duration::from_millis(6000),
|
|
contains: Some("+CIEV".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn fw_revision() -> Command {
|
|
Command {
|
|
text: "AT+CGMR".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn battery() -> Command {
|
|
Command {
|
|
text: "AT+CBC".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn scan() -> Command {
|
|
Command {
|
|
text: "AT+COPS=?".to_string(),
|
|
timeout: Duration::from_millis(60000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn network() -> Command {
|
|
Command {
|
|
text: "AT+COPS?".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn signal() -> Command {
|
|
Command {
|
|
text: "AT+CSQ".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn check_reg() -> Command {
|
|
Command {
|
|
text: "AT+CREG?".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: None,
|
|
}
|
|
}
|
|
|
|
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_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()),
|
|
}
|
|
}
|
|
|
|
pub fn gprs_bearer_status() -> Command {
|
|
Command {
|
|
text: "AT+SAPBR=2,1".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn gprs_bearer_open() -> Command {
|
|
Command {
|
|
text: "AT+SAPBR=1,1".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn gprs_bearer_close() -> Command {
|
|
Command {
|
|
text: "AT+SAPBR=0,1".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn get_local_ip_addr() -> Command {
|
|
Command {
|
|
text: "AT+CIFSR".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn ping(domain: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPPING=\"{}\"", domain),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_init() -> Command {
|
|
Command {
|
|
text: "AT+HTTPINIT".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_cid() -> Command {
|
|
Command {
|
|
text: "AT+HTTPPARA=\"CID\",1".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_url(url: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPPARA=\"URL\",\"{}\"", url),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_ssl(enabled: bool) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPSSL={}", enabled as u8),
|
|
timeout: Duration::from_millis(1000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_header(header: &str, value: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPPARA=\"USERDATA\",\"{}: {}\"", header, value),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_get() -> Command {
|
|
Command {
|
|
text: "AT+HTTPACTION=0".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("+HTTPACTION".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_post() -> Command {
|
|
Command {
|
|
text: "AT+HTTPACTION=1".to_string(),
|
|
timeout: Duration::from_millis(10000),
|
|
contains: Some("HTTPACTION".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_content(content: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPPARA=\"CONTENT\",\"{}\"", content),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_set_redirect(redirect: bool) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPPARA=\"REDIR\",\"{}\"", redirect as u8),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_post_len(size: usize, time: usize) -> Command {
|
|
Command {
|
|
text: format!("AT+HTTPDATA={},{}", size, time),
|
|
timeout: Duration::from_millis(5000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_read_response() -> Command {
|
|
Command {
|
|
text: "AT+HTTPREAD".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn http_close() -> Command {
|
|
Command {
|
|
text: "AT+HTTPTERM".to_string(),
|
|
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()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_ssl_set(enabled: bool) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPSSL={}", if enabled { 1 } else { 0 }),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_ssl_check() -> Command {
|
|
Command {
|
|
text: "AT+CIPSSL=?".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_connect(addr: &str, port: u16) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPSTART=\"TCP\",\"{}\",\"{}\"", addr, port),
|
|
timeout: Duration::from_millis(5000),
|
|
contains: Some("CONNECT OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_send_size(size: usize) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPSEND={}", size),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
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()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_send() -> Command {
|
|
Command {
|
|
text: "AT+CIPSEND".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some(">".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_set_quick_mode(quick_mode: bool) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPQSEND={}", quick_mode as u8),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_receive(size: usize) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPRXGET=2,{}", size),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_receive_reply_len() -> Command {
|
|
Command {
|
|
text: "AT+CIPRXGET=4".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn tcp_set_manual_receive(is_manual: bool) -> Command {
|
|
Command {
|
|
text: format!("AT+CIPRXGET={}", is_manual as u8),
|
|
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()),
|
|
}
|
|
}
|
|
|
|
pub fn manufacturer_id() -> Command {
|
|
Command {
|
|
text: "AT+GMI".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn model_id() -> Command {
|
|
Command {
|
|
text: "AT+GMM".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn release_id() -> Command {
|
|
Command {
|
|
text: "AT+GMR".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn get_location() -> Command {
|
|
Command {
|
|
text: "AT+CLBS=1,1".to_string(),
|
|
timeout: Duration::from_millis(10000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn ssl_opt() -> Command {
|
|
Command {
|
|
text: "AT+SSLOPT=1,1".to_string(),
|
|
timeout: Duration::from_millis(3000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn ssl_set_client_cert(path: &str, password: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+SSLSETCERT={},{}", path, password),
|
|
timeout: Duration::from_millis(2000),
|
|
contains: Some("SSLSETCERT".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn ssl_set_root_cert(path: &str, size: usize) -> Command {
|
|
Command {
|
|
text: format!("AT+SSLSETROOT={},{}", path, size),
|
|
timeout: Duration::from_millis(2000),
|
|
contains: Some("SSLSETCERT".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn fs_file_create(path: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+FSCREATE={}", path),
|
|
timeout: Duration::from_millis(2000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn fs_file_write(path: &str, append: bool, size: usize, input_time_sec: usize) -> Command {
|
|
Command {
|
|
text: format!("AT+FSWRITE={},{},{},{}", path, append as u8, size, input_time_sec),
|
|
timeout: Duration::from_millis(20000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn fs_list(path: &str) -> Command {
|
|
Command {
|
|
text: format!("AT+FSLS={}", path),
|
|
timeout: Duration::from_millis(2000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn fs_free_size() -> Command {
|
|
Command {
|
|
text: "AT+FSMEM".to_string(),
|
|
timeout: Duration::from_millis(2000),
|
|
contains: Some("OK".to_string()),
|
|
}
|
|
}
|
|
}
|