Browse Source

v1.0 完成散货调试

qzyReal 1 year ago
parent
commit
f0ef4522c2
42 changed files with 665 additions and 313 deletions
  1. 39 21
      config.xml
  2. 1 2
      pom.xml
  3. 1 1
      src/main/java/com/gzlh/background/client/BackgroundClientHandler.java
  4. 8 8
      src/main/java/com/gzlh/background/client/BackgroundClientNetty.java
  5. 0 14
      src/main/java/com/gzlh/background/properties/BackgroundPropertiesConfig.java
  6. 1 1
      src/main/java/com/gzlh/bus/EventDataManager.java
  7. 22 12
      src/main/java/com/gzlh/bus/EventThread.java
  8. 5 4
      src/main/java/com/gzlh/bus/SysConfig.java
  9. 5 0
      src/main/java/com/gzlh/bus/task/CountManager.java
  10. 39 0
      src/main/java/com/gzlh/bus/task/InitTask.java
  11. 0 16
      src/main/java/com/gzlh/config/ApplicationConfig.java
  12. 2 5
      src/main/java/com/gzlh/config/SystemObject.java
  13. 4 0
      src/main/java/com/gzlh/config/dto/ApplicationConfigDTO.java
  14. 26 0
      src/main/java/com/gzlh/config/dto/ChannelSetting.java
  15. 15 0
      src/main/java/com/gzlh/config/dto/ManagerSetting.java
  16. 15 0
      src/main/java/com/gzlh/config/dto/SerialSetting.java
  17. 15 13
      src/main/java/com/gzlh/config/hksdk/AlarmParseService.java
  18. 1 1
      src/main/java/com/gzlh/config/hksdk/EventCallback.java
  19. 2 1
      src/main/java/com/gzlh/device/camera/controller/CameraController.java
  20. 19 6
      src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java
  21. 2 2
      src/main/java/com/gzlh/device/electron/client/ElectronClientHandler.java
  22. 2 3
      src/main/java/com/gzlh/device/led/client/LedClientHandler.java
  23. 1 1
      src/main/java/com/gzlh/device/led/client/LedNettyConfig.java
  24. 6 4
      src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java
  25. 0 1
      src/main/java/com/gzlh/device/led/utils/FengLiYuanPackUtils.java
  26. 2 2
      src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java
  27. 6 3
      src/main/java/com/gzlh/device/plc/client/PlcNettyConfig.java
  28. 37 0
      src/main/java/com/gzlh/device/plc/handler/CheckDownTask.java
  29. 53 0
      src/main/java/com/gzlh/device/plc/handler/CheckUpTask.java
  30. 133 59
      src/main/java/com/gzlh/device/plc/handler/PLCHadnler.java
  31. 19 10
      src/main/java/com/gzlh/device/plc/job/SearchJob.java
  32. 6 5
      src/main/java/com/gzlh/device/plc/service/PLCService.java
  33. 1 0
      src/main/java/com/gzlh/device/weighbridge/action/WeighbridgeCommonAction.java
  34. 1 1
      src/main/java/com/gzlh/device/weighbridge/brand/WeighbridgeBrandType.java
  35. 2 2
      src/main/java/com/gzlh/device/weighbridge/client/WeighbridgeClientHandler.java
  36. 5 2
      src/main/java/com/gzlh/device/weighbridge/client/WeighbridgeNettyConfig.java
  37. 38 33
      src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java
  38. 61 12
      src/main/java/com/gzlh/device/weighbridge/handler/impl/WeighbridgeHandlerKeLi.java
  39. 4 4
      src/main/java/com/gzlh/startup/StartupRunner.java
  40. 61 50
      src/main/java/com/gzlh/utils/DeviceCache.java
  41. 4 2
      src/main/java/com/gzlh/utils/WordHandlerUtils.java
  42. 1 12
      src/main/resources/application.yml

+ 39 - 21
config.xml

@@ -1,30 +1,48 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <config>
+    <managerSetting>
+        <enable>true</enable>
+        <host>10.26.1.25</host>
+        <beatPort>8050</beatPort>
+        <serverUrl>http://10.26.1.25:9191</serverUrl>
+    </managerSetting>
+    <!--通道属性配置-->
+    <channelSetting>
+        <!--本机IP-->
+        <ip>10.26.1.26</ip>
+        <channelCode>A1002</channelCode>
+        <channelName>货运进道2</channelName>
+        <!--0 货运通道 1 行政通道-->
+        <channelType>0</channelType>
+        <!--车牌保存路径-->
+        <fileRootPath>D:\\file</fileRootPath>
+    </channelSetting>
+    <!--设备相关设置-->
     <sysConfig>
         <caputreSetting>
             <enable>true</enable>
-            <host>192.168.1.11</host>
+            <host>10.26.6.51</host>
             <port>8000</port>
             <username>admin</username>
-            <pwd>ap123456</pwd>
+            <pwd>ABCabc123</pwd>
             <brand>5000</brand>
         </caputreSetting>
         <serialSetting>
-            <host>192.168.1.254</host>
+            <host>10.26.6.50</host>
             <weighbridge>
                 <enable>true</enable>
-                <port>4005</port>
+                <port>4003</port>
                 <brand>3000</brand>
-                <minKg>5000</minKg>
+                <minKg>1000</minKg>
             </weighbridge>
             <led>
                 <enable>true</enable>
-                <port>4003</port>
+                <port>4002</port>
                 <brand>2000</brand>
             </led>
             <electron>
-                <enable>true</enable>
+                <enable>false</enable>
                 <port>4002</port>
                 <brand>2000</brand>
             </electron>
@@ -33,9 +51,9 @@
                 <port>4001</port>
                 <!--输出-->
                 <out>
+                    <gatePoint>00</gatePoint>
                     <signalRedPoint>02</signalRedPoint>
                     <signalGreenPoint>03</signalGreenPoint>
-                    <gatePoint>00</gatePoint>
                 </out>
                 <!--状态信号-->
                 <status>
@@ -53,18 +71,17 @@
             </plc>
         </serialSetting>
     </sysConfig>
+    <!--事件时序-->
     <eventList>
         <event>
             <name>WEIGHBRIDGE.READ</name>
             <!--动作格式 模块.命令-->
             <actionList>
-                <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>CENTER.TIMER_SLEEP(1000)</action>
+                <action>LED.LED_SHOW_CONTENT(04|即将称重,请停车)</action>
+                <action>CENTER.TIMER_SLEEP(3000)</action>
                 <action>WEIGHBRIDGE.START_READ</action>
-                <action>CENTER.TIMER_SLEEP(4000)</action>
+                <action>CENTER.TIMER_SLEEP(5000)</action>
                 <action>LED.LED_SHOW_CONTENT(${weight})</action>
                 <action>CENTER.TIMER_SLEEP(500)</action>
                 <action>LED.LED_SHOW_CONTENT(04|称重成功,后台验放通讯中)</action>
@@ -84,10 +101,9 @@
             <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>
+                <action>PLC.GREEN_LIGHT_OFF</action>
+                <action>LED.LED_SHOW_CONTENT(04|请继续行驶)</action>
             </actionList>
         </event>
         <event>
@@ -95,7 +111,7 @@
             <name>PLC.RAILING_RISE</name>
             <actionList>
                 <action>PLC.RAILING_RISE_ON</action>
-                <action>CENTER.TIMER_SLEEP(5000)</action>
+                <action>CENTER.TIMER_SLEEP(100)</action>
                 <action>PLC.RAILING_RISE_OFF</action>
             </actionList>
         </event>
@@ -110,14 +126,16 @@
             <!--通道重置-->
             <name>PLC.IDLE</name>
             <actionList>
-                <action>CENTER.TIMER_SLEEP(5000)</action>
+                <action>WEIGHBRIDGE.CLEAN</action>
+                <action>CENTER.TIMER_SLEEP(20)</action>
+                <action>PLC.RED_LIGHT_OFF</action>
+                <action>CENTER.TIMER_SLEEP(30)</action>
                 <action>PLC.GREEN_LIGHT_ON</action>
+                <action>PLC.RAILING_RISE_OFF</action>
                 <action>LED.LED_SHOW_CONTENT(${channel})</action>
                 <action>LED.LED_SHOW_CONTENT(${platNo})</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>
         </event>
         <event>

+ 1 - 2
pom.xml

@@ -73,7 +73,7 @@
 
     <!-- 构建配置 -->
     <build>
-        <finalName>weighbridge-server</finalName>
+        <finalName>gather-server</finalName>
         <!-- 配置资源目录  -->
         <resources>
             <resource>
@@ -138,7 +138,6 @@
                             <artifactId>spring-core</artifactId>
                         </include>
                     </includes>
-                    >
                 </configuration>
             </plugin>
             <plugin>

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

@@ -79,7 +79,7 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
                     HKCacheManager.add(ModuleEnum.CAPTURE_MODULE,loginV40);
                 }
              }
-            DeviceCache.changeDeviceStatus(ModuleEnum.CAPTURE_MODULE.getModuleEn(), loginV40!=-1?1:0);
+            DeviceCache.changeDeviceStatus(ModuleEnum.CAPTURE_MODULE.getModuleZh(), loginV40!=-1?1:0);
         }
 
         String jsonStr = DeviceCache.getDeviceStatusJson();

+ 8 - 8
src/main/java/com/gzlh/background/client/BackgroundClientNetty.java

@@ -1,7 +1,7 @@
 package com.gzlh.background.client;
 
-import com.gzlh.background.properties.BackgroundPropertiesConfig;
-import com.gzlh.utils.DeviceCache;
+import com.gzlh.bus.SysConfig;
+import com.gzlh.config.dto.ManagerSetting;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -23,8 +23,7 @@ import java.util.concurrent.TimeUnit;
 @Slf4j
 public class BackgroundClientNetty {
 
-    @Resource
-    private BackgroundPropertiesConfig config;
+
     @Autowired
     private BackgroundClientHandler backgroundClientHandler;
     Bootstrap bootstrap;
@@ -33,12 +32,12 @@ public class BackgroundClientNetty {
 
     @Bean("backgroundClient")
     public Bootstrap bootstrap() {
-
+        ManagerSetting managerSetting= SysConfig.managerSetting;
         EventLoopGroup group = new NioEventLoopGroup();
         bootstrap = new Bootstrap();
         return bootstrap.group(group)
                 .channel(NioSocketChannel.class)
-                .remoteAddress(config.getHost(), config.getPort())
+                .remoteAddress(managerSetting.getHost(), managerSetting.getBeatPort())
                 .handler(new ChannelInitializer<SocketChannel>() {
                     @Override
                     protected void initChannel(SocketChannel socketChannel) {
@@ -59,12 +58,13 @@ public class BackgroundClientNetty {
 
     public void connect() {
         ChannelFuture future = bootstrap().connect();
+        ManagerSetting managerSetting= SysConfig.managerSetting;
         future.addListener((ChannelFutureListener) future1 -> {
             if (future1.isSuccess()) {
                 channel = future1.channel();
-                log.info("后端服务器连接成功,{},{}",config.getHost(), config.getPort());
+                log.info("后端服务器连接成功,{},{}",managerSetting.getHost(), managerSetting.getBeatPort());
             } else {
-                log.error("-------------后端连接服务器失败,{},{}-----------,进行重连",config.getHost(), config.getPort());
+                log.error("-------------后端连接服务器失败,{},{}-----------,进行重连",managerSetting.getHost(), managerSetting.getBeatPort());
                 future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);
             }
         });

+ 0 - 14
src/main/java/com/gzlh/background/properties/BackgroundPropertiesConfig.java

@@ -1,14 +0,0 @@
-package com.gzlh.background.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-@ConfigurationProperties(prefix = "background")
-@Configuration
-@Data
-public class BackgroundPropertiesConfig {
-    private String host;
-    private int port;
-    private boolean enable;
-}

+ 1 - 1
src/main/java/com/gzlh/bus/EventDataManager.java

@@ -26,7 +26,7 @@ public class EventDataManager {
             reqBO = new ReqBO();
             reqBO.setDirection(1);
         }
-        reqBO.setChannelCode(SystemObject.applicationConfig.getChannelCode());
+        reqBO.setChannelCode(SysConfig.channelSetting.getChannelCode());
         ReflectUtil.setFieldValue(reqBO, field, value);
         CACHE_MAP.put(KEY, reqBO);
         StaticLog.info("cache bo:{}", JSONUtil.toJsonStr(reqBO));

+ 22 - 12
src/main/java/com/gzlh/bus/EventThread.java

@@ -19,7 +19,9 @@ 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.action.WeighbridgeCommonAction;
 import com.gzlh.device.weighbridge.factory.WeighbridgeFactory;
+import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
 import com.gzlh.entity.CommandBO;
 import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.DeviceCache;
@@ -51,7 +53,7 @@ public class EventThread implements Runnable{
         PLCHadnler plcHadnler= SpringUtil.getBean(PLCHadnler.class);
         CaptureFactory captureFactory=SystemObject.captureFactory;
         CaputreSetting caputreSetting=SysConfig.caputreSetting;
-        log.info("event:{}", eventName);
+      //  log.info("event:{}", eventName);
         SysConfig.eventDTOList.stream().filter(eventDTO -> StrUtil.equals(eventName, eventDTO.getName()))
                 .findFirst().ifPresent(eventDTO -> {
             List<String> actionList = eventDTO.getActionList().getAction();
@@ -61,6 +63,8 @@ public class EventThread implements Runnable{
                 String command = StrUtil.subAfter(action, ".", true);
 //                中断事件动作
                 if (DeviceCache.isInterrupt()){
+                    //停止读数
+                    CommonWeighbridgeHandler.isStart=false;
                     DeviceCache.setInterrupt(false);
                     break;
                 }
@@ -123,26 +127,35 @@ public class EventThread implements Runnable{
      * @param
      */
     private void handlerSubmit() {
-        String address = SystemObject.applicationConfig.getServerUrl();
-        String api="/open/submit";
-        HttpResponse response = request(address+api, JSONUtil.toJsonStr(EventDataManager.getCacheData()));
+        String api=SysConfig.managerSetting.getServerUrl()+"/open/submit";
+        String bodyParams=JSONUtil.toJsonStr(EventDataManager.getCacheData());
+        if (StrUtil.isEmpty(bodyParams)){
+            return;
+        }
+        log.info("Req:{}",bodyParams);
         EventBus eventBus= SpringUtil.getBean(EventBus.class);
+        HttpResponse response = request(api, bodyParams);
         log.info("提交通道数据-返回结果:{}",response.body());
         if (response.getStatus() == 200){
             String body = response.body();
-            JSONObject jsonObject = new JSONObject(body);
+            JSONObject jsonObject = JSONUtil.parseObj(body);
 //            返回数据解密
             String data = WordHandlerUtils.AESDecrypt(jsonObject.get("data").toString());
-//            String data = jsonObject.get("data").toString();
+            log.info("data:{}",data);
             CommandBO commandBO = JSONUtil.toBean(data, CommandBO.class);
             LedOptions options = new LedOptions().setLine("04").setShowType("00");
-            if ("200".equals(jsonObject.get("code"))){
+            if (jsonObject.getInt("code")==200){
+                log.info("抬杆放行============");
+                eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.RAILING_RISE);
                 options.setColor("02");
                 if (ModuleEnum.LED_MODULE.getModuleEn().equalsIgnoreCase(commandBO.getCommand().getModule())){
                     SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
                             .sendMsg(commandBO.getCommand().getExtra(),options);
                 }
-                eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.RAILING_RISE);
+                if (SysConfig.channelSetting.getChannelType()==0){
+                   // EventDataManager.cleanData();
+                   // eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn()+"."+ PLCEvent.IDLE);
+                }
             }else{
                 options.setColor("01");
                 if (ModuleEnum.LED_MODULE.getModuleEn().equalsIgnoreCase(commandBO.getCommand().getModule())){
@@ -155,10 +168,7 @@ public class EventThread implements Runnable{
         }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();
     }

+ 5 - 4
src/main/java/com/gzlh/bus/SysConfig.java

@@ -3,10 +3,7 @@ package com.gzlh.bus;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.XML;
-import com.gzlh.config.dto.ApplicationConfigDTO;
-import com.gzlh.config.dto.CaputreSetting;
-import com.gzlh.config.dto.EventDTO;
-import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.config.dto.*;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -20,6 +17,8 @@ public class SysConfig {
     public static List<EventDTO> eventDTOList;
     public static SerialSetting serialSetting;
     public static CaputreSetting caputreSetting;
+    public static ChannelSetting channelSetting;
+    public static ManagerSetting managerSetting;
 
     public static void initConfig() {
         Properties properties = System.getProperties();
@@ -37,5 +36,7 @@ public class SysConfig {
         eventDTOList=configDTO.getConfig().getEventList().getEvent();
         serialSetting=configDTO.getConfig().getSysConfig().getSerialSetting();
         caputreSetting=configDTO.getConfig().getSysConfig().getCaputreSetting();
+        channelSetting=configDTO.getConfig().getChannelSetting();
+        managerSetting=configDTO.getConfig().getManagerSetting();
     }
 }

+ 5 - 0
src/main/java/com/gzlh/bus/task/CountManager.java

@@ -0,0 +1,5 @@
+package com.gzlh.bus.task;
+
+public class CountManager {
+
+}

+ 39 - 0
src/main/java/com/gzlh/bus/task/InitTask.java

@@ -0,0 +1,39 @@
+package com.gzlh.bus.task;
+
+import cn.hutool.cache.CacheUtil;
+import cn.hutool.cache.impl.TimedCache;
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.EventBus;
+import com.gzlh.config.ModuleEnum;
+import com.gzlh.device.plc.event.PLCEvent;
+import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+//@Component
+@Slf4j
+public class InitTask {
+    private final TimedCache<String, Integer> COUNT = CacheUtil.newTimedCache(60000);
+
+//    @Scheduled(fixedDelay = 5000)
+    public void init() {
+        String key = "cache";
+        Integer count = COUNT.get(key, false);
+        if (count == null || CommonWeighbridgeHandler.hsCar) {
+            count = 1;
+            COUNT.put(key, count);
+            return;
+        }
+      //  log.info("count:{}", count);
+        if (!CommonWeighbridgeHandler.hsCar && count > 3) {
+            EventBus eventBus = SpringUtil.getBean(EventBus.class);
+            log.info("init");
+            count = 0;
+            COUNT.put(key, count);
+            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+        }
+        count = count + 1;
+        COUNT.put(key, count);
+    }
+}

+ 0 - 16
src/main/java/com/gzlh/config/ApplicationConfig.java

@@ -1,16 +0,0 @@
-package com.gzlh.config;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-@ConfigurationProperties(prefix = "application")
-@Data
-@Configuration
-public class ApplicationConfig {
-  private String serverUrl;
-  private String channelName;
-  private String channelCode;
-//  0 货运通道 1 行政通道
-  private int channelType;
-}

+ 2 - 5
src/main/java/com/gzlh/config/SystemObject.java

@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
 @Component
 public class SystemObject {
 
-    public static ApplicationConfig applicationConfig;
+
 
     public static FilePropertiesConfig filePropertiesConfig;
 
@@ -28,10 +28,7 @@ public class SystemObject {
         SystemObject.electronFactory = electronFactory;
     }
 
-    @Autowired
-    void setApplicationConfig(ApplicationConfig applicationConfig) {
-        SystemObject.applicationConfig = applicationConfig;
-    }
+
 
     @Autowired
     void setFilePropertiesConfig(FilePropertiesConfig filePropertiesConfig) {

+ 4 - 0
src/main/java/com/gzlh/config/dto/ApplicationConfigDTO.java

@@ -21,6 +21,10 @@ public class ApplicationConfigDTO implements Serializable {
         private ConfigListDTO sysConfig;
         @JsonProperty("eventList")
         private EventListDTO eventList;
+        @JsonProperty("channelSetting")
+        private ChannelSetting channelSetting;
+        @JsonProperty("managerSetting")
+        private ManagerSetting managerSetting;
         @NoArgsConstructor
         @Data
         public static class EventListDTO {

+ 26 - 0
src/main/java/com/gzlh/config/dto/ChannelSetting.java

@@ -0,0 +1,26 @@
+package com.gzlh.config.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+@Data
+@Accessors(chain = true)
+public class ChannelSetting implements Serializable {
+
+    @JsonProperty("ip")
+    private String ip;
+
+    @JsonProperty("channelName")
+    private String channelName;
+
+    @JsonProperty("channelCode")
+    private String channelCode;
+
+    @JsonProperty("channelType")
+    private int channelType=0;
+    @JsonProperty("fileRootPath")
+    private String fileRootPath;
+}

+ 15 - 0
src/main/java/com/gzlh/config/dto/ManagerSetting.java

@@ -0,0 +1,15 @@
+package com.gzlh.config.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+@Data
+@Accessors(chain = true)
+public class ManagerSetting implements Serializable {
+    private boolean enable;
+    private String host;
+    private int beatPort;
+    private String serverUrl;
+}

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

@@ -61,10 +61,25 @@ public class SerialSetting implements Serializable {
         @Data
         @Accessors(chain = true)
         public static class StatusDTO{
+            /**
+             * 上到位
+             */
             private String upPoint;
+            /**
+             * 下到位
+             */
             private String downPoint;
+            /**
+             * 雷达
+             */
             private String radarPoint;
+            /**
+             * 前红外
+             */
             private String fRedPoint;
+            /**
+             * 后红外
+             */
             private String bRedPoint;
         }
     }

+ 15 - 13
src/main/java/com/gzlh/config/hksdk/AlarmParseService.java

@@ -7,7 +7,9 @@ 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.bus.SysConfig;
 import com.gzlh.config.SystemObject;
+import com.gzlh.config.dto.ChannelSetting;
 import com.gzlh.device.capture.task.HandlerCarImage;
 import com.gzlh.config.FilePropertiesConfig;
 import com.gzlh.config.task.TaskService;
@@ -47,7 +49,7 @@ public class AlarmParseService {
     TaskService taskService;
 
 
-    TimedCache<String, Integer> CACHE_MAP = CacheUtil.newTimedCache(20000);
+   public static final TimedCache<String, Integer> CACHE_MAP = CacheUtil.newTimedCache(5000);
 
     public void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
         //lCommand是传的报警类型
@@ -69,6 +71,9 @@ public class AlarmParseService {
 //            byte VehicleType = strItsPlateResult.byVehicleType;  //0-其他车辆,1-小型车,2-大型车,3- 行人触发,4- 二轮车触发,5- 三轮车触发,6- 机动车触发
 //            log.info("车牌号:{} ;车辆类型:{}", sLicense, VehicleType);
             sLicense = StrUtil.trim(StrUtil.sub(sLicense, 1, -1));
+            if (StrUtil.isEmpty(sLicense)||StrUtil.equals("车牌",sLicense)){
+                return;
+            }
             if (CACHE_MAP.get(sLicense) != null) {
                 log.error("重复上传:{}", sLicense);
                 return;
@@ -82,18 +87,19 @@ public class AlarmParseService {
             if (strItsPlateResult.struPicInfo.length > 0) {
                 HCNetSDK.NET_ITS_PICTURE_INFO net_its_picture_info = strItsPlateResult.struPicInfo[0];
                 if (net_its_picture_info.dwDataLen > 0) {
-                    String currDateFolder = new SimpleDateFormat("MMdd").format(nowTime);
-                    String newName = DateUtil.format(nowTime, "yyyyMMddHHmm");
+                    String newName = DateUtil.format(nowTime, "yyMMddHHmm");
                     FileOutputStream fout;
                     try {
                         // 文件名
                         String fileName =sLicense+"-" +newName + ".jpg";
                         // 需要保存到的文件夹地址
-                        String fileFolder=filePropertiesConfig.getRootPath()+ LocalDate.now().getYear() +currDateFolder;;
-                        FileUtil.mkdir(fileFolder);
+                        LocalDate now=LocalDate.now();
+                        ChannelSetting channelSetting= SysConfig.channelSetting;
+                        String fileFolder=channelSetting.getChannelCode()+separator+now.getYear()+separator+now.getMonthValue()+separator+now.getDayOfMonth();
+                        FileUtil.mkdir(channelSetting.getFileRootPath()+separator+fileFolder);
                         String filePath=fileFolder +separator+ fileName;
-                        log.info("车牌保存路径:{},{}",sLicense,filePath);
-                        fout = new FileOutputStream(filePath);
+                        //log.info("车牌保存路径:{},{}",sLicense,filePath);
+                        fout = new FileOutputStream(channelSetting.getFileRootPath()+separator+filePath);
                         //将字节写入文件
                         long offset = 0;
                         ByteBuffer buffers = net_its_picture_info.pBuffer.getByteBuffer(offset, net_its_picture_info.dwDataLen);
@@ -102,12 +108,8 @@ 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));
+                        String httpUrl="http://"+channelSetting.getIp()+"/"+filePath.replace("\\","/");
+                        taskService.addTask(new HandlerCarImage(RandomUtil.randomNumbers(10),100,httpUrl,sLicense));
                     } catch (IOException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();

+ 1 - 1
src/main/java/com/gzlh/config/hksdk/EventCallback.java

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
 public class EventCallback implements HCNetSDK.FMSGCallBack_V31 {
     @Override
     public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
-        log.info("回调:{},",lCommand);
+       // log.info("回调:{},",lCommand);
         return false;
     }
 }

+ 2 - 1
src/main/java/com/gzlh/device/camera/controller/CameraController.java

@@ -3,6 +3,7 @@ package com.gzlh.device.camera.controller;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.XmlUtil;
 import com.gzlh.bus.EventDataManager;
+import com.gzlh.bus.SysConfig;
 import com.gzlh.config.SystemObject;
 import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.FileUtils;
@@ -34,7 +35,7 @@ public class CameraController {
     ) throws IOException {
 //        String xmlStr = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
         String path=SystemObject.filePropertiesConfig.getRootPath();
-        String channelCode=SystemObject.applicationConfig.getChannelCode();
+        String channelCode= SysConfig.channelSetting.getChannelCode();
         Map<String, Object> StringObjectMap = new HashMap<>();
         Document document = XmlUtil.parseXml(xmlStr);
         Element rootElement = XmlUtil.getRootElement(document);

+ 19 - 6
src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java

@@ -1,8 +1,10 @@
 package com.gzlh.device.capture.task;
 
 import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 
+import com.gzlh.bus.SysConfig;
 import com.gzlh.config.SystemObject;
 import com.gzlh.device.capture.event.CaptureEvent;
 
@@ -10,7 +12,10 @@ import com.gzlh.config.ModuleEnum;
 import com.gzlh.bus.EventBus;
 import com.gzlh.bus.EventDataManager;
 import com.gzlh.config.task.Task;
+import com.gzlh.device.led.utils.LedOptions;
+import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
 import com.gzlh.entity.ReqBO;
+import com.gzlh.utils.DeviceCache;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.autoconfigure.web.ServerProperties;
@@ -26,11 +31,11 @@ import java.util.Date;
  */
 @Slf4j
 public class HandlerCarImage extends Task {
-    private String filePath;
+    private String httpUrl;
     private String carNo;
-    public HandlerCarImage(String id, long delayInMilliseconds, String filePath, String carNo) {
+    public HandlerCarImage(String id, long delayInMilliseconds, String httpUrl, String carNo) {
         super(id, delayInMilliseconds);
-        this.filePath=filePath;
+        this.httpUrl=httpUrl;
         this.carNo=carNo;
     }
 
@@ -38,16 +43,24 @@ public class HandlerCarImage extends Task {
     @Override
     public void run() {
         ReqBO reqBO = EventDataManager.getCacheData();
-        if (reqBO!=null&&!StringUtils.isEmpty(reqBO.getCarNo())){
+        //已经有车牌,又有车进来===>跟车
+        if (reqBO!=null&&!StringUtils.isEmpty(reqBO.getCarNo())&& !StrUtil.equals(reqBO.getCarNo(),carNo)){
+           //中断
+            DeviceCache.setInterrupt(true);
+            DeviceCache.setInterrupt(true);
+            LedOptions options = new LedOptions().setShowType("00");
+            SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
+                    .sendMsg("跟车中断称重,请退出重进", options.setLine("04").setColor("01"));
             return;
         }
+        CommonWeighbridgeHandler.hsCar=true;
 //      String base64=  Base64.encode(new File(filePath));
-        EventDataManager.cacheData("carImg",filePath);
+        EventDataManager.cacheData("carImg",httpUrl);
         EventDataManager.cacheData("carNo",carNo);
         EventDataManager.cacheData("gatherTime",new Date());
         EventBus eventBus=SpringUtil.getBean(EventBus.class);
         //向总线发送抓拍到车牌事件
-        if (SystemObject.applicationConfig.getChannelType()==0){
+        if (SysConfig.channelSetting.getChannelType() ==0){
             eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn()+"."+ CaptureEvent.CAPTURE_CAR_NO);
         }else{
             eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn()+"."+ CaptureEvent.CAPTURE_ADMIN);

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

@@ -24,7 +24,7 @@ public class ElectronClientHandler extends SimpleChannelInboundHandler<String> {
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleEn(), 1);
+        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleZh(), 1);
         if (StrUtil.isEmpty(msg)){
             return;
         }
@@ -39,7 +39,7 @@ public class ElectronClientHandler extends SimpleChannelInboundHandler<String> {
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("电子车牌 客户端 连接断开,进行重连");
-        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleEn(), 0);
+        DeviceCache.changeDeviceStatus(ModuleEnum.ELECTRON_MODULE.getModuleZh(), 0);
         electronNettyConfig.connect();
     }
 

+ 2 - 3
src/main/java/com/gzlh/device/led/client/LedClientHandler.java

@@ -19,14 +19,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);
+        DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleZh(),1);
     }
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("led 客户端 连接断开,进行重连");
-        DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),0);
+        DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleZh(),0);
         ledNettyConfig.connect();
     }
 

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

@@ -76,7 +76,7 @@ public class LedNettyConfig {
             if (future1.isSuccess()) {
                 channel = future1.channel();
                 log.info("led 串口服务器连接成功,{},{}", host, port);
-                DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),1);
+                DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleZh(),1);
             } else {
                 log.error("-------------led 连接服务器失败,{},{}-----------,进行重连", host, port);
                 future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);

+ 6 - 4
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.bus.SysConfig;
 import com.gzlh.config.SystemObject;
 import com.gzlh.device.led.action.LedAction;
 import com.gzlh.device.led.brand.LedBrandType;
@@ -29,9 +30,9 @@ public class LedHandlerFengLiYuan implements ILedHandler {
 
     @Override
     public void sendMsg(String content, LedOptions options) {
-        log.info("丰利源发送led消息:{}", content);
+       log.info("丰利源发送led消息:{}", content);
         String msgHex = FengLiYuanPackUtils.build(content, options);
-        log.info("数据包:{}", msgHex);
+       // log.info("数据包:{}", msgHex);
         ledNettyConfig.send(msgHex);
     }
 
@@ -79,11 +80,12 @@ public class LedHandlerFengLiYuan implements ILedHandler {
                 if (reqBO != null && reqBO.getWeight() != null) {
                     weight = String.format("%.0f", EventDataManager.getCacheData().getWeight()).concat("kg");
                 }
-                ledOptions.setColor("04").setLine("03").setShowType("0B");
+                ledOptions.setColor("02").setLine("03").setShowType("0B");
+                log.info("send weight:{}",weight);
                 sendMsg(weight, ledOptions);
             }else if (StrUtil.contains(action, "channel")) {
                 ledOptions.setColor("06").setLine("01").setShowType("0B");
-                sendMsg(SystemObject.applicationConfig.getChannelName(), ledOptions);
+                sendMsg(SysConfig.channelSetting.getChannelName(), ledOptions);
             }  else {
                 ledOptions.setShowType("00");
                 sendMsg(action, ledOptions);

+ 0 - 1
src/main/java/com/gzlh/device/led/utils/FengLiYuanPackUtils.java

@@ -54,7 +54,6 @@ public class FengLiYuanPackUtils {
         String str=dataContent+xor;
         int len=str.length();
         StringBuilder sb=new StringBuilder();
-       log.info ("xor:{}",xor);
         for (int i=0;i<len;i+=2){
             String hex=  str.substring(i,i+2);
             if (hex.equals("F5")){

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

@@ -27,7 +27,7 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
 //        log.info("PLC 客户端收到消息:" + msg);
 //        修改设备状态信息
-        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleEn(),1);
+        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleZh(),1);
 //        String crc = msg.substring(msg.length() - 4 );
         String data = msg.substring(0, msg.length() - 4);
         String str = ModbusUtils.buildRequestPacket(data);
@@ -40,7 +40,7 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("PLC 客户端 连接断开,进行重连");
 //        断连设备状态设为0
-        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleEn(),0);
+        DeviceCache.changeDeviceStatus(ModuleEnum.PLC_MODULE.getModuleZh(),0);
         ledNettyConfig.connect();
     }
 

+ 6 - 3
src/main/java/com/gzlh/device/plc/client/PlcNettyConfig.java

@@ -1,8 +1,10 @@
 package com.gzlh.device.plc.client;
 
+import cn.hutool.core.thread.ThreadUtil;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.config.netty.NettyDecoder;
+
 import com.gzlh.utils.XorUtils;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import javax.annotation.Resource;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
 
@@ -29,6 +32,8 @@ public class PlcNettyConfig {
     @Autowired
     private PlcClientHandler plcClientHandler;
 
+
+
     private Channel channel;
 
     @Bean("plcBootstrap")
@@ -71,6 +76,7 @@ public class PlcNettyConfig {
             if (future1.isSuccess()) {
                 channel = future1.channel();
                 log.info("plc 串口服务器连接成功,{},{}", host, port);
+
             } else {
                 log.error("-------------plc 连接服务器失败,{},{}-----------,进行重连", host, port);
                 future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);
@@ -84,13 +90,10 @@ public class PlcNettyConfig {
     }
 
     public void send(String message) {
-
         if (channel != null && channel.isActive()) {
             ByteBuf bufff = Unpooled.buffer();
             bufff.writeBytes(XorUtils.hexString2Bytes(message));
             channel.writeAndFlush(bufff);
-        } else {
-            log.error("未建立连接,无法发送消息");
         }
     }
 

+ 37 - 0
src/main/java/com/gzlh/device/plc/handler/CheckDownTask.java

@@ -0,0 +1,37 @@
+package com.gzlh.device.plc.handler;
+
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.SysConfig;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.config.task.Task;
+import com.gzlh.config.task.TaskService;
+import com.gzlh.device.plc.client.PlcNettyConfig;
+import com.gzlh.utils.DeviceCache;
+import com.gzlh.utils.ModbusUtils;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 检查下发落杆指令下发之后任然没有抬杆
+ */
+@Slf4j
+public class CheckDownTask extends Task {
+
+
+    private int tryCount;
+
+    public CheckDownTask(String id, long delayInMilliseconds, int tryCount) {
+        super(id, delayInMilliseconds);
+        this.tryCount = tryCount;
+    }
+
+    @Override
+    public void run() {
+        String gatePoint = SysConfig.serialSetting.getPlc().getOut().getGatePoint();
+        String command = PLCHadnler.COMMAND_PREFIX + gatePoint + PLCHadnler.COMMAND_OFF;
+        String packData = ModbusUtils.buildRequestPacket(command);
+        log.info("plc发送落杆指令:{},{}", packData, tryCount);
+        PlcNettyConfig plcNettyConfig = SpringUtil.getBean(PlcNettyConfig.class);
+        plcNettyConfig.send(packData);
+    }
+}

+ 53 - 0
src/main/java/com/gzlh/device/plc/handler/CheckUpTask.java

@@ -0,0 +1,53 @@
+package com.gzlh.device.plc.handler;
+
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.EventBus;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.bus.SysConfig;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.config.task.Task;
+import com.gzlh.config.task.TaskService;
+import com.gzlh.device.plc.client.PlcNettyConfig;
+import com.gzlh.utils.DeviceCache;
+import com.gzlh.utils.ModbusUtils;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 检查下发落杆指令下发之后任然没有抬杆
+ */
+@Slf4j
+public class CheckUpTask extends Task {
+
+
+    private int tryCount;
+
+    public CheckUpTask(String id, long delayInMilliseconds, int tryCount) {
+        super(id, delayInMilliseconds);
+        this.tryCount = tryCount;
+    }
+
+    @Override
+    public void run() {
+        if (tryCount >= 3) {
+            return;
+        }
+       String plcStatus= DeviceCache.getPlcStatus();
+        SerialSetting.PlcDTO.StatusDTO statusDTO= SysConfig.serialSetting.getPlc().getStatus();
+       String upPoint= statusDTO.getUpPoint();
+       String upStatus=plcStatus.charAt(Integer.parseInt(upPoint))+"";
+       if (upStatus.equals("1")){
+           //已经上到位了,所以停止检查
+           return;
+       }
+        String gatePoint = SysConfig.serialSetting.getPlc().getOut().getGatePoint();
+        String command = PLCHadnler.COMMAND_PREFIX + gatePoint + PLCHadnler.COMMAND_ON;
+        String packData = ModbusUtils.buildRequestPacket(command);
+        log.info("plc发送抬杆:{},{}", packData,tryCount);
+        PlcNettyConfig plcNettyConfig = SpringUtil.getBean(PlcNettyConfig.class);
+        plcNettyConfig.send(packData);
+        tryCount = tryCount + 1;
+        TaskService taskService = SpringUtil.getBean(TaskService.class);
+        taskService.addTask(new CheckUpTask(RandomUtil.randomNumbers(10), 300, tryCount));
+    }
+}

+ 133 - 59
src/main/java/com/gzlh/device/plc/handler/PLCHadnler.java

@@ -1,11 +1,25 @@
 package com.gzlh.device.plc.handler;
 
+import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.EventBus;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.bus.EventThread;
 import com.gzlh.bus.SysConfig;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.config.task.TaskService;
+import com.gzlh.device.led.client.LedNettyConfig;
+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.client.PlcNettyConfig;
+import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.plc.service.PLCService;
+import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
+import com.gzlh.device.weighbridge.handler.impl.CommonWeighbridgeHandler;
+import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.DeviceCache;
 import com.gzlh.utils.ModbusUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -20,124 +34,184 @@ import java.util.Date;
 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";
+    @Resource
+    private LedFactory ledFactory;
+    @Resource
+    private TaskService taskService;
+    public static final String COMMAND_PREFIX = "010500";
+    public static final String COMMAND_ON = "FF00";
+    public static final String COMMAND_OFF = "0000";
 
-    private PLCService plcService = new PLCService();
 
     public void handlerAction(String action) {
+        log.info("plc handler action:{}", action);
         SerialSetting serialSetting = SysConfig.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);
+          //  log.info("plc发送消息:{}", packData);
             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);
+           // log.info("plc发送消息:{}", command);
             String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
         } 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);
+           // log.info("plc发送消息:{}", command);
             String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
         } 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);
+           // log.info("plc发送消息:{}", command);
             String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
         } 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);
+           // log.info("plc发送消息:{}", command);
             String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
+            taskService.addTask(new CheckUpTask(RandomUtil.randomNumbers(10),200,1));
         } 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);
+           // log.info("plc发送消息:{}", command);
             String packData = ModbusUtils.buildRequestPacket(command);
             plcNettyConfig.send(packData);
+            taskService.addTask(new CheckDownTask(RandomUtil.randomNumbers(10),100,1));
         }
     }
 
-    public void handlerMsg(String msg) throws Exception{
+    public void handlerMsg(String msg) throws Exception {
+        // log.info("plc:{}", msg);
 //        不是返回的plc状态信息就中断
-        if (!msg.substring(0,4).equals("0102")){
+        if (!msg.startsWith("0102")) {
             return;
         }
-        String result = Integer.toBinaryString(Integer.parseInt(msg.substring(6, 8),16));
+        String result = Integer.toBinaryString(Integer.parseInt(msg.substring(6, 8), 16));
 
         String oldPlcInfo = DeviceCache.getPlcStatus();
+        //  log.info("oldPlcInfo status:{}", oldPlcInfo);
 //        将plc的设备信息补到8存入缓存
         String newPlcInfo = String.format("%8s", result).replace(" ", "0");
-        DeviceCache.setPlcStatus(newPlcInfo);
+//         log.info("new plc status:{}", newPlcInfo);
+        String newReverse = new StringBuffer(newPlcInfo).reverse().toString();
+//          log.info("new plc reverse status:{}", newReverse);
+        doHandler(oldPlcInfo, newReverse);
+    }
 
-//        设备信息发生变化时进入
-        if (oldPlcInfo!=null&&!newPlcInfo.equals(oldPlcInfo)){
-            SerialSetting.PlcDTO.StatusDTO status = SysConfig.serialSetting.getPlc().getStatus();
+    private void doHandler(String oldPlcInfo, String newReverse) {
+        if (StrUtil.isEmpty(oldPlcInfo)) {
+            DeviceCache.setPlcStatus(newReverse);
+            return;
+        }
+        if (!StrUtil.equals(newReverse, oldPlcInfo)) {
+            DeviceCache.setPlcStatus(newReverse);
 
-            String newReverse = new StringBuffer(newPlcInfo).reverse().toString();
-            String oldReverse = new StringBuffer(oldPlcInfo).reverse().toString();
+            SerialSetting.PlcDTO.StatusDTO status = SysConfig.serialSetting.getPlc().getStatus();
+            SerialSetting.LedDTO ledDTO = SysConfig.serialSetting.getLed();
+            int len = newReverse.length();
+            EventBus eventBus = SpringUtil.getBean(EventBus.class);
 
-            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());
+            for (int i = 0; i < len; i++) {
+                //第几位
+                String newPointStatus = newReverse.charAt(i) + "";
+                String oldPointStatus = oldPlcInfo.charAt(i) + "";
+                String judgePoint = i + "";
+                String radarPoint = status.getRadarPoint();
+                String fRedPoint = status.getFRedPoint();
+                String bRedPoint = status.getBRedPoint();
+                String upPoint = status.getUpPoint();
+                String downPoint = status.getDownPoint();//默认是1
+                //状态变化
+                if (!newPointStatus.equals(oldPointStatus)) {
+//                    log.info("newReverse:{}", newReverse);
+                    //看下是哪个状态发生变化
+                    if (radarPoint.equals(judgePoint)) {
+                        //雷达变化0--->1不管  1--->0,判断是否是退出
+                        if (newPointStatus.equals("1")) {
+                            //变化时间
+                            DeviceCache.putTime(judgePoint, 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();
+                        //退车
+                        if (((newReverse.charAt(Integer.parseInt(fRedPoint)) + "").equals("0"))
+                                && !CommonWeighbridgeHandler.hsCar) {
+                            log.info("----通道初始化-----");
+                            eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+                        }
+                    } else if (fRedPoint.equals(judgePoint)) {
+                        //前红外发生变化 1--->0时,判断是否开始读地磅数;0--->1时不管
+                        if (newPointStatus.equals("0")) {
+                            String radarPointStatus = newReverse.charAt(Integer.parseInt(radarPoint)) + "";
+                            //判断是否跟车
+                            // if (radarPointStatus.equals("1")) {
+                            //   log.info("init----------");
+                            //  eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+                            // break;
+                            // }
+                            //开始称重逻辑:存在车牌,并且雷达状态是0
+                            if (CommonWeighbridgeHandler.hsCar
+                                    && radarPointStatus.equals("0")) {
+                                log.info("read----------");
+                                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
                             }
-                        }).start();
+                        }
+                    } else if (bRedPoint.equals(judgePoint)) {
+                        //后红外发生变化 0--->1:看下是否是下到位=0时车头碰到红外
+                        String downStatus = newReverse.charAt(Integer.parseInt(downPoint)) + "";
+//                        log.info("new point:{},{}", newPointStatus, downStatus);
+                        if (newPointStatus.equals("1") && (downStatus.equals("1")) && CommonWeighbridgeHandler.hsCar) {
+                            DeviceCache.setInterrupt(true);
+                            LedOptions ledOptions = new LedOptions();
+                            ledOptions.setLine("04").setColor("01");
+                            String msg = "请后退";
+                            ledFactory.handler(ledDTO.getBrand()).sendMsg(msg, ledOptions);
+                            //变化时间
+                            DeviceCache.putTime(judgePoint, new Date());
+                            break;
+                        }
+                        ReqBO reqBO = EventDataManager.getCacheData();
+                        //后退进行称重 1--->0
+                        if (newPointStatus.equals("0")
+                                && (downStatus.equals("1")) && reqBO != null && StrUtil.isNotEmpty(reqBO.getCarNo())) {
+                            DeviceCache.setInterrupt(false);
+                            eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
+                        }
+                    } else if (downPoint.equals(judgePoint)) {
+                        //下到位触发
+                        String downStatus = newReverse.charAt(Integer.parseInt(downPoint)) + "";
+                        if (downStatus.equals("1") && !CommonWeighbridgeHandler.hsCar) {//洛干
+                             eventBus.startEvent(ModuleEnum.PLC_MODULE.getModuleEn() + "." + PLCEvent.IDLE);
+                        }
                     }
+                    //变化时间
+                    DeviceCache.putTime(judgePoint, new Date());
                 }
+
             }
         }
     }
+
+    public static void main(String[] args) {
+        String str = "10";
+        String result = Integer.toBinaryString(Integer.parseInt(str, 16));
+        System.out.println(result);
+//        将plc的设备信息补到8存入缓存
+        String newPlcInfo = String.format("%8s", result).replace(" ", "0");
+        System.out.println(newPlcInfo);
+        String newReverse = new StringBuffer(newPlcInfo).reverse().toString();
+        System.out.println(newReverse);
+    }
 }

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

@@ -1,23 +1,32 @@
 package com.gzlh.device.plc.job;
 
+import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.log.StaticLog;
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.device.plc.client.PlcNettyConfig;
+import com.gzlh.entity.DeviceStatus;
+import com.gzlh.utils.DeviceCache;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.annotation.Order;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.Optional;
 
-@Component
-@Slf4j
-@Order(999)
-public class SearchJob {
-    @Resource
-    private PlcNettyConfig plcNettyConfig;
-    @Scheduled(fixedDelay = 2000)
-    public void searchJob(){
-        plcNettyConfig.send("0102000000187800");
-    }
 
+public class SearchJob implements Runnable {
+    private PlcNettyConfig plcNettyConfig = SpringUtil.getBean(PlcNettyConfig.class);
+
+
+    @Override
+    public void run() {
+        while (true) {
+            plcNettyConfig.send("0102000000187800");
+            ThreadUtil.sleep(100);
+        }
+    }
 }

+ 6 - 5
src/main/java/com/gzlh/device/plc/service/PLCService.java

@@ -2,6 +2,7 @@ package com.gzlh.device.plc.service;
 
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.log.StaticLog;
 import com.gzlh.bus.EventBus;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.bus.EventDataManager;
@@ -24,11 +25,11 @@ public class PLCService {
         ReqBO reqBO = EventDataManager.getCacheData();
 //        车牌采集失败
         if (reqBO==null||StringUtils.isEmpty(reqBO.getCarNo())){
-            eventBus.startEvent(ModuleEnum.CAPTURE_MODULE.getModuleEn() + "." + CaptureEvent.CAPTURE_FAILED);
+          //  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;
+           // return;
         }
         //向总线发送抓拍到车牌事件
         SerialSetting.PlcDTO.StatusDTO status = SysConfig.serialSetting.getPlc().getStatus();
@@ -51,13 +52,14 @@ public class PLCService {
 //        Thread.sleep(5000);
         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)) {
+                //开始读书
+                StaticLog.info("开始地磅读书-----------");
                 eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
             }
         }else{
@@ -70,7 +72,7 @@ public class PLCService {
         EventBus eventBus = SpringUtil.getBean(EventBus.class);
         SerialSetting.PlcDTO.StatusDTO status = SysConfig.serialSetting.getPlc().getStatus();
         //读取电子车牌
-        if(DeviceCache.getTime(status.getFRedPoint())==null){
+        if(DeviceCache.getTime(status.getFRedPoint())==null&&SysConfig.serialSetting.getElectron().getEnable()){
             ElectronReadJob job=   new ElectronReadJob("4002FEC0");
             ThreadUtil.execute(job);
         }
@@ -112,7 +114,6 @@ public class PLCService {
 
     public void upTrigger() throws InterruptedException {
         EventBus eventBus = SpringUtil.getBean(EventBus.class);
-        //向总线发送抓拍到车牌事件
         SerialSetting.PlcDTO.StatusDTO status = SysConfig.serialSetting.getPlc().getStatus();
 //        将plc设备信息的字符串反转
         String newStatus = null;

+ 1 - 0
src/main/java/com/gzlh/device/weighbridge/action/WeighbridgeCommonAction.java

@@ -16,4 +16,5 @@ public interface WeighbridgeCommonAction {
      * 读取超时
      */
     String READ_TIMEOUT="READ_TIMEOUT";
+    String CLEAN="CLEAN";
 }

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

@@ -11,7 +11,7 @@ import lombok.Getter;
 @AllArgsConstructor
 public enum WeighbridgeBrandType {
 
-    NINGBO_KELI(3000,"宁波科力"),
+    NINGBO_KELI(3000,"托利多"),
     KEDA_KD_8137(3001,"广东科达KD-8137")
 
     ;

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

@@ -24,7 +24,7 @@ public class WeighbridgeClientHandler extends SimpleChannelInboundHandler<String
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
         SerialSetting.Weighbridge weighbridge = SysConfig.serialSetting.getWeighbridge();
-        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn(),1);
+        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleZh(),1);
         WeighbridgeFactory weighbridgeFactory = SpringUtil.getBean(WeighbridgeFactory.class);
         weighbridgeFactory.handler(weighbridge.getBrand()).handlerMsg(msg);
     }
@@ -32,7 +32,7 @@ public class WeighbridgeClientHandler extends SimpleChannelInboundHandler<String
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         log.error("地磅 连接断开,进行重连");
-        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn(),0);
+        DeviceCache.changeDeviceStatus(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleZh(),0);
         nettyConfig.connect();
     }
 

+ 5 - 2
src/main/java/com/gzlh/device/weighbridge/client/WeighbridgeNettyConfig.java

@@ -2,6 +2,7 @@ package com.gzlh.device.weighbridge.client;
 
 import com.gzlh.bus.SysConfig;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.config.netty.NettyDecoder;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
 
 @Configuration
@@ -46,8 +48,9 @@ public class WeighbridgeNettyConfig {
                     protected void initChannel(SocketChannel ch) {
                         try {
                             ChannelPipeline pipeline = ch.pipeline();
-                            pipeline.addLast("decoder", new StringDecoder());
-                            pipeline.addLast("encoder", new StringEncoder());
+                            pipeline.addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
+                            pipeline.addLast("encoder", new StringEncoder(StandardCharsets.UTF_8));
+
                             pipeline.addLast("handler", nettyClientHandler);
                         } catch (Exception e) {
                             log.info("error connect:{}", e.getMessage());

+ 38 - 33
src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java

@@ -2,10 +2,10 @@ package com.gzlh.device.weighbridge.handler.impl;
 
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.StaticLog;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.bus.EventDataManager;
-import com.gzlh.config.ApplicationConfig;
-import com.gzlh.config.ModuleEnum;
 import com.gzlh.bus.EventBus;
 import com.gzlh.config.SystemObject;
 import com.gzlh.config.dto.SerialSetting;
@@ -13,10 +13,10 @@ import com.gzlh.device.led.utils.LedOptions;
 import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
 import com.gzlh.utils.DeviceCache;
 
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 public class CommonWeighbridgeHandler {
 
@@ -25,6 +25,8 @@ public class CommonWeighbridgeHandler {
 
 
     public static boolean isStart = false;
+    public static boolean hsCar = false;
+
 
     /**
      * 添加地磅数据到缓存
@@ -57,52 +59,55 @@ public class CommonWeighbridgeHandler {
         @Override
         public void run() {
             int averaWeight = 0;
-            String deviceStatus= null;
+            String deviceStatus = null;
             SerialSetting serialSetting = SysConfig.serialSetting;
             SerialSetting.PlcDTO.StatusDTO status = 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();
-//                检查前后红外和雷达的触发情况
-                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("03").setColor("04").setShowType("00");
-                    SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
-                            .sendMsg("车辆位置异常或异常跟车",options);
-
-                    SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
-                            .sendMsg("请完全退出通道后再次进入通道",options.setLine("04").setColor("01"));
-//                    eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.POSITION_ERROR);
+                if (!isStart) {
                     return;
                 }
+                time = time - 1000;
+//                检查前后红外和雷达的触发情况
+  //              deviceStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
                 ThreadUtil.sleep(1000);
             }
-            isStart=false;
+            isStart = false;
+            averaWeight = handlerWeight();
+            StaticLog.info("----------weight---------:{}", averaWeight);
             if (averaWeight == 0 || serialSetting.getWeighbridge().getMinKg() > averaWeight) {
                 //todo read timeout
                 //读取超时
                 DeviceCache.setInterrupt(true);
-//                ThreadUtil.sleep(500);
-//                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
                 LedOptions options = new LedOptions().setLine("03").setColor("04").setShowType("0B");
                 SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
-                        .sendMsg("称重异常",options);
-
+                        .sendMsg("称重异常", options);
                 SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
-                        .sendMsg("请退出通道后并联系工作人员",options.setLine("04").setColor("01"));
+                        .sendMsg("请退出通道", options.setLine("04").setColor("01"));
                 return;
             }
-            ApplicationConfig applicationConfig = SpringUtil.getBean(ApplicationConfig.class);
-            //上传地磅数据
-            String channelName = applicationConfig.getChannelName();
-            String serverUrl = applicationConfig.getServerUrl();
-            EventDataManager.cacheData("weight",averaWeight);
-            EventDataManager.cacheData("gatherTime",new Date());
+            EventDataManager.cacheData("weight", averaWeight);
+            EventDataManager.cacheData("gatherTime", new Date());
+        }
+
+        private int handlerWeight() {
+            StaticLog.info("w:{}", JSONUtil.toJsonStr(WEIGHT_CACHE));
+            Collections.sort(WEIGHT_CACHE);
+            int size=WEIGHT_CACHE.size();
+            int index=( size*3)/4;
+           return WEIGHT_CACHE.get(index);
         }
     }
+
+    public static void main(String[] args) {
+//        Integer[]array=new Integer[]{50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50080,50080,50080,50080,50080,50080,50080,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50120,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50100,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120,50120};
+        Integer[]array=new Integer[]{17340,17340,17340,17360,17380,17380,17380,17380,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360,17360};
+        ;
+       List<Integer>list= Stream.of(array).collect(Collectors.toList());
+        Collections.sort(list);
+        int size=list.size();
+        int index=( size*3)/4;
+        System.out.println(index);
+        System.out.println(list.get(index));
+    }
 }

+ 61 - 12
src/main/java/com/gzlh/device/weighbridge/handler/impl/WeighbridgeHandlerKeLi.java

@@ -1,6 +1,10 @@
 package com.gzlh.device.weighbridge.handler.impl;
 
+import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.StrUtil;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.bus.SysConfig;
+import com.gzlh.config.hksdk.AlarmParseService;
 import com.gzlh.device.weighbridge.action.WeighbridgeCommonAction;
 import com.gzlh.device.weighbridge.brand.WeighbridgeBrandType;
 import com.gzlh.device.weighbridge.handler.IWeighbridgeHandler;
@@ -9,7 +13,9 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigInteger;
 import java.util.Arrays;
+import java.util.Map;
 
 /**
  * 宁波柯力地磅处理器
@@ -24,21 +30,27 @@ public class WeighbridgeHandlerKeLi implements IWeighbridgeHandler {
     }
 
 
-
     @Override
     public void handlerMsg(String msg) {
-        log.info(WeighbridgeBrandType.NINGBO_KELI.getBrand() + "地磅:{}", msg);
-//        log.info("客户端收到消息:" + msg);
-        msg = StrUtil.replace(msg, "\u0003", "").replace("\u0002", "");
-//        log.info("转换后消息:" + msg);
-        // 去掉开头和结尾的特殊字符
-        msg = msg.substring(1, msg.length() - 1);
+        msg = StrUtil.removeAll(msg, "\u0002");
+        msg = StrUtil.removeAll(msg, "\r");
+        msg = msg.replaceFirst("^0*", "");
+//        log.info(WeighbridgeBrandType.NINGBO_KELI.getBrand() + "地磅:{}", msg);
+        msg=msg.substring(3);
+        Integer weight = convertMsgToWeight(msg);
+//        log.info(WeighbridgeBrandType.NINGBO_KELI.getBrand() + "地磅 weight:{}", weight);
+        if (weight==0){
+            CommonWeighbridgeHandler.hsCar=false;
+        }
+        Integer minKg = SysConfig.serialSetting.getWeighbridge().getMinKg();
+        CommonWeighbridgeHandler.hsCar=true;
+        if (minKg > weight) {
+            CommonWeighbridgeHandler.hsCar=false;
+            return;
+        }
+       // log.info(WeighbridgeBrandType.NINGBO_KELI.getBrand() + "地磅:{}", weight);
         // 将字符串转换成字节数组类型
-        byte[] bytes = msg.getBytes();
-        // 取出有效数据
-        byte[] validData = Arrays.copyOfRange(bytes, 1, bytes.length - 1);
-        // 将有效数据转换成实际重量值
-        int weight = Integer.parseInt(new String(validData)) / 10;
+        // int weight = Integer.parseInt(new String(validData)) / 10;
         CommonWeighbridgeHandler.cacheWeight(weight);
     }
 
@@ -48,6 +60,43 @@ public class WeighbridgeHandlerKeLi implements IWeighbridgeHandler {
         if (StrUtil.equals(actionCommand, WeighbridgeCommonAction.START_READ)) {
             //开始读取地磅数据
             CommonWeighbridgeHandler.startToRead();
+        } else if (StrUtil.equals(actionCommand, WeighbridgeCommonAction.CLEAN)) {
+            EventDataManager.cleanData();
+            AlarmParseService.CACHE_MAP.clear();
+            CommonWeighbridgeHandler.hsCar=false;
+        }
+    }
+
+
+    private static Integer convertMsgToWeight(String msg) {
+        //粘包的情况下,截取第一个数据包数据包;
+        msg = msg.substring(0, 12);
+        //重量包
+//        msg = msg.substring(3);
+        //替换前面的所有"0"
+        msg = msg.replaceFirst("^0*", "");
+        int len = msg.length();
+        String numStr = "0";
+        for (int i = 0; i < len; i++) {
+            char bit = msg.charAt(i);
+            if (!"0".equals(bit + "")) {
+                numStr = msg.substring(i);
+                break;
+            }
         }
+        Long we=Long.parseLong(numStr) / 1000000;
+        return Integer.parseInt(we+"");
+    }
+
+    public static void main(String[] args) {
+        String str = "0090 00010000000090 000100000000";
+        str = str.replaceFirst("^0*", "");
+        System.out.println(str);
+        str=str.substring(3);
+//        log.info(WeighbridgeBrandType.NINGBO_KELI.getBrand() + "地磅:{}", msg);
+        // 去掉开头和结尾的特殊字符
+        Integer weight = convertMsgToWeight(str);
+        System.out.println(weight);
     }
+
 }

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

@@ -3,7 +3,6 @@ package com.gzlh.startup;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import com.gzlh.background.client.BackgroundClientNetty;
-import com.gzlh.background.properties.BackgroundPropertiesConfig;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.config.dto.CaputreSetting;
 import com.gzlh.config.dto.SerialSetting;
@@ -17,6 +16,7 @@ import com.gzlh.device.electron.client.ElectronNettyConfig;
 import com.gzlh.device.led.client.LedNettyConfig;
 import com.gzlh.device.plc.client.PlcNettyConfig;
 import com.gzlh.device.plc.event.PLCEvent;
+import com.gzlh.device.plc.job.SearchJob;
 import com.gzlh.device.weighbridge.client.WeighbridgeNettyConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.CommandLineRunner;
@@ -39,8 +39,7 @@ public class StartupRunner implements CommandLineRunner {
     private ElectronNettyConfig electronNettyConfig;
 
 
-    @Resource
-    private BackgroundPropertiesConfig backgroundPropertiesConfig;
+
     @Resource
     private BackgroundClientNetty backgroundClientNetty;
 
@@ -59,11 +58,12 @@ public class StartupRunner implements CommandLineRunner {
         }
         if (serialSetting.getPlc().getEnable()){
             ThreadUtil.execute(() -> plcNettyConfig.connect());
+            ThreadUtil.execute(new SearchJob());
         }
         if (serialSetting.getElectron().getEnable()){
             ThreadUtil.execute(() -> electronNettyConfig.connect());
         }
-        if (backgroundPropertiesConfig.isEnable()) {
+        if (SysConfig.managerSetting.isEnable()) {
             ThreadUtil.execute(() -> backgroundClientNetty.connect());
         }
         CaputreSetting caputreSetting=SysConfig.caputreSetting;

+ 61 - 50
src/main/java/com/gzlh/utils/DeviceCache.java

@@ -7,6 +7,7 @@ import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.SystemObject;
 import com.gzlh.config.dto.CaputreSetting;
 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;
@@ -21,78 +22,88 @@ import java.util.stream.Collectors;
 
 public class DeviceCache {
     private static DeviceStatus deviceStatus = new DeviceStatus();
-    private static Map<String, Date> plcTimeMap = new ConcurrentHashMap<String,Date>();
+    private static Map<String, Date> plcTimeMap = new ConcurrentHashMap<String, Date>();
 
-    static boolean interrupt=false;
+    static boolean interrupt = false;
 
     static String plcStatus = null;
 
-    public static void setPlcStatus(String status){
-        plcStatus=status;
+    public static void setPlcStatus(String status) {
+        plcStatus = status;
     }
 
-    public static String getPlcStatus(){
+    public static String getPlcStatus() {
         return plcStatus;
     }
 
-    public static void putTime(String k, Date v){
-        plcTimeMap.put(k,v);
+    public static void putTime(String k, Date v) {
+        plcTimeMap.put(k, v);
     }
-    public static Date getTime(String k){
+
+    public static Date getTime(String k) {
         return plcTimeMap.get(k);
     }
-    public static void resetTimeMap(){
-        plcTimeMap=new ConcurrentHashMap<String,Date>();;
+
+    public static void resetTimeMap() {
+        plcTimeMap = new ConcurrentHashMap<String, Date>();
+        ;
     }
 
-    public static String getDeviceStatusJson(){
-        if (StringUtils.isEmpty(deviceStatus.getChannelCode())){
+    public static String getDeviceStatusJson() {
+        if (StringUtils.isEmpty(deviceStatus.getChannelCode())) {
             deviceStatusInit();
         }
         return JSONUtil.toJsonStr(deviceStatus);
     }
 
-    public static void deviceStatusInit(){
-        SerialSetting serialSetting= SysConfig.serialSetting;
-        deviceStatus.setChannelCode(SystemObject.applicationConfig.getChannelCode());
-        deviceStatus.setChannelName(SystemObject.applicationConfig.getChannelName());
-        CaputreSetting caputreSetting=SysConfig.caputreSetting;
-        DeviceStatus.Device capture =  new DeviceStatus.Device(caputreSetting.getHost(),
-                caputreSetting.getPort(),
-                LedBrandType.getBrandByCode(caputreSetting.getBrand()),
-                ModuleEnum.CAPTURE_MODULE.getModuleZh());
-        deviceStatus.getDeviceList().add(capture);
-
-        DeviceStatus.Device plc =  new DeviceStatus.Device(serialSetting.getHost(),
-                serialSetting.getPlc().getPort(),
-                "",
-                ModuleEnum.PLC_MODULE.getModuleZh());
-        deviceStatus.getDeviceList().add(plc);
-
-        DeviceStatus.Device led = new DeviceStatus.Device(serialSetting.getHost(),
-                serialSetting.getLed().getPort(),
-                LedBrandType.getBrandByCode(serialSetting.getLed().getBrand()),
-                ModuleEnum.LED_MODULE.getModuleZh());
-        deviceStatus.getDeviceList().add(led);
-
-        DeviceStatus.Device weighbridge = new DeviceStatus.Device(serialSetting.getHost(),
-                serialSetting.getWeighbridge().getPort(),
-                WeighbridgeBrandType.getBrandByCode(serialSetting.getWeighbridge().getBrand()),
-                ModuleEnum.WEIGHBRIDGE_MODULE.getModuleZh());
-        deviceStatus.getDeviceList().add(weighbridge);
-
-        DeviceStatus.Device electron = new DeviceStatus.Device(serialSetting.getHost(),
-                serialSetting.getElectron().getPort(),
-                ElectronBrandType.getBrandByCode(serialSetting.getElectron().getBrand()),
-                ModuleEnum.ELECTRON_MODULE.getModuleZh());
-        deviceStatus.getDeviceList().add(electron);
+    public static void deviceStatusInit() {
+        SerialSetting serialSetting = SysConfig.serialSetting;
+        deviceStatus.setChannelCode(SysConfig.channelSetting.getChannelCode());
+        deviceStatus.setChannelName(SysConfig.channelSetting.getChannelName());
+        CaputreSetting caputreSetting = SysConfig.caputreSetting;
+        if (caputreSetting.isEnable()) {
+            DeviceStatus.Device capture = new DeviceStatus.Device(caputreSetting.getHost(),
+                    caputreSetting.getPort(),
+                    CaptureBrandType.getBrandByCode(caputreSetting.getBrand()),
+                    ModuleEnum.CAPTURE_MODULE.getModuleZh());
+            deviceStatus.getDeviceList().add(capture);
+        }
+        if (serialSetting.getPlc().getEnable()) {
+            DeviceStatus.Device plc = new DeviceStatus.Device(serialSetting.getHost(),
+                    serialSetting.getPlc().getPort(),
+                    "smart 200",
+                    ModuleEnum.PLC_MODULE.getModuleZh());
+            deviceStatus.getDeviceList().add(plc);
+        }
+        if (serialSetting.getLed().getEnable()) {
+            DeviceStatus.Device led = new DeviceStatus.Device(serialSetting.getHost(),
+                    serialSetting.getLed().getPort(),
+                    LedBrandType.getBrandByCode(serialSetting.getLed().getBrand()),
+                    ModuleEnum.LED_MODULE.getModuleZh());
+            deviceStatus.getDeviceList().add(led);
+        }
+
+        if (serialSetting.getWeighbridge().getEnable()) {
+            DeviceStatus.Device weighbridge = new DeviceStatus.Device(serialSetting.getHost(),
+                    serialSetting.getWeighbridge().getPort(),
+                    WeighbridgeBrandType.getBrandByCode(serialSetting.getWeighbridge().getBrand()),
+                    ModuleEnum.WEIGHBRIDGE_MODULE.getModuleZh());
+            deviceStatus.getDeviceList().add(weighbridge);
+        }
+        if (serialSetting.getElectron().getEnable()) {
+            DeviceStatus.Device electron = new DeviceStatus.Device(serialSetting.getHost(),
+                    serialSetting.getElectron().getPort(),
+                    ElectronBrandType.getBrandByCode(serialSetting.getElectron().getBrand()),
+                    ModuleEnum.ELECTRON_MODULE.getModuleZh());
+            deviceStatus.getDeviceList().add(electron);
+        }
     }
 
-    public static DeviceStatus getDeviceStatus(){
+    public static DeviceStatus getDeviceStatus() {
         return deviceStatus;
     }
 
-    public static Map<String, Date> getTimeMap(){
+    public static Map<String, Date> getTimeMap() {
         return plcTimeMap;
     }
 
@@ -104,9 +115,9 @@ public class DeviceCache {
         DeviceCache.interrupt = interrupt;
     }
 
-    public static void changeDeviceStatus(String name,int status) {
+    public static void changeDeviceStatus(String name, int status) {
         List<DeviceStatus.Device> devices = DeviceCache.getDeviceStatus().getDeviceList();
-        if (devices.stream().anyMatch(device -> device.getName().equalsIgnoreCase(name))){
+        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());
         }

+ 4 - 2
src/main/java/com/gzlh/utils/WordHandlerUtils.java

@@ -46,8 +46,10 @@ public class WordHandlerUtils {
 
     public static void main(String[] args) throws Exception {
         System.out.println(msgToASCII("你好ssss"));
-        String ssss = AESEncrypt("你好ssss");
-        AESDecrypt(ssss);
+        String ssss = "1CABC683A8F381F47EAC5AD5838C1FB7A08283BBC529298F8FF6DB44684C6AEC36C5973857E482E9A157D690D1E431C79414A55D2BEA40E46A520170CF1B353EDDC35BFDF27033D3E61D5BC275DB07BF";
+        System.out.println(AESDecrypt(ssss));
+        String s="{\"direction\":1,\"channelCode\":\"B1001\",\"carNo\":\"桂A0746T\",\"carImg\":\"http://10.26.1.26/B1001/2023/12/26/桂A0746T-2312260950.jpg\",\"weight\":1361,\"gatherTime\":1703555420546}";
+        System.out.println(AESEncrypt(s));
     }
 
     /**

+ 1 - 12
src/main/resources/application.yml

@@ -1,19 +1,8 @@
 server:
   port: 8086
-application:
-  server-url: http://192.168.1.3:9191 #后端服务器地址
-  channel-name: "A1地磅通道"
-  channel-code: "A1001"
-  #0 货运通道 1 行政通道
-  channel-type: 0
-#后端SOCKET地址
-background:
-  host: 192.168.1.3
-  port: 8050
-  enable: true
   #图片存储根路径
 file:
-  root-path: D:\\upload\\
+  root-path: D:\\file\\
 #海康配置文件
 hk:
   log-home: D:\project\face\face-admin\logs\hk