Jelajahi Sumber

监控捕捉车牌图片路径修改、流程调整、电子车牌

985653680@qq.com 11 bulan lalu
induk
melakukan
ba014a45aa

+ 22 - 25
config.xml

@@ -5,16 +5,11 @@
         <serialSetting>
             <host>192.168.1.254</host>
             <weighbridge>
-                <enable>false</enable>
+                <enable>true</enable>
                 <port>4005</port>
                 <brand>3000</brand>
                 <minKg>5000</minKg>
             </weighbridge>
-            <car>
-                <enable>false</enable>
-                <port>4002</port>
-                <brand>1000</brand>
-            </car>
             <led>
                 <enable>true</enable>
                 <port>4003</port>
@@ -52,21 +47,19 @@
     </sysConfig>
     <eventList>
         <event>
-            <name>WEIGHBRIDGE.READY</name>
-            <!--动作格式 模块.命令-->
-            <actionList>
-                <action>LED.LED_SHOW_CONTENT(地磅初始化)</action>
-                <action>CENTER.TIMER_SLEEP(1500)</action>
-                <action>LED.LED_SHOW_CONTENT(即将称重,请停稳车辆)</action>
-            </actionList>
-        </event>
-        <event>
             <name>WEIGHBRIDGE.READ</name>
             <!--动作格式 模块.命令-->
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(地磅称重中)</action>
+                <action>LED.LED_SHOW_CONTENT(03|地磅初始化)</action>
+                <action>CENTER.TIMER_SLEEP(1500)</action>
+                <action>LED.LED_SHOW_CONTENT(04|即将称重,请停稳车辆)</action>
+                <action>CENTER.TIMER_SLEEP(2000)</action>
+                <action>LED.LED_SHOW_CONTENT(03|地磅称重中)</action>
                 <action>WEIGHBRIDGE.START_READ</action>
+                <action>CENTER.TIMER_SLEEP(4000)</action>
                 <action>LED.LED_SHOW_CONTENT(${weight})</action>
+                <action>CENTER.TIMER_SLEEP(500)</action>
+                <action>LED.LED_SHOW_CONTENT(04|称重成功,后台验放通讯中)</action>
                 <action>CENTER.SUBMIT</action>
             </actionList>
         </event>
@@ -83,6 +76,7 @@
             <name>CAPTURE.CAPTURE_CAR_NO</name>
             <actionList>
                 <action>LED.LED_SHOW_CONTENT(${platNo})</action>
+                <action>LED.LED_SHOW_CONTENT(04|请继续行驶)</action>
                 <action>PLC.RED_LIGHT_ON</action>
                 <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>PLC.RED_LIGHT_OFF</action>
@@ -92,7 +86,6 @@
             <!--通过校验,抬杆-->
             <name>PLC.RAILING_RISE</name>
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(校验已通过)</action>
                 <action>PLC.RAILING_RISE_ON</action>
                 <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>PLC.RAILING_RISE_OFF</action>
@@ -100,9 +93,9 @@
         </event>
         <event>
             <!--校验失败-->
-            <name>PLC.CHECK_FAILED</name>
+            <name>PLC.SUBMIT_TIMEOUT</name>
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(校验失败,请退出通道)</action>
+                <action>LED.LED_SHOW_CONTENT(04|提交数据请求失败,请联系管理人员)</action>
             </actionList>
         </event>
         <event>
@@ -110,8 +103,10 @@
             <name>PLC.IDLE</name>
             <actionList>
                 <action>PLC.GREEN_LIGHT_ON</action>
+                <action>LED.LED_SHOW_CONTENT(${channel})</action>
                 <action>LED.LED_SHOW_CONTENT(${platNo})</action>
-                <action>LED.LED_SHOW_CONTENT(通道就绪,请通行)</action>
+                <action>LED.LED_SHOW_CONTENT(${weight})</action>
+                <action>LED.LED_SHOW_CONTENT(04|通道就绪,请通行)</action>
                 <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>PLC.GREEN_LIGHT_OFF</action>
             </actionList>
@@ -119,21 +114,23 @@
         <event>
             <name>WEIGHBRIDGE.TIMEOUT</name>
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(地磅称重数据异常,请联系管理人员)</action>
+                <action>CENTER.TIMER_SLEEP(1000)</action>
+                <action>LED.LED_SHOW_CONTENT(03|称重异常)</action>
+                <action>LED.LED_SHOW_CONTENT(04|请退车并请联系管理人员)</action>
             </actionList>
         </event>
-
         <event>
             <name>WEIGHBRIDGE.POSITION_ERROR</name>
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(车辆位置异常,请完全退出通道后再次进入通道)</action>
+                <action>LED.LED_SHOW_CONTENT(03|车辆位置异常或异常跟车)</action>
+                <action>LED.LED_SHOW_CONTENT(04|请完全退出通道后再次进入通道)</action>
             </actionList>
         </event>
-        <!--识别车牌异常-->
         <event>
             <name>CAPTURE.CAPTURE_FAILED</name>
             <actionList>
-                <action>LED.LED_SHOW_CONTENT(车牌获取异常,请退车并申请人工处理)</action>
+                <action>LED.LED_SHOW_CONTENT(02|车牌获取异常)</action>
+                <action>LED.LED_SHOW_CONTENT(04|请退车并申请人工处理)</action>
             </actionList>
         </event>
     </eventList>

+ 25 - 6
src/main/java/com/gzlh/bus/EventThread.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.device.capture.factory.CaptureFactory;
@@ -16,10 +17,12 @@ import com.gzlh.device.electron.factory.ElectronFactory;
 import com.gzlh.device.infrared.config.RedPropertiesConfig;
 import com.gzlh.device.infrared.factory.RedFactory;
 import com.gzlh.device.led.factory.LedFactory;
+import com.gzlh.device.led.utils.LedOptions;
 import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.plc.handler.PLCHadnler;
 import com.gzlh.device.weighbridge.config.WeighbridgePropertiesConfig;
 import com.gzlh.device.weighbridge.factory.WeighbridgeFactory;
+import com.gzlh.entity.CommandBO;
 import com.gzlh.utils.DeviceCache;
 import lombok.extern.slf4j.Slf4j;
 
@@ -54,13 +57,13 @@ public class EventThread implements Runnable{
                 .findFirst().ifPresent(eventDTO -> {
             List<String> actionList = eventDTO.getActionList().getAction();
             //依次执行动作
-            actionList.forEach(action -> {
+            for (String action:actionList) {
                 String module = StrUtil.subBefore(action, ".", true);
                 String command = StrUtil.subAfter(action, ".", true);
 //                中断事件动作
                 if (DeviceCache.isInterrupt()){
                     DeviceCache.setInterrupt(false);
-                    return;
+                    break;
                 }
                 if (StrUtil.equals(module, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
                     //动作属于红外
@@ -85,7 +88,7 @@ public class EventThread implements Runnable{
                     handlerAction(command);
                 }
                 ThreadUtil.sleep(250);
-            });
+            }
         });
 
     }
@@ -126,8 +129,24 @@ public class EventThread implements Runnable{
         String api="/open/submit";
         HttpResponse response = request(address+api, JSONUtil.toJsonStr(EventDataManager.getCacheData()));
         EventBus eventBus= SpringUtil.getBean(EventBus.class);
-        if (response!=null&&response.getStatus()==200){
-            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.RAILING_RISE);
+        log.info("提交通道数据-返回结果 code:{},body:{}",response.getStatus(),response.body());
+        if (response.getStatus() == 200 || response.getStatus() == 500){
+            JSONObject jsonObject = new JSONObject(response.body());
+            String data = jsonObject.get("data").toString();
+            log.info("提交通道数据-返回结果:{}",data);
+            CommandBO commandBO = JSONUtil.toBean(data, CommandBO.class);
+            LedOptions options = new LedOptions().setLine("04").setShowType("00");
+            if (response.getStatus()==200){
+                options.setColor("02");
+            }else{
+                options.setColor("01");
+            }
+            if (ModuleEnum.LED_MODULE.getModuleEn().equalsIgnoreCase(commandBO.getCommand().getModule())){
+                SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                        .sendMsg(commandBO.getCommand().getExtra(),options);
+            }else{
+                eventBus.startEvent(commandBO.getCommand().getModule()+"."+ commandBO.getCommand().getCommand());
+            }
         }else {
             eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.CHECK_FAILED);
         }
@@ -140,7 +159,7 @@ public class EventThread implements Runnable{
         HttpResponse res = null;
 //        url = "http://192.168.1.8:9191/open/submit";
         long startTime = System.currentTimeMillis();
-        System.out.println(startTime);
+//        System.out.println(startTime);
 
         String body = json;
         try {

+ 9 - 0
src/main/java/com/gzlh/config/hksdk/AlarmParseService.java

@@ -6,11 +6,14 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.config.SystemObject;
 import com.gzlh.device.capture.task.HandlerCarImage;
 import com.gzlh.config.FilePropertiesConfig;
 import com.gzlh.config.task.TaskService;
 import com.sun.jna.Pointer;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
@@ -19,6 +22,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -98,6 +102,11 @@ public class AlarmParseService {
                         buffers.get(bytes);
                         fout.write(bytes);
                         fout.close();
+                        String path= SystemObject.filePropertiesConfig.getRootPath();
+                        ServerProperties serverProperties = SpringUtil.getBean(ServerProperties.class);
+                        String ipAddr = InetAddress.getLocalHost().getHostAddress()+":"+String.valueOf(serverProperties.getPort());
+                        filePath=filePath.replace(path,ipAddr+"/files/");
+                        filePath=filePath.replace("\\","/");
                         taskService.addTask(new HandlerCarImage(RandomUtil.randomNumbers(10),100,filePath,sLicense));
                     } catch (IOException e) {
                         // TODO Auto-generated catch block

+ 22 - 13
src/main/java/com/gzlh/device/camera/controller/CameraController.java

@@ -6,6 +6,7 @@ import com.gzlh.bus.EventDataManager;
 import com.gzlh.config.SystemObject;
 import com.gzlh.device.camera.factory.CameraFactory;
 import com.gzlh.device.camera.properties.CameraPropertiesConfig;
+import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.FileUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.autoconfigure.web.ServerProperties;
@@ -44,7 +45,7 @@ public class CameraController {
         Map<String, Object> StringObjectMap = new HashMap<>();
         Document document = XmlUtil.parseXml(xmlStr);
         Element rootElement = XmlUtil.getRootElement(document);
-        String i_e_type = rootElement.getAttribute("I_E_TYPE");
+//        String i_e_type = rootElement.getAttribute("I_E_TYPE");
         XmlUtil.xmlToMap(xmlStr, StringObjectMap);
 
         Map<String, Object> ic = BeanUtil.beanToMap(StringObjectMap.get("IC"));
@@ -55,33 +56,41 @@ public class CameraController {
 
 
         Map<String, String> boxNoMap = new HashMap<>();
-//        cacheMap.put("carEcNo", (String) car.get("CAR_EC_NO"));
-        boxNoMap.put("boxNoF", !StringUtils.isEmpty((String) conta.get("CONTA_ID_F"))?(String) conta.get("CONTA_ID_F"):"");
-        boxNoMap.put("boxNoB", !StringUtils.isEmpty((String) conta.get("CONTA_ID_B"))?(String) conta.get("CONTA_ID_B"):"");
 
-        EventDataManager.cacheData("boxNoList",boxNoMap);
+        ReqBO.Box box = new ReqBO.Box();
+        if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_F"))) {
+            box.setBoxF((String) conta.get("CONTA_ID_F"));
+        }
+        if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_B"))) {
+            box.setBoxB((String) conta.get("CONTA_ID_B"));
+        }
+        if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_F"))) {
+            box.setModelF((String) conta.get("CONTA_MODEL_F"));
+        }
+        if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_B"))) {
+            box.setModelB((String) conta.get("CONTA_MODEL_B"));
+        }
 
         Calendar calendar = Calendar.getInstance();
         String ipAddr =InetAddress.getLocalHost().getHostAddress()+":"+String.valueOf(serverProperties.getPort());
 
         String savePath=path+"/"+channelCode+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
-        List<String> fList = new ArrayList();
-        List<String> bList = new ArrayList();
+        String fBoxImg = "";
+        String bBoxImg = "";
         for (Map.Entry<String, Object> entry : conta.entrySet()) {
             if(entry.getKey().contains("PIC")&& !StringUtils.isEmpty((String) entry.getValue())){
                 String filePath = FileUtils.downLoad((String) entry.getValue(),savePath);
                 filePath=filePath.replace(path,ipAddr+"/files");
 //                String base64 = FileUtils.getBase64FromImg(filePath);
                 if (entry.getKey().contains("CONTA_F")){
-                    fList.add(filePath);
+                    fBoxImg=fBoxImg.concat(filePath).concat(",");
                 }else if (entry.getKey().contains("CONTA_B")){
-                    bList.add(filePath);
+                    bBoxImg=bBoxImg.concat(filePath).concat(",");
                 }
             }
         }
-        EventDataManager.cacheData("boxFImgList",fList);
-        EventDataManager.cacheData("boxBImgList",bList);
-
-
+        box.setBoxFImg(fBoxImg);
+        box.setBoxBImg(bBoxImg);
+        EventDataManager.cacheData("box",box);
     }
 }

+ 5 - 0
src/main/java/com/gzlh/device/capture/event/CaptureEvent.java

@@ -5,4 +5,9 @@ public interface CaptureEvent {
      * 抓拍到车牌
      */
     String CAPTURE_CAR_NO="CAPTURE_CAR_NO";
+    /**
+     * 抓拍车牌失败
+     */
+    String CAPTURE_FAILED="CAPTURE_FAILED";
+
 }

+ 12 - 0
src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java

@@ -3,6 +3,7 @@ package com.gzlh.device.capture.task;
 import cn.hutool.core.codec.Base64;
 import cn.hutool.extra.spring.SpringUtil;
 
+import com.gzlh.config.SystemObject;
 import com.gzlh.device.capture.event.CaptureEvent;
 import com.gzlh.device.capture.factory.CaptureFactory;
 import com.gzlh.device.capture.properties.CapturePropertiesConfig;
@@ -10,9 +11,15 @@ import com.gzlh.config.ModuleEnum;
 import com.gzlh.bus.EventBus;
 import com.gzlh.bus.EventDataManager;
 import com.gzlh.config.task.Task;
+import com.gzlh.entity.ReqBO;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
+import org.springframework.util.StringUtils;
 
+import javax.annotation.Resource;
 import java.io.File;
+import java.net.InetAddress;
 
 /***
  * 将本地的车牌图片、车牌号缓存到数据中心
@@ -29,8 +36,13 @@ public class HandlerCarImage extends Task {
         this.carNo=carNo;
     }
 
+    @SneakyThrows
     @Override
     public void run() {
+        ReqBO reqBO = EventDataManager.getCacheData();
+        if (reqBO!=null&&!StringUtils.isEmpty(reqBO.getCarNo())){
+            return;
+        }
 //      String base64=  Base64.encode(new File(filePath));
         EventDataManager.cacheData("carImg",filePath);
         EventDataManager.cacheData("carNo",carNo);

+ 67 - 1
src/main/java/com/gzlh/device/electron/handler/impl/ElectronHandlerRuiDe.java

@@ -1,14 +1,25 @@
 package com.gzlh.device.electron.handler.impl;
 
+import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
+import com.gzlh.bus.EventConfig;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.SystemObject;
+import com.gzlh.device.electron.action.IElectronAction;
 import com.gzlh.device.electron.brand.ElectronBrandType;
 import com.gzlh.device.electron.client.ElectronNettyConfig;
 import com.gzlh.device.electron.handler.IElectronHandler;
+import com.gzlh.device.electron.job.ElectronReadJob;
 import com.gzlh.device.electron.utils.CheckNumUtils;
+import com.gzlh.device.led.utils.LedOptions;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.*;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
 
 /**
  * 瑞德电子车牌处理类
@@ -18,6 +29,8 @@ import javax.annotation.Resource;
 public class ElectronHandlerRuiDe implements IElectronHandler {
     private final String CALL_BACK_HEADER="F0";
 
+    private final static List<String> ERI_CACHE = new CopyOnWriteArrayList<>();
+
     @Resource
     private ElectronNettyConfig electronNettyConfig;
     @Override
@@ -27,7 +40,9 @@ public class ElectronHandlerRuiDe implements IElectronHandler {
 
     @Override
     public void handlerAction(String action) {
-
+        if (action.equals(IElectronAction.START_READ_CARD)){
+            readERI();
+        }
     }
 
     @Override
@@ -54,7 +69,58 @@ public class ElectronHandlerRuiDe implements IElectronHandler {
            if (!StrUtil.equals(checkNum,num)){
                return;
            }
+            String returnData = StrUtil.sub(data,6, len);
+            int count = Integer.parseInt(StrUtil.sub(returnData,0, 2));
+            String idStr = returnData.substring(2);
+            String[] idArray = new String[count];
+           for (int i=0;i<count;i++){
+//               id长度为16
+               ERI_CACHE.add(StrUtil.sub(idStr,i*16, (i+1)*16));
+           }
         }
     }
 
+
+    public void readERI(){
+        ERI_CACHE.clear();
+        int i=0;
+        while (i<10){
+            i++;
+//            发送读取电子车牌的指令
+            sendMsg("4002FEC0");
+            ThreadUtil.sleep(500);
+        }
+        if (ERI_CACHE.size()<1){
+            return;
+        }
+        Map<String, Long> collect = ERI_CACHE.stream().collect(Collectors.groupingBy(v -> v, Collectors.counting()));
+        Map<String, Long> maxValue = getMaxValue(collect);
+//        判断数据是否只有一个
+//        if (maxValue.size()>1){
+//            readERI();
+//        }else {
+            for (String eri:maxValue.keySet()){
+                EventDataManager.cacheData("eri",eri);
+            }
+//        }
+        ERI_CACHE.clear();
+
+    }
+
+    public static Map<String ,Long> getMaxValue(Map<String, Long> map){
+        if(map == null){
+            return new HashMap<>();
+        }
+        Map<String,Long> maxMap = new HashMap<>();
+        int length =map.size();
+        Collection<Long> c = map.values();
+        Object[] obj = c.toArray();
+        Arrays.sort(obj);
+        for(Map.Entry<String,Long> entry : map.entrySet()){
+            if(entry.getValue() == obj[length-1]){
+                maxMap.put(entry.getKey(),entry.getValue());
+            }
+        }
+        return maxMap;
+    }
 }

+ 2 - 1
src/main/java/com/gzlh/device/electron/job/ElectronReadJob.java

@@ -3,6 +3,7 @@ package com.gzlh.device.electron.job;
 import cn.hutool.extra.spring.SpringUtil;
 import com.gzlh.bus.EventConfig;
 import com.gzlh.config.SystemObject;
+import com.gzlh.device.electron.action.IElectronAction;
 import com.gzlh.device.electron.client.ElectronNettyConfig;
 
 /**
@@ -18,6 +19,6 @@ public class ElectronReadJob implements Runnable{
     @Override
     public void run() {
         SystemObject.electronFactory.handler(EventConfig.serialSetting.getElectron().getBrand())
-                .sendMsg(command);
+                .handlerAction(IElectronAction.START_READ_CARD);
     }
 }

+ 42 - 21
src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java

@@ -2,6 +2,7 @@ package com.gzlh.device.led.handler.impl;
 
 import cn.hutool.core.util.StrUtil;
 import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.SystemObject;
 import com.gzlh.device.led.action.LedAction;
 import com.gzlh.device.led.brand.LedBrandType;
 import com.gzlh.device.led.client.LedNettyConfig;
@@ -28,44 +29,64 @@ public class LedHandlerFengLiYuan implements ILedHandler {
 
     @Override
     public void sendMsg(String content, LedOptions options) {
-        log.info("丰利源发送led消息:{}",content);
-        String msgHex= FengLiYuanPackUtils.build(content,options);
-        log.info("数据包:{}",msgHex);
+        log.info("丰利源发送led消息:{}", content);
+        String msgHex = FengLiYuanPackUtils.build(content, options);
+        log.info("数据包:{}", msgHex);
         ledNettyConfig.send(msgHex);
     }
 
     @Override
     public void handlerAction(String action) {
         if (StrUtil.contains(action, LedAction.LED_SHOW_CONTENT)) {
+            LedOptions ledOptions = new LedOptions();
+//            默认显示到第一行
+            ledOptions.setLine("01");
+            action = action.substring(action.indexOf("(") + 1, action.indexOf(")"));
+            if (StrUtil.contains(action, "|")) {
+                String[] split = action.split("\\|");
+                ledOptions.setLine(split[0]);
+                action = split[1];
+            }
+            switch (ledOptions.getLine()) {
+                case "02":
+                    ledOptions.setColor("05");
+                    break;
+                case "03":
+                    ledOptions.setColor("04");
+                    break;
+                case "04":
+                    ledOptions.setColor("01");
+                    break;
+                default:
+                    ledOptions.setColor("06");
+                    break;
+            }
             ReqBO reqBO = null;
             //展示内容
-            if (StrUtil.contains(action,"platNo")){
-                String carNo="";
+            if (StrUtil.contains(action, "platNo")) {
+                String carNo = "";
                 reqBO = EventDataManager.getCacheData();
-                if (reqBO!=null){
+                if (reqBO != null) {
                     if (!StringUtils.isEmpty(reqBO.getCarNo())) {
                         carNo = reqBO.getCarNo();
                     }
                 }
-                LedOptions ledOptions=new LedOptions();
                 ledOptions.setColor("05").setLine("02").setShowType("0B");
-                sendMsg(carNo,ledOptions);
-            }else  if (StrUtil.contains(action,"weight")){
-                String weight ="";
+                sendMsg(carNo, ledOptions);
+            } else if (StrUtil.contains(action, "weight")) {
+                String weight = "";
                 reqBO = EventDataManager.getCacheData();
-                if (reqBO!=null){
-                    if (reqBO.getWeight()!=null) {
-                        weight= String.format("%.0f", EventDataManager.getCacheData().getWeight());
-                    }
+                if (reqBO != null && reqBO.getWeight() != null) {
+                    weight = String.format("%.0f", EventDataManager.getCacheData().getWeight()).concat("kg");
                 }
-                LedOptions ledOptions=new LedOptions();
                 ledOptions.setColor("04").setLine("03").setShowType("0B");
-                sendMsg(weight,ledOptions);
-            }else{
-                String content = action.substring(action.indexOf("(")+1, action.indexOf(")"));
-                LedOptions ledOptions=new LedOptions();
-                ledOptions.setColor("03").setLine("04").setShowType("00");
-                sendMsg(content,ledOptions);
+                sendMsg(weight, ledOptions);
+            }else if (StrUtil.contains(action, "channel")) {
+                ledOptions.setColor("06").setLine("01").setShowType("0B");
+                sendMsg(SystemObject.applicationConfig.getChannelName(), ledOptions);
+            }  else {
+                ledOptions.setShowType("00");
+                sendMsg(action, ledOptions);
             }
         }
     }

+ 12 - 70
src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java

@@ -1,13 +1,18 @@
 package com.gzlh.device.plc.client;
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.gzlh.bus.EventConfig;
+import com.gzlh.config.SystemObject;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.plc.handler.PLCHadnler;
 import com.gzlh.device.plc.service.PLCService;
 import com.gzlh.utils.DeviceCache;
+import com.gzlh.utils.ModbusUtils;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.lang.reflect.Field;
 import java.util.*;
@@ -18,7 +23,8 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
 
     private PlcNettyConfig ledNettyConfig;
 
-    private PLCService plcService = new PLCService();
+    @Autowired
+    private PLCHadnler plcHadnler;
 
     public PlcClientHandler(PlcNettyConfig ledNettyConfig) {
         this.ledNettyConfig = ledNettyConfig;
@@ -27,80 +33,16 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
         log.info("PLC 客户端收到消息:" + msg);
-        DeviceCache.put("plc",1);
-        String result = Integer.toBinaryString(Integer.parseInt(msg.substring(6, 8),16));
 
-        String oldPlcInfo = DeviceCache.getPlcStatus();
-//        将plc的设备信息补到8存入缓存
-        String newPlcInfo = String.format("%8s", result).replace(" ", "0");
-        DeviceCache.setPlcStatus(newPlcInfo);
-
-//        设备信息发生变化时进入
-        if (oldPlcInfo!=null&&!newPlcInfo.equals(oldPlcInfo)){
-            SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
-
-            String newStr = new StringBuffer(newPlcInfo).reverse().toString();
-            String oldStr = new StringBuffer(oldPlcInfo).reverse().toString();
-
-            for (int i=0;i<newStr.length();i++){
-//                第i位设备的值
-                String value = String.valueOf(newStr.charAt(i));
-//                设备被触发
-                if (value.equals("1")&&!value.equals(String.valueOf(oldStr.charAt(i)))){
-//                    记录时间 配置的设备地址为map的key
-                    for (Field field:status.getClass().getDeclaredFields()){
-                        field.setAccessible(true);
-                        if (Integer.parseInt(String.valueOf(field.get(status)))==i){
-//                            String name = fields[i].getName();
-                            DeviceCache.putTime((String) field.get(status),new Date());
-                            break;
-                        }
-                    }
-//                    前红外触发时调用方法
-                    if (String.valueOf(i).equals(status.getFRedPoint())){
-                        new Thread(()-> {
-                            try {
-                                plcService.fRedTrigger(newPlcInfo);
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
-                            }
-                        }).start();
-                    }
-//                    雷达外触发时调用方法
-                    if (String.valueOf(i).equals(status.getRadarPoint())){
-                        new Thread(()-> {
-                            try {
-                                plcService.radarTrigger();
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
-                            }
-                        }).start();
-                    }
-//                    上到位触发时调用方法
-                    if (String.valueOf(i).equals(status.getUpPoint())){
-                        new Thread(()-> {
-                            try {
-                                plcService.upTrigger();
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
-                            }
-                        }).start();
-                    }
-                }
-            }
+//        String crc = msg.substring(msg.length() - 4 );
+        String data = msg.substring(0, msg.length() - 4);
+        String str = ModbusUtils.buildRequestPacket(data);
+        if (msg.equalsIgnoreCase(str)){
+            plcHadnler.handlerMsg(msg);
         }
 
 
 
-        //        for (int i=0;i<result.length();i++){
-//            String status = String.valueOf(result.charAt((result.length() - 1) - i));
-//            if (status.equals("1")){
-//                list.add(i);
-//            }
-//        }
-//        System.out.println(list);
-//        log.info("PLC 客户端收到消息:" + msg);
-
     }
 
     @Override

+ 1 - 1
src/main/java/com/gzlh/device/plc/event/PLCEvent.java

@@ -7,7 +7,7 @@ public interface PLCEvent {
 
     String RAILING_RISE = "RAILING_RISE";
 
-    String CHECK_FAILED = "CHECK_FAILED";
+    String CHECK_FAILED = "SUBMIT_TIMEOUT";
 
     String IDLE = "IDLE";
 }

+ 111 - 36
src/main/java/com/gzlh/device/plc/handler/PLCHadnler.java

@@ -5,66 +5,141 @@ import com.gzlh.bus.EventConfig;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.device.plc.action.PLCAction;
 import com.gzlh.device.plc.client.PlcNettyConfig;
+import com.gzlh.device.plc.service.PLCService;
+import com.gzlh.utils.DeviceCache;
 import com.gzlh.utils.ModbusUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.lang.reflect.Field;
+import java.util.Date;
 
 @Service
 @Slf4j
 public class PLCHadnler {
     @Resource
     private PlcNettyConfig plcNettyConfig;
-    private final String COMMAND_PREFIX="010500";
-    private final String COMMAND_ON="FF00";
-    private final String COMMAND_OFF="0000";
+    private final String COMMAND_PREFIX = "010500";
+    private final String COMMAND_ON = "FF00";
+    private final String COMMAND_OFF = "0000";
 
-    public void handlerAction(String action){
-      SerialSetting serialSetting= EventConfig.serialSetting;
-        if (StrUtil.equals(action, PLCAction.RED_LIGHT_ON)){
+    private PLCService plcService = new PLCService();
+
+    public void handlerAction(String action) {
+        SerialSetting serialSetting = EventConfig.serialSetting;
+        if (StrUtil.equals(action, PLCAction.RED_LIGHT_ON)) {
             //亮红灯
-            String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
-            String command= COMMAND_PREFIX+redPoint+COMMAND_ON;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
-           plcNettyConfig.send(packData);
-        }else if (StrUtil.equals(action, PLCAction.RED_LIGHT_OFF)){
+            String redPoint = serialSetting.getPlc().getOut().getSignalRedPoint();
+            String command = COMMAND_PREFIX + redPoint + COMMAND_ON;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
+            plcNettyConfig.send(packData);
+        } else if (StrUtil.equals(action, PLCAction.RED_LIGHT_OFF)) {
             //灭红灯
-            String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
-            String command= COMMAND_PREFIX+redPoint+COMMAND_OFF;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
+            String redPoint = serialSetting.getPlc().getOut().getSignalRedPoint();
+            String command = COMMAND_PREFIX + redPoint + COMMAND_OFF;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
-        }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_ON)){
+        } else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_ON)) {
             //亮绿灯
-            String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
-            String command= COMMAND_PREFIX+greenPoint+COMMAND_ON;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
+            String greenPoint = serialSetting.getPlc().getOut().getSignalGreenPoint();
+            String command = COMMAND_PREFIX + greenPoint + COMMAND_ON;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
-        }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_OFF)){
+        } else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_OFF)) {
             //灭绿灯
-            String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
-            String command= COMMAND_PREFIX+greenPoint+COMMAND_OFF;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
+            String greenPoint = serialSetting.getPlc().getOut().getSignalGreenPoint();
+            String command = COMMAND_PREFIX + greenPoint + COMMAND_OFF;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
-        }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_ON)){
+        } else if (StrUtil.equals(action, PLCAction.RAILING_RISE_ON)) {
             //抬杆
-            String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
-            String command= COMMAND_PREFIX+gatePoint+COMMAND_ON;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
+            String gatePoint = serialSetting.getPlc().getOut().getGatePoint();
+            String command = COMMAND_PREFIX + gatePoint + COMMAND_ON;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
-        }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_OFF)){
+        } else if (StrUtil.equals(action, PLCAction.RAILING_RISE_OFF)) {
             //抬杆关闭
-            String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
-            String command= COMMAND_PREFIX+gatePoint+COMMAND_OFF;
-            log.info("plc发送消息:{}",command);
-            String packData= ModbusUtils.buildRequestPacket(command);
+            String gatePoint = serialSetting.getPlc().getOut().getGatePoint();
+            String command = COMMAND_PREFIX + gatePoint + COMMAND_OFF;
+            log.info("plc发送消息:{}", command);
+            String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
         }
     }
 
+    public void handlerMsg(String msg) throws Exception{
+
+        DeviceCache.put("plc",1);
+//        不是返回的plc状态信息就中断
+        if (!msg.substring(0,4).equals("0102")){
+            return;
+        }
+        String result = Integer.toBinaryString(Integer.parseInt(msg.substring(6, 8),16));
+
+        String oldPlcInfo = DeviceCache.getPlcStatus();
+//        将plc的设备信息补到8存入缓存
+        String newPlcInfo = String.format("%8s", result).replace(" ", "0");
+        DeviceCache.setPlcStatus(newPlcInfo);
+
+//        设备信息发生变化时进入
+        if (oldPlcInfo!=null&&!newPlcInfo.equals(oldPlcInfo)){
+            SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+
+            String newReverse = new StringBuffer(newPlcInfo).reverse().toString();
+            String oldReverse = new StringBuffer(oldPlcInfo).reverse().toString();
+
+            for (int i=0;i<newReverse.length();i++){
+//                第i位设备的值
+                String value = String.valueOf(newReverse.charAt(i));
+//                设备被触发
+                if (value.equals("1")&&!value.equals(String.valueOf(oldReverse.charAt(i)))){
+//                    记录时间 配置的设备地址为map的key
+                    for (Field field:status.getClass().getDeclaredFields()){
+                        field.setAccessible(true);
+                        if (Integer.parseInt(String.valueOf(field.get(status)))==i){
+//                            String name = fields[i].getName();
+                            DeviceCache.putTime((String) field.get(status),new Date());
+                            break;
+                        }
+                    }
+//                    前红外触发时调用方法
+                    if (String.valueOf(i).equals(status.getFRedPoint())){
+                        new Thread(()-> {
+                            try {
+                                plcService.fRedTrigger(newPlcInfo);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }).start();
+                    }
+//                    雷达外触发时调用方法
+                    if (String.valueOf(i).equals(status.getRadarPoint())){
+                        new Thread(()-> {
+                            try {
+                                plcService.radarTrigger();
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }).start();
+                    }
+//                    上到位触发时调用方法
+                    if (String.valueOf(i).equals(status.getUpPoint())){
+                        new Thread(()-> {
+                            try {
+                                plcService.upTrigger();
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                        }).start();
+                    }
+                }
+            }
+        }
+    }
 }

+ 1 - 1
src/main/java/com/gzlh/device/plc/job/SearchJob.java

@@ -17,7 +17,7 @@ public class SearchJob {
     private PlcNettyConfig plcNettyConfig;
     @Scheduled(fixedDelay = 2000)
     public void searchJob(){
-       // plcNettyConfig.send("0102000000187800");
+        plcNettyConfig.send("0102000000187800");
     }
 
 }

+ 24 - 10
src/main/java/com/gzlh/device/plc/service/PLCService.java

@@ -1,14 +1,20 @@
 package com.gzlh.device.plc.service;
 
+import cn.hutool.core.thread.ThreadUtil;
 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.SystemObject;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.capture.event.CaptureEvent;
+import com.gzlh.device.electron.job.ElectronReadJob;
 import com.gzlh.device.led.event.LedDefaultEvent;
+import com.gzlh.device.led.utils.LedOptions;
 import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
+import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.DeviceCache;
 import org.springframework.util.StringUtils;
 
@@ -18,10 +24,13 @@ public class PLCService {
     public void fRedTrigger(String plcInfo) throws InterruptedException {
         EventBus eventBus = SpringUtil.getBean(EventBus.class);
 
-        String carNo = EventDataManager.getCacheData().getCarNo();
+        ReqBO reqBO = EventDataManager.getCacheData();
 //        车牌采集失败
-        if (StringUtils.isEmpty(carNo)){
-            eventBus.startEvent(ModuleEnum.LED_MODULE.getModuleEn() + "." + LedDefaultEvent.READ);
+        if (reqBO==null||StringUtils.isEmpty(reqBO.getCarNo())){
+            eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn() + "." + CaptureEvent.CAPTURE_FAILED);
+//            LedOptions options = new LedOptions().setLine("02").setColor("01").setShowType("00");
+//            SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+//                    .sendMsg("车牌采集失败",options);
             return;
         }
         //向总线发送抓拍到车牌事件
@@ -39,7 +48,6 @@ public class PLCService {
             if (oldFRed.equals(newFRed)) {
                 Thread.sleep(2000);
             } else {
-                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READY);
                 bool = false;
             }
         }
@@ -51,7 +59,9 @@ public class PLCService {
         if (newFRed.equals("0") && bRed.equals("0")) {
             Date fRedTime = DeviceCache.getTime(status.getFRedPoint());
             Date radarTime = DeviceCache.getTime(status.getRadarPoint());
-
+            System.out.println("radarTime"+radarTime);
+            System.out.println("fRedTime"+fRedTime);
+            System.out.println("雷达时间小于前红外时间"+radarTime.before(fRedTime));
 //            雷达时间小于前红外时间为进,车辆前后红外之间
             if (radarTime.before(fRedTime)) {
                 eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
@@ -64,8 +74,12 @@ public class PLCService {
 
     public void radarTrigger() throws InterruptedException {
         EventBus eventBus = SpringUtil.getBean(EventBus.class);
-        //向总线发送抓拍到车牌事件
         SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+        //读取电子车牌
+        if(DeviceCache.getTime(status.getFRedPoint())==null){
+            ElectronReadJob job=   new ElectronReadJob("4002FEC0");
+            ThreadUtil.execute(job);
+        }
 //        将plc设备信息的字符串反转
         String newStatus = null;
         String newRadar = null;
@@ -81,7 +95,6 @@ public class PLCService {
                 Thread.sleep(2000);
             }
         }
-
 //        String bRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
 //        String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
 
@@ -90,14 +103,14 @@ public class PLCService {
         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)) {
+//           雷达时间大于前红外时间为退(或触发雷达后直接退车),并且只有下到位触发,判断车辆不在通道内,触发通道空闲状态
+            if (fRedTime == null || radarTime.after(fRedTime)) {
                 EventDataManager.cleanData();
+                DeviceCache.resetTimeMap();
                 eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
             }
         }
@@ -132,6 +145,7 @@ public class PLCService {
 //        判断当前PLC状态
         if (downOnly.equals(newStatus)) {
             EventDataManager.cleanData();
+            DeviceCache.resetTimeMap();
             eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
         }
     }

+ 0 - 1
src/main/java/com/gzlh/device/weighbridge/event/WeighbridgeEvent.java

@@ -4,7 +4,6 @@ package com.gzlh.device.weighbridge.event;
  * 地磅内置事件
  */
 public interface WeighbridgeEvent {
-    String READY="READY";
     String READ="READ";
     String TIMEOUT="TIMEOUT";
     String POSITION_ERROR="POSITION_ERROR";

+ 15 - 13
src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java

@@ -15,6 +15,7 @@ import com.gzlh.device.weighbridge.config.WeighbridgePropertiesConfig;
 import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
 import com.gzlh.utils.DeviceCache;
 
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.stream.Collectors;
@@ -60,38 +61,39 @@ public class CommonWeighbridgeHandler {
             int averaWeight = 0;
             String deviceStatus= null;
             SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
-
+            EventBus eventBus = SpringUtil.getBean(EventBus.class);
             while (time > 0) {
                 time = time - 1000;
                 averaWeight = WEIGHT_CACHE.stream().collect(Collectors.averagingInt(Integer::intValue)).intValue();
-                averaWeight = 12580;
+//                检查前后红外和雷达的触发情况
                 deviceStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
                 String fRed = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getFRedPoint())));
                 String bRed = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getBRedPoint())));
                 String radar = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getRadarPoint())));
                 if (fRed.equals("1")||bRed.equals("1")||radar.equals("1")){
                     DeviceCache.setInterrupt(true);
-                    LedOptions options = new LedOptions().setLine("04").setColor("01").setShowType("00");
-                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
-                            .sendMsg("车辆位置异常或异常跟车,请完全退出通道后再次进入通道",options);
+//                    LedOptions options = new LedOptions().setLine("04").setColor("01").setShowType("00");
+//                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+//                            .sendMsg("车辆位置异常或异常跟车,请完全退出通道后再次进入通道",options);
+                    eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.POSITION_ERROR);
                     break;
                 }
                 ThreadUtil.sleep(1000);
             }
-//            EventBus eventBus = SpringUtil.getBean(EventBus.class);
-//            WeighbridgePropertiesConfig weighbridgePropertiesConfig = SpringUtil.getBean(WeighbridgePropertiesConfig.class);
-//            if (averaWeight == 0 || weighbridgePropertiesConfig.getMinKg() > averaWeight) {
-//                //todo read timeout
-//                //读取超时
-//                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
-//                return;
-//            }
+            WeighbridgePropertiesConfig weighbridgePropertiesConfig = SpringUtil.getBean(WeighbridgePropertiesConfig.class);
+            if (averaWeight == 0 || weighbridgePropertiesConfig.getMinKg() > averaWeight) {
+                //todo read timeout
+                //读取超时
+                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
+                return;
+            }
             isStart=false;
             ApplicationConfig applicationConfig = SpringUtil.getBean(ApplicationConfig.class);
             //上传地磅数据
             String channelName = applicationConfig.getChannelName();
             String serverUrl = applicationConfig.getServerUrl();
             EventDataManager.cacheData("weight",averaWeight);
+            EventDataManager.cacheData("gatherTime",new Date());
         }
     }
 }

+ 2 - 2
src/main/java/com/gzlh/device/weighbridge/handler/impl/WeighbridgeHandlerKeDaKD8137.java

@@ -22,7 +22,7 @@ public class WeighbridgeHandlerKeDaKD8137 implements IWeighbridgeHandler {
 
     @Override
     public void handlerMsg(String msg) {
-        log.info(WeighbridgeBrandType.KEDA_KD_8137.getBrand() + "地磅:{}", msg);
+//        log.info(WeighbridgeBrandType.KEDA_KD_8137.getBrand() + "地磅:{}", msg);
         //处理后的磅数
         int weight = parseWeight(msg);
         CommonWeighbridgeHandler.cacheWeight(weight);
@@ -46,7 +46,7 @@ public class WeighbridgeHandlerKeDaKD8137 implements IWeighbridgeHandler {
      * @return
      */
     private int parseWeight(String msg) {
-        return 0;
+        return Integer.parseInt(msg.trim());
     }
 
 }

+ 1 - 1
src/main/java/com/gzlh/entity/CommandBO.java

@@ -22,7 +22,7 @@ public class CommandBO implements Serializable {
 
     @Data
     @Accessors(chain = true)
-    static class Command{
+    public static class Command{
         /**
          * 设备模块 gate
          */

+ 36 - 8
src/main/java/com/gzlh/entity/ReqBO.java

@@ -1,6 +1,7 @@
 package com.gzlh.entity;
 
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import org.springframework.context.annotation.Lazy;
 
@@ -19,6 +20,10 @@ public class ReqBO implements Serializable {
      */
     private String channelCode;
     /**
+     * 电子车牌 ERI
+     */
+    private String eri;
+    /**
      * 车牌
      */
     private String carNo;
@@ -30,21 +35,44 @@ public class ReqBO implements Serializable {
      * 称重重量kg
      */
     private Double weight;
+
     /**
-     * 车厢号
-     */
-    private Map<String,String> boxNoList=new HashMap<>();
-    /**
-     * 前后箱号图片List base64
+     * 箱数据
      */
-    private List<String> boxFImgList=new ArrayList<>();
-
-    private List<String> boxBImgList=new ArrayList<>();
+    private Box box;
 
     /**
      * 采集时间
      */
     private Date gatherTime;
 
+    @Data
+    public static class Box {
+        /**
+         * 前箱号
+         */
+        private String boxF;
+        /**
+         * 后箱号
+         */
+        private String boxB;
+        /**
+         * 后箱号图片多张,号分割
+         */
+        private String boxBImg;
+        /**
+         * 后箱号图片 多张,号分割
+         */
+        private String boxFImg;
+        /**
+         * 前箱型
+         */
+        private String modelF;
+        /**
+         * 后箱型
+         */
+        private String modelB;
+    }
+
 
 }

+ 4 - 1
src/main/java/com/gzlh/startup/StartupRunner.java

@@ -2,6 +2,7 @@ package com.gzlh.startup;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.XML;
 import com.gzlh.background.client.BackgroundClientNetty;
@@ -20,6 +21,7 @@ import com.gzlh.device.electron.client.ElectronNettyConfig;
 import com.gzlh.device.led.client.LedNettyConfig;
 import com.gzlh.device.infrared.client.RedNettyConfig;
 import com.gzlh.device.plc.client.PlcNettyConfig;
+import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.weighbridge.client.WeighbridgeNettyConfig;
 import com.gzlh.utils.WordHandlerUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -86,8 +88,9 @@ public class StartupRunner implements CommandLineRunner {
             }else {
                 log.info("登录海康抓拍设备失败:{},{}",hcNetSDK.NET_DVR_GetLastError(),userId);
             }
+            EventBus eventBus = SpringUtil.getBean(EventBus.class);
+            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
         }
-
     }