v4.5 上报焊接时长到平台 branch_v4
authorkyz <kongyuzhong@google.com>
Sun, 27 Apr 2025 05:50:48 +0000 (13:50 +0800)
committerkyz <kongyuzhong@google.com>
Sun, 27 Apr 2025 05:50:48 +0000 (13:50 +0800)
user/user.h
user/user_lfs.c
user/user_lfs.h
user/user_report.c
user/user_valve_ctrl.c

index 99c27b4b132e74aa96b860ec2c060208c6a9c3b4..e605dfbb1db2a7db393824eb92535cde0b6a9f44 100644 (file)
@@ -27,7 +27,7 @@
 //#include "fmc.h"
 //--------------------
 #define APP_VER_MAJOR 4
-#define APP_VER_MINOR 4
+#define APP_VER_MINOR 5
 
 #define HW_V2  2
 #define HW_V3  3
index c004ded0d8e7216a328b6b5d649c37bad5aa2186..e5bfb66f6feb343c8f4e4155749aec6359570028 100644 (file)
@@ -165,6 +165,44 @@ int32_t lfs_store_device_serial( char *sn )
     return user_lfs_write( DEVICE_SN_PATH, (uint8_t*)sn, strlen( sn ) ) == strlen(sn)?0:-1;
 }
 
+uint32_t lfs_load_all_time(void)
+{
+       uint32_t secs = 0;
+       if( user_lfs_read( ALL_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+
+    }
+    return secs;
+}
+
+uint32_t lfs_store_all_time(uint32_t secs)
+{
+       int32_t ret = -1;
+
+    if( user_lfs_write( ALL_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+            ret = 0;
+    }
+    return ret;
+}
+
+uint32_t lfs_load_weld_time(void)
+{
+       uint32_t secs = 0;
+       if( user_lfs_read( WELD_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+
+    }
+    return secs;
+}
+
+uint32_t lfs_store_weld_time(uint32_t secs)
+{
+       int32_t ret = -1;
+
+    if( user_lfs_write( WELD_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+            ret = 0;
+    }
+    return ret;
+}
+
 uint32_t lfs_load_offline_time( void )
 {
     uint32_t secs = 0;
index 29157fff9b561feb5a4983a9eb0a0404f92c0a94..5a6881fa0861f6c7c211d4fdd3b8caaecbbd63cd 100644 (file)
@@ -8,7 +8,8 @@
 #define DEVICE_SN_PATH  "device_serial"
 #define DEVICE_CONFIG_PATH "device_config"
 #define DEVICE_CONFIG_V2_PATH "device_config_v2"
-
+#define WELD_TIME_PATH "weld_time"
+#define        ALL_TIME_PATH   "all_time"
 
 int32_t user_lfs_init( void );
 int32_t user_lfs_read( char *path, uint8_t *read_buffer, uint32_t read_size );
@@ -19,4 +20,9 @@ int32_t lfs_load_device_serial( char *read_buffer, uint32_t buffer_size );
 int32_t lfs_store_device_serial( char *sn );
 uint32_t lfs_load_offline_time( void );
 int32_t lfs_store_offline_time( uint32_t secs );
+uint32_t lfs_store_weld_time(uint32_t secs);
+uint32_t lfs_load_weld_time(void);
+uint32_t lfs_store_all_time(uint32_t secs);
+uint32_t lfs_load_all_time(void);
+
 #endif //__USER_LFS_H__
index 3c937008f095223fcc69815f28263cfc194fcbde..1c683491b013f03054283233518ebaa6883ed6cc 100644 (file)
@@ -36,7 +36,8 @@ static const char *fmt = "{\n\
 \"val\":{\n\
  \"c\":\"%0.1f\",\n\
  \"s\":\"%d\",\n\
- \"g\":\"%0.1f\"\n\
+ \"g\":\"%0.1f\",\n\
+ \"v\":\"%0.1f\"\n\
 },\n\
 \"weldTech\":\"%s\",\n\
 \"solarTermFactor\":\"%d\",\n\
@@ -49,7 +50,10 @@ static const char *fmt = "{\n\
 \"gasPathType\":%d,\n\
 \"airRatio\":%d,\n\
 \"syncFrequency\":%d,\n\
-\"gasType\":%d\n\
+\"gasType\":%d,\n\
+\"totalTime\":%d,\n\
+\"alarmType\":%s,\n\
+\"onTime\":%d\n\
 }";
 
 #endif
@@ -62,6 +66,7 @@ typedef struct{
        uint32_t curr_x10;
        uint32_t weld_st;
        uint32_t flow_x10;
+       uint32_t vol_x10;//电压
        uint32_t weld_tech;
        uint32_t factor;
        uint32_t pressure;
@@ -74,6 +79,9 @@ typedef struct{
        uint32_t prev;
        uint32_t freq;
        uint32_t gas; //1,2,3
+       uint32_t weld_time;
+       uint32_t alarm;//1,2,3
+       uint32_t on_time;
 }rpt_info_t;
 
 static rpt_info_t g_rpt_sent;
@@ -102,6 +110,7 @@ int32_t get_new_rpt_info( rpt_info_t *rpt )
        rpt->curr_x10 = (uint32_t)(welding_curr_disp_value( g_dev.welding_current )*10);
        rpt->weld_st = g_dev.welding_start;
        rpt->flow_x10 = (uint32_t)(g_dev.flowmeter.flow_speed*10);
+       rpt->vol_x10  = 0; //(uint32_t)(g_dev.welding_voltage*10);
        rpt->weld_tech = g_dev.cfg.welding_method;
        rpt->factor = g_dev.cfg.save_gas_factor,
        rpt->pressure = (uint32_t)g_dev.pressure;
@@ -113,7 +122,7 @@ int32_t get_new_rpt_info( rpt_info_t *rpt )
        rpt->path = g_dev.cfg.bypass?0:1, //平台定义节气为1, 旁路为0
        rpt->prev = g_dev.cfg.valve_open_default;
        rpt->freq = g_dev.cfg.iot_rpt_period;
-       
+
        if( g_dev.cfg2.gas > GAS_DEFAULT && g_dev.cfg2.gas <=  GAS_MAX ){
                rpt->gas  = g_dev.cfg2.gas;
        }else{
@@ -125,6 +134,33 @@ int32_t get_new_rpt_info( rpt_info_t *rpt )
                        rpt->gas = 1;
        }
 
+       rpt->weld_time = g_dev.welding_time_total/1000;
+#if 1
+/*
+E1 :电流传感器故障
+E2:流量计故障
+E3:压力计故障
+E9:漏气故障
+E10:流量故障
+*/
+       rpt->alarm = g_dev.state;
+#else
+       if(g_dev.alarm.leakage == 1)
+       {
+               rpt->alarm = 2;
+       }
+       else if(g_dev.alarm.flow_rate_low == 1)
+       {
+               rpt->alarm = 1;
+       }
+       else
+       {
+               rpt->alarm = 0;
+       }
+#endif
+       rpt->on_time = 0;
+
+
        if( memcmp( rpt, &g_rpt_sent, sizeof( g_rpt_sent ) ) ){
                rpt->cid++;
                return 0;
@@ -167,6 +203,31 @@ static void mac_str_init( void )
 static const char * weld_method_str[3] = {"TIG", "MIG", "MAG" };
 
 
+char *rpt_fault_code( uint32_t alarm )
+{
+       static char falt_code[128];
+       char buf[16];
+       int nr;
+
+       if( alarm == 0 ){
+               strcpy( falt_code, "[ 0 ]" );
+       }else{
+               sprintf( falt_code, "[ " );
+               nr = 0;
+               for( int i=0; i<32; i++ ){
+                       if( alarm& (1<<i)){
+                               if( nr )
+                                       sprintf( buf, ", %d", i+1 );
+                               else
+                                       sprintf( buf, "%d", i+1 );
+                               nr++;
+                               strcat( falt_code, buf );
+                       }
+               }
+               strcat( falt_code, " ]" );
+       }
+       return falt_code;
+}
 
 char * devinfo_report_str( void )
 {
@@ -197,6 +258,7 @@ char * devinfo_report_str( void )
                    g_rpt_sent.curr_x10/10.0f,
                          g_rpt_sent.weld_st,
                          g_rpt_sent.flow_x10/10.0f,
+                         g_rpt_sent.vol_x10/10.0f,
         weld_method_str[g_rpt_sent.weld_tech],
                          g_rpt_sent.factor,
                          g_rpt_sent.pressure,
@@ -208,7 +270,10 @@ char * devinfo_report_str( void )
                          g_rpt_sent.path,
                          g_rpt_sent.prev,
                          g_rpt_sent.freq,
-                         g_rpt_sent.gas
+                         g_rpt_sent.gas,
+                         g_rpt_sent.weld_time,
+                         rpt_fault_code(g_rpt_sent.alarm),
+                         g_rpt_sent.on_time
                                );
        last_rpt_tick = now;
     return tx_buf;
index a3481605ff6545da12bbb508a69ab7bae3e7f764..f64500dec962d7a207e552d08cbaf97c2b4c5378 100644 (file)
@@ -424,7 +424,7 @@ void user_valve_ctrl_task( void* unused )
 
     HAL_DAC_SetValue( &hdac1, DAC_CHANNEL_2, DAC_ALIGN_12B_R, 0 );
     HAL_DAC_Start(&hdac1, DAC_CHANNEL_2);
-       
+
        g_dev.welding_time_total = lfs_load_weld_time() * 1000;  //sec x 1000 -> ms
 
 #if 0