#include "system.h" #include "app_client_step.h" #include "app_flash.h" #include "bsp_time.h" #include "system.h" #include "app_host.h" #include "app_step.h" #include "ble_comm.h" #include "app_flash.h" /************************ 函数定义 ***************************/ void cb_BLE_Client_T_UPDATE_STEPNUM(void* handle); /************************ 获取步数 ***************************/ static uint32_t timeCNT = 0; static uint8_t isScan = 0; uint8_t app_client_step_GetIsScan(void) { return isScan; } static void app_client_step_Process(void) { uint32_t sec = 0; static uint32_t cnt_b=0; uint32_t cnt = NRF_RTC0->COUNTER; if(cnt= 130000 )SEGGER_RTT_printf(0,"!!!!!!!!!!!!!!! sec over,%d,%d,%d\n",cnt,cnt_b,sec); if(cnt >16777216)cnt_b = cnt - 16777216; else cnt_b = cnt; // SEGGER_RTT_printf(0,"timeCNT(%d)(%d)\n",timeCNT,sec); if(sec>=60*60-10) isScan = 1; if(sec>=60*60){ SEGGER_RTT_printf(0,"====>1 hour:%d,%d,%d\n",timeCNT,sec,TIME_GetTicks()/1000); timeCNT = 0; Flash_SaveStep(); Flash_SaveInfomation(); isScan = 0; } } /************************ 删除步数 ***************************/ void app_client_DeleteStep(BLE_Client_Rx_t* target) { for(uint8_t i=0;i<8;i++) mFlash.mStep.startTime[i] = target->pDat[i+1]; Flash_DeleteAllStep(); } /************************ 发送步数 ***************************/ #define PACK_STEP_LEN 40 //发送 PACK_STEP_LEN*4 个字节 static uint8_t isSendAll = 0; static uint16_t packDex = 0; static uint16_t packNum = 0; static uint16_t lastNum = 0; BLE_Client_Tx_t mSendStep = { .n = 1, .t = 1, .cb = cb_BLE_Client_T_UPDATE_STEPNUM, }; void app_client_SendStepAll(uint16_t n) { static uint8_t buf[250]; uint8_t L=0; uint32_t addr = (Flash_GetStepZoneStartAddr()+PACK_STEP_LEN*4*(n-1)); buf[L++] = BLE_Client_T_UPDATE_STEPNUM; for(int i=0;i<8;i++){buf[L++] = mFlash.mStep.startTime[i];} buf[L++] = (uint8_t)(packNum>>8); buf[L++] = (uint8_t)(packNum>>0); buf[L++] = (uint8_t)(n>>8); buf[L++] = (uint8_t)(n>>0); if(n==0){ uint32_t step = app_step_GetStep_L() + app_step_GetStep_R(); //SEGGER_RTT_printf(0,"====>step=%d,app_step_GetStep_L()=%d,app_step_GetStep_R()=%d\n",step,app_step_GetStep_L(),app_step_GetStep_R()); buf[L++] = (uint8_t)(step>>24); buf[L++] = (uint8_t)(step>>16); buf[L++] = (uint8_t)(step>>8); buf[L++] = (uint8_t)(step>>0); }else if(n==packNum){ Zone_Read(addr,(uint32_t*)&buf[L],lastNum*4); L+=lastNum*4; }else{ Zone_Read(addr,(uint32_t*)&buf[L],PACK_STEP_LEN*4); L+=PACK_STEP_LEN*4; } SEGGER_RTT_printf(0,"app_client_SendStepAll:"); for(int i=0;i>8); buf[L++] = (uint8_t)(packNum>>0); buf[L++] = (uint8_t)(n>>8); buf[L++] = (uint8_t)(n>>0); if(n==packNum){ Zone_Read(addr,(uint32_t*)&buf[L],lastNum*4); L+=lastNum*4; }else{ Zone_Read(addr,(uint32_t*)&buf[L],PACK_STEP_LEN*4); L+=PACK_STEP_LEN*4; } SEGGER_RTT_printf(0,"app_client_SendStepN:"); for(int i=0;ipDat[1]<<8)|((uint16_t)target->pDat[2]<<0); if(mFlash.mStep.num>0){ packNum = ((mFlash.mStep.num-1)/PACK_STEP_LEN)+1; lastNum = ((mFlash.mStep.num-1)%PACK_STEP_LEN)+1; }else{ packNum = 0; lastNum = 0; } //SEGGER_RTT_printf(0,"====>mFlash.mStep.num=%d,packNum=%d,lastNum=%d\n",mFlash.mStep.num,packNum,lastNum); if(n==0){ isSendAll = 1; packDex = 0; app_client_SendStepAll(packDex); }else{ app_client_SendStepN(n); } } static void cb_BLE_Client_T_UPDATE_STEPNUM(void* handle) { if(isSendAll==0) return; if(packDex=packNum) isSendAll = 0; app_client_SendStepAll(packDex); } } /************************ 初始化 ***************************/ void app_client_step_Initialize(void) { Process_Start(1000,"app_client_step",app_client_step_Process); }