From bda423b1aae1d5322116511651ae03a54cdcd231 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 26 十一月 2024 17:25:39 +0800
Subject: [PATCH] 1、几个测试模块系统的log4j.xml配置中的编码修改; 2、RTU升级模拟器增加命令行设置服务端IP和端口功能; 3、应王江海要求,井电双控协议中也实现远程升级功能,因井电双控协议、阀控器协议不同,而双方协议中的升级子协议相同,所以通信中间件做增量开发、适应性修改,以适应这种混合协议情况,同时也提高通信中间件运行效率。

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/PrefixedDataAvailableV2.java |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/PrefixedDataAvailableV2.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/PrefixedDataAvailableV2.java
index 43fa369..74ba6f7 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/PrefixedDataAvailableV2.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/PrefixedDataAvailableV2.java
@@ -8,11 +8,13 @@
 import org.apache.logging.log4j.Logger;
 import org.apache.mina.core.buffer.BufferDataException;
 import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
 
 
 @AnnotationPrefixedDataAvailable(
 		enable = true,
 		protocolName = ProtocolConstantV206V2.protocolName,
+		protocolVersion = ProtocolConstantV206V2.protocolVer,
 		priority = ProtocolConstantV206V2.priority,
 		onLineDataMinLength = ProtocolConstantV206V2.onLineDataMinLength,
 		headMinLength = ProtocolConstantV206V2.headMinLength)
@@ -22,7 +24,7 @@
 	private static final Logger log = LogManager.getLogger(PrefixedDataAvailableV2.class) ;
 	
 	private static final String protocolName = ProtocolConstantV206V2.protocolName ;
-
+	private static final short protocolVersion = ProtocolConstantV206V2.protocolVer ;
 
 	/**
 	 * 鍒嗘瀽涓婄嚎鏁版嵁(缃戠粶杩炴帴鍚庣涓�鍖呮暟鎹�)鏄惁鍙幏寰�
@@ -33,11 +35,12 @@
 	 * @return 涓嶆槸鏈崗璁暟鎹椂杩斿洖绌�
 	 * @throws Exception 寮傚父
 	 */
-	public PrefixedDataAvailableStatus forOnLine(IoBuffer in, 
-			int remain,
-			int minDataLength, //瀵瑰簲ProtocolConstantV2_0.onLineDataMinLength
-			int maxDataLength //瀵瑰簲ProtocolConstant.errorMaxLength
-			) throws Exception {
+	public PrefixedDataAvailableStatus forOnLine(IoSession ioSession,
+												 IoBuffer in,
+												 int remain,
+												 int minDataLength, //瀵瑰簲ProtocolConstantV2_0.onLineDataMinLength
+												 int maxDataLength //瀵瑰簲ProtocolConstant.errorMaxLength
+												 ) throws Exception {
 		
 		int oldPosition = in.position() ;
 		byte[] preByte = new byte[remain];
@@ -45,7 +48,7 @@
 		//in.position(0) ;//閿欒鐢ㄦ硶锛屽鏋滃彂鐢熺矘鍖呮暟鎹紝灏嗕細姝诲惊鐜�
 		in.position(oldPosition) ;
 
-		return this.doForData(preByte, minDataLength, maxDataLength) ;
+		return this.doForData(ioSession, preByte, minDataLength, maxDataLength) ;
 	}
 
 	/**
@@ -58,32 +61,34 @@
 	 * @throws Exception 寮傚父
 	 */
 	@Override
-	public PrefixedDataAvailableStatus forUpData(IoBuffer in, 
-			int remain,
-			int minDataLength,
-			int maxDataLength) throws Exception {
+	public PrefixedDataAvailableStatus forUpData(IoSession ioSession,
+												 IoBuffer in,
+												 int remain,
+												 int minDataLength,
+												 int maxDataLength) throws Exception {
 		int oldPosition = in.position() ;
 		byte[] preByte = new byte[remain];
 		in.get(preByte) ;
 		//in.position(0) ;//閿欒鐢ㄦ硶锛屽鏋滃彂鐢熺矘鍖呮暟鎹紝灏嗕細姝诲惊鐜�
 		in.position(oldPosition) ;
 		
-		return this.doForData(preByte, minDataLength, maxDataLength) ;
+		return this.doForData(ioSession, preByte, minDataLength, maxDataLength) ;
 
     }
 	/**
 	 * 杩涜鍒ゆ柇
+	 * @param ioSession ioSession
 	 * @param preByte byte[]
 	 * @param minDataLength 鏈�灏忔暟鎹暱搴�
 	 * @param maxDataLength 鏈�澶ф暟鎹暱搴�
 	 * @return PrefixedDataAvailableStatus
 	 * @throws Exception 寮傚父
 	 */
-	private PrefixedDataAvailableStatus doForData(byte[] preByte, int minDataLength, int maxDataLength) throws Exception{
+	private PrefixedDataAvailableStatus doForData(IoSession ioSession, byte[] preByte, int minDataLength, int maxDataLength) throws Exception{
 		int remain = preByte.length ;
     	
         if (remain < minDataLength) {
-        	log.warn("鍩轰簬鍗忚锛�" + protocolName + "锛夊垽鏂暟鎹ご閮ㄥ彂鐢熸柇鍖呯幇璞°��") ;
+        	log.warn("鍩轰簬鍗忚锛�" + (protocolName + protocolVersion) + "锛夊垽鏂暟鎹ご閮ㄥ彂鐢熸柇鍖呯幇璞°��") ;
             return new PrefixedDataAvailableStatus().breaked() ;
         }
         
@@ -92,7 +97,6 @@
 			return new PrefixedDataAvailableStatus().rubbish(remain) ;
 		}
 
-		
         CommonV2 parseCommon = new CommonV2();
 		Boolean[] isThisProtocolData = parseCommon.isThisProtocolHead(preByte) ;
 		if(isThisProtocolData == null || isThisProtocolData.length != 2 || !isThisProtocolData[0].booleanValue()){
@@ -114,11 +118,11 @@
         
         if(remain == dataLen){
         	//涓嶆柇涓嶇矘
-            return new PrefixedDataAvailableStatus().completed(dataLen) ;
+            return new PrefixedDataAvailableStatus().completed(dataLen, protocolName, protocolVersion) ;
         }else if(remain > dataLen){
 			String headHex = ByteUtil.bytes2Hex(preByte, true) ;
         	log.warn("鏀跺埌鏁版嵁涔嬪抚鍓嶉儴锛�" + headHex + "锛屼絾鍙戠敓绮樺寘鐜拌薄銆�") ;
-            return new PrefixedDataAvailableStatus().adjoined(dataLen) ;
+            return new PrefixedDataAvailableStatus().adjoined(dataLen, protocolName, protocolVersion) ;
         }else{
         	// remain < dataLen
 			String headHex = ByteUtil.bytes2Hex(preByte, true) ;

--
Gitblit v1.8.0