Explorar o código

丰利源LED处理

985653680@qq.com hai 1 ano
pai
achega
5f068e87ef

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

@@ -2,7 +2,9 @@ package com.gzlh.background.client;
 
 import cn.hutool.json.JSONUtil;
 import com.gzlh.background.properties.BackgroundPropertiesConfig;
-import com.gzlh.event.EventBus;
+import com.gzlh.bus.EventBus;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.SystemObject;
 import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
@@ -31,15 +33,16 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-//        System.out.println("Client received: " + msg);
-        if (!"Heartbeat".equalsIgnoreCase(msg)){
-            eventBus.start(msg);
-        }
+        System.out.println("Client received: " + msg);
+//        if (!"back message".equalsIgnoreCase(msg)){
+//            eventBus.startEvent(msg);
+//        }
     }
 
 
     protected void sendHeartbeat(ChannelHandlerContext context) {
 //        向后台发送设备信息json字符串
+        DeviceCache.add("channelCode", SystemObject.applicationConfig.getChannelCode());
         String jsonStr = JSONUtil.toJsonStr(DeviceCache.getCacheMap());
         context.writeAndFlush(jsonStr);
 //        System.out.println(" sent ping msg to " + context.channel().remoteAddress());
@@ -74,6 +77,7 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
     protected void handleWriterIdle(ChannelHandlerContext ctx) {
         //写空闲时发送心跳包
         sendHeartbeat(ctx);
+
 //        System.err.println("---WRITER_IDLE---");
     }
 

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

@@ -1,7 +1,6 @@
 package com.gzlh.background.client;
 
 import com.gzlh.background.properties.BackgroundPropertiesConfig;
-import com.gzlh.led.properties.LedPropertiesConfig;
 import com.gzlh.utils.DeviceCache;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.*;

+ 40 - 0
src/main/java/com/gzlh/device/led/action/FengLiYuanCmdEnum.java

@@ -0,0 +1,40 @@
+package com.gzlh.device.led.action;
+
+public enum FengLiYuanCmdEnum {
+
+    ETERNAL("01","固定文字信息(永久保存)"),
+    TEMP("02","临时文字信息(不保存)"),
+    CLEAR_LINE("03","清除行临时信息"),
+    CLEAR_ALL("04","清除全部临时信息"),
+    ADJUST_BRIGHTNESS("05","亮度调节"),
+    CORRECTION_TIME("06","校正时间"),
+    TRAFFIC_LIGHT("07","控制红绿灯"),
+    VOICE_MSG("08","播放语音"),
+    PARKING_GUIDE("09","车位引导(不保存)"),
+    SEND_IMG_LEN("0A","发送图片的长度(bmp文件)(永久保存)"),
+    SEND_IMG_CONTENT("0B","发送图片的内容(永久保存)"),
+    SHOW_IMG("0C","显示固定图片(永久保存)"),
+    POWERUP_DISPLAY("0E","开机显示"),
+    RELAY_SWITCH("0F","控制继电器"),
+    TOTAL_PARKING_PLACE("10","总车位(关机保存)"),
+    QR_CODE("11","二维码");
+
+    private final String code;
+    private final String info;
+
+    FengLiYuanCmdEnum(String code, String info) {
+        this.code = code;
+        this.info = info;
+    }
+
+
+    public String getCode()
+    {
+        return code;
+    }
+
+    public String getInfo()
+    {
+        return info;
+    }
+}

+ 4 - 2
src/main/java/com/gzlh/device/led/brand/LedBrandType.java

@@ -7,9 +7,11 @@ import lombok.Getter;
 @AllArgsConstructor
 public enum  LedBrandType {
 
-    SHANGHAI_YANGBAND_BX(1000,"上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2")
+    SHANGHAI_YANGBAND_BX(1000,"上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2"),
+    FENGLIYUAN(2000,"深圳市丰利源光电有限公司")
 
-    ;
+
+            ;
 
 
     private int code;

+ 53 - 0
src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java

@@ -0,0 +1,53 @@
+package com.gzlh.device.led.handler.impl;
+
+import com.gzlh.device.infrared.brand.RedBrandType;
+import com.gzlh.device.led.action.FengLiYuanCmdEnum;
+import com.gzlh.device.led.brand.LedBrandType;
+import com.gzlh.device.led.client.LedNettyConfig;
+import com.gzlh.device.led.handler.ILedHandler;
+import com.gzlh.device.led.utils.ColorConver;
+import com.gzlh.device.led.utils.FengLiYuanPackage;
+import com.gzlh.device.led.utils.YangBandPackage;
+import com.gzlh.utils.WordHandlerUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * 深圳市丰利源光电有限公司 led发送处理器
+ */
+@Service
+@Slf4j
+public class LedHandlerFengLiYuan implements ILedHandler {
+
+    @Resource
+    private LedNettyConfig ledNettyConfig;
+
+    @Override
+    public LedBrandType brandType() {
+        return LedBrandType.FENGLIYUAN;
+    }
+
+    @Override
+    public void sendMsg(String pack) {
+        log.info(LedBrandType.FENGLIYUAN.getBrand() + "发送数据:{}", pack);
+        ledNettyConfig.send(pack);
+    }
+
+    /**
+     * 特殊站位符 ${platNo}
+     * @param action
+     */
+    @Override
+    public void handlerAction(String action) {
+        String command=null;
+        if (action.contains("LED_SHOW_CONTENT")){
+            command= FengLiYuanCmdEnum.ETERNAL.getCode();
+            String content = action.substring(action.indexOf("(")+1, action.indexOf(")"));
+            String pack = FengLiYuanPackage.buildPackage(command,WordHandlerUtils.msgToASCII(content));
+            sendMsg(pack);
+        }
+        log.info("action:{}",action);
+    }
+}

+ 68 - 0
src/main/java/com/gzlh/device/led/utils/FengLiYuanPackage.java

@@ -0,0 +1,68 @@
+package com.gzlh.device.led.utils;
+
+import com.gzlh.device.led.action.FengLiYuanCmdEnum;
+import com.gzlh.utils.WordHandlerUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+public class FengLiYuanPackage {
+    /**
+     * 帧头
+     */
+    private static final String HEAD = "F501";
+
+    private static final String LedAddr="01";
+
+    private static final String send="01";
+
+
+    public static String buildPackage(String command,String data) {
+        //包数据= 起始字(两字节长度,固定0xF5,0x01)+长度(两字节长度)+屏地址+命令+发送+数据+总包校验
+        //长度=2Byte,从[屏地址]到[数据]最后字节。高字节在前,低字节在后。
+        //发送=0X00=发送,不需要应答,0X01=发送,需要应答
+        //数据=N Byte,可以为空
+        //总包校验=1byte,是从[起始字]到[数据]最后字节所有字节的异或校验
+
+        String str=LedAddr+command+send+data;
+
+        StringBuilder len = new StringBuilder(Integer.toHexString(str.length() / 2));
+        if (len.length()>4){
+            throw new RuntimeException("数据超出长度");
+        }
+        while (len.length()<4){
+            len.insert(0, "0");
+        }
+        String dataStr = HEAD+len+str;
+
+        return xorComputeResult(dataStr);
+    }
+
+    //输入字符串进行异或校验,并加上校验结果
+    public static String xorComputeResult(String data) {
+
+        if (data.length()%2!=0){
+            return null;
+        }
+        int xorCheckSum = 0;
+        List<String> list= new ArrayList<>();
+        for (int i=0;i<data.length();i+=2){
+            list.add(data.substring(i,i+2));
+        }
+
+        for (int i = 0; i < list.size(); i++) {
+            xorCheckSum^=Integer.valueOf(list.get(i),16);
+        }
+//        System.out.println(xorCheckSum);
+        String hex = Integer.toHexString(xorCheckSum);
+        if (hex.length() == 1) {
+            hex = '0' + hex;
+        }
+
+        list.add(hex.toUpperCase(Locale.getDefault()));
+
+        String str = list.toString().substring(1, list.toString().length() - 1);
+        return str.replaceAll(", ", "");
+    }
+}