app_safe.c 1.7 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. if(1 == flag){
  26. if(temp ==0){temp++;
  27. Process_SetHoldOn(app_safe_Process,1);
  28. LED_Start(LED_RESTART,COLOR_PURPLE);
  29. }
  30. else if(temp <200){
  31. temp++;
  32. if(temp >20){temp =220;
  33. Process_SetHoldOn(app_safe_Process,0);
  34. LED_Stop(LED_RESTART);
  35. flag =2;
  36. }
  37. }
  38. }
  39. if(mBackup.RestartCnt > 1){
  40. char buff[40]={0};
  41. memset(buff,0,sizeof(buff));
  42. if(mFlash.isHost){
  43. sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
  44. }else{
  45. sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
  46. }
  47. if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
  48. mBackup.RestartCnt =0;
  49. }
  50. }
  51. }
  52. //恢复出厂设置
  53. static void cb_BLE_RESTSETTING(void* handle)
  54. {
  55. Flash_DeleteAllInfor();
  56. Flash_DeleteAllStep();
  57. Flash_DeleteAllBackup();
  58. BLE_Client_Rx_t* target = handle;
  59. uint8_t cmd = target->pDat[0];
  60. BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
  61. nrf_delay_ms(500);
  62. NVIC_SystemReset();
  63. }
  64. void app_safe_Init(void)
  65. {
  66. mBackup.RestartCnt++;
  67. Process_Start(1000,"app_safe",app_safe_Process);
  68. BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
  69. }