Bläddra i källkod

合并电子车牌代码

qzyReal 11 månader sedan
förälder
incheckning
7db4fbb662

+ 3 - 3
src/main/java/com/gzlh/bus/EventThread.java

@@ -12,7 +12,7 @@ import com.gzlh.device.capture.factory.CaptureFactory;
 import com.gzlh.device.capture.properties.CapturePropertiesConfig;
 import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.SystemObject;
-import com.gzlh.device.car.factory.CarFactory;
+import com.gzlh.device.electron.factory.ElectronFactory;
 import com.gzlh.device.infrared.config.RedPropertiesConfig;
 import com.gzlh.device.infrared.factory.RedFactory;
 import com.gzlh.device.led.factory.LedFactory;
@@ -43,7 +43,7 @@ public class EventThread implements Runnable{
         LedFactory ledFactory= SystemObject.ledFactory;
         RedFactory redFactory=SystemObject.redFactory;
         WeighbridgeFactory weighbridgeFactory=SystemObject.weighbridgeFactory;
-        CarFactory carFactory= SystemObject.carFactory;
+        ElectronFactory electronFactory= SystemObject.electronFactory;
         WeighbridgePropertiesConfig weighbridgePropertiesConfig=SystemObject.weighbridgePropertiesConfig;
         RedPropertiesConfig redPropertiesConfig=SystemObject.redPropertiesConfig;
         PLCHadnler plcHadnler= SpringUtil.getBean(PLCHadnler.class);
@@ -74,7 +74,7 @@ public class EventThread implements Runnable{
                     plcHadnler.handlerAction(command);
                 }else if (StrUtil.equals(module, ModuleEnum.CAR_MODULE.getModuleEn())) {
                     //动作属于电子车牌
-                    carFactory.handler(serialSetting.getCar().getBrand()).handlerAction(command);
+                    electronFactory.handler(serialSetting.getCar().getBrand()).handlerAction(command);
                 }   else if (StrUtil.equals(module, ModuleEnum.CENTER_MODULE.getModuleEn())) {
                     //动作属于中心总线
                     handlerAction(command);

+ 0 - 8
src/main/java/com/gzlh/device/car/action/CarAction.java

@@ -1,8 +0,0 @@
-package com.gzlh.device.car.action;
-
-public interface CarAction {
-    /**
-     * 展示内容
-     */
-    String READ="READ";
-}

+ 0 - 17
src/main/java/com/gzlh/device/car/brand/CarBrandType.java

@@ -1,17 +0,0 @@
-package com.gzlh.device.car.brand;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-@Getter
-@AllArgsConstructor
-public enum CarBrandType {
-
-    SHENZHEN_RUIDEI(1000,"深圳市瑞得智能技术有限公司"),
-
-    ;
-
-
-    private int code;
-    private String brand;
-}

+ 0 - 37
src/main/java/com/gzlh/device/car/client/CarClientHandler.java

@@ -1,37 +0,0 @@
-package com.gzlh.device.car.client;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@ChannelHandler.Sharable
-public class CarClientHandler extends SimpleChannelInboundHandler<String> {
-
-    private CarNettyConfig carNettyConfig;
-
-    public CarClientHandler(CarNettyConfig carNettyConfig) {
-        this.carNettyConfig = carNettyConfig;
-    }
-
-    @Override
-    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-        log.info("Car 客户端收到消息:" + msg);
-
-    }
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        log.error("car 客户端 连接断开,进行重连");
-        carNettyConfig.connect();
-    }
-
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        cause.printStackTrace();
-        ctx.close();
-    }
-
-}
-

+ 0 - 115
src/main/java/com/gzlh/device/car/client/CarNettyConfig.java

@@ -1,115 +0,0 @@
-package com.gzlh.device.car.client;
-
-import com.gzlh.bus.EventConfig;
-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;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.*;
-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 lombok.extern.slf4j.Slf4j;
-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
-@Slf4j
-public class CarNettyConfig {
-
-
-
-    @Autowired
-    private CarClientHandler carClientHandler;
-
-    private Channel channel;
-
-    @Bean("carBootstrap")
-    public Bootstrap bootstrap() {
-        SerialSetting serialSetting= EventConfig.serialSetting;
-        String host = serialSetting.getHost();
-        int port = serialSetting.getCar().getPort();
-        if (serialSetting.getCar().getEnable()) {
-            log.info("初始化 car:{},{}", host, port);
-        }
-        EventLoopGroup group = new NioEventLoopGroup();
-        return new Bootstrap()
-                .group(group)
-                .channel(NioSocketChannel.class)
-                .remoteAddress(host, port)
-                .option(ChannelOption.SO_KEEPALIVE, true)
-                .handler(new ChannelInitializer<SocketChannel>() {
-                    @Override
-                    protected void initChannel(SocketChannel ch) {
-                        try {
-                            ChannelPipeline pipeline = ch.pipeline();
-                            pipeline.addLast( new NettyDecoder());
-                            pipeline.addLast( new StringEncoder(StandardCharsets.UTF_8));
-                            pipeline.addLast("handler", carClientHandler);
-                        } catch (Exception e) {
-                            log.info("error connect:{}", e.getMessage());
-                        }
-                    }
-                });
-    }
-
-    @Bean("carClientHandler")
-    public CarClientHandler carClientHandler() {
-        return new CarClientHandler(this);
-    }
-
-    public void connect() {
-        SerialSetting serialSetting= EventConfig.serialSetting;
-        String host = serialSetting.getHost();
-        int port = serialSetting.getCar().getPort();
-        ChannelFuture future = bootstrap().connect();
-        future.addListener((ChannelFutureListener) future1 -> {
-            if (future1.isSuccess()) {
-                channel = future1.channel();
-                log.info("car 串口服务器连接成功,{},{}", host, port);
-            } else {
-                log.error("-------------car 连接服务器失败,{},{}-----------,进行重连", host, port);
-                future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);
-            }
-        });
-        try {
-            future.channel().closeFuture().sync();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    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("未建立连接,无法发送消息");
-        }
-    }
-
-    public void close() {
-        if (channel != null) {
-            channel.close();
-        }
-    }
-    private byte[] hexStringToByteArray(String hexString) {
-
-        int len = hexString.length();
-        byte[] data = new byte[len / 2];
-        for (int i = 0; i < len; i += 2) {
-            data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
-                    + Character.digit(hexString.charAt(i+1), 16));
-        }
-        return data;
-    }
-}
-

+ 0 - 21
src/main/java/com/gzlh/device/car/factory/CarFactory.java

@@ -1,21 +0,0 @@
-package com.gzlh.device.car.factory;
-
-
-
-import com.gzlh.device.car.handler.ICarHandler;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-@Service
-public class CarFactory {
-    @Autowired
-    private List<ICarHandler>handlers;
-
-    public ICarHandler handler(int code){
-       return handlers.stream().filter(h->h.brandType().getCode()==code)
-                .findAny().orElseThrow(()->new IllegalArgumentException("不支持交互"));
-    }
-
-}

+ 0 - 12
src/main/java/com/gzlh/device/car/handler/ICarHandler.java

@@ -1,12 +0,0 @@
-package com.gzlh.device.car.handler;
-
-import com.gzlh.device.car.brand.CarBrandType;
-
-public interface ICarHandler {
-
-    CarBrandType brandType();
-
-    void sendMsg(String content, String param);
-
-    void handlerAction(String action);
-}

+ 0 - 39
src/main/java/com/gzlh/device/car/handler/impl/CarHandlerRuiDei.java

@@ -1,39 +0,0 @@
-package com.gzlh.device.car.handler.impl;
-
-import cn.hutool.core.util.StrUtil;
-import com.gzlh.device.car.action.CarAction;
-import com.gzlh.device.car.brand.CarBrandType;
-import com.gzlh.device.car.client.CarNettyConfig;
-import com.gzlh.device.car.handler.ICarHandler;
-import com.gzlh.device.car.utils.RuiDeiPackUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-
-@Service
-@Slf4j
-public class CarHandlerRuiDei implements ICarHandler {
-    @Resource
-    CarNettyConfig carNettyConfig;
-
-    @Override
-    public CarBrandType brandType() {
-        return CarBrandType.SHENZHEN_RUIDEI;
-    }
-
-    @Override
-    public void sendMsg(String content, String param) {
-        log.info("发送电子车牌消息:{}",content);
-        String msgHex= RuiDeiPackUtils.build(content,param);
-        log.info("数据包:{}",msgHex);
-        carNettyConfig.send(msgHex);
-    }
-
-    @Override
-    public void handlerAction(String action) {
-        if (StrUtil.contains(action, CarAction.READ)) {
-            sendMsg("","");
-        }
-    }
-}

+ 0 - 56
src/main/java/com/gzlh/device/car/utils/RuiDeiPackUtils.java

@@ -1,56 +0,0 @@
-package com.gzlh.device.car.utils;
-
-import com.gzlh.utils.WordHandlerUtils;
-import com.gzlh.utils.XorUtils;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class RuiDeiPackUtils {
-    private static final String bootCode = "40";
-
-    /**
-     * 构建
-     *
-     * @param command       命令
-     * @param commandParam  命令参数
-     * @return 起始字40 长度(从[命令]到[校验和]最后字节)
-     *
-     */
-    public static String build(String command, String commandParam) {
-        //消息的16进制
-        String msgHex = WordHandlerUtils.msgToASCII(commandParam);
-
-        String content = command + commandParam;
-        int packLength = content.length();
-//        计算长度,校验和长度固定为1
-        String packLengthHex = Integer.toHexString((packLength / 2) + 1);
-        if (packLengthHex.length() == 1) {
-            packLengthHex = "0" + packLengthHex;
-        }
-        //长度->内容
-        String dataContent = bootCode + packLengthHex + content;
-        String checkSum = checkSum(dataContent);
-        String str = dataContent + checkSum;
-        System.out.println(str);
-        return str;
-    }
-
-    public static String checkSum(String dataContent) {
-        String checkSum = "";
-        byte[] bytes = XorUtils.hexString2Bytes(dataContent);
-        byte sum = 0;
-        for (byte b : bytes) {
-            sum += b;
-        }
-//        和取补去进位,转为十六进制字符串
-        checkSum = String.format("%02x", (~sum + 1 & 0xff)).toUpperCase();
-//        System.out.println("TCC-Hex:"+checkSum);
-        return checkSum;
-    }
-
-    public static void main(String[] args) {
-        RuiDeiPackUtils.build("FE","");
-    }
-
-
-}

+ 1 - 1
src/main/java/com/gzlh/device/car/event/CarDefaultEvent.java → src/main/java/com/gzlh/device/electron/event/CarDefaultEvent.java

@@ -1,4 +1,4 @@
-package com.gzlh.device.car.event;
+package com.gzlh.device.electron.event;
 
 /**
  * Car内置事件

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

@@ -17,7 +17,6 @@ import com.gzlh.config.hksdk.HCNetSDK;
 import com.gzlh.config.hksdk.HkUtils;
 import com.gzlh.config.hksdk.bo.HKCacheManager;
 import com.gzlh.device.electron.client.ElectronNettyConfig;
-import com.gzlh.device.car.client.CarNettyConfig;
 import com.gzlh.device.led.client.LedNettyConfig;
 import com.gzlh.device.infrared.client.RedNettyConfig;
 import com.gzlh.device.plc.client.PlcNettyConfig;
@@ -46,8 +45,7 @@ public class StartupRunner implements CommandLineRunner {
     private PlcNettyConfig plcNettyConfig;
     @Resource
     private ElectronNettyConfig electronNettyConfig;
-    @Resource
-    private CarNettyConfig carNettyConfig;
+
 
     @Resource
     private BackgroundPropertiesConfig backgroundPropertiesConfig;