|
|
|
|
#ifndef __AT_PARSER_H__
|
|
|
|
|
#define __AT_PARSER_H__
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include "com.h"
|
|
|
|
|
|
|
|
|
|
#define AT_RX_BUFFER_SIZE 256
|
|
|
|
|
#define AT_CMD_MAX_LEN 64
|
|
|
|
|
#define AT_LINE_MAX_LEN 128
|
|
|
|
|
#define AT_MAX_RESPONSES 8
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
AT_OK = 0,
|
|
|
|
|
AT_ERROR,
|
|
|
|
|
AT_TIMEOUT,
|
|
|
|
|
AT_BUSY,
|
|
|
|
|
AT_UNKNOWN
|
|
|
|
|
} at_status_t;
|
|
|
|
|
|
|
|
|
|
typedef void (*at_response_cbk)(const char *data, int len);
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const char *prefix;
|
|
|
|
|
at_response_cbk callback;
|
|
|
|
|
} at_response_item_t;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
TComCtrl *m_ptCom;
|
|
|
|
|
|
|
|
|
|
char m_acLineBuffer[AT_LINE_MAX_LEN];
|
|
|
|
|
|
|
|
|
|
volatile bool m_bWaitingResponse;
|
|
|
|
|
uint32_t m_u32WaitStartTime;
|
|
|
|
|
uint32_t m_u32TimeoutMs;
|
|
|
|
|
volatile at_status_t m_eLastStatus;
|
|
|
|
|
|
|
|
|
|
at_response_item_t m_stResponses[AT_MAX_RESPONSES];
|
|
|
|
|
uint8_t m_u8ResponseCount;
|
|
|
|
|
|
|
|
|
|
void (*m_pfHwSend)(const uint8_t *data, uint16_t len);
|
|
|
|
|
uint32_t (*m_pfGetTick)(void);
|
|
|
|
|
} at_parser_t;
|
|
|
|
|
|
|
|
|
|
int at_parser_init(at_parser_t *parser,
|
|
|
|
|
void (*send_cb)(const uint8_t *data, uint16_t len),
|
|
|
|
|
uint32_t (*tick_cb)(void));
|
|
|
|
|
|
|
|
|
|
void at_parser_deinit(at_parser_t *parser);
|
|
|
|
|
|
|
|
|
|
bool at_parser_register_response(at_parser_t *parser,
|
|
|
|
|
const char *prefix,
|
|
|
|
|
at_response_cbk cb);
|
|
|
|
|
|
|
|
|
|
void at_parser_feed(at_parser_t *parser,
|
|
|
|
|
const uint8_t *data,
|
|
|
|
|
uint16_t len);
|
|
|
|
|
|
|
|
|
|
void at_parser_feed_byte(at_parser_t *parser,
|
|
|
|
|
uint8_t data);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 接收处理函数。
|
|
|
|
|
* 建议放在 AT 接收线程里循环调用。
|
|
|
|
|
*
|
|
|
|
|
* 注意:
|
|
|
|
|
* 这个函数内部会调用 rd_ComRead()。
|
|
|
|
|
* 你的 rd_ComRead() 在无数据时会等待信号量,所以它适合放在单独接收任务中。
|
|
|
|
|
*/
|
|
|
|
|
int at_parser_recv_process(at_parser_t *parser);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 阻塞式发送命令。
|
|
|
|
|
*
|
|
|
|
|
* 重要:
|
|
|
|
|
* 使用这个函数时,必须同时有另一个 AT 接收任务在调用 at_parser_recv_process()。
|
|
|
|
|
* 否则收到的数据只会进入 com 缓冲区,不会被解析成 OK / ERROR。
|
|
|
|
|
*/
|
|
|
|
|
at_status_t at_parser_send_cmd(at_parser_t *parser,
|
|
|
|
|
const char *cmd,
|
|
|
|
|
uint32_t timeout_ms);
|
|
|
|
|
|
|
|
|
|
void at_parser_send_raw(at_parser_t *parser,
|
|
|
|
|
const uint8_t *data,
|
|
|
|
|
uint16_t len);
|
|
|
|
|
|
|
|
|
|
void at_parser_process(at_parser_t *parser);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|