#
luxiaotao1123
2024-12-27 663e6eddbcb14299881ada97e9e3c1ca0cdaa6b5
#
1个文件已修改
1个文件已添加
137 ■■■■■ 已修改文件
zy-acs-gateway/src/main/java/com/zy/acs/gateway/mock/ParseProtocolUtils.java 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-gateway/src/main/java/com/zy/acs/gateway/mock/ParseProtocolUtils.java
New file
@@ -0,0 +1,136 @@
package com.zy.acs.gateway.mock;
import com.alibaba.fastjson.JSON;
import com.zy.acs.common.domain.protocol.AGV_12_UP;
import com.zy.acs.common.domain.protocol.IMessageBody;
import com.zy.acs.common.utils.Utils;
import com.zy.acs.framework.common.RadixTools;
import com.zy.acs.gateway.constant.ProtocolType;
import com.zy.acs.gateway.domain.AgvPackage;
import com.zy.acs.gateway.handler.MessageBodyHandler;
import com.zy.acs.gateway.handler.coder.ProtocolDecoder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
public class ParseProtocolUtils {
    public static void main(String[] args) {
        String protocolMsg = "AA30000F0000003DF06C67124B000000DCFFDDFF358EB043000029BAC0358EB043000000000000000000000000A6FF40020C031909";
        byte[] bytes = RadixTools.hexStringToBytes(protocolMsg);
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(256);
        buffer.writeBytes(bytes);
        ProtocolDecoder protocolDecoder = new ProtocolDecoder(1024);
        AgvPackage pac = AgvPackage.valueOfEmpty();
        pac.setSourceBuff(buffer);
        protocolDecoder.analyzeProtocol(pac);
        Boolean b = msgChannelRead(pac);
        System.out.println(JSON.toJSONString(pac));
        IMessageBody messageBody = pac.getBody().getMessageBody();
        if (messageBody instanceof AGV_12_UP) {
            AGV_12_UP agv_12_up = (AGV_12_UP) messageBody;
            System.out.println(agv_12_up.getQrCode());
        }
    }
    private static Boolean msgChannelRead(AgvPackage pac) {
        String namespace = IMessageBody.class.getPackage().getName();
        ProtocolType protocolType = pac.getHeader().getProtocolType();
        if (null == protocolType) {
            // 未知包
            return Boolean.FALSE;
        }
        String className =  namespace +  ".AGV_" + Utils.zeroFill(Integer.toHexString(protocolType.getCode()).toUpperCase(), 2)
                +"_"
                +  pac.getHeader().getProtocolType().getDirection().toString().toUpperCase();
        Class<?> cls = null;
        try {
            cls  =   Class.forName(className);;
        } catch (ClassNotFoundException e) {
            return Boolean.FALSE;
        }
        Object obj = null;
        if (null != cls) {
            try {
                obj = cls.newInstance();
            } catch (ReflectiveOperationException reflectiveOperationException) {
                // 。。。
                return Boolean.FALSE;
            }
        }
        ByteBuf contentBuf = pac.getBody().getContent();           contentBuf.markReaderIndex();   // sign
        // body.buf 属于切片获取, slice 与 channel中的缓冲区 为同一 refenec
        contentBuf.resetReaderIndex();
        int len= contentBuf.readableBytes();
        byte[] bytes = new byte[len];
        pac.getBody().getContent().readBytes(bytes);
        // 读取字节数组 ===>>     实际报文类型
        IMessageBody iMessageBody = null;
        if (null != obj) {
            if ( obj  instanceof IMessageBody) {
                iMessageBody = (IMessageBody) obj;
                iMessageBody.readFromBytes(bytes);
            }
        }
        pac.getBody().setMessageBody(iMessageBody);     contentBuf.resetReaderIndex();
        return true;
    }
}
// AA 30000F0000001DEE6C67120B0000001200EDFF8340B5420100E76FC28340B542000000000000000000000000A6FF40020C030674
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java
@@ -70,6 +70,7 @@
        String laneDataStr = redis.getValue(RedisConstant.MAP_LANE_DATA, String.valueOf(lev));
        if (!Cools.isEmpty(laneDataStr)) {
            this.lanes = GsonUtils.fromJsonToList(laneDataStr, Lane.class);
            this.initialized = Boolean.TRUE;
        } else {
            StopWatch stopWatch = new StopWatch();