zxl 3 недель назад
Родитель
Сommit
ad417a6a7e

+ 29 - 4
src/main/java/com/mes/config/HgLineProfiles.java

@@ -3,7 +3,9 @@ package com.mes.config;
 import java.util.List;
 
 /**
- * 弧焊产线 PLC IP 预设:配置 {@code mes.line-profile} 后自动套到五站。
+ * 弧焊产线 PLC IP 预设:配置 {@code mes.line-profile} 后自动套到当前五站 IP。
+ * 工位编码在 yml {@code mes.line-stations}(三条线共 15 个)自配,这里不覆盖。
+ * 端口按 IP:.2/.6/.11/.16 → 5020,其余 5006。
  * <ul>
  *   <li>T13J:.51 / .56 / .61 / .66 / .71</li>
  *   <li>T1E:.26 / .31 / .36 / .41 / .46</li>
@@ -14,6 +16,10 @@ public final class HgLineProfiles {
 
 	/** 默认产线 */
 	public static final String DEFAULT = "T13J";
+	/** 多数站 MC UDP 端口 */
+	public static final int PORT_DEFAULT = 5006;
+	/** T1GC 前四站(.2/.6/.11/.16)MC UDP 端口 */
+	public static final int PORT_T1GC_FRONT = 5020;
 
 	private static final String[] IPS_T13J = {
 			"192.168.31.51", "192.168.31.56", "192.168.31.61", "192.168.31.66", "192.168.31.71"
@@ -55,11 +61,25 @@ public final class HgLineProfiles {
 	}
 
 	/**
-	 * 按工位 id(1~5)或列表顺序,把产线 IP 写进 stations.plcIp。
+	 * 按 PLC IP 选 MC UDP 端口:192.168.31.2/.6/.11/.16 → 5020,其余 → 5006。
+	 */
+	public static int portOf(String plcIp) {
+		String ip = plcIp == null ? "" : plcIp.trim();
+		if ("192.168.31.2".equals(ip)
+				|| "192.168.31.6".equals(ip)
+				|| "192.168.31.11".equals(ip)
+				|| "192.168.31.16".equals(ip)) {
+			return PORT_T1GC_FRONT;
+		}
+		return PORT_DEFAULT;
+	}
+
+	/**
+	 * 按工位 id(1~5)只写产线 PLC IP;station-sn / title 保持 yml(line-stations)原值。
 	 *
 	 * @return 实际生效的产线名
 	 */
-	public static String applyToStations(String profile, List<MesClientProperties.StationConfig> stations) {
+	public static String applyPlcIp(String profile, List<MesClientProperties.StationConfig> stations) {
 		String p = normalize(profile);
 		if (stations == null || stations.isEmpty()) {
 			return p;
@@ -71,11 +91,16 @@ public final class HgLineProfiles {
 			}
 			int idx = s.getId() - 1;
 			if (idx < 0 || idx >= ips.length) {
-				// id 异常时按列表顺序兜底无意义,跳过
 				continue;
 			}
 			s.setPlcIp(ips[idx]);
 		}
 		return p;
 	}
+
+	/** @deprecated 用 {@link #applyPlcIp};保留兼容旧调用名 */
+	@Deprecated
+	public static String applyToStations(String profile, List<MesClientProperties.StationConfig> stations) {
+		return applyPlcIp(profile, stations);
+	}
 }

+ 43 - 5
src/main/java/com/mes/config/MesClientProperties.java

@@ -3,11 +3,13 @@ package com.mes.config;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 柔性线一拖五客户端配置,对应 application.yml 中 {@code mes.*}。
- * 工位列表驱动多 PLC;upload 路径/参数档由各工位类型客户端自行配置。
+ * 三条产线各 5 站工位编码在 {@code line-stations} 自配;切 {@code line-profile} 启用其中一组。
  */
 @ConfigurationProperties(prefix = "mes")
 public class MesClientProperties {
@@ -38,10 +40,17 @@ public class MesClientProperties {
 	private boolean autoNextOnPush = true;
 	/**
 	 * 产线开关:T13J / T1E / T1GC。
-	 * 启动时按 {@link HgLineProfiles} 自动填充五站 plc-ip。
+	 * 启动时从 {@link #lineStations} 取出该线 5 站,再按 {@link HgLineProfiles} 填 PLC IP。
 	 */
 	private String lineProfile = HgLineProfiles.DEFAULT;
-	/** 五工位配置(编码 + Tab;plc-ip 由 line-profile 自动适配) */
+	/**
+	 * 三条产线各自的五站配置(共 15 个工位编码),key=T13J/T1E/T1GC。
+	 * 工位编码、标题在 yml 自配。
+	 */
+	private Map<String, List<StationConfig>> lineStations = new LinkedHashMap<String, List<StationConfig>>();
+	/**
+	 * 当前启用产线的五站(启动时由 line-profile + line-stations 解析填入,业务只读这里)。
+	 */
 	private List<StationConfig> stations = new ArrayList<StationConfig>();
 
 	/** 兼容旧字段,主流程不读 */
@@ -57,11 +66,11 @@ public class MesClientProperties {
 	public static class StationConfig {
 		/** 序号 1~5 */
 		private int id;
-		/** 柔性工位编码(入队/取码/过站,不分 A/B) */
+		/** 柔性工位编码(入队/取码/过站),在 line-stations 里配 */
 		private String stationSn = "";
 		/** 该站 PLC IP(三菱);启动时由 line-profile 自动填充 */
 		private String plcIp = "";
-		/** Tab 显示名 */
+		/** Tab 显示名,在 line-stations 里配 */
 		private String title = "";
 
 		public int getId() {
@@ -169,6 +178,14 @@ public class MesClientProperties {
 		this.lineProfile = lineProfile;
 	}
 
+	public Map<String, List<StationConfig>> getLineStations() {
+		return lineStations;
+	}
+
+	public void setLineStations(Map<String, List<StationConfig>> lineStations) {
+		this.lineStations = lineStations;
+	}
+
 	public List<StationConfig> getStations() {
 		return stations;
 	}
@@ -177,6 +194,27 @@ public class MesClientProperties {
 		this.stations = stations;
 	}
 
+	/**
+	 * 按产线名取出 yml 里配置的五站(不改 IP)。
+	 * key 大小写不敏感;找不到则空列表。
+	 */
+	public List<StationConfig> stationsOfLine(String profile) {
+		String p = HgLineProfiles.normalize(profile);
+		if (lineStations == null || lineStations.isEmpty()) {
+			return new ArrayList<StationConfig>();
+		}
+		List<StationConfig> hit = lineStations.get(p);
+		if (hit != null) {
+			return hit;
+		}
+		for (Map.Entry<String, List<StationConfig>> e : lineStations.entrySet()) {
+			if (e.getKey() != null && p.equalsIgnoreCase(e.getKey().trim())) {
+				return e.getValue() == null ? new ArrayList<StationConfig>() : e.getValue();
+			}
+		}
+		return new ArrayList<StationConfig>();
+	}
+
 	public String getGw() {
 		return gw;
 	}

+ 2 - 2
src/main/java/com/mes/service/HgPlcClient.java

@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
 /**
  * 单工位弧焊 PLC(三菱 MC UDP binary):一拖五每站独立连接。
  * <p>
- * 现场约定:MC 协议 UDP 二进制,默认端口 5006。
+ * 现场约定:MC 协议 UDP 二进制;多数站 5006,192.168.31.2/.6/.11/.16 为 5020。
  * 断线重连:指数退避 2s→4s→8s→16s→30s(封顶后固定 30s),连上后复位。
  * 点位:L180=MES允许启动;M1200 设备运行;A/B 面 M1216/1222、M1217/1223;
  * R1=D822/803/805+D970;R2=D826/807/809+D980。
@@ -20,7 +20,7 @@ public class HgPlcClient {
 
 	private static final Logger log = LoggerFactory.getLogger(HgPlcClient.class);
 
-	/** 现场 MC UDP binary 端口 */
+	/** 现场 MC UDP binary 默认端口(特殊 IP 见 {@link com.mes.config.HgLineProfiles#portOf}) */
 	public static final int DEFAULT_PORT = 5006;
 	/** UDP 收包超时(毫秒) */
 	private static final int RECEIVE_TIMEOUT_MS = 5000;

+ 8 - 5
src/main/java/com/mes/ui/MainFrame.java

@@ -165,17 +165,20 @@ public class MainFrame extends JFrame {
 		}
 		user20 = mes_user_code;
 		mes_auto_next_on_push = p.isAutoNextOnPush();
-		List<MesClientProperties.StationConfig> list = p.getStations();
-		// 产线开关:按 T13J / T1E / T1GC 自动套五站 PLC IP
-		String line = HgLineProfiles.applyToStations(p.getLineProfile(), list);
+		// 产线开关:从 line-stations 取该线 5 站工位编码,再只套 PLC IP
+		String line = HgLineProfiles.normalize(p.getLineProfile());
 		p.setLineProfile(line);
+		List<MesClientProperties.StationConfig> list = p.stationsOfLine(line);
+		HgLineProfiles.applyPlcIp(line, list);
+		p.setStations(list);
 		if (list == null || list.isEmpty()) {
-			log.warn("mes.stations 为空,请在 application.yml 配置五工位");
+			log.warn("产线[{}] 无工位:请在 application.yml 的 mes.line-stations.{} 配置 5 站", line, line);
 		} else {
 			log.info("加载工位数={} 产线={} upload={} profile={}",
 					list.size(), line, mes_upload_path, mes_param_profile);
 			for (MesClientProperties.StationConfig s : list) {
-				log.info("工位 id={} sn={} plc={}", s.getId(), s.getStationSn(), s.getPlcIp());
+				log.info("工位 id={} sn={} title={} plc={}:{}", s.getId(), s.getStationSn(), s.getTitle(),
+						s.getPlcIp(), Integer.valueOf(HgLineProfiles.portOf(s.getPlcIp())));
 			}
 		}
 		// 标题带上产线,现场一眼能看出来

+ 12 - 5
src/main/java/com/mes/ui/StationPanel.java

@@ -2,6 +2,7 @@ package com.mes.ui;
 
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.mes.config.HgLineProfiles;
 import com.mes.config.MesClientProperties;
 import com.mes.entity.WeldParams;
 import com.mes.service.HgPlcClient;
@@ -91,7 +92,8 @@ public class StationPanel extends JPanel {
 		this.cfg = cfg;
 		this.serverIp = serverIp == null ? "" : serverIp.trim();
 		this.userCode = (userCode == null || userCode.trim().isEmpty()) ? "system" : userCode.trim();
-		this.plc = new HgPlcClient(cfg.getStationSn(), cfg.getPlcIp());
+		// 端口按 IP:.2/.6/.11/.16 → 5020,其余 5006
+		this.plc = new HgPlcClient(cfg.getStationSn(), cfg.getPlcIp(), HgLineProfiles.portOf(cfg.getPlcIp()));
 
 		setLayout(new BorderLayout(0, 0));
 		setBackground(UiTheme.BG);
@@ -116,8 +118,7 @@ public class StationPanel extends JPanel {
 		titleCol.add(lblStation);
 		titleCol.add(Box.createVerticalStrut(3));
 		titleCol.add(lblCode);
-		// 现场 MC UDP binary:5006
-		lblPlc = new JLabel("PLC " + nvl(cfg.getPlcIp()) + ":5006(UDP)  ·  未连接");
+		lblPlc = new JLabel(plcAddrText(false));
 		lblPlc.setFont(UiTheme.FONT_BODY);
 		UiTheme.stylePlcPill(lblPlc, false);
 		serverHeartbeat = new BreathingLight();
@@ -777,16 +778,22 @@ public class StationPanel extends JPanel {
 			@Override
 			public void run() {
 				if (ok) {
-					lblPlc.setText("PLC " + nvl(cfg.getPlcIp()) + ":5006(UDP)  ·  已连接" + (runUi ? " · 设备运行" : ""));
+					lblPlc.setText(plcAddrText(true) + (runUi ? " · 设备运行" : ""));
 					UiTheme.stylePlcPill(lblPlc, true);
 				} else {
-					lblPlc.setText("PLC " + nvl(cfg.getPlcIp()) + ":5006(UDP)  ·  未连接");
+					lblPlc.setText(plcAddrText(false));
 					UiTheme.stylePlcPill(lblPlc, false);
 				}
 			}
 		});
 	}
 
+	/** 顶栏 PLC 地址文案(含按 IP 解析的 UDP 端口) */
+	private String plcAddrText(boolean connected) {
+		return "PLC " + nvl(cfg.getPlcIp()) + ":" + plc.getPlcPort() + "(UDP)  ·  "
+				+ (connected ? "已连接" : "未连接");
+	}
+
 	/** 按 MainFrame SSE 连接状态刷新呼吸灯 */
 	private void uiServerHeartbeat() {
 		final boolean online = MainFrame.isMesServerOnline();

+ 56 - 22
src/main/resources/config/application.yml

@@ -11,7 +11,7 @@ logging:
     root: INFO
     com.mes: INFO
 
-# 弧焊一拖五:每站一个工位编码 + 一台三菱 PLC(MC UDP binary,端口 5006)
+# 弧焊一拖五:每站一个工位编码 + 一台三菱 PLC(MC UDP binary)
 # 点位:L180=MES允许启动;M1216/M1222=A运行/完成;M1217/M1223=B;R1=D822/803/805+D970;R2=D826/807/809+D980
 mes:
   app-title: MES 弧焊客户端
@@ -22,24 +22,58 @@ mes:
   device-type: 弧焊
   device-heartbeat-minutes: 5
   auto-next-on-push: true
-  # 产线(改这一处即可,五站 PLC IP 自动适配):
-  #   T13J → 192.168.31.51 / .56 / .61 / .66 / .71
-  #   T1E  → 192.168.31.26 / .31 / .36 / .41 / .46
-  #   T1GC → 192.168.31.2  / .6  / .11 / .16 / .21
-  line-profile: T13J
-  stations:
-    - id: 1
-      title: 弧焊1#
-      station-sn: HG01
-    - id: 2
-      title: 弧焊2#
-      station-sn: HG02
-    - id: 3
-      title: 弧焊3#
-      station-sn: HG03
-    - id: 4
-      title: 弧焊4#
-      station-sn: HG04
-    - id: 5
-      title: 弧焊5#
-      station-sn: HG05
+  # 启用哪条产线:启动时取 line-stations 下对应 5 站,并自动套该线 PLC IP
+  #   T13J → IP .51/.56/.61/.66/.71(5006)
+  #   T1E  → IP .26/.31/.36/.41/.46(5006)
+  #   T1GC → IP .2/.6/.11/.16(5020),.21(5006)
+  line-profile: T1E
+
+  line-stations:
+    T13J:
+      - id: 1
+        title: T13J 弧焊1#
+        station-sn: HG01
+      - id: 2
+        title: T13J 弧焊2#
+        station-sn: HG02
+      - id: 3
+        title: T13J 弧焊3#
+        station-sn: HG03
+      - id: 4
+        title: T13J 弧焊4#
+        station-sn: HG04
+      - id: 5
+        title: T13J 弧焊5#
+        station-sn: HG05
+    T1E:
+      - id: 1
+        title: T1E 弧焊1#
+        station-sn: T1E01
+      - id: 2
+        title: T1E 弧焊2#
+        station-sn: T1E02
+      - id: 3
+        title: T1E 弧焊3#
+        station-sn: T1E03
+      - id: 4
+        title: T1E 弧焊4#
+        station-sn: T1E04
+      - id: 5
+        title: T1E 弧焊5#
+        station-sn: T1E05
+    T1GC:
+      - id: 1
+        title: T1GC 弧焊1#
+        station-sn: T1GC01
+      - id: 2
+        title: T1GC 弧焊2#
+        station-sn: T1GC02
+      - id: 3
+        title: T1GC 弧焊3#
+        station-sn: T1GC03
+      - id: 4
+        title: T1GC 弧焊4#
+        station-sn: T1GC04
+      - id: 5
+        title: T1GC 弧焊5#
+        station-sn: T1GC05