ecode.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2026, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2026-03-06 user first version
  9. */
  10. #ifndef __ECODE_H__
  11. #define __ECODE_H__
  12. #include <rtthread.h>
  13. #include <stdint.h>
  14. #define ECODE_MAGIC 0xEC0DE09D
  15. #define ECODE_VERSION 3
  16. #include "peri.h"
  17. extern struct rtc_time time_now;
  18. typedef enum
  19. {
  20. e_reboot = 1,
  21. e_clearecode,
  22. e_test_fun,
  23. e_update_timeout,
  24. e_bak_restore,
  25. e_bak_backup,
  26. e_update,
  27. e_update_ok,
  28. e_update_fail,
  29. e_update_WSUCC,
  30. e_update_WFAIL,
  31. e_hardfault,
  32. e_iwdg,
  33. e_mqtt0_outtime,
  34. e_BL,
  35. e_GUARD_NET,
  36. e_NET_INIT_FAIL,
  37. e_tilt_trigger,
  38. e_tilt_restore,
  39. e_rain_trigger,
  40. e_rain_restore,
  41. e_WARN,
  42. e_protect,
  43. e_work_start,
  44. e_work_stop,
  45. e_work_resume,
  46. e_platform_chg,
  47. e_mqtt_cmd,
  48. e_hv_info,
  49. e_protect_stopwork,
  50. e_CMD_restartwork,
  51. e_upload_ecode,
  52. e_para_setdef,
  53. e_work_without_ntp,
  54. e_SYSWATCH_KILL,
  55. e_typeMAX
  56. } ecode_list;
  57. typedef struct __attribute__((packed))
  58. {
  59. struct TM time_stamp; // 时间戳
  60. uint16_t code; // 异常码
  61. uint16_t para; // 附带参数
  62. uint32_t num; // 序号(全局递增)
  63. char detail[50]; // 内容
  64. } ecode_record_t;
  65. void Recode_e_code(ecode_list code, uint16_t para, char *detail);
  66. int ecode_read(uint32_t index, ecode_record_t *rec);
  67. uint32_t ecode_get_count(void);
  68. void ecode_clear(void);
  69. #endif /* __ECODE_H__ */