sys_monitor.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2026-02-04 Administrator the first version
  9. */
  10. #ifndef APPLICATIONS_SYS_MONITOR_H_
  11. #define APPLICATIONS_SYS_MONITOR_H_
  12. #include <rtthread.h>
  13. /* 根据你的MCU字长选择合适的数据类型 */
  14. typedef uint32_t time_sec_t; // 用于秒级的时间统计
  15. typedef uint64_t time_ms_t; // 用于毫秒级的时间统计
  16. typedef uint32_t counter_t; // 用于计数器
  17. typedef uint16_t small_counter_t; // 用于小计数器
  18. /* 系统运行统计结构体 */
  19. typedef struct
  20. {
  21. /* 1. 系统运行时间相关 */
  22. time_sec_t system_uptime; // 系统总运行时长(秒)
  23. time_sec_t network_connected_time; // 联网时间(秒)
  24. time_sec_t network_disconnected_time; // 断网时间(秒)
  25. /* 2. CPU相关 */
  26. uint8_t cpu_tempture;
  27. uint8_t cpu_usage; // CPU占用率(0-100%)
  28. uint8_t cpu_usage_max; // 历史最大CPU占用率
  29. /* 3. 通信统计 */
  30. counter_t uart2_rx_bytes; // 串口接收字节数
  31. counter_t uart2_tx_bytes; // 串口发送字节数
  32. counter_t json_upload_count; // JSON数据上传次数
  33. counter_t uart4_rx_bytes; // 串口接收字节数
  34. counter_t uart4_tx_bytes; // 串口发送字节数
  35. /* 4. 动作次数统计 */
  36. counter_t photo_taken_count; // 拍照次数统计
  37. counter_t cleaning_count; // 清扫次数统计
  38. counter_t vibration_count; // 震动次数统计
  39. /* 5. 仓门状态统计 */
  40. counter_t upper_door_open_count; // 上仓门打开次数
  41. counter_t upper_door_close_count; // 上仓门关闭次数
  42. counter_t lower_door_open_count; // 下仓门打开次数
  43. counter_t lower_door_close_count; // 下仓门关闭次数
  44. /* 6. 传感器触发统计 */
  45. counter_t rain_control_triggers; // 雨控触发次数
  46. counter_t light_control_triggers; // 光控触发次数
  47. /* 7. 设备运行时间统计 */
  48. time_sec_t lamp_start_time;
  49. time_sec_t lamp_running_time; // 灯管运行时间
  50. time_sec_t heat_start_time;
  51. time_sec_t heater_running_time; // 加热时间
  52. time_sec_t fill_light_running_time; // 补光灯运行时间
  53. /* 8. 时间戳信息(可选) */
  54. time_sec_t last_reset_time; // 上次重置时间戳
  55. uint32_t reset_count; // 系统重置次数
  56. uint32_t rain_value;
  57. } System_stats_t;
  58. /* ★ system_status 的唯一定义在 sys_monitor.c。
  59. 历史写法: 在 5 个 .c 里各写一行 `System_stats_t system_status;`,
  60. 靠 -fcommon 把 5 个 tentative definition 合并成一个 COMMON 符号。
  61. 只要谁给它加个初值、或工程换成 -fno-common 编译, 立刻 multiple definition
  62. —— 这正是 device_status 已经踩过并修掉的同款坑。
  63. 现在统一 extern 声明, 其余 .c 一律删掉自己的定义。 */
  64. extern System_stats_t system_status;
  65. /* 刷新实时统计字段(CPU 温度/利用率/运行时长)。
  66. * 原 sys_monitor 后台线程已取消(同步 master):统计改为"用到时现场采集",
  67. * 由控制台命令 top/Msh_DisplaySysMonitor 与 upload_sys_monitor_info() 上报前调用。
  68. * 非阻塞快速操作,可在任意线程上下文安全调用。 */
  69. void sys_monitor_refresh(void);
  70. #endif /* APPLICATIONS_SYS_MONITOR_H_ */