app_safe.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "hal_led.h"
  10. static void app_safe_Process(void)
  11. {
  12. static uint8_t cnt =0;
  13. if(mBackup.ErrStartCnt >0){
  14. cnt++;
  15. if(cnt >=60){//一分钟后清空标志位
  16. mBackup.ErrStartCnt =0;
  17. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save ErrStartCnt fail");
  18. DEBUG_LOG("clear mBackup.ErrorStartFlag\n");
  19. }
  20. }
  21. // //测试使用
  22. // static uint8_t temp =0;
  23. // static uint8_t flag =0;
  24. // if(mBackup.RestartCnt > 1 && flag ==0){flag =1;}
  25. //
  26. // if(1 == flag){
  27. // if(temp ==0){temp++;
  28. // Process_SetHoldOn(app_safe_Process,1);
  29. // LED_Start(LED_RESTART,COLOR_PURPLE);
  30. // }
  31. // else if(temp <200){
  32. // temp++;
  33. // if(temp >20){temp =220;
  34. // Process_SetHoldOn(app_safe_Process,0);
  35. // LED_Stop(LED_RESTART);
  36. // flag =2;
  37. // }
  38. // }
  39. // }
  40. if(mBackup.RestartCnt > 1){
  41. char buff[40]={0};
  42. memset(buff,0,sizeof(buff));
  43. if(mFlash.isHost){
  44. sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
  45. }else{
  46. sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
  47. }
  48. if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
  49. mBackup.RestartCnt =0;
  50. }
  51. }
  52. }
  53. //恢复出厂设置
  54. static void cb_BLE_RESTSETTING(void* handle)
  55. {
  56. Flash_DeleteAllInfor();
  57. Flash_DeleteAllStep();
  58. Flash_DeleteAllBackup();
  59. BLE_Client_Rx_t* target = handle;
  60. uint8_t cmd = target->pDat[0];
  61. BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
  62. nrf_delay_ms(500);
  63. NVIC_SystemReset();
  64. }
  65. void app_safe_Init(void)
  66. {
  67. mBackup.RestartCnt++;
  68. Process_Start(1000,"app_safe",app_safe_Process);
  69. BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
  70. }