HgLineProfiles.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.mes.config;
  2. import java.util.List;
  3. /**
  4. * 弧焊产线 PLC IP 预设:配置 {@code mes.line-profile} 后自动套到当前五站 IP。
  5. * 工位编码在 yml {@code mes.line-stations}(三条线共 15 个)自配,这里不覆盖。
  6. * 端口按 IP:.2/.6/.11/.16 → 5020,其余 5006。
  7. * <ul>
  8. * <li>T13J:.51 / .56 / .61 / .66 / .71</li>
  9. * <li>T1E:.26 / .31 / .36 / .41 / .46</li>
  10. * <li>T1GC:.2 / .6 / .11 / .16 / .21</li>
  11. * </ul>
  12. */
  13. public final class HgLineProfiles {
  14. /** 默认产线 */
  15. public static final String DEFAULT = "T13J";
  16. /** 多数站 MC UDP 端口 */
  17. public static final int PORT_DEFAULT = 5006;
  18. /** T1GC 前四站(.2/.6/.11/.16)MC UDP 端口 */
  19. public static final int PORT_T1GC_FRONT = 5020;
  20. private static final String[] IPS_T13J = {
  21. "192.168.31.51", "192.168.31.56", "192.168.31.61", "192.168.31.66", "192.168.31.71"
  22. };
  23. private static final String[] IPS_T1E = {
  24. "192.168.31.26", "192.168.31.31", "192.168.31.36", "192.168.31.41", "192.168.31.46"
  25. };
  26. private static final String[] IPS_T1GC = {
  27. "192.168.31.2", "192.168.31.6", "192.168.31.11", "192.168.31.16", "192.168.31.21"
  28. };
  29. private HgLineProfiles() {
  30. }
  31. /**
  32. * 规范化产线名;未知则回落 {@link #DEFAULT}。
  33. */
  34. public static String normalize(String profile) {
  35. if (profile == null) {
  36. return DEFAULT;
  37. }
  38. String p = profile.trim().toUpperCase();
  39. if ("T1E".equals(p) || "T1GC".equals(p) || "T13J".equals(p)) {
  40. return p;
  41. }
  42. return DEFAULT;
  43. }
  44. /** 该产线 1#~5# 的 PLC IP(长度 5) */
  45. public static String[] ipsOf(String profile) {
  46. String p = normalize(profile);
  47. if ("T1E".equals(p)) {
  48. return IPS_T1E.clone();
  49. }
  50. if ("T1GC".equals(p)) {
  51. return IPS_T1GC.clone();
  52. }
  53. return IPS_T13J.clone();
  54. }
  55. /**
  56. * 按 PLC IP 选 MC UDP 端口:192.168.31.2/.6/.11/.16 → 5020,其余 → 5006。
  57. */
  58. public static int portOf(String plcIp) {
  59. String ip = plcIp == null ? "" : plcIp.trim();
  60. if ("192.168.31.2".equals(ip)
  61. || "192.168.31.6".equals(ip)
  62. || "192.168.31.11".equals(ip)
  63. || "192.168.31.16".equals(ip)) {
  64. return PORT_T1GC_FRONT;
  65. }
  66. return PORT_DEFAULT;
  67. }
  68. /**
  69. * 按工位 id(1~5)只写产线 PLC IP;station-sn / title 保持 yml(line-stations)原值。
  70. *
  71. * @return 实际生效的产线名
  72. */
  73. public static String applyPlcIp(String profile, List<MesClientProperties.StationConfig> stations) {
  74. String p = normalize(profile);
  75. if (stations == null || stations.isEmpty()) {
  76. return p;
  77. }
  78. String[] ips = ipsOf(p);
  79. for (MesClientProperties.StationConfig s : stations) {
  80. if (s == null) {
  81. continue;
  82. }
  83. int idx = s.getId() - 1;
  84. if (idx < 0 || idx >= ips.length) {
  85. continue;
  86. }
  87. s.setPlcIp(ips[idx]);
  88. }
  89. return p;
  90. }
  91. /** @deprecated 用 {@link #applyPlcIp};保留兼容旧调用名 */
  92. @Deprecated
  93. public static String applyToStations(String profile, List<MesClientProperties.StationConfig> stations) {
  94. return applyPlcIp(profile, stations);
  95. }
  96. }