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.
406 lines
12 KiB
406 lines
12 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_EXPECT "OK"
|
|
#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 CEREG_OK_2 "+CEREG: 0,1"
|
|
#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_CEREG2 "AT+CEREG=2\r\n"
|
|
#define AT_CSQ "AT+CSQ\r\n"
|
|
#define AT_QNWINFO "AT+QNWINFO\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_QLTS "AT+QLTS=2\r\n"
|
|
#define AT_CTZU "AT+CTZU=1\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 AT_QISDE0 "AT+QISDE=0\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_BUFFER \
|
|
"AT+QIOPEN=1,%d,\"%s\",\"%s\",%s,0,0\r\n" // buffer 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"
|
|
#define AT_QICSGP_CTIOT "AT+QICSGP=1,1,\"ctiot\",\"\",\"\"\r\n"
|
|
#define AT_QICSGP_CMTDS "AT+QICSGP=1,1,\"cmtds\",\"\",\"\"\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 AT_CFG_RECV_IND "AT+QICFG=\"recvind\",1\r\n"
|
|
#define AT_CFG_PASSIVE_CLOSED "AT+QICFG=\"passiveclosed\",1\r\n"
|
|
#define AT_CFG_TCP_KEEPALIVE "AT+QICFG=\"tcp/keepalive\",1,30,25,3\r\n"
|
|
|
|
#define LTE_CMD_WAIT_QIOPEN (150000)
|
|
#define LTE_CMD_WAIT_QICLOSE (10000)
|
|
#define LTE_CMD_WAIT_QIACT (150000)
|
|
#define LTE_CMD_WAIT_QIDEACT (40000)
|
|
#define LTE_CMD_WAIT_PROMPT (3000)
|
|
#define LTE_CMD_WAIT_SEND (10000)
|
|
#define LTE_SOCKET_RX_CHUNK_SIZE (128)
|
|
#define LTE_SOCKET_TX_CHUNK_SIZE (256)
|
|
|
|
/* Set after confirming the server MAVLink heartbeat period. */
|
|
#define LTE_SERVER_SILENCE_TIMEOUT_SEC (15)
|
|
|
|
typedef struct {
|
|
char mode[4];
|
|
char ip[50];
|
|
char port[16];
|
|
bool connect_sta;
|
|
unsigned char connect_ID;
|
|
unsigned char error_cnt;
|
|
} Cclient_t;
|
|
|
|
typedef enum {
|
|
LTE_DISC_CLOSED = 0,
|
|
LTE_DISC_NO_CARRIER,
|
|
LTE_DISC_NO_CARRIER_SPLIT,
|
|
LTE_DISC_AT_TIMEOUT,
|
|
LTE_DISC_QIOPEN_FAILED,
|
|
LTE_DISC_MODULE_RESET,
|
|
LTE_DISC_SERVER_SILENCE,
|
|
LTE_DISC_SOCKET_SEND,
|
|
} lte_disconnect_reason_t;
|
|
|
|
typedef struct {
|
|
int8_t cereg;
|
|
int8_t cgatt;
|
|
int8_t pdp;
|
|
int8_t csq;
|
|
char rat[12];
|
|
char oper[16];
|
|
char band[16];
|
|
char tac[9];
|
|
char cell[12];
|
|
rt_uint32_t channel;
|
|
} lte_network_snapshot_t;
|
|
|
|
typedef struct {
|
|
rt_uint32_t uart2_rx_bytes;
|
|
rt_uint32_t uart2_tx_bytes;
|
|
rt_uint32_t uart2_rx_events;
|
|
rt_uint32_t uart2_write_failures;
|
|
rt_uint32_t uart2_error_count;
|
|
rt_uint32_t uart3_error_count;
|
|
rt_uint32_t last_uart_error_code;
|
|
rt_uint32_t fmu_rx_bytes;
|
|
rt_uint32_t fmu_tx_bytes;
|
|
rt_uint32_t at_commands;
|
|
rt_uint32_t at_timeouts;
|
|
rt_uint32_t at_errors;
|
|
rt_uint32_t connect_attempts;
|
|
rt_uint32_t reconnect_count;
|
|
rt_uint32_t qioopen_failures;
|
|
rt_uint32_t reset_count;
|
|
rt_uint32_t disconnect_count;
|
|
rt_uint32_t server_rx_bytes;
|
|
rt_uint32_t server_rx_read_events;
|
|
rt_uint32_t server_silence_timeout_count;
|
|
rt_uint32_t socket_tx_bytes;
|
|
rt_uint32_t socket_send_ok;
|
|
rt_uint32_t socket_send_fail;
|
|
rt_uint32_t socket_prompt_timeouts;
|
|
rt_uint32_t socket_read_errors;
|
|
rt_uint32_t socket_acked_bytes;
|
|
rt_uint32_t socket_unacked_bytes;
|
|
rt_uint32_t socket_ack_queries;
|
|
rt_uint32_t socket_ack_errors;
|
|
rt_uint32_t tx_queue_drops;
|
|
rt_uint32_t tx_queue_high_water;
|
|
rt_uint32_t fmu_heartbeats;
|
|
rt_uint32_t server_heartbeats;
|
|
rt_uint32_t pdpdeact_count;
|
|
rt_uint32_t conn_fmu_rx_base;
|
|
rt_uint32_t conn_fmu_tx_base;
|
|
rt_uint32_t conn_server_rx_base;
|
|
rt_uint32_t conn_server_events_base;
|
|
rt_uint32_t conn_socket_tx_base;
|
|
rt_uint32_t conn_send_ok_base;
|
|
rt_uint32_t conn_send_fail_base;
|
|
rt_uint32_t conn_ack_queries_base;
|
|
rt_uint32_t conn_queue_drops_base;
|
|
rt_uint32_t conn_fmu_heartbeat_base;
|
|
rt_uint32_t conn_server_heartbeat_base;
|
|
rt_tick_t last_uart2_rx_tick;
|
|
rt_tick_t last_uart2_tx_tick;
|
|
rt_tick_t last_fmu_rx_tick;
|
|
rt_tick_t last_fmu_tx_tick;
|
|
rt_tick_t last_server_rx_tick;
|
|
rt_tick_t last_socket_ack_tick;
|
|
rt_tick_t connect_tick;
|
|
rt_tick_t last_disconnect_tick;
|
|
rt_tick_t last_at_elapsed;
|
|
rt_int32_t last_at_result;
|
|
char last_at_cmd[20];
|
|
lte_disconnect_reason_t last_disconnect_reason;
|
|
lte_network_snapshot_t network;
|
|
bool disconnect_report_pending;
|
|
} lte_diag_t;
|
|
|
|
extern lte_diag_t lte_diag;
|
|
|
|
void lte_diag_at_begin(const char *cmd);
|
|
void lte_diag_at_end(rt_int32_t result);
|
|
void lte_diag_uart2_rx(rt_size_t size);
|
|
void lte_diag_uart2_tx(rt_size_t size);
|
|
void lte_diag_uart_error(const char *name, rt_uint32_t error_code);
|
|
void lte_diag_fmu_rx(rt_size_t size);
|
|
void lte_diag_fmu_tx(rt_size_t size);
|
|
void lte_diag_fmu_data(const uint8_t *data, rt_size_t size);
|
|
void lte_diag_server_data(const uint8_t *data, rt_size_t size);
|
|
void lte_diag_connect_attempt(void);
|
|
void lte_diag_connect_success(void);
|
|
void lte_diag_disconnect(lte_disconnect_reason_t reason);
|
|
void lte_diag_module_reset(void);
|
|
|
|
typedef struct {
|
|
char imei[32];
|
|
char iccid[32];
|
|
|
|
uint8_t eps_sta;
|
|
int8_t csq;
|
|
|
|
bool config_sta;
|
|
|
|
Cclient_t *client1;
|
|
|
|
rt_device_t com_dev;
|
|
rt_sem_t com_dev_rx_sem;
|
|
rt_mutex_t data_tx_mutex;
|
|
rt_uint8_t at_buf[256];
|
|
|
|
rt_thread_t tid1;
|
|
rt_thread_t tid2;
|
|
|
|
bool reset_flag;
|
|
bool dev_init_flag;
|
|
volatile bool data_tx_paused;
|
|
volatile bool socket_recv_pending;
|
|
volatile bool socket_closed_pending;
|
|
volatile bool socket_pdpdeact_pending;
|
|
} CLte_dev_t;
|
|
extern CLte_dev_t lte_dev;
|
|
|
|
|
|
enum {
|
|
DTU_CF_NO_NEED_RESET = 0,
|
|
DTU_CF_NEED_RESET = 1,
|
|
};
|
|
|
|
|
|
enum {
|
|
NO_MATCH = 0,
|
|
HALF_MATCH = 1,
|
|
COMPLETE_MATCH = 2,
|
|
};
|
|
|
|
void BSP_LTE_SendData(uint8_t *pdata, uint32_t length);
|
|
void BSP_LTE_SetDataTxPaused(bool paused);
|
|
|
|
void BSP_LTE_Config(void);
|
|
void BSP_LTE_InitLogClock(void);
|
|
int16_t BSP_LTE_OpenSocket(const char *cmd, uint8_t connect_id);
|
|
int16_t BSP_LTE_SendSocketData(uint8_t connect_id, const uint8_t *data,
|
|
uint16_t length);
|
|
int16_t BSP_LTE_ReadSocketData(uint8_t connect_id, uint8_t *data,
|
|
uint16_t capacity);
|
|
int16_t BSP_LTE_QuerySocketSendStatus(uint8_t connect_id);
|
|
void BSP_LTE_PollSocketUrc(uint32_t waittime);
|
|
void BSP_LTE_ClearSocketEvents(void);
|
|
void BSP_LTE_CollectNetworkSnapshot(void);
|
|
|
|
int BSP_LTE_GetICCID(char *pICCID);
|
|
|
|
int8_t BSP_LTE_GetCSQ(void);
|
|
|
|
int16_t BSP_LTE_SendCmd(const char *cmd, const char *expect, const char *error,
|
|
uint32_t waittime);
|
|
|
|
void BSP_LET_Register_Com(rt_device_t com_dev);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
//------------------End of File----------------------------
|
|
|