From 959dcca95276888cd9c092d93d276ef9aa580aef Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 30 四月 2025 16:26:19 +0800
Subject: [PATCH] 1、增加远程透传命令; 2、表阀一体机协议优化;

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/tasks/RtuDownConstantTask.java |  156 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/tasks/RtuDownConstantTask.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/tasks/RtuDownConstantTask.java
new file mode 100644
index 0000000..0af8480
--- /dev/null
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/tasks/RtuDownConstantTask.java
@@ -0,0 +1,156 @@
+package com.dy.rtuMw.server.tasks;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import com.dy.common.queue.Node;
+import com.dy.common.mw.core.CoreTask;
+import com.dy.rtuMw.server.forTcp.TcpDownCommandCache;
+import com.dy.rtuMw.server.forTcp.TcpDownCommandObj;
+import com.dy.rtuMw.server.forTcp.TcpSessionCache;
+
+/**
+ * 澶勭悊RTU涓嬭鍛戒护鏁版嵁鐨勬亽涔呬换鍔�
+ */
+public class RtuDownConstantTask extends CoreTask {
+	private static final Logger log = LogManager.getLogger(RtuDownConstantTask.class.getName());
+
+	/**
+	 * 鍦ㄥ崟绾跨▼鐜涓繍琛�
+	 */
+	@Override
+	public Integer execute() {
+		try{
+			dealTcpSession() ;
+		}catch(Exception e){
+			log.error("鏇存柊RTU浼氳瘽涓婃姤鏁版嵁鏃跺埢鏃跺彂鐢熼泦鍚堟搷浣滃紓甯革紝姝ゅ紓甯稿苟涓嶅奖鍝嶇郴缁熸甯歌繍琛�", e);
+		}
+		try{
+			//log.info("褰撳墠涓嬭鍛戒护闃熷垪涓繕鏈夌粨鐐规暟閲忥細" + TcpDownCommandCache.size());
+			dealDownCom() ;
+		}catch(Exception e){
+			log.error(e);
+		}
+		return TcpDownCommandCache.size()>0?0:1 ;
+	}
+	/**
+	 * 澶勭悊TCP缂撳瓨涓殑鍚勪釜TCP Session鐨勪笂琛屾暟鎹椂鍒�
+	 */
+	private void dealTcpSession(){
+		TcpSessionCache.updateRtuStatus(System.currentTimeMillis() ) ;
+	}
+
+
+	/**
+	 * 澶勭悊涓嬭鍛戒护
+	 */
+	public void dealDownCom() {
+		Node first = TcpDownCommandCache.getFirstQueueNode() ;
+		if(first != null){
+			Node last = TcpDownCommandCache.getLastQueueNode() ;
+			while (last != null){
+				last = this.doDealDownComm(System.currentTimeMillis(), first, last);
+			}
+		}
+	}
+	/**
+	 * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐�
+	 * @param now 褰撳墠鏃跺埢
+	 * @param first 绗竴涓妭鐐�
+	 * @param last 鏈�鍚庝竴涓妭鐐�
+	 */
+	private Node doDealDownComm(Long now, Node first, Node last){
+		if(last != null){
+			//鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸last浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秎ast.pre涓虹┖锛屾墍浠ユ彁鍓嶆妸last.pre鍙栧嚭鏉�
+			Node pre = last.pre ;
+			dealNode(now, last) ;
+			if(first != last){
+				return pre ;
+			}else{
+				//鍋滄
+				return null ;
+			}
+		}else{
+			return null ;
+		}
+	}
+
+
+
+	////////////////////////////////////////////////
+	//
+	//浠ヤ笅瀹炵幇锛岄噰鐢ㄤ簡閫掑綊璋冪敤锛屽綋闃熷垪缂撳瓨缁撶偣寰堝鏃讹紝浼氫骇鐢熸爤婧㈠嚭寮傚父
+	//
+	////////////////////////////////////////////////
+	/**
+	 * 澶勭悊涓嬭鍛戒护
+	public Integer dealDownCommand(Long now) {
+		Node first = TcpDownCommandCache.getFirstQueueNode() ;
+		if(first != null){
+			Integer count = TcpDownCommandCache.size() ;
+			Node last = TcpDownCommandCache.getLastQueueNode() ;
+			this.doDealDownCommand(now, first, last);
+			return count ;
+		}
+		return null ;
+	}
+	 */
+	/**
+	 * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐�
+	 * @param now 褰撳墠鏃跺埢
+	 * @param first 绗竴涓妭鐐�
+	 * @param last 鏈�鍚庝竴涓妭鐐�
+	private void doDealDownCommand1(Long now, Node first, Node last){
+		if(first != null){
+			//鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸first浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秄irst.next涓虹┖锛屾墍浠ユ彁鍓嶆妸first.next鍙栧嚭鏉�
+			Node next = first.next ;
+			dealNode(now, first) ;
+			if(last != null && first != last){
+				doDealDownCommand(now, next, last) ;
+			}else if(last != null && first == last){
+				//鍋滄
+			}else if(last == null){
+				//杩欑鎯呭喌涓嶄細瀛樺湪
+				doDealDownCommand(now, next, last) ;
+			}
+		}
+	}
+	 */
+	/**
+	 * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐�
+	 * @param now 褰撳墠鏃跺埢
+	 * @param first 绗竴涓妭鐐�
+	 * @param last 鏈�鍚庝竴涓妭鐐�
+	private void doDealDownCommand(Long now, Node first, Node last){
+		if(last != null){
+			//鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸last浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秎ast.pre涓虹┖锛屾墍浠ユ彁鍓嶆妸last.pre鍙栧嚭鏉�
+			Node pre = last.pre ;
+			dealNode(now, last) ;
+			if(first != null && first != last){
+				doDealDownCommand(now, first, pre) ;
+			}else if(first != null && first == last){
+				//鍋滄
+			}else if(first == null){
+				//杩欑鎯呭喌涓嶄細瀛樺湪
+				doDealDownCommand(now, null, pre) ;
+			}
+		}
+	}
+	 */
+	/**
+	 * 澶勭悊涓�涓妭鐐�
+	 * @param now 鐜板湪鏃跺埢
+	 * @param node 鑺傜偣
+	 */
+	private void dealNode(Long now, Node node){
+		if(node != null && node.obj != null){
+			TcpDownCommandObj obj = (TcpDownCommandObj)node.obj ;
+			boolean removeNode = obj.dealSelf(now) ;
+			if(removeNode){
+				TcpDownCommandCache.removeNode(node);
+			}
+		}
+	}
+
+
+}

--
Gitblit v1.8.0