sys_monitor.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "sys_monitor.h"
  11. #include "cpu_usage.h"
  12. #include "control.h"
  13. #include "sht30_collect.h"
  14. #define DBG_ENABLE
  15. #define DBG_COLOR
  16. #define DBG_TAG "sysmonitor"
  17. #define DBG_LEVEL DBG_LOG
  18. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  19. rt_thread_t tid_sys_monitor = RT_NULL;
  20. Device_Status_typedef device_status;
  21. System_stats_t system_status;
  22. static void sys_monitor_thread_entry(void *parameter)
  23. {
  24. uint8_t sec_t;
  25. system_status.lamp_start_time = 0;
  26. system_status.heat_start_time = 0;
  27. while(1)
  28. {
  29. sec_t++;
  30. system_status.cpu_usage = (int)cpu_load_average();
  31. if(system_status.cpu_usage>system_status.cpu_usage_max){
  32. system_status.cpu_usage_max = system_status.cpu_usage;
  33. }
  34. rt_tick_t tick = rt_tick_get();
  35. rt_uint32_t total_sec = (rt_uint32_t)(tick / RT_TICK_PER_SECOND);
  36. system_status.system_uptime = total_sec;
  37. system_status.cpu_tempture = (int)Get_Temprate()/100;
  38. rt_uint32_t hours = total_sec / 3600;
  39. rt_uint32_t minutes = (total_sec % 3600) / 60;
  40. rt_uint32_t seconds = total_sec % 60;
  41. rt_thread_delay(1000);
  42. if(sec_t%10==0){
  43. LOG_D("CPU温度:%d℃",system_status.cpu_tempture);
  44. LOG_D("CPU利用率 :%d% Max:%d%",system_status.cpu_usage,system_status.cpu_usage_max);
  45. LOG_D("系统运行时长:%d时%d分%d秒",hours,minutes,seconds);
  46. LOG_D("重启次数:%d",device_status.rebootcnt);
  47. LOG_D("串口2累计发送字节:%d",system_status.uart2_tx_bytes);
  48. LOG_D("串口2累计接收字节:%d",system_status.uart2_rx_bytes);
  49. LOG_D("串口4累计发送字节:%d",system_status.uart4_tx_bytes);
  50. LOG_D("串口4累计接收字节:%d",system_status.uart4_rx_bytes);
  51. LOG_D("累计上传数据:%d 条",system_status.json_upload_count);
  52. LOG_D("累计拍照次数:%d ",system_status.photo_taken_count);
  53. LOG_D("累计清扫次数:%d ",system_status.cleaning_count);
  54. LOG_D("累计震动次数:%d ",system_status.vibration_count);
  55. LOG_D("上仓门累计打开:%d ",system_status.upper_door_open_count);
  56. LOG_D("上仓门累计关闭:%d ",system_status.upper_door_close_count);
  57. LOG_D("下仓门累计打开:%d ",system_status.lower_door_open_count);
  58. LOG_D("下仓门累计关闭:%d ",system_status.lower_door_close_count);
  59. LOG_D("灯管累计运行:%d S",system_status.lamp_running_time/RT_TICK_PER_SECOND);
  60. LOG_D("加热累计运行:%d S",system_status.heater_running_time/RT_TICK_PER_SECOND);
  61. }
  62. }
  63. }
  64. int Sys_Motor_Task(void)
  65. {
  66. /* 创建线程*/
  67. tid_sys_monitor = rt_thread_create("sys_monitor",
  68. sys_monitor_thread_entry, RT_NULL,
  69. 1024, //2048
  70. 28, //12
  71. 5); //5
  72. if(tid_sys_monitor!=RT_NULL)
  73. {
  74. rt_thread_startup(tid_sys_monitor);
  75. }
  76. return 0;
  77. }