自动化立体仓库 - WCS系统
zhangc
2025-03-11 d5449236ef0b3adafb3e4cc872f50479efa0ce7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.zy.core.netty.handle;
 
import com.zy.core.netty.domain.ChPackage;
import com.zy.core.netty.properties.TcpProperties;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
 * 国标编码器
 * 此解码器将会生成校验码
 * 处理方式: 异或和
 * Created by vincent on 2019-04-02
 */
@Slf4j
@Component
@ChannelHandler.Sharable
public class ProtocolEncoder extends MessageToByteEncoder<Object> {
 
    @Autowired
    private TcpProperties tcpProperties;
 
    @Override
    protected void encode(ChannelHandlerContext ctx, Object obj, ByteBuf out) {
        boolean upgradeLog = true;
        if (obj instanceof ByteBuf) {
            out.writeBytes((ByteBuf) obj);
        } else if (obj instanceof byte[]) {
            out.writeBytes((byte[]) obj);
        } else if (obj instanceof ChPackage) {
 
        }
//        if (tcpProperties.isPrintPacLog() || upgradeLog){
//            log.info("uuid={} 下行 >>> {}", getVin(out), ByteBufUtil.hexDump(out));
//        }
 
    }
 
//    private String getVin(ByteBuf byteBuf){
//        byte[] bytes = new byte[PackagePart.UNIQUENO.getLen()];
//        byteBuf.markReaderIndex();
//        byteBuf.readerIndex(PackagePart.UNIQUENO.getStartIndex());
//        byteBuf.readBytes(bytes);
//        byteBuf.resetReaderIndex();
//        return RadixTools.bytesToStr(bytes);
//    }
}