| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package com.mes.config;
- import java.util.List;
- /**
- * 弧焊产线 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>
- * <li>T1GC:.2 / .6 / .11 / .16 / .21</li>
- * </ul>
- */
- 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"
- };
- private static final String[] IPS_T1E = {
- "192.168.31.26", "192.168.31.31", "192.168.31.36", "192.168.31.41", "192.168.31.46"
- };
- private static final String[] IPS_T1GC = {
- "192.168.31.2", "192.168.31.6", "192.168.31.11", "192.168.31.16", "192.168.31.21"
- };
- private HgLineProfiles() {
- }
- /**
- * 规范化产线名;未知则回落 {@link #DEFAULT}。
- */
- public static String normalize(String profile) {
- if (profile == null) {
- return DEFAULT;
- }
- String p = profile.trim().toUpperCase();
- if ("T1E".equals(p) || "T1GC".equals(p) || "T13J".equals(p)) {
- return p;
- }
- return DEFAULT;
- }
- /** 该产线 1#~5# 的 PLC IP(长度 5) */
- public static String[] ipsOf(String profile) {
- String p = normalize(profile);
- if ("T1E".equals(p)) {
- return IPS_T1E.clone();
- }
- if ("T1GC".equals(p)) {
- return IPS_T1GC.clone();
- }
- return IPS_T13J.clone();
- }
- /**
- * 按 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 applyPlcIp(String profile, List<MesClientProperties.StationConfig> stations) {
- String p = normalize(profile);
- if (stations == null || stations.isEmpty()) {
- return p;
- }
- String[] ips = ipsOf(p);
- for (MesClientProperties.StationConfig s : stations) {
- if (s == null) {
- continue;
- }
- int idx = s.getId() - 1;
- if (idx < 0 || idx >= ips.length) {
- 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);
- }
- }
|