123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include "system.h"
- #include "app_client.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "bsp_time.h"
- #include "hal_led.h"
- #include "ble_gap.h"
- #include "app_host.h"
- #include "app_flash.h"
- #include "app_client_step.h"
- #include "hal_battery.h"
- #include "ble_comm.h"
- #include "app_game.h"
- #include "app_step.h"
- void app_client_DataUpdate_Send(void)
- {
-
-
- uint8_t buf[32];
- uint8_t L=0;
- int32_t temperature;
-
- memset(buf,0,sizeof(buf));
-
- sd_temp_get(&temperature);
- temperature = temperature>>2;
-
-
- buf[L++] = BLE_UPDATE_DATA;
-
- buf[L++] = GetBatteryPersent();
- buf[L++] = (uint8_t)temperature;
-
- L +=4;
-
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>24);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>16);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>8);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>0);
-
- buf[L++] = app_host_GetVol_R();
- buf[L++] = app_host_GetTemp_R();
-
- L +=4;
-
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[1]>>24);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[1]>>16);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[1]>>8);
- buf[L++] = (uint8_t)(mFlash.mStep.stepCur[1]>>0);
-
- int16_t left_adc = hal_GetBatttery_Adc();
- buf[L++] = (uint8_t)(left_adc>>8);
- buf[L++] = (uint8_t)(left_adc);
-
- buf[L++] = (uint8_t)(app_host_GetVolAdc_R()>>8);
- buf[L++] = (uint8_t)(app_host_GetVolAdc_R());
-
- BLE_Client_Tx_Send(0,BLE_UPDATE,buf,L);
- }
- void app_client_infomation_Send(void)
- {
-
-
- uint8_t buf[128];
- uint8_t L = SHOES_NAME_LEN+1;
- int i=0;
-
- memset(buf,0,sizeof(buf));
-
- buf[0] = BLE_UPDATE_BASEINFO;
-
- for(i=0;i<sizeof(SHOES_NAME);i++){
- buf[i+1] = SHOES_NAME[i];
- }
-
- Get_MACaddr(&buf[L]);
-
- L +=6;
-
-
- buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>24);
- buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>16);
- buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>8);
- buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>0);
-
- buf[L++] = (uint8_t)(SOFTWARE_VERSION>>8);
- buf[L++] = (uint8_t)(SOFTWARE_VERSION>>0);
-
-
- for(i=0;i<6;i++) buf[L++] = mFlash.mClient.macAddr[i];
-
- buf[L++] = (uint8_t)((uint32_t)mFlash.mClient.hardVersion>>24);
- buf[L++] = (uint8_t)((uint32_t)mFlash.mClient.hardVersion>>16);
- buf[L++] = (uint8_t)((uint32_t)mFlash.mClient.hardVersion>>8);
- buf[L++] = (uint8_t)((uint32_t)mFlash.mClient.hardVersion>>0);
-
- buf[L++] = (uint8_t)(mFlash.mClient.sotfVersion>>8);
- buf[L++] = (uint8_t)(mFlash.mClient.sotfVersion>>0);
-
- BLE_Client_Tx_Send(0,BLE_UPDATE,buf,L);
- }
- void cb_BLE_Client_R_UPDATE(void* handle)
- {
- BLE_Client_Rx_t *target = handle;
- uint8_t _cmd = target->pDat[0];
- switch(_cmd){
- case BLE_UPDATE_BASEINFO:{
-
-
-
-
- if(1 == mFlash.isHost){
- app_host_GetClientInfo();
- }
- else app_client_infomation_Send();
- break;}
- case BLE_UPDATE_DATA:{
-
-
-
- if(1 == mFlash.isHost){
- app_host_GetClientData(20);
- }
- else app_client_DataUpdate_Send();
- break;}
- case BLE_UPDATE_STEPNUM:{
-
-
- if(!app_step_Real_Get())app_client_SendStep(target);
- break;}
- case BLE_UPDATE_STEPNUM_CLERA:{
-
-
- BLE_Client_Tx_Send(0,BLE_UPDATE,target->pDat,target->datLen);
- app_client_DeleteStep(target);
- break;}
- default:break;
- }
- }
- static void app_client_Process(void)
- {
- static uint8_t cnt =0;
- if(mFlash.isHost)return;
- if(slave_isconnect()){
- if(app_game_GetGameMode()){
- if(cnt++ >= 4){cnt =0;
- app_client_DataUpdate_Send();
- }
- }
- else app_client_DataUpdate_Send();
- }
- }
- void app_client_Initialize(void)
- {
- BLE_Client_Rx_Regist(BLE_UPDATE,cb_BLE_Client_R_UPDATE);
- app_client_step_Initialize();
- Process_Start(2000,"app_client",app_client_Process);
- }
|