From d20d38e22b06559d758c568769017e2acf632583 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 23 四月 2025 14:06:48 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu202404/src/main/java/com/dy/simRtu202404/tcpClient/Worker.java | 121 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu202404/src/main/java/com/dy/simRtu202404/tcpClient/Worker.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu202404/src/main/java/com/dy/simRtu202404/tcpClient/Worker.java
new file mode 100644
index 0000000..09f97ab
--- /dev/null
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-simulate-rtu202404/src/main/java/com/dy/simRtu202404/tcpClient/Worker.java
@@ -0,0 +1,121 @@
+package com.dy.simRtu202404.tcpClient;
+
+import com.dy.simRtu202404.ServerProperties;
+import com.dy.simRtu202404.tcpClient.upData.UpData;
+import com.dy.simRtu202404.tcpClient.upData.UpHeartBeat;
+import com.dy.simRtu202404.tcpClient.upData.UpOpenCloseValve;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.mina.core.session.IoSession;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/2/26 14:39
+ * @Description
+ */
+public class Worker {
+
+ private static final Logger log = LogManager.getLogger(TcpClUnit.class) ;
+
+ protected static IoSession session ;
+
+ private static Worker instance = new Worker() ;
+
+ private static Integer UpHeartBeatTimes = 0 ;
+ private static boolean isOpenValve = false ;
+ private static boolean isCloseValve = false ;
+ private static Integer OpenedCount = 0 ;
+ private static Integer ClosedCount = 0 ;
+
+ private Worker(){
+ }
+
+ public static Worker getInstance(IoSession session){
+ Worker.session = session ;
+ return instance ;
+ }
+
+ public void doWork(){
+ UpData.setSession(Starter.session);
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ while(true){
+ try {
+ reportData() ;
+ Thread.sleep(1000L);
+ }catch (Exception e){
+ continue;
+ }
+ }
+ }
+ }).start();
+ }
+ private void reportData() throws Exception{
+ UpHeartBeat.upCd02Data(ServerProperties.rtuAddr);
+ UpHeartBeatTimes += 1 ;
+
+ Thread.sleep(10000L);
+
+ if(UpHeartBeatTimes == 2){
+ UpHeartBeatTimes = 0 ;
+ if(ServerProperties.type == 1){
+ if(!isOpenValve){
+ UpOpenCloseValve.upCd84Data(ServerProperties.rtuAddr);
+ isOpenValve = true ;
+ }
+ }
+
+ if(ServerProperties.type == 2){
+ if(!isCloseValve){
+ UpOpenCloseValve.upCd85Data(ServerProperties.rtuAddr);
+ isCloseValve = true ;
+ }
+ }
+
+ if(ServerProperties.type == 3){
+ if(!isOpenValve){
+ UpOpenCloseValve.upCd84Data(ServerProperties.rtuAddr);
+ isOpenValve = true ;
+ }
+ OpenedCount += 1 ;
+ if(OpenedCount == 10){
+ OpenedCount = 0 ;
+ if(!isCloseValve){
+ UpOpenCloseValve.upCd85Data(ServerProperties.rtuAddr);
+ isCloseValve = true ;
+ }
+ }
+ }
+
+ if(ServerProperties.type == 4){
+ if(!isOpenValve && !isCloseValve){
+ //鍒濇
+ UpOpenCloseValve.upCd84Data(ServerProperties.rtuAddr);
+ isOpenValve = true ;
+ isCloseValve = false ;
+ }else{
+ if(isOpenValve){
+ OpenedCount += 1 ;
+ }
+ if(OpenedCount == 10){
+ OpenedCount = 0 ;
+ UpOpenCloseValve.upCd85Data(ServerProperties.rtuAddr);
+ isOpenValve = false ;
+ isCloseValve = true ;
+ }
+
+ if(isCloseValve){
+ ClosedCount += 1 ;
+ }
+ if(ClosedCount == 10){
+ ClosedCount = 0 ;
+ UpOpenCloseValve.upCd84Data(ServerProperties.rtuAddr);
+ isOpenValve = true ;
+ isCloseValve = false ;
+ }
+ }
+ }
+ }
+ }
+}
--
Gitblit v1.8.0