فهرست منبع

获取设备状态、行政通道判定

985653680@qq.com 11 ماه پیش
والد
کامیت
9d16fc801a
27فایلهای تغییر یافته به همراه312 افزوده شده و 84 حذف شده
  1. 11 0
      config.xml
  2. 19 25
      src/main/java/com/gzlh/background/client/BackgroundClientHandler.java
  3. 1 0
      src/main/java/com/gzlh/bus/EventConfig.java
  4. 18 8
      src/main/java/com/gzlh/bus/EventThread.java
  5. 1 1
      src/main/java/com/gzlh/config/ApplicationConfig.java
  6. 1 1
      src/main/java/com/gzlh/config/ModuleEnum.java
  7. 0 9
      src/main/java/com/gzlh/config/dto/SerialSetting.java
  8. 9 0
      src/main/java/com/gzlh/device/capture/brand/CaptureBrandType.java
  9. 6 1
      src/main/java/com/gzlh/device/capture/event/CaptureEvent.java
  10. 7 1
      src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java
  11. 2 0
      src/main/java/com/gzlh/device/electron/action/IElectronAction.java
  12. 10 0
      src/main/java/com/gzlh/device/electron/brand/ElectronBrandType.java
  13. 45 0
      src/main/java/com/gzlh/device/electron/client/ElectronClientHandler.java
  14. 6 1
      src/main/java/com/gzlh/device/electron/client/ElectronNettyConfig.java
  15. 7 0
      src/main/java/com/gzlh/device/electron/handler/impl/ElectronHandlerRuiDe.java
  16. 10 0
      src/main/java/com/gzlh/device/led/brand/LedBrandType.java
  17. 11 1
      src/main/java/com/gzlh/device/led/client/LedClientHandler.java
  18. 7 0
      src/main/java/com/gzlh/device/led/client/LedNettyConfig.java
  19. 6 5
      src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java
  20. 4 2
      src/main/java/com/gzlh/device/plc/handler/PLCHadnler.java
  21. 10 0
      src/main/java/com/gzlh/device/weighbridge/brand/WeighbridgeBrandType.java
  22. 5 3
      src/main/java/com/gzlh/device/weighbridge/client/WeighbridgeClientHandler.java
  23. 10 6
      src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java
  24. 30 0
      src/main/java/com/gzlh/entity/DeviceStatus.java
  25. 1 0
      src/main/java/com/gzlh/startup/StartupRunner.java
  26. 65 11
      src/main/java/com/gzlh/utils/DeviceCache.java
  27. 10 9
      src/main/resources/application.yml

+ 11 - 0
config.xml

@@ -102,6 +102,7 @@
             <!--通道重置-->
             <name>PLC.IDLE</name>
             <actionList>
+                <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>PLC.GREEN_LIGHT_ON</action>
                 <action>LED.LED_SHOW_CONTENT(${channel})</action>
                 <action>LED.LED_SHOW_CONTENT(${platNo})</action>
@@ -133,5 +134,15 @@
                 <action>LED.LED_SHOW_CONTENT(04|请退车并申请人工处理)</action>
             </actionList>
         </event>
+        <event>
+            <!--行政通道 识别到车牌-->
+            <name>CAPTURE.CAPTURE_ADMIN</name>
+            <actionList>
+                <action>LED.LED_SHOW_CONTENT(${platNo})</action>
+                <action>CENTER.TIMER_SLEEP(500)</action>
+                <action>LED.LED_SHOW_CONTENT(04|后台验放通讯中)</action>
+                <action>CENTER.SUBMIT</action>
+            </actionList>
+        </event>
     </eventList>
 </config>

+ 19 - 25
src/main/java/com/gzlh/background/client/BackgroundClientHandler.java

@@ -1,5 +1,6 @@
 package com.gzlh.background.client;
 
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.bus.EventBus;
 import com.gzlh.bus.EventConfig;
@@ -10,12 +11,17 @@ import com.gzlh.config.hksdk.HkUtils;
 import com.gzlh.config.hksdk.bo.HKCacheManager;
 import com.gzlh.device.capture.brand.CaptureBrandType;
 import com.gzlh.device.capture.properties.CapturePropertiesConfig;
+import com.gzlh.device.led.utils.LedOptions;
+import com.gzlh.entity.CommandBO;
+import com.gzlh.entity.DeviceStatus;
 import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import io.netty.handler.timeout.IdleStateEvent;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
@@ -41,9 +47,18 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-        System.out.println("Client received: " + msg);
+//        System.out.println("Client received: " + msg);
         if (!"back message".equalsIgnoreCase(msg)){
-            eventBus.startEvent(msg);
+            log.info(msg);
+            CommandBO commandBO = JSONUtil.toBean(msg, CommandBO.class);
+//            log.info(commandBO.toString());
+            CommandBO.Command command = commandBO.getCommand();
+            eventBus.startEvent(command.getModule()+"."+command.getCommand());
+            if (!StringUtils.isEmpty(command.getExtra())){
+                LedOptions options = new LedOptions().setLine("04").setColor("03").setShowType("00");
+                SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                            .sendMsg(command.getExtra(),options);
+            }
         }
     }
 
@@ -53,9 +68,6 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
 //        获取海康摄像头连接状态
         if (SystemObject.capturePropertiesConfig.getBrand()== CaptureBrandType.HK_BRAND.getCode()){
             Map<String,Object> captrue = new HashMap<String,Object>();
-            captrue.put("brand",SystemObject.capturePropertiesConfig.getBrand());
-            captrue.put("host",SystemObject.capturePropertiesConfig.getHost());
-            captrue.put("port",SystemObject.capturePropertiesConfig.getPort());
             int userId = HKCacheManager.getUserId(ModuleEnum.CAPTURE_MODULE);
             boolean status = hkUtils.getStatus(hcNetSDK, userId);
 
@@ -66,29 +78,11 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
                 String ip=capturePropertiesConfig.getHost();
                 loginV40 = hkUtils.Login_V40(ip, port, capturePropertiesConfig.getUsername(), capturePropertiesConfig.getPwd(), hcNetSDK);
             }
-            captrue.put("status",loginV40!=-1?1:0);
-            DeviceCache.put("captrue",captrue);
+            DeviceCache.changeDeviceStatus(ModuleEnum.CAPTURE_MODULE.getModuleEn(), loginV40!=-1?1:0);
         }
 
-//        Map<String,Object> led = new HashMap<String,Object>();
-//        led.put("brand",SystemObject.ledPropertiesConfig.getBrand());
-//        led.put("host",SystemObject.ledPropertiesConfig.getHost());
-//        led.put("port",SystemObject.ledPropertiesConfig.getPort());
-//        led.put("status",0);
-//        DeviceCache.add("led",led);
-
-        Map<String,Object> led = new HashMap<String,Object>();
-        led.put("brand",EventConfig.serialSetting.getLed().getBrand());
-        led.put("host",EventConfig.serialSetting.getHost());
-        led.put("port",EventConfig.serialSetting.getLed().getPort());
-        led.put("status",0);
-        DeviceCache.put("led",led);
-
-
-        DeviceCache.put("channelCode", SystemObject.applicationConfig.getChannelCode());
-        String jsonStr = JSONUtil.toJsonStr(DeviceCache.getCacheMap());
+        String jsonStr = DeviceCache.getDeviceStatusJson();
         context.writeAndFlush(jsonStr);
-//        System.out.println(" sent ping msg to " + context.channel().remoteAddress());
     }
 
 

+ 1 - 0
src/main/java/com/gzlh/bus/EventConfig.java

@@ -6,6 +6,7 @@ import cn.hutool.json.XML;
 import com.gzlh.config.dto.ApplicationConfigDTO;
 import com.gzlh.config.dto.EventDTO;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.utils.DeviceCache;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 

+ 18 - 8
src/main/java/com/gzlh/bus/EventThread.java

@@ -18,6 +18,7 @@ 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.action.PLCAction;
 import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.plc.handler.PLCHadnler;
 import com.gzlh.device.weighbridge.config.WeighbridgePropertiesConfig;
@@ -80,9 +81,9 @@ public class EventThread implements Runnable{
                 }else if (StrUtil.equals(module, ModuleEnum.PLC_MODULE.getModuleEn())) {
                     //动作属于plc
                     plcHadnler.handlerAction(command);
-                }else if (StrUtil.equals(module, ModuleEnum.CAR_MODULE.getModuleEn())) {
+                }else if (StrUtil.equals(module, ModuleEnum.ELECTRON_MODULE.getModuleEn())) {
                     //动作属于电子车牌
-                    electronFactory.handler(serialSetting.getCar().getBrand()).handlerAction(command);
+                    electronFactory.handler(serialSetting.getElectron().getBrand()).handlerAction(command);
                 }   else if (StrUtil.equals(module, ModuleEnum.CENTER_MODULE.getModuleEn())) {
                     //动作属于中心总线
                     handlerAction(command);
@@ -138,18 +139,27 @@ public class EventThread implements Runnable{
             LedOptions options = new LedOptions().setLine("04").setShowType("00");
             if (response.getStatus()==200){
                 options.setColor("02");
+                if (ModuleEnum.LED_MODULE.getModuleEn().equalsIgnoreCase(commandBO.getCommand().getModule())){
+                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                            .sendMsg(commandBO.getCommand().getExtra(),options);
+                }
+                eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.RAILING_RISE);
             }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());
+                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);
         }
+        if (SystemObject.applicationConfig.getChannelType()==1){
+            EventDataManager.cleanData();
+            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.IDLE);
+        }
 //        重置记录的设备触发时间
         DeviceCache.resetTimeMap();
     }

+ 1 - 1
src/main/java/com/gzlh/config/ApplicationConfig.java

@@ -11,5 +11,5 @@ public class ApplicationConfig {
   private String serverUrl;
   private String channelName;
   private String channelCode;
-
+  private int channelType;
 }

+ 1 - 1
src/main/java/com/gzlh/config/ModuleEnum.java

@@ -14,7 +14,7 @@ public enum ModuleEnum {
     CAPTURE_MODULE("抓拍单元","CAPTURE"),
     PLC_MODULE("PLC","PLC"),
     CENTER_MODULE("action调度中心","CENTER"),
-    CAR_MODULE("电子车牌","CAR"),
+    ELECTRON_MODULE("电子车牌","ELECTRON"),
     ;
     /**
      * 模块(硬件)中文名

+ 0 - 9
src/main/java/com/gzlh/config/dto/SerialSetting.java

@@ -17,8 +17,6 @@ public class SerialSetting implements Serializable {
     private LedDTO led;
     @JsonProperty("plc")
     private PlcDTO plc;
-    @JsonProperty("car")
-    private CarDTO car;
 
     @JsonProperty("electron")
     private ElectronSetting electron;
@@ -47,13 +45,6 @@ public class SerialSetting implements Serializable {
     }
     @Data
     @NoArgsConstructor
-    public static class CarDTO{
-        private Boolean enable;
-        private int port;
-        private Integer brand;
-    }
-    @Data
-    @NoArgsConstructor
     public static class PlcDTO{
         private Boolean enable;
         private int port;

+ 9 - 0
src/main/java/com/gzlh/device/capture/brand/CaptureBrandType.java

@@ -13,4 +13,13 @@ public enum CaptureBrandType {
 
     private int code;
     private String brand;
+
+    public static String getBrandByCode(int code) {
+        for (CaptureBrandType brandType : CaptureBrandType.values()) {
+            if (brandType.getCode() == code) {
+                return brandType.getBrand();
+            }
+        }
+        return null;
+    }
 }

+ 6 - 1
src/main/java/com/gzlh/device/capture/event/CaptureEvent.java

@@ -2,7 +2,7 @@ package com.gzlh.device.capture.event;
 
 public interface CaptureEvent {
     /**
-     * 抓拍到车牌
+     * 货运通道 抓拍到车牌
      */
     String CAPTURE_CAR_NO="CAPTURE_CAR_NO";
     /**
@@ -10,4 +10,9 @@ public interface CaptureEvent {
      */
     String CAPTURE_FAILED="CAPTURE_FAILED";
 
+    /**
+     * 行政车道 抓拍到车牌
+     */
+    String CAPTURE_ADMIN="CAPTURE_ADMIN";
+
 }

+ 7 - 1
src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java

@@ -20,6 +20,7 @@ import org.springframework.util.StringUtils;
 import javax.annotation.Resource;
 import java.io.File;
 import java.net.InetAddress;
+import java.util.Date;
 
 /***
  * 将本地的车牌图片、车牌号缓存到数据中心
@@ -46,8 +47,13 @@ public class HandlerCarImage extends Task {
 //      String base64=  Base64.encode(new File(filePath));
         EventDataManager.cacheData("carImg",filePath);
         EventDataManager.cacheData("carNo",carNo);
+        EventDataManager.cacheData("gatherTime",new Date());
         EventBus eventBus=SpringUtil.getBean(EventBus.class);
         //向总线发送抓拍到车牌事件
-        eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn()+"."+ CaptureEvent.CAPTURE_CAR_NO);
+        if (SystemObject.applicationConfig.getChannelType()==0){
+            eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn()+"."+ CaptureEvent.CAPTURE_CAR_NO);
+        }else{
+            eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn()+"."+ CaptureEvent.CAPTURE_ADMIN);
+        }
     }
 }

+ 2 - 0
src/main/java/com/gzlh/device/electron/action/IElectronAction.java

@@ -5,4 +5,6 @@ public interface IElectronAction {
      * 开始读卡
      */
     String START_READ_CARD="START_READ_CARD";
+
+    String VERSION="VERSION";
 }

+ 10 - 0
src/main/java/com/gzlh/device/electron/brand/ElectronBrandType.java

@@ -1,5 +1,6 @@
 package com.gzlh.device.electron.brand;
 
+import com.gzlh.device.capture.brand.CaptureBrandType;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
@@ -13,4 +14,13 @@ public enum ElectronBrandType {
 
     private int code;
     private String brand;
+
+    public static String getBrandByCode(int code) {
+        for (ElectronBrandType brandType : ElectronBrandType.values()) {
+            if (brandType.getCode() == code) {
+                return brandType.getBrand();
+            }
+        }
+        return null;
+    }
 }

+ 45 - 0
src/main/java/com/gzlh/device/electron/client/ElectronClientHandler.java

@@ -2,10 +2,15 @@ package com.gzlh.device.electron.client;
 
 import cn.hutool.core.util.StrUtil;
 import com.gzlh.bus.EventConfig;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.SystemObject;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.electron.action.IElectronAction;
+import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.timeout.IdleStateEvent;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -20,9 +25,13 @@ public class ElectronClientHandler extends SimpleChannelInboundHandler<String> {
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
+        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleEn(), 1);
         if (StrUtil.isEmpty(msg)){
             return;
         }
+        if (StrUtil.sub(msg,4,6).equalsIgnoreCase("02")){
+            return;
+        }
         log.info("电子车牌 客户端收到消息:" + msg);
         SystemObject.electronFactory.handler(EventConfig.serialSetting.getElectron().getBrand())
                 .handlerMsg(msg.toUpperCase());
@@ -31,6 +40,7 @@ public class ElectronClientHandler extends SimpleChannelInboundHandler<String> {
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("电子车牌 客户端 连接断开,进行重连");
+        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleEn(), 0);
         electronNettyConfig.connect();
     }
 
@@ -40,5 +50,40 @@ public class ElectronClientHandler extends SimpleChannelInboundHandler<String> {
         ctx.close();
     }
 
+    @Override
+    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
+        // IdleStateHandler 所产生的 IdleStateEvent 的处理逻辑.
+        if (evt instanceof IdleStateEvent) {
+            IdleStateEvent e = (IdleStateEvent) evt;
+            switch (e.state()) {
+                case READER_IDLE:
+                    handleReaderIdle(ctx);
+                    break;
+                case WRITER_IDLE:
+                    handleWriterIdle(ctx);
+                    break;
+                case ALL_IDLE:
+                    handleAllIdle(ctx);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+    protected void handleReaderIdle(ChannelHandlerContext ctx) {
+//        System.err.println("---READER_IDLE---");
+    }
+
+    protected void handleWriterIdle(ChannelHandlerContext ctx) {
+        //写空闲时发送读取版本信息指令
+        SystemObject.electronFactory.handler(EventConfig.serialSetting.getElectron().getBrand())
+                .handlerAction(IElectronAction.VERSION);
+//        System.err.println("---WRITER_IDLE---");
+    }
+
+    protected void handleAllIdle(ChannelHandlerContext ctx) {
+        System.err.println("---ALL_IDLE---");
+//        sendHeartbeat(ctx);
+    }
 }
 

+ 6 - 1
src/main/java/com/gzlh/device/electron/client/ElectronNettyConfig.java

@@ -12,6 +12,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.timeout.IdleStateHandler;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
@@ -49,6 +50,7 @@ public class ElectronNettyConfig {
                             ChannelPipeline pipeline = ch.pipeline();
                             pipeline.addLast( new NettyDecoder());
                             pipeline.addLast( new StringEncoder(StandardCharsets.UTF_8));
+                            pipeline.addLast( new IdleStateHandler(0, 5, 0));
                             pipeline.addLast(electronClientHandler);
                         } catch (Exception e) {
                             log.info("error connect:{}", e.getMessage());
@@ -84,7 +86,10 @@ public class ElectronNettyConfig {
     }
 
     public void send(String message) {
-        log.info("电子车牌发送命令:{}",message);
+//        获取版本号指令作为心跳信息 不显示
+        if (!message.equals("400202BC")){
+            log.info("电子车牌发送命令:{}",message);
+        }
         if (channel != null && channel.isActive()) {
             ByteBuf bufff = Unpooled.buffer();
             bufff.writeBytes(XorUtils.hexString2Bytes(message));

+ 7 - 0
src/main/java/com/gzlh/device/electron/handler/impl/ElectronHandlerRuiDe.java

@@ -42,6 +42,8 @@ public class ElectronHandlerRuiDe implements IElectronHandler {
     public void handlerAction(String action) {
         if (action.equals(IElectronAction.START_READ_CARD)){
             readERI();
+        }else if (action.equals(IElectronAction.VERSION)) {
+            getVersion();
         }
     }
 
@@ -123,4 +125,9 @@ public class ElectronHandlerRuiDe implements IElectronHandler {
         }
         return maxMap;
     }
+
+    public void getVersion(){
+//            发送读取版本信息的指令
+            sendMsg("400202BC");
+    }
 }

+ 10 - 0
src/main/java/com/gzlh/device/led/brand/LedBrandType.java

@@ -1,5 +1,6 @@
 package com.gzlh.device.led.brand;
 
+import com.gzlh.device.capture.brand.CaptureBrandType;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
@@ -16,4 +17,13 @@ public enum  LedBrandType {
 
     private int code;
     private String brand;
+
+    public static String getBrandByCode(int code) {
+        for (LedBrandType brandType : LedBrandType.values()) {
+            if (brandType.getCode() == code) {
+                return brandType.getBrand();
+            }
+        }
+        return null;
+    }
 }

+ 11 - 1
src/main/java/com/gzlh/device/led/client/LedClientHandler.java

@@ -1,10 +1,19 @@
 package com.gzlh.device.led.client;
 
+import com.gzlh.bus.EventConfig;
+import com.gzlh.config.ModuleEnum;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.led.brand.LedBrandType;
+import com.gzlh.entity.DeviceStatus;
+import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import lombok.extern.slf4j.Slf4j;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 @Slf4j
 @ChannelHandler.Sharable
 public class LedClientHandler extends SimpleChannelInboundHandler<String> {
@@ -18,12 +27,13 @@ public class LedClientHandler extends SimpleChannelInboundHandler<String> {
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
         log.info("LED 客户端收到消息:" + msg);
-
+        DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),1);
     }
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("led 客户端 连接断开,进行重连");
+        DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),0);
         ledNettyConfig.connect();
     }
 

+ 7 - 0
src/main/java/com/gzlh/device/led/client/LedNettyConfig.java

@@ -1,8 +1,12 @@
 package com.gzlh.device.led.client;
 
 import com.gzlh.bus.EventConfig;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.config.netty.NettyDecoder;
+import com.gzlh.device.led.brand.LedBrandType;
+import com.gzlh.entity.DeviceStatus;
+import com.gzlh.utils.DeviceCache;
 import com.gzlh.utils.XorUtils;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
@@ -22,7 +26,9 @@ import javax.annotation.Resource;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 @Configuration
 @Slf4j
@@ -78,6 +84,7 @@ public class LedNettyConfig {
             if (future1.isSuccess()) {
                 channel = future1.channel();
                 log.info("led 串口服务器连接成功,{},{}", host, port);
+                DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleEn(),1);
             } else {
                 log.error("-------------led 连接服务器失败,{},{}-----------,进行重连", host, port);
                 future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);

+ 6 - 5
src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java

@@ -2,6 +2,7 @@ package com.gzlh.device.plc.client;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.gzlh.bus.EventConfig;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.SystemObject;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.device.plc.handler.PLCHadnler;
@@ -32,22 +33,22 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-        log.info("PLC 客户端收到消息:" + msg);
-
+//        log.info("PLC 客户端收到消息:" + msg);
+//        修改设备状态信息
+        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleEn(),1);
 //        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);
         }
-
-
-
     }
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("PLC 客户端 连接断开,进行重连");
+//        断连设备状态设为0
+        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleEn(),0);
         ledNettyConfig.connect();
     }
 

+ 4 - 2
src/main/java/com/gzlh/device/plc/handler/PLCHadnler.java

@@ -3,9 +3,11 @@ package com.gzlh.device.plc.handler;
 import cn.hutool.core.util.StrUtil;
 import com.gzlh.bus.EventConfig;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.led.brand.LedBrandType;
 import com.gzlh.device.plc.action.PLCAction;
 import com.gzlh.device.plc.client.PlcNettyConfig;
 import com.gzlh.device.plc.service.PLCService;
+import com.gzlh.entity.DeviceStatus;
 import com.gzlh.utils.DeviceCache;
 import com.gzlh.utils.ModbusUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -14,6 +16,8 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.lang.reflect.Field;
 import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -74,8 +78,6 @@ public class PLCHadnler {
     }
 
     public void handlerMsg(String msg) throws Exception{
-
-        DeviceCache.put("plc",1);
 //        不是返回的plc状态信息就中断
         if (!msg.substring(0,4).equals("0102")){
             return;

+ 10 - 0
src/main/java/com/gzlh/device/weighbridge/brand/WeighbridgeBrandType.java

@@ -1,5 +1,6 @@
 package com.gzlh.device.weighbridge.brand;
 
+import com.gzlh.device.capture.brand.CaptureBrandType;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
@@ -18,4 +19,13 @@ public enum WeighbridgeBrandType {
 
     private int code;
     private String brand;
+
+    public static String getBrandByCode(int code) {
+        for (WeighbridgeBrandType brandType : WeighbridgeBrandType.values()) {
+            if (brandType.getCode() == code) {
+                return brandType.getBrand();
+            }
+        }
+        return null;
+    }
 }

+ 5 - 3
src/main/java/com/gzlh/device/weighbridge/client/WeighbridgeClientHandler.java

@@ -1,8 +1,10 @@
 package com.gzlh.device.weighbridge.client;
 
 import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.device.weighbridge.config.WeighbridgePropertiesConfig;
 import com.gzlh.device.weighbridge.factory.WeighbridgeFactory;
+import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
@@ -20,8 +22,7 @@ public class WeighbridgeClientHandler extends SimpleChannelInboundHandler<String
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-
-
+        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn(),1);
         WeighbridgePropertiesConfig weighbridgePropertiesConfig = SpringUtil.getBean(WeighbridgePropertiesConfig.class);
         WeighbridgeFactory weighbridgeFactory = SpringUtil.getBean(WeighbridgeFactory.class);
         weighbridgeFactory.handler(weighbridgePropertiesConfig.getBrand()).handlerMsg(msg);
@@ -29,7 +30,8 @@ public class WeighbridgeClientHandler extends SimpleChannelInboundHandler<String
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        System.out.println("连接断开,进行重连");
+        log.error("地磅 连接断开,进行重连");
+        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn(),0);
         nettyConfig.connect();
     }
 

+ 10 - 6
src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java

@@ -54,7 +54,7 @@ public class CommonWeighbridgeHandler {
      * 监控2秒内的地磅数
      */
     static class WatchThread implements Runnable {
-        private int time = 3000;
+        private int time = 4000;
 
         @Override
         public void run() {
@@ -70,13 +70,17 @@ public class CommonWeighbridgeHandler {
                 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())));
+                System.out.println(fRed+","+bRed+","+radar);
                 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);
-                    eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.POSITION_ERROR);
-                    break;
+                    LedOptions options = new LedOptions().setLine("03").setColor("04").setShowType("00");
+                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                            .sendMsg("车辆位置异常或异常跟车",options);
+
+                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                            .sendMsg("请完全退出通道后再次进入通道",options.setLine("04").setColor("01"));
+//                    eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.POSITION_ERROR);
+                    return;
                 }
                 ThreadUtil.sleep(1000);
             }

+ 30 - 0
src/main/java/com/gzlh/entity/DeviceStatus.java

@@ -0,0 +1,30 @@
+package com.gzlh.entity;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+@Data
+@Accessors(chain = true)
+public class DeviceStatus {
+    private String channelCode;
+    private String channelName;
+    private List<Device> deviceList = new CopyOnWriteArrayList<>();
+    @Data
+    public static class Device{
+        String host;
+        Integer port;
+        String brand;
+        String name;
+        Integer status = 0;
+
+        public Device(String host, Integer port, String brand, String name) {
+            this.host = host;
+            this.port = port;
+            this.brand = brand;
+            this.name = name;
+        }
+    }
+}

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

@@ -23,6 +23,7 @@ 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.DeviceCache;
 import com.gzlh.utils.WordHandlerUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;

+ 65 - 11
src/main/java/com/gzlh/utils/DeviceCache.java

@@ -1,12 +1,27 @@
 package com.gzlh.utils;
 
 
+import cn.hutool.json.JSONUtil;
+import com.gzlh.bus.EventConfig;
+import com.gzlh.config.ModuleEnum;
+import com.gzlh.config.SystemObject;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.capture.brand.CaptureBrandType;
+import com.gzlh.device.electron.brand.ElectronBrandType;
+import com.gzlh.device.led.brand.LedBrandType;
+import com.gzlh.device.weighbridge.brand.WeighbridgeBrandType;
+import com.gzlh.entity.DeviceStatus;
+import org.springframework.beans.BeanUtils;
+import org.springframework.util.StringUtils;
+
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 public class DeviceCache {
-    private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();
+    private static DeviceStatus deviceStatus = new DeviceStatus();
     private static Map<String, Date> plcTimeMap = new ConcurrentHashMap<String,Date>();
 
     static boolean interrupt=false;
@@ -31,22 +46,53 @@ public class DeviceCache {
         plcTimeMap=new ConcurrentHashMap<String,Date>();;
     }
 
-
-    public static void put(String k, Object v){
-        map.put(k,v);
+    public static String getDeviceStatusJson(){
+        if (StringUtils.isEmpty(deviceStatus.getChannelCode())){
+            deviceStatusInit();
+        }
+        return JSONUtil.toJsonStr(deviceStatus);
     }
 
-    public static Object get(String k){
-        return map.get(k);
-    }
+    public static void deviceStatusInit(){
+        SerialSetting serialSetting= EventConfig.serialSetting;
+        deviceStatus.setChannelCode(SystemObject.applicationConfig.getChannelCode());
+        deviceStatus.setChannelName(SystemObject.applicationConfig.getChannelName());
+
+        DeviceStatus.Device capture =  new DeviceStatus.Device(SystemObject.capturePropertiesConfig.getHost(),
+                SystemObject.capturePropertiesConfig.getPort(),
+                LedBrandType.getBrandByCode(SystemObject.capturePropertiesConfig.getBrand()),
+                ModuleEnum.CAPTURE_MODULE.getModuleEn());
+        deviceStatus.getDeviceList().add(capture);
+
+        DeviceStatus.Device plc =  new DeviceStatus.Device(serialSetting.getHost(),
+                serialSetting.getPlc().getPort(),
+                "",
+                ModuleEnum.PLC_MODULE.getModuleEn());
+        deviceStatus.getDeviceList().add(plc);
 
-    public static void remove(String k){
-        map.remove(k);
+        DeviceStatus.Device led = new DeviceStatus.Device(serialSetting.getHost(),
+                serialSetting.getLed().getPort(),
+                LedBrandType.getBrandByCode(serialSetting.getLed().getBrand()),
+                ModuleEnum.LED_MODULE.getModuleEn());
+        deviceStatus.getDeviceList().add(led);
+
+        DeviceStatus.Device weighbridge = new DeviceStatus.Device(serialSetting.getHost(),
+                serialSetting.getWeighbridge().getPort(),
+                WeighbridgeBrandType.getBrandByCode(serialSetting.getWeighbridge().getBrand()),
+                ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn());
+        deviceStatus.getDeviceList().add(weighbridge);
+
+        DeviceStatus.Device electron = new DeviceStatus.Device(serialSetting.getHost(),
+                serialSetting.getElectron().getPort(),
+                ElectronBrandType.getBrandByCode(serialSetting.getElectron().getBrand()),
+                ModuleEnum.ELECTRON_MODULE.getModuleEn());
+        deviceStatus.getDeviceList().add(electron);
     }
 
-    public static Map<String,Object> getCacheMap(){
-        return map;
+    public static DeviceStatus getDeviceStatus(){
+        return deviceStatus;
     }
+
     public static Map<String, Date> getTimeMap(){
         return plcTimeMap;
     }
@@ -58,4 +104,12 @@ public class DeviceCache {
     public static void setInterrupt(boolean interrupt) {
         DeviceCache.interrupt = interrupt;
     }
+
+    public static void changeDeviceStatus(String name,int status) {
+        List<DeviceStatus.Device> devices = DeviceCache.getDeviceStatus().getDeviceList();
+        if (devices.stream().anyMatch(device -> device.getName().equalsIgnoreCase(name))){
+            devices.stream().filter(device -> device.getName().equalsIgnoreCase(name))
+                    .map(e -> e.setStatus(status)).collect(Collectors.toList());
+        }
+    }
 }

+ 10 - 9
src/main/resources/application.yml

@@ -1,21 +1,22 @@
 server:
   port: 8086
 application:
-  server-url: http://127.0.0.1:8099/pro #后端服务器地址
-  channel-name: "A1园内地磅通道"
+  server-url: http://192.168.1.3:9191 #后端服务器地址
+  channel-name: "A1地磅通道"
   channel-code: "A1001"
+  channel-type: 0
 #地磅配置
 weighbridge:
   host: 127.0.0.1
-  port: 9096
-  brand: 3000
+  port: 4005
+  brand: 3001
   min-kg: 1000
-  enable: false
+  enable: true
 #LED配置
 led:
   host: 192.168.1.254
   port: 4003
-  brand: 1000
+  brand: 2000
   enable: true
  #红外
 red:
@@ -43,9 +44,9 @@ capture:
   enable: true
 
 background:
-  host: 127.0.0.1
-  port: 8080
-  enable: false
+  host: 192.168.1.3
+  port: 8050
+  enable: true
   #图片存储根路径
 file:
   root-path: D:\\upload\\