|
|
@@ -109,7 +109,27 @@ public class ProtocolParam {
|
|
|
}
|
|
|
return Integer.parseInt(nn);
|
|
|
}
|
|
|
- // 获取参数的总长度
|
|
|
+ // 获取参数段的期望总长度:只按报文声明的参数个数计算,不判断数据是否已到齐。
|
|
|
+ // 用于粘包/半包拆分时判断"这条报文一共该有多长",数据没收够时也要返回完整的期望值,
|
|
|
+ // 否则会把半包当完整包切走,导致参数段丢失(表现为服务端返回 NS)。
|
|
|
+ public static Integer getExpectParamLenth(String msg){
|
|
|
+ if(msg.length() < fixedLength){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ Integer length = getParamNums(msg);
|
|
|
+ if(length == 0){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ String msgType = getMsgType(msg);
|
|
|
+ if(msgType.equals("MBDW")||msgType.equals("MJBW")||msgType.equals("VLDW")||msgType.equals("AQDW")||msgType.equals("MCJW")||msgType.equals("MKSW")){ // 绑定类报文,每个参数36字符
|
|
|
+ return length*36;
|
|
|
+ }else if(msgType.equals("MSBW")){ // 设备状态,每个参数4字符
|
|
|
+ return length*4;
|
|
|
+ }
|
|
|
+ return length*12;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取参数的总长度(数据未到齐时返回 0,表示当前报文里还取不到参数)
|
|
|
public static Integer getParamLenth(String msg){
|
|
|
if(msg.length() < fixedLength){
|
|
|
return 0;
|