tangle %!s(int64=2) %!d(string=hai) anos
pai
achega
a29b0f364e

+ 9 - 9
pom.xml

@@ -31,15 +31,15 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-java</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-boot-starter</artifactId>
-            <version>3.5.2</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>mysql</groupId>-->
+<!--            <artifactId>mysql-connector-java</artifactId>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>com.baomidou</groupId>-->
+<!--            <artifactId>mybatis-plus-boot-starter</artifactId>-->
+<!--            <version>3.5.2</version>-->
+<!--        </dependency>-->
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 0 - 6
simulation-receive/src/main/java/com/jiayue/simulation/ReceiveApplication.java

@@ -9,10 +9,4 @@ public class ReceiveApplication {
     public static void main(String[] args) {
         SpringApplication.run(ReceiveApplication.class);
     }
-
-
-    @Bean
-    void netty(){
-
-    }
 }

+ 21 - 11
simulation-receive/src/main/java/com/jiayue/simulation/config/ReceiveConfig.java

@@ -1,15 +1,12 @@
 package com.jiayue.simulation.config;
 
 import com.jiayue.simulation.ice102.Client;
-import com.jiayue.simulation.ice102.ConsoleInterface;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
 @Component
 public class ReceiveConfig {
 
-
     /**
      * 暂时使用配置形式启动
      * 想法:使用按钮选择启动各省份各类型的通信
@@ -18,14 +15,27 @@ public class ReceiveConfig {
     void start(){
 
 
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                new Client("192.168.1.77",3000);
-            }
-        }).start();
-
-        new Client("192.168.1.77",3000);
+//        new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//
+//            }
+//        }).start();
+//        new Client("192.168.1.77",3000);
+//        new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//                new Client("192.168.10.205",65534,"192.168.1.77",3000);
+//            }
+//        }).start();
+//        new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//                new Client("192.168.10.206",65534,"192.168.1.77",3000);
+//            }
+//        }).start();
+//
+//        
 
     }
 

+ 1 - 1
simulation-receive/src/main/java/com/jiayue/simulation/ice102/Client.java

@@ -67,8 +67,8 @@ public class Client implements ConsoleInterface {
                     if (future.isSuccess()) {
                         System.out.println("客户端连接成功");
                     } else {
-
                         System.out.println("客户端连接失败");
+                        start();
                     }
                 }
             });

+ 0 - 1
simulation-receive/src/main/java/com/jiayue/simulation/ice102/codec/Decoder.java

@@ -14,7 +14,6 @@ import java.util.List;
 
 /**
  * 解码器
- * @author tl
  *
  */
 @Slf4j

+ 0 - 1
simulation-receive/src/main/java/com/jiayue/simulation/ice102/codec/Encoder.java

@@ -9,7 +9,6 @@ import java.math.BigInteger;
 /**
  * 编码器
  *
- * @author tl
  */
 public class Encoder extends MessageToByteEncoder<String> {
     @Override

+ 18 - 0
simulation-receive/src/main/java/com/jiayue/simulation/ice102/controller/ClientController.java

@@ -0,0 +1,18 @@
+package com.jiayue.simulation.ice102.controller;
+
+import com.jiayue.simulation.ice102.Client;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/t")
+@RestController
+public class ClientController {
+
+    @GetMapping("/{ip}/{port}")
+    public void test(@PathVariable String ip,@PathVariable Integer port){
+
+        new Client(ip,port);
+    }
+}

+ 3 - 2
simulation-receive/src/main/java/com/jiayue/simulation/ice102/handler/ClientHandler.java

@@ -24,7 +24,7 @@ public class ClientHandler extends ChannelInboundHandlerAdapter {
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
 
-        ctx.channel().writeAndFlush("1049FFFF4716");
+        ctx.channel().writeAndFlush("1040FFFF3E16");
     }
 
     //接收消息触发
@@ -32,7 +32,7 @@ public class ClientHandler extends ChannelInboundHandlerAdapter {
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
 
         log.info("接收消息:{}",msg);
-        Thread.sleep(1000);
+
         String s = clientService.sendMessage(msg.toString());
         log.info("发送消息:{}",s);
         ctx.channel().writeAndFlush(s);
@@ -48,6 +48,7 @@ public class ClientHandler extends ChannelInboundHandlerAdapter {
     //客户端重连
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+
         super.channelInactive(ctx);
     }
 }

+ 9 - 5
simulation-receive/src/main/java/com/jiayue/simulation/ice102/service/ClientService.java

@@ -1,6 +1,5 @@
 package com.jiayue.simulation.ice102.service;
 
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jiayue.simulation.util.IEC102Uitl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,21 +8,25 @@ import org.springframework.stereotype.Service;
 @Service
 public class ClientService {
 
+    //一级召唤
     private String zh1 = "105AFFFF5916";
+    //二级召唤
     private String zh2 = "105BFFFF5916";
 
+
+
     public String sendMessage(String receiveMessage){
 
         String sendMessage = "";
         String[] rmArray = IEC102Uitl.stingToArray(receiveMessage);
 
-        //召唤链路状态
+        //复位通信单元
         if (rmArray.length==0) {
-            sendMessage = "1049FFFF4716";
-        }else if(receiveMessage.startsWith("100B")){
-            //链路状态回应请求->复位通信单元
             sendMessage = "1040FFFF3E16";
         }else if(receiveMessage.startsWith("1000")){
+            //召唤链路状态
+            sendMessage = "1049FFFF4716";
+        }else if(receiveMessage.startsWith("100B")){
             //确认帧->召唤二级数据
             if(!zh2.equals("105BFFFF5916")){
                 sendMessage = "105BFFFF5916";
@@ -78,4 +81,5 @@ public class ClientService {
         return sendMessage.toUpperCase();
 
     }
+
 }

+ 59 - 0
simulation-receive/src/main/java/com/jiayue/simulation/ice102/service/CommonService.java

@@ -0,0 +1,59 @@
+package com.jiayue.simulation.ice102.service;
+
+import org.springframework.stereotype.Service;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+
+public abstract class CommonService {
+
+    public void generateFile(String messageStr,Integer fileNameLength,String charset,String filePath) throws IOException {
+//        // 报文用逗号分隔
+//        String messageStr = "";
+//        // 文件名称长度
+//        Integer fileNameLength = 64;
+//        // 生成文件编码格式
+//        String charset = "GBK";
+        messageStr = messageStr.replace(" ", "");
+        String[] tempMessage = messageStr.split(",");
+        String fileNameHex = "";
+        StringBuffer sb = new StringBuffer("");
+        for (int i = 0; i < tempMessage.length; i++) {
+            // 循环每一帧的报文
+            String m = tempMessage[i];
+            // 获取文件内容帧
+            if ("".equals(fileNameHex)) {
+                fileNameHex = m.substring(26, 26 + fileNameLength * 2);
+            }
+            // 拼接文件内容
+            sb.append(m.substring(26 + fileNameLength * 2, m.length() - 4));
+        }
+        // 文件名去掉尾部占位的0
+        fileNameHex = fileNameHex.replaceAll("0*$", "");
+        int fileNameHexLength = fileNameHex.length();
+        byte[] fnData = new byte[fileNameHexLength / 2];
+        for (
+                int k = 0;
+                k < fileNameHexLength; k += 2) {
+            fnData[k / 2] = (byte) ((Character.digit(fileNameHex.charAt(k), 16) << 4)
+                    + Character.digit(fileNameHex.charAt(k + 1), 16));
+        }
+        String filename = new String(fnData, charset);
+        // 生成文件内容
+        String contentStr = sb.toString();
+        int fileContentHexLength = contentStr.length();
+        byte[] data = new byte[fileContentHexLength / 2];
+        for (
+                int i = 0;
+                i < fileContentHexLength; i += 2) {
+            data[i / 2] = (byte) ((Character.digit(contentStr.charAt(i), 16) << 4)
+                    + Character.digit(contentStr.charAt(i + 1), 16));
+        }
+        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(filePath + filename), charset);
+        String res = new String(data, charset);
+        osw.write(res);
+        osw.close();
+    }
+}

+ 14 - 14
simulation-receive/src/main/java/com/jiayue/simulation/util/ByteUtil.java

@@ -1,7 +1,7 @@
 package com.jiayue.simulation.util;
 
 
-import com.sun.istack.internal.NotNull;
+
 import io.netty.buffer.ByteBuf;
 
 import javax.xml.bind.DatatypeConverter;
@@ -19,7 +19,7 @@ public abstract class ByteUtil {
    * @param n 被转换int
    * @return byte[4]
    */
-  public static byte[] intToBytesFromHighToLow(@NotNull int n) {
+  public static byte[] intToBytesFromHighToLow( int n) {
     byte[] result = new byte[4];
     result[0] = (byte) ((n >> 24) & 0xFF);
     result[1] = (byte) ((n >> 16) & 0xFF);
@@ -34,7 +34,7 @@ public abstract class ByteUtil {
    * @param b 被转换的字节数组
    * @return int
    */
-  public static int bytesToIntFromHighToLow(@NotNull byte[] b) {
+  public static int bytesToIntFromHighToLow( byte[] b) {
 
     return (b[(0)] & 0xFF) << 24 | (b[(1)] & 0xFF) << 16 |
       (b[(2)] & 0xFF) << 8 | b[3] & 0xFF;
@@ -47,7 +47,7 @@ public abstract class ByteUtil {
    * @param n 被转换int
    * @return byte[4]
    */
-  public static byte[] intToBytesFromLowToHigh(@NotNull int n) {
+  public static byte[] intToBytesFromLowToHigh( int n) {
     byte[] targets = new byte[4];
 
     targets[0] = ((byte) (n & 0xFF));
@@ -63,7 +63,7 @@ public abstract class ByteUtil {
    * @param b 被转换的字节数组
    * @return int
    */
-  public static int bytesToIntFromLowToHigh(@NotNull byte[] b) {
+  public static int bytesToIntFromLowToHigh( byte[] b) {
     return (b[(3)] & 0xFF) << 24 | (b[(2)] & 0xFF) << 16 |
       (b[(1)] & 0xFF) << 8 | b[0] & 0xFF;
   }
@@ -74,7 +74,7 @@ public abstract class ByteUtil {
    * @param b 二进制数组
    * @return 十六进制字符串
    */
-  public static String bytesToHexStringFromHighToLow(@NotNull byte[] b) {
+  public static String bytesToHexStringFromHighToLow( byte[] b) {
     return DatatypeConverter.printHexBinary(b);
   }
 
@@ -84,7 +84,7 @@ public abstract class ByteUtil {
    * @param hexString 十六进制字符串
    * @return 二进制数组
    */
-  public static byte[] hexStringToBytesFromHighToLow(@NotNull String hexString) {
+  public static byte[] hexStringToBytesFromHighToLow( String hexString) {
     return DatatypeConverter.parseHexBinary(hexString);
   }
 
@@ -94,7 +94,7 @@ public abstract class ByteUtil {
    * @param b 二进制数组
    * @return 十六进制字符串
    */
-  public static String bytesToHexStringFromLowToHigh(@NotNull byte[] b) {
+  public static String bytesToHexStringFromLowToHigh( byte[] b) {
 
     byte[] dest = ByteUtil.bytesFlipping(b);
     return DatatypeConverter.printHexBinary(dest);
@@ -106,7 +106,7 @@ public abstract class ByteUtil {
    * @param hexString 十六进制字符串
    * @return 二进制数组
    */
-  public static byte[] hexStringToBytesFromLowToHigh(@NotNull String hexString) {
+  public static byte[] hexStringToBytesFromLowToHigh( String hexString) {
     byte[] dest = DatatypeConverter.parseHexBinary(hexString);
     return ByteUtil.bytesFlipping(dest);
   }
@@ -117,7 +117,7 @@ public abstract class ByteUtil {
    * @param f 被转换float
    * @return byte[4]
    */
-  public static byte[] floatToBytesFromLowToHigh(@NotNull float f) {
+  public static byte[] floatToBytesFromLowToHigh( float f) {
     int fbit = Float.floatToIntBits(f);
 
     byte[] b = new byte[4];
@@ -134,7 +134,7 @@ public abstract class ByteUtil {
    * @param b 被转换字节数组
    * @return float
    */
-  public static float bytesToFloatFromLowToHigh(@NotNull byte[] b) {
+  public static float bytesToFloatFromLowToHigh( byte[] b) {
     int l = b[(0)];
     l &= 255;
     l = l | b[(1)] << 8;
@@ -151,7 +151,7 @@ public abstract class ByteUtil {
    * @param f 被转换float
    * @return byte[4]
    */
-  public static byte[] floatToBytesFromHighToLow(@NotNull float f) {
+  public static byte[] floatToBytesFromHighToLow( float f) {
     int fbit = Float.floatToIntBits(f);
 
     byte[] b = new byte[4];
@@ -167,7 +167,7 @@ public abstract class ByteUtil {
    * @param b 被转换字节数组
    * @return float
    */
-  public static float bytesToFloatFromHighToLow(@NotNull byte[] b) {
+  public static float bytesToFloatFromHighToLow( byte[] b) {
     byte[] dest = ByteUtil.bytesFlipping(b);
     return ByteUtil.bytesToFloatFromLowToHigh(dest);
   }
@@ -178,7 +178,7 @@ public abstract class ByteUtil {
    * @param res 原数组
    * @return 翻转后的数组
    */
-  public static byte[] bytesFlipping(@NotNull byte[] res) {
+  public static byte[] bytesFlipping( byte[] res) {
     // 翻转数组
     int len = res.length;
     // 建立一个与源数组元素类型相同的数组

+ 2 - 0
simulation-receive/src/main/java/resources/application.yml

@@ -0,0 +1,2 @@
+server:
+  port: 8081

+ 0 - 58
simulation-receive/src/main/java/resources/mate-info/index.html

@@ -1,58 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>Title</title>
-</head>
-<body>
-<form onsubmit="return false">
-    <p>输入文本</p>
-    <textarea id="message" name="message" style="height: 300px; width: 300px"></textarea>
-    <input type="button" value="发送消息" onclick="send(this.form.message.value)">
-
-    <p>回复文本</p>
-    <textarea id="responseText" style="height: 300px; width: 300px"></textarea>
-    <input type="button" value="清空内容" onclick="document.getElementById('responseText').value=''">
-</form>
-</body>
-<script>
-    var socket;
-    // 判断当前浏览器是否支持 WebSocket
-    if (window.WebSocket){
-        socket = new WebSocket("ws://localhost:8000/hello");
-        // 相当于 channelRead0 方法,ev 收到服务器端回送的消息
-        socket.onmessage = function (ev){
-            var rt = document.getElementById("responseText");
-            rt.value = rt.value + "\n" + ev.data;
-        }
-        // 相当于连接开启,感知到连接开启
-        socket.onopen = function (){
-            var rt = document.getElementById("responseText");
-            rt.value = rt.value + "\n" + "连接开启……";
-        }
-        // 感知连接关闭
-        socket.onclose = function (){
-            var rt = document.getElementById("responseText");
-            rt.value = rt.value + "\n" + "连接关闭……";
-        }
-    }else {
-        alert("不支持 WebSocket");
-    }
-
-    // 发送消息到服务器
-    function send(message){
-        // 判断 WebSocket 是否创建好了
-        if (!window.socket){
-            return ;
-        }
-        // 判断 WebSocket 是否开启
-        if (socket.readyState == WebSocket.OPEN){
-            // 通过 Socket 发送消息
-            socket.send(message);
-        }else {
-            alert("连接未开启");
-        }
-    }
-</script>
-
-</html>