Bladeren bron

mock数据

FutureYu 1 jaar geleden
bovenliggende
commit
9d0af2523a

+ 1 - 1
common/src/main/java/db/Globals.java

@@ -50,7 +50,7 @@ public class Globals {
     public static final String DB_HOST = "192.168.233.153";
     public static final Integer DB_PORT = 9090;
 
-    public static String BROADCAST_HOST = "192.168.66.255";
+    public static String BROADCAST_HOST = "255.255.255.255";
     public static final int BROADCAST_PORT = 1200;
 
     @Value("${ip.broadcast}")

+ 3 - 3
insert-app/src/main/java/db/netty/NettyClientHandler.java

@@ -34,9 +34,9 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<BasePackage>
 
     public void sendScanResponse(ChannelHandlerContext ctx, String toHost, int toPort) {
         ScanResponsePackage scanResponsePackage = new ScanResponsePackage(Globals.RESPONSE_SUCCESS, (short) 0x0A,
-                0x5e43bbbb000aL, 0x7F000001, 0xFFFF0000, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
-                (short) 0, (byte) 0, (byte) 0, (byte) 0, (short) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
-                (byte) 0, (byte) 0, (byte) 0, (byte) 0);
+                0x5e43bbbb000aL, 0x7F000001, 0xFFFF0000, (byte) 0x35, (byte) 0xAA, (byte) 0x1, (byte) 31,
+                (short) 32, (byte) 0x55, (byte) 0x2, (byte) 35, (short) 36, (byte) 0xAA, (byte) 0xAA,
+                (byte) 0xAA, (byte) 0xAA, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0xAA);
         scanResponsePackage.setToHostPort(toHost, toPort);
         send(ctx, scanResponsePackage);
     }

+ 40 - 4
insert-app/src/main/java/db/service/ProbeService.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.io.IOException;
 import java.util.*;
 
@@ -34,6 +35,23 @@ public class ProbeService {
         return probes;
     }
 
+    /**
+     * 创建mock探针
+     */
+//    @PostConstruct
+    private void initMockProbe() {
+        Probe a = new Probe((short) 0x0A,
+                0x5e43bbbb000aL, 0x7F000001, 0xFFFF0000, (byte) 0x35, (byte) 0xAA, (byte) 0x1, (byte) 31,
+                (short) 32, (byte) 0x55, (byte) 0x2, (byte) 35, (short) 36, (byte) 0xAA, (byte) 0xAA,
+                (byte) 0xAA, (byte) 0xAA, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0xAA);
+        Probe b = new Probe((short) 0x0B,
+                0x6c5a33d92137L, 0x7F000002, 0xFFFF0000, (byte) 0x3A, (byte) 0xAA, (byte) 0x0, (byte) 31,
+                (short) 32, (byte) 0x55, (byte) 0x3, (byte) 35, (short) 36, (byte) 0xAA, (byte) 0xAA,
+                (byte) 0xAA, (byte) 0xAA, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0xAA);
+        probes.put((short) 0x0A, a);
+        probes.put((short) 0x0B, b);
+    }
+
     public void listenConfig(String typeStr, String modeStr) {
 
 //        byte mode;
@@ -72,11 +90,29 @@ public class ProbeService {
     }
 
     public List<ProbeDto> queryProbes() {
-        Collection<Probe> valueCollection = probes.values();
+
+        //------------------
+        // 创建mock数据
+        Probe a = new Probe((short) 0x0A,
+                0x5e43bbbb000aL, 0x7F000001, 0xFFFF0000, (byte) 0x35, (byte) 0xAA, (byte) 0x1, (byte) 31,
+                (short) 32, (byte) 0x55, (byte) 0x2, (byte) 35, (short) 36, (byte) 0xAA, (byte) 0xAA,
+                (byte) 0xAA, (byte) 0xAA, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0xAA);
+        Probe b = new Probe((short) 0x0B,
+                0x6c5a33d92137L, 0x7F000002, 0xFFFF0000, (byte) 0x3A, (byte) 0xAA, (byte) 0x0, (byte) 31,
+                (short) 32, (byte) 0x55, (byte) 0x3, (byte) 35, (short) 36, (byte) 0xAA, (byte) 0xAA,
+                (byte) 0xAA, (byte) 0xAA, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0xAA);
         List<ProbeDto> res = new ArrayList<>();
-        for (Probe probe : valueCollection) {
-            res.add(probe.toDto());
-        }
+        res.add(a.toDto());
+        res.add(b.toDto());
+
+        // 以上为mock代码
+        //------------------
+        // 以下为原始正常代码
+//        Collection<Probe> valueCollection = probes.values();
+//        List<ProbeDto> res = new ArrayList<>();
+//        for (Probe probe : valueCollection) {
+//            res.add(probe.toDto());
+//        }
         return res;
     }
 

BIN
meta.db