app_safe.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if(mBackup.RestartCnt > 1){
  22. char buff[40]={0};
  23. memset(buff,0,sizeof(buff));
  24. if(mFlash.isHost){
  25. sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
  26. }else{
  27. sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
  28. }
  29. if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
  30. mBackup.RestartCnt =0;
  31. }
  32. }
  33. }
  34. //恢复出厂设置
  35. static void cb_BLE_RESTSETTING(void* handle)
  36. {
  37. Flash_DeleteAllInfor();
  38. Flash_DeleteAllStep();
  39. Flash_DeleteAllBackup();
  40. BLE_Client_Rx_t* target = handle;
  41. uint8_t cmd = target->pDat[0];
  42. BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
  43. nrf_delay_ms(500);
  44. NVIC_SystemReset();
  45. }
  46. //static void app_CONNTED_LED_Process(void){
  47. // static uint8_t lastconeted =0;
  48. // static uint8_t BlinkTime =0;
  49. // static uint8_t BlinkfLAG =0;
  50. // uint8_t nowconeted =0;
  51. // if(mFlash.isHost)
  52. // nowconeted = host_isconnect();
  53. // else
  54. // nowconeted = slave_isconnect();
  55. //
  56. //// DEBUG_LOG("mFlash.isHost %d,nowconeted:%d,\n",mFlash.isHost,nowconeted);
  57. // if(nowconeted != lastconeted){
  58. // lastconeted = nowconeted;
  59. // if(nowconeted){
  60. // BlinkfLAG =1;
  61. // BlinkTime =0;
  62. // DEBUG_LOG("COLOR_PURPLE\r\n");
  63. // LED_Start(LED_LRCHECK,COLOR_CYAN);
  64. // Process_SetHoldOn(app_CONNTED_LED_Process,1);
  65. // }
  66. // else{
  67. // BlinkfLAG =0;
  68. // BlinkTime =0;
  69. // Process_SetHoldOn(app_CONNTED_LED_Process,0);
  70. // LED_Stop(LED_LRCHECK);
  71. // }
  72. // }
  73. //
  74. // if(BlinkfLAG){BlinkTime++;
  75. // if(BlinkTime <=30){
  76. // BlinkfLAG =1;
  77. // }
  78. // else{
  79. // BlinkfLAG =0;
  80. // BlinkTime =0;
  81. // LED_Stop(LED_LRCHECK);
  82. // }
  83. // }
  84. //}
  85. void app_safe_Init(void)
  86. {
  87. mBackup.RestartCnt++;
  88. Process_Start(1000,"app_safe",app_safe_Process);
  89. // Process_Start(100,"app_CONNTED_LED",app_CONNTED_LED_Process);
  90. BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
  91. }