hal_ble_client.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef __hal_ble_client__
  2. #define __hal_ble_client__
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include "sdk_common.h"
  7. #include "SEGGER_RTT.h"
  8. #include "usr_config.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #ifdef __cplusplus
  13. }
  14. #endif
  15. /*************** 发送命令 ********************/
  16. typedef enum {
  17. BLE_Client_T_HEART = 0,
  18. BLE_Client_T_MOTION, //动作
  19. BLE_Client_T_TRACK = 0x04, //轨迹
  20. BLE_Client_T_CONNET_LED = 0x10, //连接灯通知
  21. BLE_Client_T_CONFIG, //配对
  22. BLE_Client_T_UPDATE = 0xA1, //数据更新
  23. BLE_Client_T_GAMEMODE, //游戏模式
  24. BLE_Client_T_CONNET_R, //右鞋连接通知
  25. BLE_Client_T_SHOCK, //震动
  26. BLE_Client_T_REALTIMESTEP, //实时步数
  27. BLE_Client_T_DFU, //空中升级
  28. BLE_Client_T_CHARGE, //充电通知
  29. BLE_CLient_T_CHAR_VOL, //共享充电电量
  30. BLE_CLient_T_SET_ORGAN, //激光的开关
  31. BLE_Client_T_ERR, //错误信息
  32. // BLE_Client_NUM_OF_T, //命令连续用此值
  33. }BLE_Client_T_n;
  34. //#define BLE_Client_NUM_OF_T 9 //注意:::此值根据命令的数量改变
  35. /*************** 发送子命令 ********************/
  36. enum { //BLE_Client_T_UPDATE
  37. BLE_Client_T_UPDATE_BASEINFO = 0, //设备基本信息
  38. BLE_Client_T_UPDATE_DATA , //设备数据
  39. BLE_Client_T_UPDATE_STEPNUM , //回复存储步数
  40. BLE_Client_T_UPDATE_STEPNUM_CLERA, //删除存储步数
  41. };
  42. enum { //BLE_Client_T_CHARGE
  43. BLE_Client_T_CHARGE_NONE = 0,
  44. BLE_Client_T_CHARGE_PULLOUT,
  45. BLE_Client_T_CHARGE_INSERT,
  46. BLE_Client_T_CHARGE_DONE,
  47. };
  48. //#define BLE_Client_NUM_OF_T 20 //注意:::此值根据命令的数量改变(包括子命令)
  49. /*************** 接收命令 ********************/
  50. typedef enum {
  51. BLE_Client_R_HEART = 0,
  52. BLE_Client_R_MOTION, //动作
  53. BLE_Client_R_TRACK = 0x04, //轨迹
  54. BLE_Client_R_CONNET_LED = 0x10, //连接灯通知
  55. BLE_Client_R_CONFIG, //配对
  56. BLE_Client_R_UPDATE = 0xA1, //数据更新
  57. BLE_Client_R_GAMEMODE, //游戏模式
  58. BLE_Client_R_CONNET_R, //右鞋连接通知
  59. BLE_Client_R_SHOCK, //震动
  60. BLE_Client_R_REALTIMESTEP, //实时步数
  61. BLE_Client_R_DFU, //空中升级
  62. BLE_Client_R_CHARGE, //充电通知
  63. BLE_CLient_R_CHAR_VOL, //共享充电电量
  64. BLE_CLient_R_SET_ORGAN, //激光的开关
  65. BLE_Client_R_ERR, //错误信息
  66. // BLE_Client_NUM_OF_R, //命令连续用此值
  67. }BLE_Client_R_n;
  68. #define BLE_Client_NUM_OF_R 15 //注意:::此值根据命令的数量改变
  69. /*************** 接收子命令 ********************/
  70. enum { //BLE_Client_R_UPDATE
  71. BLE_Client_R_UPDATE_BASEINFO = 0,
  72. BLE_Client_R_UPDATE_DATA ,
  73. BLE_Client_R_UPDATE_STEPNUM,
  74. BLE_Client_R_UPDATE_STEPNUM_CLERA,
  75. };
  76. enum { //BLE_Client_R_REALTIMESTEP
  77. BLE_Client_R_REALTIMESTEP_EXIT = 0, //实时计步退出
  78. BLE_Client_R_REALTIMESTEP_ENTER, //实时计步进入
  79. BLE_Client_R_REALTIMESTEP_HANDUP, //实时计步挂起
  80. };
  81. typedef void (*BLE_Client_Callback)(void*);
  82. typedef struct _BLE_Client_Rx{
  83. uint8_t cmd;
  84. uint8_t* pDat;
  85. uint8_t datLen;
  86. BLE_Client_Callback cb;
  87. }BLE_Client_Rx_t;
  88. typedef struct _BLE_Client_Tx{
  89. uint8_t n;
  90. uint32_t t;
  91. uint8_t ncnt;
  92. uint32_t tcnt;
  93. uint8_t cmd;
  94. uint8_t* pDat;
  95. uint8_t datLen;
  96. uint8_t holdon;
  97. BLE_Client_Callback cb;
  98. struct _BLE_Client_Tx *next; //单向链表
  99. }BLE_Client_Tx_t;
  100. void BLE_Client_Initialize(void);
  101. void BLE_Client_Send(unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  102. int BLE_Client_Rx_Regist(unsigned char cmd,BLE_Client_Callback cb);
  103. void BLE_Client_Tx_Send(BLE_Client_Tx_t* handle,unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  104. void BLE_Client_Tx_Clear(BLE_Client_Tx_t* handle);
  105. void BLE_Client_Push(unsigned char* p,int len);
  106. #endif