From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 15:18:51 +0800 Subject: [PATCH] 整理版本 --- 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