123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*********************************************************************
- * INCLUDES
- */
- #include "ble_comm.h"
- #include "app_flash.h"
- #include "app_safe.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "hal_led.h"
- static void app_safe_Process(void)
- {
- static uint8_t cnt =0;
- if(mBackup.ErrStartCnt >0){
- cnt++;
- if(cnt >=60){//一分钟后清空标志位
- mBackup.ErrStartCnt =0;
- if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save ErrStartCnt fail");
- DEBUG_LOG("clear mBackup.ErrorStartFlag\n");
- }
- }
- //测试使用
- static uint8_t temp =0;
- static uint8_t flag =0;
- if(mBackup.RestartCnt > 1 && flag ==0){flag =1;}
-
- if(1 == flag){
- if(temp ==0){temp++;
- Process_SetHoldOn(app_safe_Process,1);
- LED_Start(LED_RESTART,COLOR_PURPLE);
- }
- else if(temp <200){
- temp++;
- if(temp >20){temp =220;
- Process_SetHoldOn(app_safe_Process,0);
- LED_Stop(LED_RESTART);
- flag =2;
- }
- }
- }
-
- if(mBackup.RestartCnt > 1){
-
- char buff[40]={0};
- memset(buff,0,sizeof(buff));
- if(mFlash.isHost){
- sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
- }else{
- sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
- }
- if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
- mBackup.RestartCnt =0;
- }
- }
- }
- //恢复出厂设置
- static void cb_BLE_RESTSETTING(void* handle)
- {
- uint8_t isHost;
- uint8_t LR_FLAG;
-
- isHost = mFlash.isHost;
- LR_FLAG = mFlash.LR_FLAG;
-
- memset((uint8_t*)(&mFlash),0,sizeof(Flash_t));
- memset((uint8_t*)(&mBackup),0,sizeof(FlashBackup_t));
-
- Flash_DeleteAllInfor();
- Flash_DeleteAllStep();
- Flash_DeleteAllBackup();
-
- mFlash.isHost = isHost;
- mFlash.LR_FLAG = LR_FLAG;
-
- Flash_SaveInfomation();
- mBackup.isHost= mFlash.isHost;
- mBackup.LR_FLAG = mFlash.LR_FLAG;
-
- if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_FLASH,"app_detect_LR save backup fail");
-
- BLE_Client_Rx_t* target = handle;
- uint8_t cmd = target->pDat[0];
-
- BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
-
- nrf_delay_ms(500);
-
- NVIC_SystemReset();
- }
- void app_safe_Init(void)
- {
- mBackup.RestartCnt++;
-
- Process_Start(1000,"app_safe",app_safe_Process);
-
- BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
- }
-
|