#include "system.h" #include "app_host.h" #include "hal_ble_client.h" #include "hal_ble_host.h" #include "bsp_time.h" #include "hal_led.h" #include "ble_gap.h" #include "hal_battery.h" #include "app_flash.h" #include "ble_comm.h" #include "app_client_infomation.h" #include "app_client_dataupdate.h" #include "hal_mode_manage.h" /************************ 定义 ***************************/ static uint8_t vol_R = 0; //右鞋电量 static uint8_t temp_R = 0; //右鞋温度 static uint32_t press_R = 0; //右鞋压力 uint8_t app_host_GetVol_R(void){ return vol_R; } uint8_t app_host_GetTemp_R(void){ return temp_R; } uint32_t app_host_GetPress_R(void){ return press_R; } /***************************** 主动获取从机信息 ******************************/ static BLE_Host_Tx_t mBLE_Host_T_UPDATE_INFO_R = { .n = 10, .t = 1000, .cb = 0, }; void app_host_GetClientInfo(void) {//AA 06 F9 A1 00 4A static uint8_t buf=BLE_Host_T_UPDATE_BASEINFO; BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_INFO_R,BLE_UPDATE,&buf,1); } static BLE_Host_Tx_t mBLE_Host_T_UPDATE_DATA_R = { .n = 0, .t = 500, .cb = 0, }; void app_host_GetClientData(uint8_t temp) {//AA 06 F9 A1 01 4B static uint8_t buf=BLE_Host_T_UPDATE_DATA; BLE_Host_Tx_Send(0,BLE_UPDATE,&buf,1); if(0 == mBLE_Host_T_UPDATE_DATA_R.n && temp >=2){ mBLE_Host_T_UPDATE_DATA_R.n = temp; BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_DATA_R,BLE_UPDATE,&buf,1); } } //>> 0xA1: 查询 void cb_BLE_Host_R_UPDATE(void* handle) { BLE_Host_Rx_t *target = handle; uint8_t _cmd = target->pDat[0]; switch(_cmd){ case BLE_Host_R_UPDATE_BASEINFO:{ //<< 0(子命令): 设备型号(64)+左鞋蓝牙地址(6)+硬件版本(2)+软件版本(2)+右鞋蓝牙地址(6)+硬件版本(6)+软件版本(2) uint8_t L = SHOES_NAME_LEN+6; for(int i=0;i<6;i++) mFlash.mClient.macAddr[i] = target->pDat[i+SHOES_NAME_LEN+1]; mFlash.mClient.hardVersion = ((uint16_t)target->pDat[L]<<8)|((uint16_t)target->pDat[L+1]<<0); mFlash.mClient.sotfVersion = ((uint16_t)target->pDat[L+2]<<8)|((uint16_t)target->pDat[L+3]<<0); app_client_infomation_Send(); break;} case BLE_Host_R_UPDATE_DATA:{ //<< 1(子命令): 左鞋电量(1)+左鞋温度(1)+左鞋压力(4)+左鞋步数(4)+右鞋电量(1)+右鞋温度(1)+右鞋压力(4)+右鞋步数(4) vol_R = target->pDat[1]; temp_R = target->pDat[2]; 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); 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); mBLE_Host_T_UPDATE_DATA_R.n = 0; app_client_DataUpdate_Send(); // SEGGER_RTT_printf(0,"right step:%d\n",mFlash.mStep.stepCur[1]); break;} default:break; } } static void app_host_Process(void) { static uint8_t cnt =0; if(host_isconnect()){ if(HAL_MODE_GAME == hal_mode_get()){ if(cnt++ >= 3){ cnt =0; app_host_GetClientData(1); } } else app_host_GetClientData(1); } } void app_host_Initialize(void) { if(mFlash.isHost==1){ BLE_Host_Rx_Regist(BLE_UPDATE,cb_BLE_Host_R_UPDATE); Process_Start(3000,"app_host",app_host_Process); } }