From b2c928eac40c4b7f495f8164eeb59005219fa350 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 11 六月 2025 17:55:29 +0800
Subject: [PATCH] 1、MQTT协议,增加设备参数命令及相关数据; 2、完善上行数据值对象; 3、完善其他代码。

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java |   35 +++++++++++++++++++++++++++--------
 1 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
index ac3e211..8085e91 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
@@ -3,12 +3,15 @@
 import com.dy.common.mw.channel.mqtt.MqttClientPool;
 import com.dy.common.mw.protocol4Mqtt.MqttNotify;
 import com.dy.common.mw.protocol4Mqtt.MqttNotifyInfo;
-import com.dy.common.mw.protocol4Mqtt.status.DevOnLineSt;
-import com.dy.common.mw.protocol4Mqtt.status.DevRunSt;
+import com.dy.common.mw.protocol4Mqtt.status.DevOnLineInfo;
+import com.dy.common.mw.protocol4Mqtt.status.DevRunInfo;
 import com.dy.rtuMw.server.ServerProperties;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.eclipse.paho.client.mqttv3.MqttClient;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @Author: liurunyu
@@ -24,6 +27,8 @@
     private MqttUnitConfigVo configVo ;
 
     private MqttClientPool pool;
+
+    private List<MqttClient> subClients ;
 
     private MqttManager(){
     }
@@ -43,8 +48,9 @@
      * @throws Exception
      */
     public void start()throws Exception{
+        subClients = new ArrayList<>();
         String URL = "tcp://" + this.configVo.svIp + ":" + this.configVo.svPort;
-        this.pool = new MqttClientPool(URL, this.configVo.svUserName, this.configVo.svUserPassword, this.configVo.poolMaxSize);
+        this.pool = new MqttClientPool(URL, this.configVo.svUserName, this.configVo.svUserPassword, this.configVo.poolMaxSize, this.configVo.useMemoryPersistence);
         if(this.pool.isClose()){
             throw new Exception("Mqtt杩炴帴姹犲垵濮嬪寲澶辫触");
         }
@@ -57,6 +63,7 @@
         if(clientSub == null || !clientSub.isConnected()){
             throw new Exception("Mqtt杩炴帴姹犺幏寰楄闃呰繛鎺ヤ笉鍙敤");
         }
+        subClients.add(clientSub) ;
         // 璁㈤槄涓婚
         for(int i = 0; i < this.configVo.subTopics.length; i++){
             for(int j = 0 ; j < this.configVo.protocolAndDeviceIds.length; j++){
@@ -70,15 +77,15 @@
                             public void notify(String devId, MqttNotifyInfo... infos) {
                                 if(devId != null && infos != null && infos.length > 0){
                                     for(MqttNotifyInfo info : infos){
-                                        if(info instanceof DevOnLineSt){
-                                            DevOnLineSt onLineSt = (DevOnLineSt)info;
+                                        if(info instanceof DevOnLineInfo){
+                                            DevOnLineInfo onLineSt = (DevOnLineInfo)info;
                                             if(onLineSt.onLine != null && onLineSt.onLine.booleanValue()){
-                                                DevStatusDealer.onLine(devId, ((DevOnLineSt)info).protocol);
+                                                DevStatusDealer.onLine(devId, ((DevOnLineInfo)info).protocol);
                                             }else{
                                                 DevStatusDealer.offLine(devId);
                                             }
-                                        } else if(info instanceof DevRunSt){
-                                            DevStatusDealer.setStatus(devId, (DevRunSt)info);
+                                        } else if(info instanceof DevRunInfo){
+                                            DevStatusDealer.setStatus(devId, (DevRunInfo)info);
                                         }
                                     }
                                 }
@@ -90,6 +97,18 @@
     }
 
     public void stop()throws Exception{
+        if(subClients != null && subClients.size() > 0){
+            for (MqttClient client : subClients) {
+                if(client != null && client.isConnected()){
+                    try{
+                        client.disconnect();
+                        client.close();
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
         if(this.pool != null){
             // 鍏抽棴杩炴帴姹�
             this.pool.close();

--
Gitblit v1.8.0