| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2026-02-04 Administrator the first version
- */
- #ifndef APPLICATIONS_SYS_MONITOR_H_
- #define APPLICATIONS_SYS_MONITOR_H_
- #include <rtthread.h>
- /* 根据你的MCU字长选择合适的数据类型 */
- typedef uint32_t time_sec_t; // 用于秒级的时间统计
- typedef uint64_t time_ms_t; // 用于毫秒级的时间统计
- typedef uint32_t counter_t; // 用于计数器
- typedef uint16_t small_counter_t; // 用于小计数器
- /* 系统运行统计结构体 */
- typedef struct
- {
- /* 1. 系统运行时间相关 */
- time_sec_t system_uptime; // 系统总运行时长(秒)
- time_sec_t network_connected_time; // 联网时间(秒)
- time_sec_t network_disconnected_time; // 断网时间(秒)
- /* 2. CPU相关 */
- uint8_t cpu_tempture;
- uint8_t cpu_usage; // CPU占用率(0-100%)
- uint8_t cpu_usage_max; // 历史最大CPU占用率
- /* 3. 通信统计 */
- counter_t uart2_rx_bytes; // 串口接收字节数
- counter_t uart2_tx_bytes; // 串口发送字节数
- counter_t json_upload_count; // JSON数据上传次数
- counter_t uart4_rx_bytes; // 串口接收字节数
- counter_t uart4_tx_bytes; // 串口发送字节数
- /* 4. 动作次数统计 */
- counter_t photo_taken_count; // 拍照次数统计
- counter_t cleaning_count; // 清扫次数统计
- counter_t vibration_count; // 震动次数统计
- /* 5. 仓门状态统计 */
- counter_t upper_door_open_count; // 上仓门打开次数
- counter_t upper_door_close_count; // 上仓门关闭次数
- counter_t lower_door_open_count; // 下仓门打开次数
- counter_t lower_door_close_count; // 下仓门关闭次数
- /* 6. 传感器触发统计 */
- counter_t rain_control_triggers; // 雨控触发次数
- counter_t light_control_triggers; // 光控触发次数
- /* 7. 设备运行时间统计 */
- time_sec_t lamp_start_time;
- time_sec_t lamp_running_time; // 灯管运行时间
- time_sec_t heat_start_time;
- time_sec_t heater_running_time; // 加热时间
- time_sec_t fill_light_running_time; // 补光灯运行时间
- /* 8. 时间戳信息(可选) */
- time_sec_t last_reset_time; // 上次重置时间戳
- uint32_t reset_count; // 系统重置次数
- uint32_t rain_value;
- } System_stats_t;
- /* ★ system_status 的唯一定义在 sys_monitor.c。
- 历史写法: 在 5 个 .c 里各写一行 `System_stats_t system_status;`,
- 靠 -fcommon 把 5 个 tentative definition 合并成一个 COMMON 符号。
- 只要谁给它加个初值、或工程换成 -fno-common 编译, 立刻 multiple definition
- —— 这正是 device_status 已经踩过并修掉的同款坑。
- 现在统一 extern 声明, 其余 .c 一律删掉自己的定义。 */
- extern System_stats_t system_status;
- int Sys_Motor_Task(void);
- #endif /* APPLICATIONS_SYS_MONITOR_H_ */
|