liurunyu
2023-11-22 429f9d85eddbb07081c149d7156964337ba688aa
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/PrefixedDataAvailableV1_0_1.java
File was renamed from pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/pMeterV1_0_1/PrefixedDataAvailableV1_0_1.java
@@ -1,36 +1,36 @@
package com.dy.common.mw.protocol.pMeterV1_0_1;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.buffer.BufferDataException;
import org.apache.mina.core.buffer.IoBuffer;
package com.dy.common.mw.protocol.p206V1_0_0;
import com.dy.common.mw.channel.tcp.PrefixedDataAvailableStatus;
import com.dy.common.mw.protocol.AnnotationPrefixedDataAvailable;
import com.dy.common.mw.protocol.PrefixedDataAvailable;
import com.dy.common.util.ByteUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.buffer.BufferDataException;
import org.apache.mina.core.buffer.IoBuffer;
@AnnotationPrefixedDataAvailable(
      protocolName = ProtocolConstantV1_0_1.protocolName,
      priority = ProtocolConstantV1_0_1.priority,
      onLineDataMinLength = ProtocolConstantV1_0_1.onLineDataMinLength,
      headMinLength = ProtocolConstantV1_0_1.headMinLength)
      protocolName = ProtocolConstantV206V1_0_0.protocolName,
      priority = ProtocolConstantV206V1_0_0.priority,
      onLineDataMinLength = ProtocolConstantV206V1_0_0.onLineDataMinLength,
      headMinLength = ProtocolConstantV206V1_0_0.headMinLength)
@SuppressWarnings("unused")
public class PrefixedDataAvailableV1_0_1  implements PrefixedDataAvailable {
   private static Logger log = LogManager.getLogger(PrefixedDataAvailableV1_0_1.class) ;
   private static final Logger log = LogManager.getLogger(PrefixedDataAvailableV1_0_1.class) ;
   
   private static String protocolName = ProtocolConstantV1_0_1.protocolName ;
   private static final String protocolName = ProtocolConstantV206V1_0_0.protocolName ;
   /**
    * 分析上线数据(网络连接后第一包数据)是否可获得
    * @param in
    * @param in IoBuffer
    * @param remain 一定时大于0的数据
    * @param minDataLength 最小数据长度
    * @param maxDataLength 最大数据长度,达到或超过此长度,认为是垃圾数据。例如:数据头部是正确的,但合法数据结尾总不出现,认为此数据垃圾数据
    * @return 不是本协议数据时返回空
    * @throws Exception
    * @throws Exception 异常
    */
   public PrefixedDataAvailableStatus forOnLine(IoBuffer in, 
         int remain,
@@ -49,11 +49,12 @@
   /**
    * 分析上线后(网络连接后非第一包数据)是否可获得
    * @param in
    * @param protocolConf Rtu配置
    * @param maxDataLength
    * @return
    * @throws Exception
    * @param in IoBuffer
    * @param remain  剩余
    * @param minDataLength 最小数据长度
    * @param maxDataLength 最大数据长度
    * @return PrefixedDataAvailableStatus
    * @throws Exception 异常
    */
   @Override
   public PrefixedDataAvailableStatus forUpData(IoBuffer in, 
@@ -71,9 +72,11 @@
    }
   /**
    * 进行判断
    * @param preByte
    * @param maxDataLength
    * @return
    * @param preByte byte[]
    * @param minDataLength 最小数据长度
    * @param maxDataLength 最大数据长度
    * @return PrefixedDataAvailableStatus
    * @throws Exception 异常
    */
   private PrefixedDataAvailableStatus doForData(byte[] preByte, int minDataLength, int maxDataLength) throws Exception{
      int remain = preByte.length ;
@@ -99,13 +102,13 @@
      Integer dataLen = parseCommon.parseDataLen(preByte) ;
      
      String headHex = ByteUtil.bytes2Hex(preByte, true) ;
      if(dataLen == null){
         String headHex = ByteUtil.bytes2Hex(preByte, true) ;
         throw new BufferDataException("收到数据之帧前部:" + headHex + ",但严重错误,在进行断包与粘包检查时,未能得到数据帧的长度。");
      }
      
        if (dataLen <= 0 || dataLen > maxDataLength) {
         String headHex = ByteUtil.bytes2Hex(preByte, true) ;
            throw new BufferDataException("收到数据之帧前部:" + headHex + ",但严重错误,在进行断包与粘包检查时,数据帧的长度(" + dataLen + ")超出合法范围。");
        }
        
@@ -113,10 +116,12 @@
           //不断不粘
            return new PrefixedDataAvailableStatus().completed(dataLen) ;
        }else if(remain > dataLen){
         String headHex = ByteUtil.bytes2Hex(preByte, true) ;
           log.warn("收到数据之帧前部:" + headHex + ",但发生粘包现象。") ;
            return new PrefixedDataAvailableStatus().adjoined(dataLen) ;
        }else{
           // remain < dataLen
         String headHex = ByteUtil.bytes2Hex(preByte, true) ;
           log.warn("收到数据之帧前部:" + headHex + ",但发生断包现象。") ;
            return new PrefixedDataAvailableStatus().breaked() ;
        }