#ifndef _BLUETOOTH_H #define _BLUETOOTH_H /*------------------------------- 宏定义 -------------------------------------- */ #define BLUETOOTH_BUF_LEN (1024) #define BL_TBUF_NUM (10) // 共有多少个buf #define BL_TBUF_LEN (256) // 每个buf长度 #define CMD_RECVBUF_LEN (64) // AT指令接收buf长度 /*------------------------------ 类型结构 ------------------------------------- */ enum _AT_CMD { AT_CMD_SACN = 0, // 扫描设备 AT_CMD_CONN, // 连接设备 AT_CMD_CHINFO, // 状态查询 AT_CMD_LESEND, // 数据发送 AT_CMD_LEDISC, // 断开连接 AT_CMD_NAME, // 设置名称 AT_CMD_MAC, // MAC 查询 AT_CMD_REBOOT, // 蓝牙重启 AT_CMD_DATA, // 数据接收 AT_CMD_STAT, // 连接状态 AT_CMD_MAX }; typedef enum _AT_CMD AT_CMD; struct at_cmd_index_match { const char *cmd_str; // AT指令字符串 const char *send_op_str; // AT指令追加字符串 不为空则填充 const char *cmd_end_str; // AT指令结束字符串 用于判断指令的结束 const char *data_end_str; // 数据段结束字符串 为空则此帧不包含数据否则包含数据 数据接收判断用 const char *sta_end_str; // AT指令结果字符串 为空则不需判断结果否则需判断结果 const u8 cmd; // 用于记录是何种操作指令 }; typedef struct bl_tbuf { volatile u8 tb_head ; volatile u8 tb_tail_send; volatile u8 tb_tail_ack; u8 tb_cmd[BL_TBUF_NUM]; // 记录发送的指令类型供接收确认用 u8 tb_data[BL_TBUF_NUM][BL_TBUF_LEN]; }bl_tbuf_t; typedef struct bluetooth { u8 chnl; u8 cTypeCounter; // 接收解析用 u8 cRecvLenth; // 接收解析用 u8 cRecvCnt; // 接收解析用 s8 cmd_type; // 指令类型 用于接收时判断数据类型 bool cmd_sta; // 指令操作结果 指令发出后判断蓝牙模块的执行结果 bool lnk_sta; // 蓝牙连接状态 bool bData; // 接收一帧报文 u8 resend_cnt; // 重发计数 struct rt_fifo recv_fifo; // 蓝牙数据接收fifo u8 recv_fifo_buf[BLUETOOTH_BUF_LEN]; // fifo缓存数组 iec_rbuf_t rx_buf; // 加密报文用 u8 recvbuf[BLUETOOTH_BUF_LEN]; // 用于存放fifo取出数据 u8 cmd_recvbuf[CMD_RECVBUF_LEN]; // u8 esambuf[BLUETOOTH_BUF_LEN]; // 用于接收加密返回数据 u8 arrSendBuf[BLUETOOTH_BUF_LEN]; // 用于发送数据组帧 bl_tbuf_t tx_buf[1]; // 发送报文缓存 unsigned long us0_sendpiece; // 发送帧间隔计时 unsigned long us0_disc_reboot; // 断连软复位计时 unsigned long us0_idle_reboot; // 空闲软复位计时 unsigned long us0_cfmtimeout; // 确认超时计时 // 接收超时处理 bool b_recv_reset; unsigned long us0_recv; } BLUETOOTH_DEF; /*------------------------------ 函数声明 ------------------------------------- */ int bluetooth_init(BLUETOOTH_DEF *p, u8 chnl); void bluetooth_recv(BLUETOOTH_DEF *pt, u8 _byte); int bluetooth_app(BLUETOOTH_DEF *p); void bluetooth_timer(BLUETOOTH_DEF *pt); #endif /* _BLUETOOTH_H */