You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
309 lines
8.7 KiB
309 lines
8.7 KiB
/*
|
|
* drv_ec800k.h
|
|
*
|
|
* Created on: Apr 6, 2025
|
|
* Author: wushufeng
|
|
*
|
|
*
|
|
*/
|
|
|
|
#ifndef _DRV_EC800K_H_
|
|
#define _DRV_EC800K_H_
|
|
|
|
#include "rtdef.h"
|
|
#include "rttypes.h"
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "rtdevice.h"
|
|
|
|
#define LTE_CMD_WAIT_NONE (10)
|
|
#define LTE_CMD_WAIT_SHORT (100)
|
|
#define LTE_CMD_WAIT_NORMAL (500)
|
|
#define LTE_CMD_WAIT_LONG (3000)
|
|
#define LTE_CMD_WAIT_LLONG (7000)
|
|
|
|
#define DEFAULT_EXPECT "\r\nOK\r\n"
|
|
#define DEFAULT_ERROR "ERROR"
|
|
#define DEFAULT_RDY "READY"
|
|
#define CGATT_OK "+CGATT: 1\r\n\r\nOK"
|
|
#define CEREG_OK "+CEREG: 0,1\r\n\r\nOK"
|
|
#define CONNECTE_OK "CONNECT"
|
|
#define CLOSED "closed"
|
|
#define SERVER_DISCONNECTED "SERVER DISCONNECTED:0"
|
|
#define AT_SUCCESS "SUCCESS\r\n"
|
|
#define TPOK ">"
|
|
#define AT_FAILURE "FAILURE\r\n"
|
|
#define NETOPEN_SUCCESS "+NETOPEN:SUCCESS"
|
|
#define NETCLOSE_SUCCESS "\r\n+NETCLOSE:SUCCESS\r\n"
|
|
#define NETCLOSE_FAILURE "\r\n+NETCLOSE:FAIL\r\n"
|
|
#define CIPOPEN_SUCCESS "+CIPOPEN: SUCCESS"
|
|
#define CIPOPEN_FAILURE " FAILURE,"
|
|
#define CIPRXGET_SUCCESS "+CIPRXGET:SUCCESS"
|
|
#define CIPSEND_SUCCESS "+CIPSEND:SUCCESS,"
|
|
#define QIURC_SUCCESS "+QIURC: \"recv\",%d,%d\r\n"
|
|
|
|
#define SOFT_RESET "AT+CFUN=1,1\r\n"
|
|
#define AT_AT "AT\r\n"
|
|
#define AT_ATE0 "ATE0\r\n"
|
|
#define AT_ATI "ATI\r\n"
|
|
#define AT_CPIN "AT+CPIN?\r\n"
|
|
#define AT_ICCID "AT+ICCID\r\n"
|
|
#define AT_IMEI "AT+CGSN\r\n"
|
|
#define AT_CGATT "AT+CGATT?\r\n"
|
|
#define AT_CGATT0 "AT+CGATT=0\r\n"
|
|
#define AT_CGATT1 "AT+CGATT=1\r\n"
|
|
#define AT_CGREG "AT+CGREG?\r\n" // GPRS REG 2G
|
|
#define AT_CEREG "AT+CEREG?\r\n" // EPS REG 4G
|
|
#define AT_CEREG0 "AT+CEREG=0\r\n"
|
|
#define AT_CSQ "AT+CSQ\r\n"
|
|
#define AT_CPSI "AT+CPSI?\r\n"
|
|
#define AT_CIPMODE "AT+CIPMODE=1\r\n"
|
|
|
|
#define AT_CCLK "AT+CCLK?\r\n"
|
|
|
|
#define AT_GTPOS "AT+GTPOS?\r\n"
|
|
#define AT_GTPOS0 "AT+GTPOS=0\r\n" // close
|
|
#define AT_GTPOS1 "AT+GTPOS=1\r\n" // open
|
|
#define AT_GTPOS2 "AT+GTPOS=2\r\n" // get
|
|
|
|
// #define AT_CIPSTART "AT+CIPSTART=\"%s\",\"%s\",\"%s\"\r\n"
|
|
// AT+CIPOPEN=1,"TCP","182.148.114.87",6600
|
|
#define AT_CIPOPEN \
|
|
"AT+CIPOPEN=0,\"%s\",\"%s\",%s\r\n" // ´«ģʽAT+CIPOPEN=0±ؐ뎪0
|
|
#define AT_CIPCLOSE "AT+CIPCLOSE=0\r\n"
|
|
#define AT_CIPSHUT "AT+CIPSHUT\r\n"
|
|
#define AT_TPCLOSE "+++\r\n"
|
|
#define AT_CIPSEND "AT+CIPSEND=%d,%d\r\n"
|
|
#define AT_QISEND "AT+QISEND=%d,%d\r\n"
|
|
#define QI_SEND_OK "\r\nSEND OK\r\n"
|
|
#define QI_SEND_FAIL "\r\nSEND FAIL\r\n"
|
|
#define AT_CGMR "AT+CGMR\r\n"
|
|
#define AT_BTPOWER_ON "AT+BTPOWER=1\r\n"
|
|
#define AT_BTPOWER_OFF "AT+BTPOWER=0\r\n"
|
|
#define AT_BTHOST "AT+BTHOST?\r\n"
|
|
#define AT_BTHOST_ "AT+BTHOST=%s\r\n"
|
|
|
|
#define AT_QIOPEN_TRANS \
|
|
"AT+QIOPEN=1,%d,\"%s\",\"%s\",%s,0,2\r\n" // transparent Mode
|
|
#define AT_QIOPEN_FORW \
|
|
"AT+QIOPEN=1,%d,\"%s\",\"%s\",%s,0,1\r\n" // Immediate Forwarding Mode
|
|
|
|
#define AT_QICLOSE "AT+QICLOSE=%d\r\n"
|
|
|
|
#define AT_CREG "AT+CREG=0\r\n"
|
|
// #define AT_QICSGP
|
|
// "AT+QICSGP=1,1,\"cmnbiot\",\"web\",\"password\",0\r\n"
|
|
#define AT_QICSGP_CMNET "AT+QICSGP=1,1,\"cmnet\",\"\",\"\"\r\n"
|
|
|
|
/*韩国APN*/
|
|
#define AT_QICSGP_SK "AT+QICSGP=1,1,\"lte.sktelecom.com \",\"\",\"\"\r\n"
|
|
|
|
/*泰国APN*/
|
|
#define AT_QICSGP_THAI "AT+QICSGP=1,1,\"internet\",\"\",\"\"\r\n"
|
|
|
|
#define AT_QICSGP "AT+QICSGP=1,1,\"cmiot\",\"\",\"\",1\r\n"
|
|
#define AT_NETOPEN "AT+NETOPEN\r\n"
|
|
#define AT_NETCLOSE "AT+NETCLOSE\r\n"
|
|
#define AT_QIACT1 "AT+QIACT=1\r\n"
|
|
#define AT_QIACT "AT+QIACT?\r\n"
|
|
#define AT_QIDEACT "AT+QIDEACT=1\r\n"
|
|
#define AT_QIPOPEN "AT+QIPOPEN=1,0,\"%s\",\"%s\",%s,0,1\r\n" //
|
|
|
|
// #define AT_MIPSTART "AT+MIPSTART=\"123.57.84.71\",1883,4\r\n"
|
|
// #define AT_MPUBEX "AT+MPUBEX=\"%s\",0,0,2\r\n"
|
|
#define AT_MUNSUB "AT+MUNSUB=\"%s\"\r\n"
|
|
|
|
#define GREATER_THAN "\r\n>"
|
|
|
|
// MQTT
|
|
#define AT_MCONFIG "AT+MCONFIG=\"%s\",\"%s\",\"%s\"\r\n"
|
|
#define AT_MIPSTART \
|
|
"AT+MIPSTART=\"%s\",%s,4\r\n" // 3 stands for mqtt version 3.1, 4 stands for
|
|
// mqtt version 3.1.1.
|
|
#define AT_MCONNECT "AT+MCONNECT=1,60\r\n"
|
|
#define AT_MSUB "AT+MSUB=\"%s\",%d\r\n" // The maximum length of 512
|
|
#define AT_MPUB "AT+MPUB=\"%s\",0,0,\"%s\"\r\n"
|
|
// AT+MPUBEX=<topic>,<qos>,<retain>,<msgLen>
|
|
#define AT_MPUBEX \
|
|
"AT+MPUBEX=\"%s\",%d,0,%d\r\n" // The message content length. The maximum
|
|
// length of65535.
|
|
#define AT_MQTTSSL0 "AT+MQTTSSL=0\r\n"
|
|
#define AT_MQTTSSL1 "AT+MQTTSSL=1\r\n"
|
|
|
|
#define AT_MDISCONNECT "AT+MDISCONNECT\r\n"
|
|
#define AT_MIPCLOSE "AT+MIPCLOSE\r\n"
|
|
|
|
// MQTT ALI
|
|
// #define AT_IMQTTAUTH "AT+IMQTTAUTH=\"%s\",\"%s\",\"%s\",\"%s\"\r\n"
|
|
#define AT_IMQTTAUTH "AT+IMQTTAUTH=\"%s\",\"\",\"%s\",\"%s\"\r\n"
|
|
#define AT_IMQTTCONN "AT+IMQTTCONN\r\n"
|
|
#define AT_IMQTTSUB "AT+IMQTTSUB=\"/%s/%s/user/get\",0\r\n"
|
|
// #define AT_IMQTTPUB
|
|
// "AT+IMQTTPUB=\"/%s/%s/user/get\",%d,%s\r\n"
|
|
#define AT_IMQTTPUB \
|
|
"AT+IMQTTPUB=\"%s\",%d,%s\r\n" // the max length is 960 bytes
|
|
#define AT_IMQTTSTATE "AT+IMQTTSTATE?\r\n"
|
|
#define AT_IMQTTDISCONN "AT+IMQTTDISCONN\r\n"
|
|
#define AT_QISWTMD \
|
|
"AT+QISWTMD=%d,%d\r\n" // 切换模式,0-缓存模式 1-直吐模式 2-透传模式
|
|
|
|
#define PUB_SUCCESS "+MPUB: SUCCESS\r\n"
|
|
#define PUB_FAILURE "+MPUB: FAILURE\r\n"
|
|
#define PUBEX_SUCCESS "+MPUBEX: SUCCESS\r\n"
|
|
#define PUBEX_FAILURE "+MPUBEX: FAILURE\r\n"
|
|
#define SUB_SUCCESS "+MSUB: SUCCESS\r\n"
|
|
#define SUB_FAILURE "+NSUB: FAILURE\r\n"
|
|
|
|
#define AT_IMQTTDISCONNECT "AT+IMQTTDISCONN\r\n"
|
|
|
|
// HTTP
|
|
#define HTTPERROR "HTTPERROR"
|
|
#define AT_HTTPOPEN "AT$HTTPOPEN\r\n"
|
|
#define AT_HTTPPARA "AT$HTTPPARA=%s,%d,%d,0\r\n"
|
|
#define AT_HTTPRQH_CONTENTLEN "AT$HTTPRQH=Content-Length,%d\r\n"
|
|
#define AT_HTTPRQH_CONTENTTYPE "AT$HTTPRQH=Content-Type,%s\r\n"
|
|
#define AT_HTTPRQH_CONNECTION "AT$HTTPRQH=Connection,keep-alive\r\n"
|
|
#define AT_HTTPTYPE "AT$HTTPTYPE=%d\r\n"
|
|
// #define AT_HTTPTYPE_1 "AT$HTTPTYPE=1\r\n"
|
|
#define AT_HTTPACTION "AT$HTTPACTION=%d\r\n"
|
|
// #define AT_HTTPACTION0 "AT$HTTPACTION=0\r\n"
|
|
#define AT_HTTP_READ_SIZE "AT+HTTPREAD=1\r\n"
|
|
#define AT_HTTP_READ_STEP "AT+HTTPREAD=%d,%d\r\n"
|
|
#define AT_HTTPRQH "AT$HTTPRQH=Range,bytes=%d-%d\r\n"
|
|
#define AT_HTTPSEND "AT$HTTPSEND\r\n"
|
|
#define AT_HTTPDATA "AT$HTTPDATA=%d\r\n"
|
|
#define AT_HTTPCLOSE "AT$HTTPCLOSE\r\n"
|
|
#define HTTP_200 "200 OK"
|
|
#define HTTP_400 ",400,"
|
|
|
|
// FILESYSTEM
|
|
#define AT_MFSLS "AT+MFSLS\r\n"
|
|
#define AT_MFSATTRI "AT+MFSATTRI=\"%s\"\r\n"
|
|
#define AT_MFSREAD "AT+MFSREAD=\"%s\",%d,%d\r\n"
|
|
|
|
|
|
//AT CFG
|
|
#define AT_CFG_TRANS_SIZE "AT+QICFG=\"transpktsize\",512\r\n"
|
|
#define AT_CFG_TRANS_WAITTM "AT+QICFG=\"transwaittm\",0\r\n"
|
|
|
|
// #define GSM_BT_LIVE 5*60*1000 // 5min
|
|
typedef struct _connect_state {
|
|
bool connected;
|
|
int16_t error_cnt;
|
|
// bool is_net_closed;
|
|
} connect_state_t;
|
|
|
|
typedef struct _lte_base_station_ifno {
|
|
int mcc;
|
|
int mnc;
|
|
int lac;
|
|
int cellid;
|
|
} __attribute__((packed)) lte_base_station_info_t;
|
|
|
|
typedef struct {
|
|
bool valid;
|
|
char mode[4];
|
|
// char domain_name[128];
|
|
char ip[50];
|
|
char port[16];
|
|
bool connect_sta;
|
|
unsigned char connect_ID;
|
|
unsigned char error_cnt;
|
|
} Cclient_t;
|
|
|
|
typedef struct {
|
|
char hard_ver[32];
|
|
char imei[32];
|
|
bool sim_inserted;
|
|
char iccid[32];
|
|
|
|
uint8_t eps_sta;
|
|
uint8_t csq;
|
|
|
|
uint8_t contextID; // 场景ID。范围:1~15。
|
|
bool config_sta;
|
|
|
|
Cclient_t *client1;
|
|
|
|
bool deviceEnable;
|
|
|
|
rt_device_t com_dev;
|
|
rt_sem_t com_dev_rx_sem;
|
|
rt_uint8_t at_buf[256];
|
|
|
|
rt_thread_t tid1;
|
|
rt_thread_t tid2;
|
|
} CLte_dev_t;
|
|
extern CLte_dev_t lte_dev;
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
bool isICCIDValid(char *str);
|
|
|
|
bool isIMEIValid(char *str);
|
|
|
|
int8_t BSP_LTE_GetCPSI(void);
|
|
|
|
void BSP_L505_WaitReady(uint16_t second);
|
|
|
|
void BSP_LTE_WaitReady(uint16_t second);
|
|
|
|
void BSP_LTE_PwrOn(void);
|
|
|
|
void BSP_LTE_PwrOff(void);
|
|
|
|
void BSP_LTE_ResetByKey(void);
|
|
|
|
void BSP_LTE_SendData(uint8_t *pdata, uint32_t length);
|
|
|
|
int16_t BSP_LTE_SendDataAT(uint8_t *pdata, uint32_t length);
|
|
|
|
void BSP_LTE_Config(void);
|
|
|
|
void BSP_LTE_GetICCID(char *pICCID);
|
|
|
|
int16_t BSP_LTE_GetBsInfo(int *lte_mcc, int *lte_mnc, int *lte_lac,
|
|
int *lte_cellid);
|
|
|
|
uint32_t BSP_LTE_GetTimeMs(void);
|
|
|
|
int16_t BSP_LTE_GetGTPOS_GET(int *lon, int *lat);
|
|
|
|
void BSP_LTE_TCP_Close(void);
|
|
|
|
int16_t BSP_LTE_SendCmd(const char *cmd, const char *expect, const char *error,
|
|
uint32_t waittime);
|
|
|
|
int16_t BSP_LTE_TCP_Connect(const char *mode, const char *ipAddr,
|
|
const char *port);
|
|
|
|
void BSP_LTE_MQTT_Close(void);
|
|
|
|
void BSP_LET_Register_Com(rt_device_t com_dev);
|
|
|
|
int16_t BSP_LTE_Send_Cmd_HTTPRead(const char *cmd, uint16_t len,
|
|
int32_t waittime);
|
|
|
|
int16_t BSP_LTE_Send_Cmd_FileRead(const char *cmd, uint16_t len,
|
|
int32_t waittime);
|
|
|
|
void tcp_connect_test(void);
|
|
|
|
void hw_printf(const char *fmt, ...);
|
|
// void test_ec800k_ota(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
//------------------End of File----------------------------
|
|
|