123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #ifndef __BLE_CMD_H
- #define __BLE_CMD_H
- #include <stdint.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifdef __BLE_CMD_H_GLOBAL
- #define __BLE_CMD_H_EXTERN
- #else
- #define __BLE_CMD_H_EXTERN extern
- #endif
- /************************************************************************************************
- * Version *
- ************************************************************************************************/
- /************************************************************************************************
- * How to use *
- ************************************************************************************************/
- /************************************************************************************************
- * Enable config *
- ************************************************************************************************/
- /************************************************************************************************
- * Includes *
- ************************************************************************************************/
- #include "uart.h"
- /************************************************************************************************
- * Defines *
- ************************************************************************************************/
- #define EC95_MTU 252
- #define BLE_NAME_LEN 20
- #define BLE_CODE_LEN 4
- #define CMD_T0 40
- #define CMD18_T0 80
- #define CMD19_T0 180
- #define CMD41_T0 180
- /************************************************************************************************
- * Typedefs *
- ************************************************************************************************/
- #pragma pack(1)
- typedef struct
- {
- uint8_t head[2];
- uint8_t cmd;
- uint8_t len;
- uint8_t status;
- } RSP_COMM_CMD;
- typedef struct
- {
- uint8_t password[BLE_CODE_LEN];
- } REQ_CMD05;
- typedef struct
- {
- uint8_t name[BLE_NAME_LEN + 1];
- } REQ_CMD07;
- typedef struct
- {
- } REQ_CMD08;
- typedef struct
- {
- } REQ_CMD0A;
- typedef struct
- {
- uint8_t tx_power; // 发射功率
- } REQ_CMD0B;
- typedef struct
- {
- } REQ_CMD0C;
- typedef struct
- {
- } REQ_CMD0E;
- typedef struct
- {
- uint8_t state; // 0,关闭蓝牙,1,开启蓝牙 2、切换到广播
- } REQ_CMD13;
- typedef struct
- {
- } REQ_CMD14;
- typedef struct
- {
- uint8_t state; // 0,自动更新MTU,关闭更新MTU
- } REQ_CMD16;
- typedef struct
- {
- uint8_t item; // 0,产品型号, 1,固件版本 2,源码版本
- } REQ_CMD18;
- typedef struct
- {
- uint8_t item; // 0,复位重启, 1,恢复出厂设置
- } REQ_CMD19;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- uint8_t name[BLE_NAME_LEN + 1];
- } RSP_CMD08;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- uint16_t adv_inter_val; // 广播间隔
- } RSP_CMD0A;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- uint8_t tx_power;
- } RSP_CMD0C;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- uint8_t adv_data[28]; // 自动广播数据
- } RSP_CMD0E;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- uint8_t state; // 0,空闲,1,广播
- } RSP_CMD14;
- typedef struct
- {
- uint8_t item;
- uint8_t model[17]; // 产品型号
- } RSP_CMD18_ITEM0;
- typedef struct
- {
- uint8_t item;
- uint8_t fwv[5]; // 固件版本
- } RSP_CMD18_ITEM1;
- typedef struct
- {
- uint8_t item;
- uint8_t ver[16]; // 源码版本
- } RSP_CMD18_ITEM2;
- typedef struct
- {
- uint8_t item;
- uint8_t mac[6]; // mac地址
- } RSP_CMD18_ITEM3;
- typedef struct
- {
- uint8_t item;
- uint8_t reason; // 最后一次断开原因
- } RSP_CMD18_ITEM4;
- typedef struct
- {
- uint8_t item;
- uint8_t mtu; // mtu
- } RSP_CMD18_ITEM5;
- typedef struct
- {
- RSP_COMM_CMD hdr;
- union
- {
- RSP_CMD18_ITEM0 item0;
- RSP_CMD18_ITEM1 item1;
- RSP_CMD18_ITEM2 item2;
- RSP_CMD18_ITEM3 item3;
- RSP_CMD18_ITEM4 item4;
- RSP_CMD18_ITEM5 item5;
- };
- } RSP_CMD18;
- typedef struct
- {
- uint8_t cmd;
- int32_t (*p_func)(uint8_t cmd, uint8_t *data, uint8_t len);
- } BLE_CMD_ASYN;
- #pragma pack(0)
- /************************************************************************************************
- * Interfaces *
- ************************************************************************************************/
- int32_t ble_exec_cmd_asyn(uint8_t cmd, uint8_t *data, uint8_t length);
- int32_t ble_exec_cmd07_asyn(uint8_t cmd, uint8_t *data, uint8_t length);
- int32_t ble_exec_cmd05(REQ_CMD05 *req);
- int32_t ble_exec_cmd07(REQ_CMD07 *req, int32_t timeout);
- int32_t ble_exec_cmd08(REQ_CMD08 *req, RSP_CMD08 *rsp);
- int32_t ble_exec_cmd0a(REQ_CMD0A *req, RSP_CMD0A *rsp);
- int32_t ble_exec_cmd0b(REQ_CMD0B *req);
- int32_t ble_exec_cmd0c(REQ_CMD0C *req, RSP_CMD0C *rsp);
- int32_t ble_exec_cmd0d(uint8_t save_flg, uint8_t *adv_data, uint8_t adv_data_len);
- int32_t ble_exec_cmd0e(REQ_CMD0E *req, RSP_CMD0E *rsp);
- int32_t ble_exec_cmd18(REQ_CMD18 *req, RSP_CMD18 *rsp);
- int32_t countof_asyn_cmd_table(void);
- #ifdef __cplusplus
- };
- #endif
- #endif // __BLE_CMD_H
|