| | |
| | | package com.zy.acs.gateway.domain; |
| | | package com.example.agvcontroller.protocol; |
| | | |
| | | import com.core.common.Cools; |
| | | import com.zy.acs.gateway.constant.AgvConstant; |
| | | import com.zy.acs.gateway.constant.PacErrorType; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.ByteBufUtil; |
| | | |
| | |
| | | * AGV报文模型 |
| | | * Created by vincent on 2023/3/10 |
| | | */ |
| | | public class AgvPackage implements PackageSupport { |
| | | public class AgvPackage { |
| | | |
| | | /** |
| | | * 源数据包缓冲区(引用) |
| | |
| | | return agvPackage; |
| | | } |
| | | |
| | | public String toLogString() { |
| | | StringBuilder pacSb = new StringBuilder(); |
| | | pacSb.append("AGV(").append(getHeader().getUniqueNo()).append(")") |
| | | .append("上传") |
| | | .append("[").append(getHeader().getProtocolType().getDes()).append("]消息.") |
| | | .append("原始消息[").append(getSourceHexStr()).append("]"); |
| | | return pacSb.toString(); |
| | | } |
| | | //public String toLogString() { |
| | | // StringBuilder pacSb = new StringBuilder(); |
| | | // pacSb.append("AGV(").append(getHeader().getUniqueNo()).append(")") |
| | | // .append("上传") |
| | | // .append("[").append(getHeader().getProtocolType().getDes()).append("]消息.") |
| | | // .append("原始消息[").append(getSourceHexStr()).append("]"); |
| | | // return pacSb.toString(); |
| | | //} |
| | | |
| | | public ByteBuf getSourceBuff() { |
| | | // 因为处理buffer时,总是希望拿到一个重置了readerIndex的buf |
| | |
| | | return this; |
| | | } |
| | | |
| | | public ByteBuf convert(ByteBuf byteBuf){ |
| | | byteBuf.writeByte(this.getHeader().getStartSymbol()) |
| | | .writeShort(this.getHeader().getContentLength()) |
| | | .writeByte(this.getHeader().getProtocolType().getCode()) |
| | | .writeBytes(this.getHeader().getUniqueNo().getBytes(AgvConstant.CHARSET_GBK)) |
| | | .writeByte(this.getHeader().getEncryptType().getCode()) |
| | | .writeBytes(this.getBody().getContent()) |
| | | .writeByte(this.getValidCode()); |
| | | // 计算并设置校验码 |
| | | // this.setValidCode(ValidUtil.caculateValidByteFromBuff(byteBuf)); |
| | | byteBuf.resetReaderIndex(); |
| | | byteBuf.writerIndex(byteBuf.readableBytes() - 1).writeByte(this.getValidCode()); |
| | | return byteBuf; |
| | | } |
| | | // public ByteBuf convert(ByteBuf byteBuf){ |
| | | // byteBuf.writeByte(this.getHeader().getStartSymbol()) |
| | | // .writeShort(this.getHeader().getContentLength()) |
| | | // .writeByte(this.getHeader().getProtocolType().getCode()) |
| | | // .writeBytes(this.getHeader().getUniqueNo().getBytes(AgvConstant.CHARSET_GBK)) |
| | | // .writeByte(this.getHeader().getEncryptType().getCode()) |
| | | // .writeBytes(this.getBody().getContent()) |
| | | // .writeByte(this.getValidCode()); |
| | | // // 计算并设置校验码 |
| | | //// this.setValidCode(ValidUtil.caculateValidByteFromBuff(byteBuf)); |
| | | // byteBuf.resetReaderIndex(); |
| | | // byteBuf.writerIndex(byteBuf.readableBytes() - 1).writeByte(this.getValidCode()); |
| | | // return byteBuf; |
| | | // } |
| | | |
| | | } |