Browse Source

扩展协议字段

wangxichen 2 weeks ago
parent
commit
6934c399d1

+ 1 - 1
src/main/java/com/jeesite/modules/mes/util/CommonUitl.java

@@ -245,7 +245,7 @@ public class CommonUitl {
                     // 例如:+KA99IS3031RA1800A201
                     
                     // 1. 验证固定前缀:+KA99IS3031 或 +KA64IS3031
-                    List<String> prefixList = Arrays.asList("+KA99IS3031", "+KA64IS3031","+KB24IS3031","+KC14IS3031");
+                    List<String> prefixList = Arrays.asList("+KA99IS3031", "+KA64IS3031","+KB24IS3031","+KC14IS3031","+KB60IS3031");
                     String snPrefix = sn.substring(0, 11);
                     if(!prefixList.contains(snPrefix)){
                         return false;

+ 4 - 4
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -1733,10 +1733,10 @@ public class MesProductRecordController extends BaseController {
 				break;
 			case "AMBW":
 				//询问目标工位报文
-				//msg=aaaabbbbbABWAMBWGWROBOT1GY      ID                                    DA2023-08-18ZT14:32:33
-				oprno = msg.substring(18,24).trim();
-				craft = msg.substring(26,32).trim();
-				sn = msg.substring(34,70).trim();
+				//msg=aaaabbbbbABWAMBWGWROBOT1  GY      ID                                    DA2023-08-18ZT14:32:33
+				oprno = msg.substring(18,26).trim();
+				craft = msg.substring(28,34).trim();
+				sn = msg.substring(40,76).trim();
 
 				ret = "RSOK";
 				break;

+ 31 - 32
src/main/java/com/jeesite/modules/utils/ProtocolParam.java

@@ -3,9 +3,10 @@ package com.jeesite.modules.utils;
 import com.jeesite.common.lang.StringUtils;
 
 // 固定格式报文各参数获取方法
+// 协议 v2(2026-06-29 修订):oprno 字段从 6 字符扩到 8 字符,后续字段偏移整体 +2
 public class ProtocolParam {
 
-    public static Integer fixedLength = 124; // 固定长度
+    public static Integer fixedLength = 126; // 固定长度(v1=124,v2 扩 oprno 6→8 后 +2)
 
     // 获取消息类型  所有报文都可使用
     public static String getMsgType(String msg){
@@ -16,85 +17,85 @@ public class ProtocolParam {
         return msg.substring(12,16);
     }
 
-    // 获取工位号
+    // 获取工位号(8 字符,原 6 字符)
     public static String getOprno(String msg){
-        if(msg.length() < 24){
+        if(msg.length() < 26){
             return "";
         }
-        return msg.substring(18,24);
+        return msg.substring(18,26);
     }
 
     // 获取工艺号
     public static String getCraft(String msg){
-        if(msg.length() < 32){
+        if(msg.length() < 34){
             return "";
         }
-        return msg.substring(26,32);
+        return msg.substring(28,34);
     }
 
     // 获取类型
     public static String getLx(String msg){
-        if(msg.length() < 36){
+        if(msg.length() < 38){
             return "";
         }
-        return msg.substring(34,36);
+        return msg.substring(36,38);
     }
 
     // 获取返回类型
     public static String getReturnLx(String msg){
-        if(msg.length() < 36){
+        if(msg.length() < 38){
             return "RS";
         }
-        String lx = msg.substring(34,36);
+        String lx = msg.substring(36,38);
         return StringUtils.isEmpty(lx.trim())?"RS":lx;
     }
 
     // 获取产线编号
     public static String getLineSn(String msg){
-        if(msg.length() < 38){
+        if(msg.length() < 40){
             return "";
         }
-        return msg.substring(36,38);
+        return msg.substring(38,40);
     }
 
     // 获取镭雕码或设备报警故障代码
     public static String getSn(String msg){
-        if(msg.length() < 74){
+        if(msg.length() < 76){
             return "";
         }
-        return msg.substring(38,74);
+        return msg.substring(40,76);
     }
 
     // 获取结果
     public static String getResult(String msg){
-        if(msg.length() < 78){
+        if(msg.length() < 80){
             return "";
         }
-        return msg.substring(76,78);
+        return msg.substring(78,80);
     }
 
     // 获取日期
     public static String getDay(String msg){
-        if(msg.length() < 90){
+        if(msg.length() < 92){
             return "";
         }
-        return msg.substring(80,90);
+        return msg.substring(82,92);
     }
 
     // 获取时间
     public static String getTime(String msg){
-        if(msg.length() < 100){
+        if(msg.length() < 102){
             return "";
         }
-        return msg.substring(92,100);
+        return msg.substring(94,102);
     }
 
     // 获取用户
     public static String getUserCode(String msg){
-        if(msg.length() < 122){
+        if(msg.length() < 124){
             return "";
         }
-        return msg.substring(102,122).trim();
+        return msg.substring(104,124).trim();
     }
 
     // 获取参数个数
@@ -102,7 +103,7 @@ public class ProtocolParam {
         if(msg.length() < fixedLength){
             return 0;
         }
-        String nn = msg.substring(122,fixedLength).trim();
+        String nn = msg.substring(124,fixedLength).trim();
         if(StringUtils.isEmpty(nn)){
             return 0;
         }
@@ -135,7 +136,6 @@ public class ProtocolParam {
                 res = length*12;
             }
         }
-
         return res;
     }
 
@@ -145,12 +145,14 @@ public class ProtocolParam {
             return "";
         }
         Integer length = getParamNums(msg);
-        if(length == 0 || length < num){
+        if(length == 0){
+            return "";
+        }
+        if(num > length){
             return "";
         }
+
         String msgType = getMsgType(msg);
-//        String cate = getProductCate(msg);
-//        String oprno = getOprno(msg);
         String res = "";
         if(msgType.equals("MBDW")||msgType.equals("MJBW")||msgType.equals("VLDW")||msgType.equals("AQDW")||msgType.equals("MCJW")||msgType.equals("MKSW")){ // 绑定报文,截取36个字符
             if(msg.length() >= fixedLength + length*36){
@@ -166,14 +168,13 @@ public class ProtocolParam {
                 res = msg.substring(fixedLength+(num-1)*12,fixedLength + num*12);
             }
         }
-
-        return res.trim();
+        return res;
     }
 
-    // 获取参数的结果
     public static String getParamResult(String param){
         if(param.length() >= 1){
             String ret = param.substring(0,1).trim();
+
             if(ret.equals("Y")){
                 return "OK";
             }
@@ -181,12 +182,10 @@ public class ProtocolParam {
         return "NG";
     }
 
-    // 获取参数结果值
     public static String getParamVal(String param){
         if(param.length() > 1){
             return param.substring(1,param.length()).trim();
         }
         return "";
     }
-
 }