Browse Source

修改,保证模拟器和RS485之间通信顺畅。

tom 5 months ago
parent
commit
6271598d0a

+ 16 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/HardwareCommDebugController.java

@@ -34,6 +34,14 @@ public class HardwareCommDebugController extends BaseController {
         return success(service.debugReadOneFaultResistance(simNum, bindHardwareMsg));
     }
 
+    @GetMapping(value = "/debugReadAllFaultResistance/{simNum}/{simType}")
+    @ApiOperation("debugReadOneFaultResistance")
+    public AjaxResult debugReadAllFaultResistance(@PathVariable("simNum") final String simNum,
+                                                  @PathVariable("simType") String simType)
+            throws IOException {
+        return success(service.debugReadAllFaultResistance(simNum, simType));
+    }
+
     @GetMapping(value = "/debugClearOneFault/{simNum}/{bindHardwareMsg}")
     @ApiOperation("debugClearOneFault")
     public AjaxResult debugClearOneFault(@PathVariable("simNum") final String simNum,
@@ -57,4 +65,12 @@ public class HardwareCommDebugController extends BaseController {
             throws IOException {
         return success(service.debugWriteOneFault(simNum, bindHardwareMsg));
     }
+
+    @GetMapping(value = "/debugWriteAllFault/{simNum}/{simType}")
+    @ApiOperation("debugWriteAllFault")
+    public AjaxResult debugWriteAllFault(@PathVariable("simNum") final String simNum,
+                                         @PathVariable("simType") final String simType)
+            throws IOException {
+        return success(service.debugWriteAllFault(simNum, simType));
+    }
 }

+ 10 - 4
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommBuildService.java

@@ -56,12 +56,18 @@ public class CommBuildService {
         /**
          * 请求间隔睡眠时间。
          */
-        Long SLEEP = 512L;
+        Long SLEEP = 256L;
 
-        String[] TYPE_1_BIND_MSG = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "0A"};
-        String[] TYPE_2_BIND_MSG = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "0A",
+        String[] TYPE_1_BIND_MSG = new String[]{"01", "02", "03", "04", "05",
+                "06", "07", "08", "09", "0A"};
+
+//        String[] TYPE_1_BIND_MSG = new String[]{"0A", "09", "08", "07", "06",
+//                "05"};
+        String[] TYPE_2_BIND_MSG = new String[]{"01", "02", "03", "04", "05",
+                "06", "07", "08", "09", "0A",
                 "0B", "0C"};
-        String[] type_3_bind_msg = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "0A",
+        String[] TYPE_3_BIND_MSG = new String[]{"01", "02", "03", "04", "05",
+                "06", "07", "08", "09", "0A",
                 "0B", "0C", "0D", "0E", "0F"};
     }
 

+ 47 - 19
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommSendService.java

@@ -125,11 +125,26 @@ public class CommSendService {
      */
     public void scheduledReadSim() {
         l.info("scheduledReadSim");
-        if (isSocketOk()) {
-            readAllAsync();
-        } else {
-            scheduledConnect();
+        //
+        try {
+            for (int i = 0; i < 5; i++) {
+                debugReadSimType("01");
+            }
+            debugReadAllFaultResistance("01", "0001");
+            debugClearAllFault("01", "0001");
+            debugWriteAllFault("01", "0001");
+            for (int i = 0; i < 5; i++) {
+                debugReadAllFaultResistance("01", "0001");
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
         }
+
+//        if (isSocketOk()) {
+//            readAllAsync();
+//        } else {
+//            scheduledConnect();
+//        }
     }
 
     /**
@@ -278,8 +293,7 @@ public class CommSendService {
 
     public List<SimMsg> debugClearAllFault(final String simNum, String simType) throws IOException {
         List<SimMsg> list = new ArrayList<>();
-        String[] array = CommBuildService.CommConst.TYPE_1_BIND_MSG;
-        for (String b : array) {
+        for (String b : CommBuildService.CommConst.TYPE_1_BIND_MSG) {
             list.add(debugClearOneFault(simNum, b));
         }
         return list;
@@ -287,7 +301,7 @@ public class CommSendService {
 
     /**
      * @param s
-     * @param reF 可以为空,表示不关联考试的。
+     * @param reF 可以为空,表示不关联考试的,单独执行的
      * @param f
      */
     public void clearOneFault(Sim s, RealExamFault reF, Fault f) {
@@ -324,6 +338,14 @@ public class CommSendService {
         return new SimMsg(msg1, msg2);
     }
 
+    public List<SimMsg> debugWriteAllFault(final String simNum, String simType) throws IOException {
+        List<SimMsg> list = new ArrayList<>();
+        for (String b : CommBuildService.CommConst.TYPE_1_BIND_MSG) {
+            list.add(debugWriteOneFault(simNum, b));
+        }
+        return list;
+    }
+
     public void writeOneFault(Sim s, RealExamFault ref, Fault f) {
         l.info("下发故障:getSimId = {},fault.getName = {}", s.getSimId(), f.getName());
         try {
@@ -378,6 +400,14 @@ public class CommSendService {
         return new SimMsg(msg1, msg2);
     }
 
+    public List<SimMsg> debugReadAllFaultResistance(final String simNum, final String simType) throws IOException {
+        List<SimMsg> list = new ArrayList<>();
+        for (String b : CommBuildService.CommConst.TYPE_1_BIND_MSG) {
+            list.add(debugReadOneFaultResistance(simNum, b));
+        }
+        return list;
+    }
+
     public void readOneFaultResistance(Sim s, RealExamFault reF, Fault f, String refState) {
         l.info("readOneFaultResistance");
         try {
@@ -437,22 +467,16 @@ public class CommSendService {
         }
         //
         {
-            if (false) {
-                try {
-                    // sleep ,追求顺序请求。
-                    Thread.sleep(CommBuildService.CommConst.SLEEP);
-                } catch (InterruptedException e) {
-                    throw new RuntimeException(e);
-                }
+            try {
+                // sleep ,追求顺序请求。
+                Thread.sleep(CommBuildService.CommConst.SLEEP);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
             }
         }
         //
+        openSocket();
         String receiveMsg = null;
-        if (!isSocketOk()) {
-            openSocket();
-            l.warn("socket not open!");
-            return "";
-        }
         InputStream is = cachedSocket.getInputStream();
         OutputStream os = cachedSocket.getOutputStream();
         os.write(hexStrToByteArrs(sendMsg));
@@ -476,11 +500,13 @@ public class CommSendService {
         if (!commBuildService.checkReceiveMsg(receiveMsg)) {
             // todo:
             l.warn("checkReceiveMsg fail receiveMsg = {}", receiveMsg);
+            // closeSocket();
             return "";
         }
         if (s != null) {
             simService.updateLastReceivedTime(s);
         }
+        // closeSocket();
         return receiveMsg;
     }
 
@@ -520,6 +546,8 @@ public class CommSendService {
      */
     public void closeSocket() throws IOException {
         if (cachedSocket != null) {
+            cachedSocket.getInputStream().close();
+            cachedSocket.getOutputStream().close();
             cachedSocket.close();
         }
         cachedSocket = null;