From bcb4178b71bfe52c91ed3bd6482f34d8585f1fde Mon Sep 17 00:00:00 2001 From: kyz Date: Thu, 6 Jun 2024 16:02:33 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=84=8A=E6=8E=A5=E6=B0=94?= =?utf8?q?=E4=BD=93=E6=B5=81=E9=87=8F=E9=94=81=E5=AE=9A=E5=8F=82=E6=95=B0?= =?utf8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E8=BF=9C=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Drivers/BSP/Components/lan8742/lan8742.c | 3 +- tools_v2/test.py | 26 ++++++++--- tools_v2/test.ui | 55 +++++++++++++++++++++--- user/user.h | 3 +- user/user_app.c | 5 ++- user/user_cdc_rx_2.c | 17 +++++--- user/user_report.c | 24 +++++++++++ user/user_valve_ctrl.c | 5 ++- 8 files changed, 118 insertions(+), 20 deletions(-) diff --git a/Drivers/BSP/Components/lan8742/lan8742.c b/Drivers/BSP/Components/lan8742/lan8742.c index aacddbc..3378b96 100644 --- a/Drivers/BSP/Components/lan8742/lan8742.c +++ b/Drivers/BSP/Components/lan8742/lan8742.c @@ -20,7 +20,7 @@ /* Includes ------------------------------------------------------------------*/ #include "lan8742.h" - +#include "user.h" /** @addtogroup BSP * @{ */ @@ -150,6 +150,7 @@ int32_t LAN8742_RegisterBusIO(lan8742_Object_t *pObj, lan8742_IOCtx_t *ioctx) /* Wait for 2s to perform initialization */ while((pObj->IO.GetTick() - tickstart) <= LAN8742_INIT_TO) { + osDelay(100); } pObj->Is_Initialized = 1; } diff --git a/tools_v2/test.py b/tools_v2/test.py index c3b2172..ad76a90 100644 --- a/tools_v2/test.py +++ b/tools_v2/test.py @@ -43,7 +43,7 @@ class App( QDialog, ui_welding.Ui_Dialog ): def __init__( self ): super().__init__() self.setupUi(self) - self.setWindowTitle( u"焊接控制器调试工具 V0.6") + self.setWindowTitle( u"焊接控制器调试工具 V0.7") self.trigger_rx_pkt.connect( self.on_rx_pkt ) self.trigger_ctrl_write.connect( self.on_ctrl_write_signal ) @@ -138,7 +138,7 @@ class App( QDialog, ui_welding.Ui_Dialog ): if item == "timer": self.tx_cmd( cmd = 0x00B6, wait=False ) else: - #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存 + #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存, fix_target_flow_x10 method = factor = prev = comp = coeff = bypass_save = bypass = 0x7FFFFFFF if item == "method" : method = 0 if action == "tig" else 1 if action=="mig" else 2 @@ -210,7 +210,7 @@ class App( QDialog, ui_welding.Ui_Dialog ): if self.connected != 0 or self.ser_opened: return if cfg == 1 or cfg == 2: - #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypass_save 4B, bypass 4B + #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypass_save 4B, bypass 4B, fix_target_flow_x10 4B cmd = 0x00B6 elif cfg == 3: cmd = 0x00B8 @@ -227,7 +227,13 @@ class App( QDialog, ui_welding.Ui_Dialog ): if cfg == 1: #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存 cmd = 0x00B7 - d = struct.pack( '>LLLlLLL', + try: + fix_target_flow_x10 = int( float( self.lineEdit_fix_target_flow.text())*10 ) + if fix_target_flow_x10 <0 or fix_target_flow_x10 >500: + fix_target_flow_x10 = 0x7FFFFFFF + except: + fix_target_flow_x10 = 0x7FFFFFFF + d = struct.pack( '>LLLlLLLL', #int(self.lineEdit_cfg_method.text()), self.cb_cfg_method.currentIndex(), int(self.lineEdit_cfg_factor.text()), @@ -235,8 +241,10 @@ class App( QDialog, ui_welding.Ui_Dialog ): 0x7FFFFFFF, #填无效值 comp 0x7FFFFFFF, #填无效值 coeff 修正系数 1 if self.cb_path_save.isChecked() else 0, - 0x7FFFFFFF #填无效值 bypass - ) + 0x7FFFFFFF, #填无效值 bypass + fix_target_flow_x10 + ) + print( "----------write fix target flow:", fix_target_flow_x10 ) print( "write cfg cmd:%04X"%cmd, d.hex()) elif cfg == 2: cmd = 0x00B7 @@ -638,6 +646,12 @@ class App( QDialog, ui_welding.Ui_Dialog ): break self.cb_path_save.setChecked( bypass_save == 1 ) + if len(data) >= 32: + fix_target_flow_x10 = struct.unpack( '>L', data[28:32] )[0] + self.lineEdit_fix_target_flow.setText( "%0.1f"%(fix_target_flow_x10/10) ) + else: + self.lineEdit_fix_target_flow.setText( "" ) + elif cmd == 0x00B8 and len(data)>=128+16: #参数读取 print( "B8 resp:", data.hex() ) #SSID 128B,passwd 16B diff --git a/tools_v2/test.ui b/tools_v2/test.ui index ee61b7c..1375eb3 100644 --- a/tools_v2/test.ui +++ b/tools_v2/test.ui @@ -6,8 +6,8 @@ 0 0 - 1333 - 845 + 1352 + 862 @@ -205,7 +205,7 @@ - 3 + 5 @@ -1834,9 +1834,9 @@ 20 - 30 + 10 421 - 171 + 201 @@ -1986,6 +1986,51 @@ 气路选择断电保存 + + + + 200 + 160 + 41 + 31 + + + + 99.9 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + + + + 40 + 160 + 151 + 31 + + + + 焊接目标流量锁定(0-50.0) + + + + + + 240 + 160 + 41 + 31 + + + + (L/min) + + diff --git a/user/user.h b/user/user.h index 195fb15..f12a407 100644 --- a/user/user.h +++ b/user/user.h @@ -173,7 +173,8 @@ typedef struct{ uint8_t bl; //0-4 5级 uint32_t offline_max_time; //0:离线不锁定; >0:允许离线时间 秒 //使用RTC获取时间 uint32_t offline_start_time; //0:未开始计时; >0:离线开始时间点 秒 //使用RTC获取时间 - uint8_t reserved[16]; + uint32_t fix_flow_x10; //固定流量值单位0.1L, 大于0 小于50L,焊接时忽略焊接电流,固定按这个值供气。 + uint8_t reserved[12]; uint8_t flag; }dev_cfg_v2_t; diff --git a/user/user_app.c b/user/user_app.c index 4c64f04..c779e8d 100644 --- a/user/user_app.c +++ b/user/user_app.c @@ -322,6 +322,7 @@ int32_t dev_cfg_v2_load( dev_cfg_v2_t *cfg ) cfg->bl = 10; cfg->flag = DEV_CFG_V2_FLAG; cfg->offline_max_time = 0; //0为默认禁用(平台协议下发值-1禁用) + cfg->fix_flow_x10 = 0; } //检查参数 @@ -339,7 +340,9 @@ int32_t dev_cfg_v2_load( dev_cfg_v2_t *cfg ) if( cfg->offline_max_time == 0xffffffff ){ cfg->offline_max_time = 0; } - + if( cfg->fix_flow_x10 > 500 ){ + cfg->fix_flow_x10 = 0; + } return 0; } diff --git a/user/user_cdc_rx_2.c b/user/user_cdc_rx_2.c index 6dceaa9..be5f014 100644 --- a/user/user_cdc_rx_2.c +++ b/user/user_cdc_rx_2.c @@ -501,7 +501,7 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) case 0xB5: //焊接数据清0 break; case 0xB6: //设备参数读取 - //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B bypass 4B + //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B bypass 4B,目标流量固定值4B put_u32_big( &resp[0], g_dev.cfg.welding_method ); put_u32_big( &resp[4], g_dev.cfg.save_gas_factor ); put_u32_big( &resp[8], g_dev.cfg.valve_open_default ); @@ -509,10 +509,11 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 ); put_u32_big( &resp[20], g_dev.cfg.bypass_save ); put_u32_big( &resp[24], g_dev.cfg.bypass ); - tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 ); + put_u32_big( &resp[28], g_dev.cfg2.fix_flow_x10 ); + tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 32 ); break; case 0xB7: //设备参数写入 - //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B, bypass 4B + //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B, bypass 4B, 目标流量固定值4B { uint32_t method = get_u32_big( &pkt->pdata[0] ); uint32_t factor = get_u32_big( &pkt->pdata[4] ); @@ -521,6 +522,7 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) uint32_t coeff = get_u32_big( &pkt->pdata[16] ); uint32_t bypass_save = get_u32_big( &pkt->pdata[20] ); uint32_t bypass = get_u32_big( &pkt->pdata[24] ); + uint32_t fix_flow_x10 = get_u32_big( &pkt->pdata[28] ); if( !g_dev.has_bypass ){ bypass = 0; @@ -540,9 +542,13 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) g_dev.cfg.bypass_save = bypass_save; if( bypass == 1 || bypass == 0 ) g_dev.cfg.bypass = bypass; - dev_cfg_store( &g_dev.cfg ); ui_cfg_remote_update(); + + if( pkt->data_len >= 32 && fix_flow_x10 <= 500 ){ + g_dev.cfg2.fix_flow_x10 = fix_flow_x10; + dev_cfg_v2_store( &g_dev.cfg2 ); + } put_u32_big( &resp[0], g_dev.cfg.welding_method ); put_u32_big( &resp[4], g_dev.cfg.save_gas_factor ); @@ -551,7 +557,8 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 ); put_u32_big( &resp[20], g_dev.cfg.bypass_save ); put_u32_big( &resp[24], g_dev.cfg.bypass ); - tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 ); + put_u32_big( &resp[28], g_dev.cfg2.fix_flow_x10 ); + tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 32 ); break; } case 0xB8: //WIFI参数读取 diff --git a/user/user_report.c b/user/user_report.c index 8a58c18..6ce62bd 100644 --- a/user/user_report.c +++ b/user/user_report.c @@ -249,6 +249,15 @@ char * lock_resp_str( void ) "offLineTime":100 } } +//焊接时气体流量固定 +{ + "action":"updateGasFlow", + "timeStamp":1716445485381, + "data":{ + "mac":"123", + "gasFlow":1.1 // 气体流量 范围0-50, 0:焊接时气体流量按电流调节, 大于0: 焊接时气体流量固定到这个值 + } +} //设备回应,原包返回 #endif @@ -261,6 +270,7 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd ) cJSON * gasPathType; cJSON * solarTermFactor; cJSON * offLineTime; + cJSON * item; int32_t act = 0; @@ -316,6 +326,20 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd ) act = 4; //原包回发。 } } + }else if( strcmp( action->valuestring, "updateGasFlow" )== 0 ){ + data = cJSON_GetObjectItem( root, "data" ); + if(data){ + mac = cJSON_GetObjectItem( data, "mac" ); + item = cJSON_GetObjectItem( data, "gasFlow" ); + if( mac && item && strcasecmp( mac->valuestring, g_mac_str ) == 0 ){ + if( item->valuedouble >= 0 && item->valuedouble <= 50 ){ + debug_printf( "fix gasFlow: %d -->%d\n", g_dev.cfg2.fix_flow_x10, item->valuedouble ); + g_dev.cfg2.fix_flow_x10 = (uint32_t)(item->valuedouble * 10); + dev_cfg_v2_store( &g_dev.cfg2 ); + act = 4; //原包回发。 + } + } + } }else if( strcmp( action->valuestring, "unlockDevice" )== 0 ){ debug_printf( "unlockdevice %d->0\n", g_dev.cfg.remote_locked ); g_dev.cfg.remote_locked = 0; diff --git a/user/user_valve_ctrl.c b/user/user_valve_ctrl.c index e81d335..b81685b 100644 --- a/user/user_valve_ctrl.c +++ b/user/user_valve_ctrl.c @@ -544,7 +544,10 @@ void user_valve_ctrl_task( void* unused ) g_dev.welding_time += 100; //0.1秒扫描一次 } - if( calc_target_flow( &target_flowspeed )== 0 ){ + if( g_dev.cfg2.fix_flow_x10 > 0 ){ + //按参数设定值作为目标流量,不考虑焊接电流 + g_dev.target_flowspeed = g_dev.cfg2.fix_flow_x10/10.0f; + }else if( calc_target_flow( &target_flowspeed )== 0 ){ //控制流量输出, 按焊接电流和节气因子计算目标流量 g_dev.target_flowspeed = target_flowspeed; } -- 2.34.1