ble_cmd.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef __BLE_CMD_H
  2. #define __BLE_CMD_H
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifdef __BLE_CMD_H_GLOBAL
  8. #define __BLE_CMD_H_EXTERN
  9. #else
  10. #define __BLE_CMD_H_EXTERN extern
  11. #endif
  12. /************************************************************************************************
  13. * Version *
  14. ************************************************************************************************/
  15. /************************************************************************************************
  16. * How to use *
  17. ************************************************************************************************/
  18. /************************************************************************************************
  19. * Enable config *
  20. ************************************************************************************************/
  21. /************************************************************************************************
  22. * Includes *
  23. ************************************************************************************************/
  24. #include "uart.h"
  25. /************************************************************************************************
  26. * Defines *
  27. ************************************************************************************************/
  28. #define EC95_MTU 252
  29. #define BLE_NAME_LEN 20
  30. #define BLE_CODE_LEN 4
  31. #define CMD_T0 40
  32. #define CMD18_T0 80
  33. #define CMD19_T0 180
  34. #define CMD41_T0 180
  35. /************************************************************************************************
  36. * Typedefs *
  37. ************************************************************************************************/
  38. #pragma pack(1)
  39. typedef struct
  40. {
  41. uint8_t head[2];
  42. uint8_t cmd;
  43. uint8_t len;
  44. uint8_t status;
  45. } RSP_COMM_CMD;
  46. typedef struct
  47. {
  48. uint8_t password[BLE_CODE_LEN];
  49. } REQ_CMD05;
  50. typedef struct
  51. {
  52. uint8_t name[BLE_NAME_LEN + 1];
  53. } REQ_CMD07;
  54. typedef struct
  55. {
  56. } REQ_CMD08;
  57. typedef struct
  58. {
  59. } REQ_CMD0A;
  60. typedef struct
  61. {
  62. uint8_t tx_power; // 发射功率
  63. } REQ_CMD0B;
  64. typedef struct
  65. {
  66. } REQ_CMD0C;
  67. typedef struct
  68. {
  69. } REQ_CMD0E;
  70. typedef struct
  71. {
  72. uint8_t state; // 0,关闭蓝牙,1,开启蓝牙 2、切换到广播
  73. } REQ_CMD13;
  74. typedef struct
  75. {
  76. } REQ_CMD14;
  77. typedef struct
  78. {
  79. uint8_t state; // 0,自动更新MTU,关闭更新MTU
  80. } REQ_CMD16;
  81. typedef struct
  82. {
  83. uint8_t item; // 0,产品型号, 1,固件版本 2,源码版本
  84. } REQ_CMD18;
  85. typedef struct
  86. {
  87. uint8_t item; // 0,复位重启, 1,恢复出厂设置
  88. } REQ_CMD19;
  89. typedef struct
  90. {
  91. RSP_COMM_CMD hdr;
  92. uint8_t name[BLE_NAME_LEN + 1];
  93. } RSP_CMD08;
  94. typedef struct
  95. {
  96. RSP_COMM_CMD hdr;
  97. uint16_t adv_inter_val; // 广播间隔
  98. } RSP_CMD0A;
  99. typedef struct
  100. {
  101. RSP_COMM_CMD hdr;
  102. uint8_t tx_power;
  103. } RSP_CMD0C;
  104. typedef struct
  105. {
  106. RSP_COMM_CMD hdr;
  107. uint8_t adv_data[28]; // 自动广播数据
  108. } RSP_CMD0E;
  109. typedef struct
  110. {
  111. RSP_COMM_CMD hdr;
  112. uint8_t state; // 0,空闲,1,广播
  113. } RSP_CMD14;
  114. typedef struct
  115. {
  116. uint8_t item;
  117. uint8_t model[17]; // 产品型号
  118. } RSP_CMD18_ITEM0;
  119. typedef struct
  120. {
  121. uint8_t item;
  122. uint8_t fwv[5]; // 固件版本
  123. } RSP_CMD18_ITEM1;
  124. typedef struct
  125. {
  126. uint8_t item;
  127. uint8_t ver[16]; // 源码版本
  128. } RSP_CMD18_ITEM2;
  129. typedef struct
  130. {
  131. uint8_t item;
  132. uint8_t mac[6]; // mac地址
  133. } RSP_CMD18_ITEM3;
  134. typedef struct
  135. {
  136. uint8_t item;
  137. uint8_t reason; // 最后一次断开原因
  138. } RSP_CMD18_ITEM4;
  139. typedef struct
  140. {
  141. uint8_t item;
  142. uint8_t mtu; // mtu
  143. } RSP_CMD18_ITEM5;
  144. typedef struct
  145. {
  146. RSP_COMM_CMD hdr;
  147. union
  148. {
  149. RSP_CMD18_ITEM0 item0;
  150. RSP_CMD18_ITEM1 item1;
  151. RSP_CMD18_ITEM2 item2;
  152. RSP_CMD18_ITEM3 item3;
  153. RSP_CMD18_ITEM4 item4;
  154. RSP_CMD18_ITEM5 item5;
  155. };
  156. } RSP_CMD18;
  157. typedef struct
  158. {
  159. uint8_t cmd;
  160. int32_t (*p_func)(uint8_t cmd, uint8_t *data, uint8_t len);
  161. } BLE_CMD_ASYN;
  162. #pragma pack(0)
  163. /************************************************************************************************
  164. * Interfaces *
  165. ************************************************************************************************/
  166. int32_t ble_exec_cmd_asyn(uint8_t cmd, uint8_t *data, uint8_t length);
  167. int32_t ble_exec_cmd07_asyn(uint8_t cmd, uint8_t *data, uint8_t length);
  168. int32_t ble_exec_cmd05(REQ_CMD05 *req);
  169. int32_t ble_exec_cmd07(REQ_CMD07 *req, int32_t timeout);
  170. int32_t ble_exec_cmd08(REQ_CMD08 *req, RSP_CMD08 *rsp);
  171. int32_t ble_exec_cmd0a(REQ_CMD0A *req, RSP_CMD0A *rsp);
  172. int32_t ble_exec_cmd0b(REQ_CMD0B *req);
  173. int32_t ble_exec_cmd0c(REQ_CMD0C *req, RSP_CMD0C *rsp);
  174. int32_t ble_exec_cmd0d(uint8_t save_flg, uint8_t *adv_data, uint8_t adv_data_len);
  175. int32_t ble_exec_cmd0e(REQ_CMD0E *req, RSP_CMD0E *rsp);
  176. int32_t ble_exec_cmd18(REQ_CMD18 *req, RSP_CMD18 *rsp);
  177. int32_t countof_asyn_cmd_table(void);
  178. #ifdef __cplusplus
  179. };
  180. #endif
  181. #endif // __BLE_CMD_H