From daad0e1e0fa586851d37121322ad95bf9e316afe Mon Sep 17 00:00:00 2001 From: kyz Date: Wed, 13 Aug 2025 12:42:16 +0800 Subject: [PATCH] add power on total time --- MDK-ARM/bootloader.uvprojx | 2 +- user/user_app.c | 23 +++++++++++++++++++++++ user/user_report.c | 5 ++--- user/user_valve_ctrl.c | 5 +++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/MDK-ARM/bootloader.uvprojx b/MDK-ARM/bootloader.uvprojx index f39587d..0792529 100644 --- a/MDK-ARM/bootloader.uvprojx +++ b/MDK-ARM/bootloader.uvprojx @@ -339,7 +339,7 @@ USE_HAL_DRIVER,STM32H730xx,BOOTLOADER - ../Core/Inc;../USB_DEVICE/App;../USB_DEVICE/Target;../Drivers/STM32H7xx_HAL_Driver/Inc;../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Middlewares/ST/STM32_USB_Device_Library/Core/Inc;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc;../Drivers/CMSIS/Device/ST/STM32H7xx/Include;../Drivers/CMSIS/Include;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../lib + ../Core/Inc;../USB_DEVICE/App;../USB_DEVICE/Target;../Drivers/STM32H7xx_HAL_Driver/Inc;../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Middlewares/ST/STM32_USB_Device_Library/Core/Inc;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc;../Drivers/CMSIS/Device/ST/STM32H7xx/Include;../Drivers/CMSIS/Include;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../lib;..\user diff --git a/user/user_app.c b/user/user_app.c index 557750f..3fdf1b9 100644 --- a/user/user_app.c +++ b/user/user_app.c @@ -76,6 +76,9 @@ void beep_init( void ); extern void user_rtc_init( void ); extern uint32_t hw_ver_read( void ); +static void device_poweron_total_time_update( uint32_t secs ); + + void StartDefaultTask(void *argument) { EventBits_t uxBits; @@ -95,6 +98,7 @@ void StartDefaultTask(void *argument) dev_cfg_v2_load(&g_dev.cfg2); lfs_load_device_serial(g_dev.serial_number, sizeof(g_dev.serial_number)); g_dev.offline_secs = lfs_load_offline_time(); + g_dev.all_time_total = lfs_load_all_time(); g_dev.hw_ver = hw_ver_read(); @@ -148,6 +152,8 @@ void StartDefaultTask(void *argument) HAL_IWDG_Refresh( &hiwdg1 ); //4s iwdg flow_total_update( 1000 ); //软件计算累计流量 + device_poweron_total_time_update(1); //开机总时长更新 + #if 1 //离线锁定检查, //g_dev.cfg2.offline_max_time, 0:离线不锁定,大于0允许离线时间,到达时间自动锁定。 time_t now = time(NULL); @@ -695,3 +701,20 @@ uint32_t hw_ver_read( void ) return HW_V3; } } + +void device_poweron_total_time_update( uint32_t secs ){ + static int n = 0; + static int welding = 0; + n++; + g_dev.all_time_total += secs; + if( n>=60 ){ + //60秒保存一次 + n = 0; + lfs_store_all_time(g_dev.all_time_total); + }else if( welding != g_dev.welding_start ){ + welding = g_dev.welding_start; + //焊接开始和停止时也保存 + n = 0; + lfs_store_all_time(g_dev.all_time_total); + } +} \ No newline at end of file diff --git a/user/user_report.c b/user/user_report.c index c522b86..9a57a1b 100644 --- a/user/user_report.c +++ b/user/user_report.c @@ -133,7 +133,7 @@ int32_t get_new_rpt_info( rpt_info_t *rpt ) else rpt->gas = 1; } - + rpt->weld_time = g_dev.welding_time_total/1000; #if 1 /* @@ -158,8 +158,7 @@ E10:流量故障 rpt->alarm = 0; } #endif - rpt->on_time = 0; - + rpt->on_time = g_dev.all_time_total; if( memcmp( rpt, &g_rpt_sent, sizeof( g_rpt_sent ) ) ){ rpt->cid++; diff --git a/user/user_valve_ctrl.c b/user/user_valve_ctrl.c index 84990ec..cab668e 100644 --- a/user/user_valve_ctrl.c +++ b/user/user_valve_ctrl.c @@ -408,7 +408,7 @@ void user_valve_set_current( float current ) } extern void welding_data_store( uint16_t index ); //记录焊接数据 - +extern int32_t is_curr_valid( float curr ); //static uint64_t g_welding_time_total = 0; //static uint64_t g_time_total = 0; @@ -480,7 +480,8 @@ void user_valve_ctrl_task( void* unused ) //200毫秒扫描一次, 考虑pid的流量计反馈,让扫描周期大于流量计的采集周期, vTaskDelayUntil(&last_tick, 100 ); welding_current = g_dev.welding_current; - + if( !is_curr_valid( welding_current ) ) + welding_current = 0; // g_time_total += 100; // // static int i = 0; -- 2.34.1