app_host.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /************************ 定义 ***************************/
  13. static uint8_t vol_R = 0; //右鞋电量
  14. static uint8_t temp_R = 0; //右鞋温度
  15. static uint32_t press_R = 0; //右鞋压力
  16. static int16_t volADC_R = 0; //右鞋电池ADC
  17. uint8_t app_host_GetVol_R(void){ return vol_R; }
  18. int16_t app_host_GetVolAdc_R(void){ return volADC_R; }
  19. uint8_t app_host_GetTemp_R(void){ return temp_R; }
  20. uint32_t app_host_GetPress_R(void){ return press_R; }
  21. /***************************** 主动获取从机信息 ******************************/
  22. static BLE_Host_Tx_t mBLE_Host_T_UPDATE_INFO_R = {
  23. .n = 10,
  24. .t = 1000,
  25. .cb = 0,
  26. };
  27. void app_host_GetClientInfo(void)
  28. {//AA 06 F9 A1 00 4A
  29. static uint8_t buf=BLE_UPDATE_BASEINFO;
  30. BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_INFO_R,BLE_UPDATE,&buf,1);
  31. }
  32. static BLE_Host_Tx_t mBLE_Host_T_UPDATE_DATA_R = {
  33. .n = 0,
  34. .t = 500,
  35. .cb = 0,
  36. };
  37. void app_host_GetClientData(uint8_t temp)
  38. {//AA 06 F9 A1 01 4B
  39. static uint8_t buf=BLE_UPDATE_DATA;
  40. BLE_Host_Tx_Send(0,BLE_UPDATE,&buf,1);
  41. if(0 == mBLE_Host_T_UPDATE_DATA_R.n && temp >=2){
  42. mBLE_Host_T_UPDATE_DATA_R.n = temp;
  43. BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_DATA_R,BLE_UPDATE,&buf,1);
  44. }
  45. }
  46. //>> 0xA1: 查询
  47. void cb_BLE_Host_R_UPDATE(void* handle)
  48. {
  49. if(!mFlash.isHost)return;
  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. BLE_Host_Rx_Regist(BLE_UPDATE,cb_BLE_Host_R_UPDATE);
  81. }