自动化立体仓库 - WCS系统
#
luxiaotao1123
2022-08-02 3b64aeaee2fcc44d69016611c827d4d0d8336910
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.zy.core.netty.domain.fire;
 
import com.zy.core.netty.IMessageBody;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import lombok.Data;
 
/**
 * 心跳 pac
 * 8230303234303030303030313130353138303E303F3131383083
 * Created by vincent on 2022/7/30
 */
@Data
public class Fire_3030 implements IMessageBody {
 
    private Integer no;
 
    private Integer year;
 
    private Integer month;
 
    private Integer day;
 
    private Integer hour;
 
    private Integer minute;
 
    private Integer seconds;
 
    private Integer validCode;
 
    @Override
    public byte[] writeToBytes() {
        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(DEFAULT_LEN);
        byteBuf.writeShort(no);
        // todo
        return ByteBufUtil.getBytes(byteBuf);
    }
 
    @Override
    public Fire_3030 readFromBytes(byte[] bytes) {
//        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(bytes.length > DEFAULT_LEN ? bytes.length + 100 : DEFAULT_LEN);
//        byteBuf.writeBytes(bytes);
//        byteBuf.resetReaderIndex();
//        byteBuf.skipBytes(3);
//        this.no = byteBuf.readShort();
//        byteBuf.skipBytes(6);
//        this.year = byteBuf.readShort();
//        this.month = byteBuf.readShort();
//        this.day = byteBuf.readShort();
//        this.hour = byteBuf.readShort();
//        this.minute = byteBuf.readShort();
//        this.seconds = byteBuf.readShort();
//        this.validCode = byteBuf.readShort();
//        byteBuf.skipBytes(1);
//        byteBuf.release();
//        System.out.println(byteBuf.refCnt());
        this.no = analyze(new byte[]{bytes[3], bytes[4]});
        this.year = analyze(new byte[]{bytes[11], bytes[12]});
        this.month = analyze(new byte[]{bytes[13], bytes[14]});
        this.day = analyze(new byte[]{bytes[15], bytes[16]});
        this.hour = analyze(new byte[]{bytes[17], bytes[18]});
        this.minute = analyze(new byte[]{bytes[19], bytes[20]});
        this.seconds = analyze(new byte[]{bytes[21], bytes[22]});
        this.validCode = analyze(new byte[]{bytes[23], bytes[24]});
        return this;
    }
 
    public static Integer analyze(byte[] bytes) {
        return Integer.parseInt(Integer.toString(bytes[0] & 0x0F, 16) + Integer.toString(bytes[1] & 0x0F, 16), 16);
    }
 
}