app_safe.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*********************************************************************
  2. * INCLUDES
  3. */
  4. #include "ble_comm.h"
  5. #include "app_flash.h"
  6. #include "app_safe.h"
  7. #include "hal_ble_client.h"
  8. #include "hal_ble_host.h"
  9. static void app_safe_Process(void)
  10. {
  11. static uint8_t cnt =0;
  12. if(mBackup.ErrStartCnt >0){
  13. cnt++;
  14. if(cnt >=6){//一分钟后清空标志位
  15. mBackup.ErrStartCnt =0;
  16. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save ErrStartCnt fail");
  17. DEBUG_LOG("clear mBackup.ErrorStartFlag\n");
  18. }
  19. }
  20. if(mBackup.RestartCnt > 1){
  21. char buff[40]={0};
  22. memset(buff,0,sizeof(buff));
  23. if(mFlash.isHost){
  24. sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
  25. }else{
  26. sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
  27. }
  28. if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
  29. mBackup.RestartCnt =0;
  30. }
  31. }
  32. }
  33. //恢复出厂设置
  34. static void cb_BLE_RESTSETTING(void* handle)
  35. {
  36. Flash_DeleteAllInfor();
  37. Flash_DeleteAllStep();
  38. Flash_DeleteAllBackup();
  39. BLE_Client_Rx_t* target = handle;
  40. uint8_t cmd = target->pDat[0];
  41. BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
  42. nrf_delay_ms(500);
  43. NVIC_SystemReset();
  44. }
  45. void app_safe_Init(void)
  46. {
  47. mBackup.RestartCnt++;
  48. Process_Start(10000,"app_safe",app_safe_Process);
  49. BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
  50. }