18045010223
2025-07-07 0d3a683a0c97154b1f2e6657398664537e4e3e82
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package org.yzh.protocol.commons.transform.passthrough;
 
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.yzh.protocol.commons.Charsets;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 信息查询
 * 外设传感器的基本信息:公司信息、产品代码、版本号、外设ID、客户代码
 * @author yezhihao
 * https://gitee.com/yezhihao/jt808-server
 */
@ToString
@Data
@Accessors(chain = true)
public class PeripheralSystem {
 
    public static final Integer key = 0xF8;
 
    private List<Item> items;
 
    public void addItem(byte id, String companyName, String productModel, String hardwareVersion, String firmwareVersion, String deviceId, String userCode) {
        if (items == null)
            items = new ArrayList<>(4);
        items.add(new Item(id, companyName, productModel, hardwareVersion, firmwareVersion, deviceId, userCode));
    }
 
    @ToString
    @Data
    @Accessors(chain = true)
    public static class Item {
        private byte id;
        private String companyName;
        private String productModel;
        private String hardwareVersion;
        private String firmwareVersion;
        private String deviceId;
        private String userCode;
 
        public Item() {
        }
 
        public Item(byte id, String companyName, String productModel, String hardwareVersion, String firmwareVersion, String deviceId, String userCode) {
            this.id = id;
            this.companyName = companyName;
            this.productModel = productModel;
            this.hardwareVersion = hardwareVersion;
            this.firmwareVersion = firmwareVersion;
            this.deviceId = deviceId;
            this.userCode = userCode;
        }
    }
 
    public static class Schema implements io.github.yezhihao.protostar.Schema<PeripheralSystem> {
 
        public static final Schema INSTANCE = new Schema();
 
        private Schema() {
        }
 
        @Override
        public PeripheralSystem readFrom(ByteBuf input) {
            byte total = input.readByte();
            List<Item> list = new ArrayList<>(total);
            while (input.isReadable()) {
                Item item = new Item();
                item.id = input.readByte();
                input.readByte();
                item.companyName = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                item.productModel = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                item.hardwareVersion = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                item.firmwareVersion = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                item.deviceId = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                item.userCode = input.readCharSequence(input.readByte(), Charsets.GBK).toString();
                list.add(item);
            }
            return new PeripheralSystem().setItems(list);
        }
 
        @Override
        public void writeTo(ByteBuf output, PeripheralSystem message) {
            List<Item> items = message.getItems();
            output.writeByte(items.size());
 
            byte[] bytes;
            for (Item item : items) {
                output.writeByte(item.id);
                int begin = output.writerIndex();
                output.writeByte(0);
                bytes = item.companyName.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                bytes = item.productModel.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                bytes = item.hardwareVersion.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                bytes = item.firmwareVersion.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                bytes = item.deviceId.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                bytes = item.userCode.getBytes(Charsets.GBK);
                output.writeByte(bytes.length).writeBytes(bytes);
                int len = output.writerIndex() - begin - 1;
                output.setByte(begin, len);
            }
        }
    }
}