app_host.c 2.4 KB

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