app_host.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "system.h"
  2. #include "app_host.h"
  3. #include "hal_ble_client.h"
  4. #include "hal_ble_host.h"
  5. #include "bsp_time.h"
  6. #include "hal_led.h"
  7. #include "ble_gap.h"
  8. #include "hal_battery.h"
  9. #include "app_flash.h"
  10. #include "ble_comm.h"
  11. #include "app_client.h"
  12. #include "hal_ser_imu_mode_manage.h"
  13. /************************ 定义 ***************************/
  14. static uint8_t vol_R = 0; //右鞋电量
  15. static uint8_t temp_R = 0; //右鞋温度
  16. static uint32_t press_R = 0; //右鞋压力
  17. uint8_t app_host_GetVol_R(void){ return vol_R; }
  18. uint8_t app_host_GetTemp_R(void){ return temp_R; }
  19. uint32_t app_host_GetPress_R(void){ return press_R; }
  20. /***************************** 主动获取从机信息 ******************************/
  21. static BLE_Host_Tx_t mBLE_Host_T_UPDATE_INFO_R = {
  22. .n = 10,
  23. .t = 1000,
  24. .cb = 0,
  25. };
  26. void app_host_GetClientInfo(void)
  27. {//AA 06 F9 A1 00 4A
  28. static uint8_t buf=BLE_UPDATE_BASEINFO;
  29. BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_INFO_R,BLE_UPDATE,&buf,1);
  30. }
  31. static BLE_Host_Tx_t mBLE_Host_T_UPDATE_DATA_R = {
  32. .n = 0,
  33. .t = 500,
  34. .cb = 0,
  35. };
  36. void app_host_GetClientData(uint8_t temp)
  37. {//AA 06 F9 A1 01 4B
  38. static uint8_t buf=BLE_UPDATE_DATA;
  39. BLE_Host_Tx_Send(0,BLE_UPDATE,&buf,1);
  40. if(0 == mBLE_Host_T_UPDATE_DATA_R.n && temp >=2){
  41. mBLE_Host_T_UPDATE_DATA_R.n = temp;
  42. BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_DATA_R,BLE_UPDATE,&buf,1);
  43. }
  44. }
  45. //>> 0xA1: 查询
  46. void cb_BLE_Host_R_UPDATE(void* handle)
  47. {
  48. BLE_Host_Rx_t *target = handle;
  49. uint8_t _cmd = target->pDat[0];
  50. switch(_cmd){
  51. case BLE_UPDATE_BASEINFO:{
  52. //<< 0(子命令): 设备型号(64)+左鞋蓝牙地址(6)+硬件版本(2)+软件版本(2)+右鞋蓝牙地址(6)+硬件版本(6)+软件版本(2)
  53. for(int i=0;i<6;i++) mFlash.mClient.macAddr[i] = target->pDat[i+1+SHOES_NAME_LEN];
  54. SEGGER_RTT_printf(0,"mFlash.mClient.macAddr:%02X %02X %02X %02X %02X %02X\n",mFlash.mClient.macAddr[0],mFlash.mClient.macAddr[1],mFlash.mClient.macAddr[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  55. uint8_t L = SHOES_NAME_LEN+7;
  56. mFlash.mClient.hardVersion = ((uint32_t)target->pDat[L]<<24) |((uint32_t)target->pDat[L+1]<<16) |((uint32_t)target->pDat[L+2]<<8) |((uint32_t)target->pDat[L+3]);
  57. mFlash.mClient.sotfVersion = target->pDat[L+4];
  58. // SEGGER_RTT_printf(0,"BLE_Host_R_UPDATE_BASEINFO:"); for(int i=64;i<(28+64);i++){SEGGER_RTT_printf(0,"%02X ",target->pDat[i]);} SEGGER_RTT_printf(0,"\r\n");
  59. // SEGGER_RTT_printf(0,"sotfVersion,hardVersion:%x,%x\n",mFlash.mClient.sotfVersion,mFlash.mClient.hardVersion);
  60. app_client_infomation_Send();
  61. break;}
  62. case BLE_UPDATE_DATA:{
  63. //<< 1(子命令): 左鞋电量(1)+左鞋温度(1)+左鞋压力(4)+左鞋步数(4)+右鞋电量(1)+右鞋温度(1)+右鞋压力(4)+右鞋步数(4)
  64. vol_R = target->pDat[1];
  65. temp_R = target->pDat[2];
  66. press_R = ((uint32_t)target->pDat[3]<<24)|((uint32_t)target->pDat[4]<<16)|((uint32_t)target->pDat[5]<<8)|((uint32_t)target->pDat[6]<<0);
  67. mFlash.mStep.stepCur[1] = ((uint32_t)target->pDat[7]<<24)|((uint32_t)target->pDat[8]<<16)|((uint32_t)target->pDat[9]<<8)|((uint32_t)target->pDat[10]<<0);
  68. mBLE_Host_T_UPDATE_DATA_R.n = 0;
  69. app_client_DataUpdate_Send();
  70. // SEGGER_RTT_printf(0,"right step:%d\n",mFlash.mStep.stepCur[1]);
  71. break;}
  72. default:break;
  73. }
  74. }
  75. void app_host_Initialize(void)
  76. {
  77. if(mFlash.isHost==1){
  78. BLE_Host_Rx_Regist(BLE_UPDATE,cb_BLE_Host_R_UPDATE);
  79. }
  80. }