985653680@qq.com преди 11 месеца
родител
ревизия
cb3ae5179b
променени са 3 файла, в които са добавени 138 реда и са изтрити 1 реда
  1. 1 0
      config.xml
  2. 11 1
      src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java
  3. 126 0
      src/main/java/com/gzlh/device/plc/service/PLCService.java

+ 1 - 0
config.xml

@@ -100,6 +100,7 @@
             <name>PLC.IDLE</name>
             <actionList>
                 <action>PLC.GREEN_LIGHT_ON</action>
+                <action>LED.LED_SHOW_CONTENT(${platNo})</action>
                 <action>LED.LED_SHOW_CONTENT(通道就绪,请通行)</action>
                 <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>PLC.GREEN_LIGHT_OFF</action>

+ 11 - 1
src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java

@@ -66,7 +66,7 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
                             }
                         }).start();
                     }
-
+//                    雷达外触发时调用方法
                     if (String.valueOf(i).equals(status.getRadarPoint())){
                         new Thread(()-> {
                             try {
@@ -76,6 +76,16 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
                             }
                         }).start();
                     }
+//                    上到位触发时调用方法
+                    if (String.valueOf(i).equals(status.getUpPoint())){
+                        new Thread(()-> {
+                            try {
+                                plcService.upTrigger();
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }).start();
+                    }
                 }
             }
         }

+ 126 - 0
src/main/java/com/gzlh/device/plc/service/PLCService.java

@@ -0,0 +1,126 @@
+package com.gzlh.device.plc.service;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.EventBus;
+import com.gzlh.bus.EventConfig;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.ModuleEnum;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.plc.event.PLCEvent;
+import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
+import com.gzlh.utils.DeviceCache;
+
+import java.util.Date;
+
+public class PLCService {
+    public void fRedTrigger(String plcInfo) throws InterruptedException {
+        EventBus eventBus = SpringUtil.getBean(EventBus.class);
+        //向总线发送抓拍到车牌事件
+        SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+//        将plc设备信息的字符串反转
+        plcInfo = new StringBuffer(plcInfo).reverse().toString();
+        String newStatus = null;
+        String oldFRed = String.valueOf(plcInfo.charAt(Integer.parseInt(status.getFRedPoint())));
+        String newFRed = null;
+        boolean bool = true;
+        while (bool) {
+            newStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
+            newFRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getFRedPoint())));
+//            前红外信息发生变化之后再继续
+            if (oldFRed.equals(newFRed)) {
+                Thread.sleep(2000);
+            } else {
+                bool = false;
+            }
+        }
+
+        String BRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
+        String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
+
+//        车辆处于前后红外之间(外)
+        if (newFRed.equals("0") && BRed.equals("0")) {
+            Date fRedTime = DeviceCache.getTime(status.getFRedPoint());
+            Date radarTime = DeviceCache.getTime(status.getRadarPoint());
+
+//            雷达时间小于前红外时间为进,车辆前后红外之间
+            if (radarTime.before(fRedTime)) {
+                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
+            }
+        }
+    }
+
+
+    public void radarTrigger() throws InterruptedException {
+        EventBus eventBus = SpringUtil.getBean(EventBus.class);
+        //向总线发送抓拍到车牌事件
+        SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+//        将plc设备信息的字符串反转
+        String newStatus = null;
+        String newRadar = null;
+        boolean bool = true;
+        while (bool) {
+//            反转当前设备信息
+            newStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
+            newRadar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
+//            雷达信息发生变化之后再继续
+            if ("0".equals(newRadar)) {
+                bool = false;
+            } else {
+                Thread.sleep(2000);
+            }
+        }
+
+        String BRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
+        String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
+
+//        设置str为只有栏杆下到位的状态
+        String str = "00000000";
+        StringBuilder sb = new StringBuilder(str);
+        sb.setCharAt(Integer.parseInt(status.getDownPoint()), '1');
+        str = sb.toString();
+        System.out.println(str);
+//        判断当前PLC状态
+        if (str.equals(newStatus)) {
+            Date fRedTime = DeviceCache.getTime(status.getFRedPoint());
+            Date radarTime = DeviceCache.getTime(status.getRadarPoint());
+//           雷达时间大于前红外时间为退,并且只有下到位触发,判断车辆不在通道内,触发通道空闲状态
+            if (radarTime.after(fRedTime)) {
+                EventDataManager.cleanData();
+                eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+            }
+        }
+    }
+
+    public void upTrigger() throws InterruptedException {
+        EventBus eventBus = SpringUtil.getBean(EventBus.class);
+        //向总线发送抓拍到车牌事件
+        SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+//        将plc设备信息的字符串反转
+        String newStatus = null;
+        String downPoint = null;
+        boolean bool = true;
+        while (bool) {
+//            反转当前设备信息
+            newStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
+            downPoint = String.valueOf(newStatus.charAt(Integer.parseInt(status.getDownPoint())));
+//            落杆后结束循环
+            if ("1".equals(downPoint)) {
+                bool = false;
+            } else {
+                Thread.sleep(2000);
+            }
+        }
+
+//        设置只有栏杆下到位的状态
+        String downOnly = "00000000";
+        StringBuilder sb = new StringBuilder(downOnly);
+        sb.setCharAt(Integer.parseInt(status.getDownPoint()), '1');
+        downOnly = sb.toString();
+//        System.out.println(downOnly);
+//        判断当前PLC状态
+        if (downOnly.equals(newStatus)) {
+            EventDataManager.cleanData();
+            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+        }
+    }
+}