app_host.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "hal_flash.h"
  10. #include "ble_comm.h"
  11. #include "hal_soft_time.h"
  12. /************************ 定义 ***************************/
  13. static uint8_t vol_R = 0; //右鞋电量
  14. static uint8_t temp_R = 0; //右鞋温度
  15. static uint32_t press_R = 0; //右鞋压力
  16. uint8_t app_host_GetVol_R(void){ return vol_R; }
  17. uint8_t app_host_GetTemp_R(void){ return temp_R; }
  18. uint32_t app_host_GetPress_R(void){ return press_R; }
  19. /***************************** 主动获取从机信息 ******************************/
  20. void app_host_GetClientInfo(void)
  21. {//AA 06 F9 A1 00 4A
  22. uint8_t buf[16];
  23. buf[0] = BLE_Host_T_UPDATE_BASEINFO;
  24. BLE_Host_Tx_Send(0,BLE_Host_T_UPDATE,buf,1);
  25. }
  26. void app_host_GetClientData(void)
  27. {//AA 06 F9 A1 01 4B
  28. uint8_t buf[1];
  29. uint8_t L=0;
  30. buf[L++] = BLE_Host_T_UPDATE_DATA;
  31. BLE_Host_Tx_Send(0,BLE_Host_T_UPDATE,buf,L);
  32. }
  33. void app_host_Process(void)
  34. {
  35. if(host_isconnect()){
  36. if(mFlash.mClient.isConfig==0) app_host_GetClientInfo(); //申请设备基本信息
  37. app_host_GetClientData();
  38. }
  39. }
  40. //>> 0xA1: 查询
  41. void cb_BLE_Host_R_UPDATE(void* handle)
  42. {
  43. BLE_Host_Rx_t *target = handle;
  44. uint8_t _cmd = target->pDat[0];
  45. switch(_cmd){
  46. case BLE_Host_R_UPDATE_BASEINFO:{
  47. //<< 0(子命令): 设备型号(64)+左鞋蓝牙地址(6)+硬件版本(2)+软件版本(2)+右鞋蓝牙地址(6)+硬件版本(6)+软件版本(2)
  48. uint8_t L = SHOES_NAME_LEN+6;
  49. for(int i=0;i<6;i++) mFlash.mClient.macAddr[i] = target->pDat[i+SHOES_NAME_LEN];
  50. mFlash.mClient.hardVersion = ((uint16_t)target->pDat[L]<<8)|((uint16_t)target->pDat[L+1]<<0);
  51. mFlash.mClient.sotfVersion = ((uint16_t)target->pDat[L+2]<<8)|((uint16_t)target->pDat[L+3]<<0);
  52. mFlash.mClient.isConfig = 1;
  53. break;}
  54. case BLE_Host_R_UPDATE_DATA:{
  55. //<< 1(子命令): 左鞋电量(1)+左鞋温度(1)+左鞋压力(4)+左鞋步数(4)+右鞋电量(1)+右鞋温度(1)+右鞋压力(4)+右鞋步数(4)
  56. vol_R = target->pDat[1];
  57. temp_R = target->pDat[2];
  58. 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);
  59. 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);
  60. if(mFlash.mStep.stepCur[1]<mFlash.mStep.step[1]) mFlash.mStep.step[1] = mFlash.mStep.stepCur[1];
  61. break;}
  62. default:break;
  63. }
  64. }
  65. void app_host_Initialize(void)
  66. {
  67. if(mFlash.isHost==1){
  68. BLE_Host_Rx_Regist(BLE_Host_R_UPDATE,cb_BLE_Host_R_UPDATE);
  69. Process_Start(3000,"app_host",app_host_Process);
  70. }
  71. }