hal_ble_host.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef __hal_BLE_Host__
  2. #define __hal_BLE_Host__
  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_Host_T_HEART = 0,
  18. BLE_Host_T_MOTION, //动作
  19. BLE_Host_T_TRACK = 0x04, //轨迹
  20. BLE_Host_T_CONNET_LED = 0x10, //连接灯通知
  21. BLE_Host_T_CONFIG, //配对
  22. BLE_Host_T_UPDATE = 0xA1, //数据更新
  23. BLE_Host_T_GAMEMODE, //游戏模式
  24. BLE_Host_T_CONNET_R, //右鞋连接通知
  25. BLE_Host_T_SHOCK, //震动
  26. BLE_Host_T_REALTIMESTEP, //实时步数
  27. BLE_Host_T_DFU, //空中升级
  28. BLE_Host_T_CHARGE, //充电通知
  29. BLE_Host_T_CHAR_VOL, //共享充电电量
  30. BLE_Host_T_SET_ORGAN, //激光的开关
  31. BLE_Host_T_ERR, //错误信息
  32. }BLE_Host_T_n;
  33. //#define BLE_Host_NUM_OF_T 9 //注意:::此值根据命令的数量改变
  34. /*************** 发送子命令 ********************/
  35. enum { //BLE_Host_T_UPDATE
  36. BLE_Host_T_UPDATE_BASEINFO = 0, //设备基本信息
  37. BLE_Host_T_UPDATE_DATA , //设备数据
  38. BLE_Host_T_UPDATE_STEPNUM , //回复存储步数
  39. BLE_Host_T_UPDATE_STEPNUM_CLERA, //删除存储步数
  40. };
  41. enum { //BLE_Host_T_CHARGE
  42. BLE_Host_T_CHARGE_NONE = 0,
  43. BLE_Host_T_CHARGE_PULLOUT,
  44. BLE_Host_T_CHARGE_INSERT,
  45. BLE_Host_T_CHARGE_DONE,
  46. BLE_Host_T_CHARGE_ERROR,
  47. };
  48. //#define BLE_Host_NUM_OF_T 20 //注意:::此值根据命令的数量改变(包括子命令)
  49. /*************** 接收命令 ********************/
  50. typedef enum {
  51. BLE_Host_R_HEART = 0,
  52. BLE_Host_R_MOTION, //动作
  53. BLE_Host_R_TRACK = 0x04, //轨迹
  54. BLE_Host_R_CONNET_LED = 0x10, //连接灯通知
  55. BLE_Host_R_CONFIG, //配对
  56. BLE_Host_R_UPDATE = 0xA1, //数据更新
  57. BLE_Host_R_GAMEMODE, //游戏模式
  58. BLE_Host_R_CONNET_R, //右鞋连接通知
  59. BLE_Host_R_SHOCK, //震动
  60. BLE_Host_R_REALTIMESTEP, //实时步数
  61. BLE_Host_R_DFU, //空中升级
  62. BLE_Host_R_CHARGE, //充电通知
  63. BLE_Host_R_CHAR_VOL, //共享充电电量
  64. BLE_Host_R_SET_ORGAN, //激光的开关
  65. BLE_Host_R_ERR, //错误信息
  66. // BLE_Host_NUM_OF_R, //命令连续用此值
  67. }BLE_Host_R_n;
  68. #define BLE_Host_NUM_OF_R 15 //注意:::此值根据命令的数量改变
  69. /*************** 接收子命令 ********************/
  70. enum { //BLE_Host_R_UPDATE
  71. BLE_Host_R_UPDATE_BASEINFO = 0,
  72. BLE_Host_R_UPDATE_DATA ,
  73. BLE_Host_R_UPDATE_STEPNUM,
  74. BLE_Host_R_UPDATE_STEPNUM_CLERA,
  75. };
  76. typedef void (*BLE_Host_Callback)(void*);
  77. typedef struct _BLE_Host_Rx{
  78. uint8_t cmd;
  79. uint8_t* pDat;
  80. uint8_t datLen;
  81. BLE_Host_Callback cb;
  82. }BLE_Host_Rx_t;
  83. typedef struct _BLE_Host_Tx{
  84. uint8_t n;
  85. uint32_t t;
  86. uint8_t ncnt;
  87. uint32_t tcnt;
  88. uint8_t cmd;
  89. uint8_t* pDat;
  90. uint8_t datLen;
  91. uint8_t holdon;
  92. BLE_Host_Callback cb;
  93. struct _BLE_Host_Tx *next; //单向链表
  94. }BLE_Host_Tx_t;
  95. void BLE_Host_Initialize(void);
  96. void BLE_Host_Send(unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  97. int BLE_Host_Rx_Regist(unsigned char cmd,BLE_Host_Callback cb);
  98. void BLE_Host_Tx_Send(BLE_Host_Tx_t* handle,unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  99. void BLE_Host_Tx_Clear(BLE_Host_Tx_t* handle);
  100. void BLE_Host_Push(unsigned char* p,int len);
  101. #endif