app_host.c 3.4 KB

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