Browse Source

文件传输完成消息发送

songwenbin 1 year ago
parent
commit
e161a0e42a

+ 24 - 2
gdnxak102/src/main/java/com/gyee/edge/gdnxak/ApplicationBootstrap.java

@@ -12,6 +12,8 @@ import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+import java.util.Date;
+
 
 @Slf4j
 @SpringBootApplication()
@@ -76,10 +78,30 @@ public class ApplicationBootstrap implements CommandLineRunner {
 
         if(iec102Client.isConnected()) {
             //发送心跳信号
-            iec102Client.sendHeartBeat();
+            //iec102Client.sendHeartBeat();
 
             //发送召唤用户数据指令
-            iec102Client.callUserData(1);
+            //todo: 此处的召唤指令可能会与长文件传输过程中的召唤指令冲突;
+            if (iec102Client.isCallLongFile() == false) {
+                iec102Client.callUserData(1);
+                return;
+            }
+
+            long ts = new Date().getTime();
+            long diff = ts - iec102Client.getLastCallUserDataTime();
+            if (diff > 20000) {
+                iec102Client.callUserData(1);
+                return;
+            }
+
+            long diff2 = ts - iec102Client.getLastActiveTime();
+            if (diff > 10000) {
+                iec102Client.sendHeartBeat();
+                return;
+            }
+
+
+
         }
 
     }

+ 25 - 3
gdnxak102/src/main/java/com/gyee/edge/gdnxak/iec102/Iec102Client.java

@@ -25,7 +25,10 @@ public class Iec102Client {
     private EventLoopGroup group;
     private Bootstrap bootstrap;
     private boolean connected = false;
-    private Date lastActiveTime;
+    private long lastActiveTime;
+    private long lastCallUserDataTime;
+
+    private boolean isCallLongFile = false;
 
     private ForcastService forcastService = SpringContextUtil.getBean(ForcastService.class);
 
@@ -122,6 +125,7 @@ public class Iec102Client {
         }
 //        Iec102Message msg23 = BasicInstruction102.createFixFrameMessage(BasicInstruction102.M_USERDATA2);
         sendMessage(iec102Message);
+        lastCallUserDataTime = new Date().getTime();
     }
 
     public void close() {
@@ -132,7 +136,7 @@ public class Iec102Client {
     public void processMessage(Iec102Message response) {
         if (response == null)
             return;
-        lastActiveTime = new Date();
+        lastActiveTime = new Date().getTime();
 
         try {
             if (Iec102FrameType.Fixed == response.getFrameType()) {
@@ -150,12 +154,14 @@ public class Iec102Client {
                 log.info("收到用户消息,文件名:" + iMsg.getDataFile());
 
                 if (0x08 == response.getCOT()) {
+                    isCallLongFile = true;
                     //再次发送召唤消息
                     callUserData(iMsg.getFrameCnt());
                     return;
                 }
 
                 if (0x07 == response.getCOT()) {
+                    isCallLongFile = false;
                     log.info("文件内容:" + iMsg.getDataContentString());
 
                     //解析光功率预测文件
@@ -165,10 +171,14 @@ public class Iec102Client {
                         forcastService.putForcastModel(forcastModel);
                     }
 
+                    //todo: 对控制位的逻辑实现有待进一步分析、理解和实现
+                    //发送文件传输结束确认消息
                     if (iMsg.getFrameCnt() > 1) {
-                        //todo: 发送文件传输结束确认消息
                         Iec102Message fileEndMsg = BasicInstruction102.createFileEndMessage(iMsg.getFrameCnt(), iMsg.getDataContent().length);
                         sendMessage(fileEndMsg);
+                    } else {
+                        Iec102Message fileEndMsg = BasicInstruction102.createFileEndMessage(2, iMsg.getDataContent().length);
+                        sendMessage(fileEndMsg);
                     }
 
                 }
@@ -232,4 +242,16 @@ public class Iec102Client {
         } catch (Exception e) {}
 
     }
+
+    public boolean isCallLongFile() {
+        return isCallLongFile;
+    }
+
+    public long getLastCallUserDataTime() {
+        return lastCallUserDataTime;
+    }
+
+    public long getLastActiveTime() {
+        return lastActiveTime;
+    }
 }