lizhanwei
2020-02-17 b3b6a944ac3f8279a04f496bc2c4533a92555a71
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package safeluck.drive.evaluation.platformMessage;
 
 
import android.text.TextUtils;
 
import com.anyun.im_lib.util.ByteUtil;
 
import safeluck.drive.evaluation.platformMessage.DriveExamProtocol;
 
/**
 * 注册消息
 * MyApplication2
 * Created by lzw on 2019/12/17. 17:51:44
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class RegisterMessage extends DriveExamProtocol {
 
    /**
     * 1.1.1    终端注册
     * 消息ID:0x0100。
     * 起始字节
     * 字段
     * 数据类型
     * 描述及要求
     * 0
     * 省域ID
     * WORD
     * 终端所在地省ID
     * 2
     * 市县域ID
     * WORD
     * 终端所在地市ID
     * 4
     * 终端型号
     * BYTE[20]
     * 20个字节,此终端型号由制造商自行定义,位数不足20位的,后补“0X00”
     * 24
     * 终端出厂序列号
     * BYTE[8]
     * 8个字节,由大写字母和数字组成,此终端ID由制造商自行定义,位数不足时,后补“0X00”
     * 32
     * IMEI
     * BYTE[15]
     * 国际移动设备标识,ASCII码
     */
    private static final int BODY_LENGTH = 55;
 
    private short proviceId;
    private short cityid;
    private String model;//终端型号
    private String sn;//出厂序列号
    private String imei;//
 
    /**
     * 构造函数
     *
     * @param msg_id 消息ID
     */
    public RegisterMessage(short msg_id) {
        super(msg_id);
    }
 
    public static int getBodyLength() {
        return BODY_LENGTH;
    }
 
    public short getProviceId() {
        return proviceId;
    }
 
    public void setProviceId(short proviceId) {
        this.proviceId = proviceId;
    }
 
    public short getCityid() {
        return cityid;
    }
 
    public void setCityid(short cityid) {
        this.cityid = cityid;
    }
 
    public String getModel() {
        return model;
    }
 
    public void setModel(String model) {
        this.model = model;
    }
 
    public String getSn() {
        return sn;
    }
 
    public void setSn(String sn) {
        this.sn = sn;
    }
 
    public String getImei() {
        return imei;
    }
 
    public void setImei(String imei) {
        this.imei = imei;
    }
 
    @Override
    protected short msgBodyLength() {
        return BODY_LENGTH;
    }
 
 
    @Override
    protected byte[] createMessageBody() {
        int pos = 0;
        byte[] messageBody = new byte[BODY_LENGTH];
        //省域ID
        byte[] provinceIdBytes = ByteUtil.shortGetBytes(proviceId);
        System.arraycopy(provinceIdBytes,0,messageBody,pos,provinceIdBytes.length);
        pos += provinceIdBytes.length;
        //市域ID
        byte[] cityIdBytes = ByteUtil.shortGetBytes(cityid);
        System.arraycopy(cityIdBytes,0,messageBody,pos,cityIdBytes.length);
        pos += cityIdBytes.length;
        //model
        byte[] modelBytes = !TextUtils.isEmpty(model)?model.getBytes():"".getBytes();
        System.arraycopy(modelBytes,0,messageBody,pos,modelBytes.length);
        pos += 20;
 
        //sn
        byte[] snBytes = !TextUtils.isEmpty(sn)?sn.getBytes():"".getBytes();
        System.arraycopy(snBytes,0,messageBody,pos,snBytes.length);
        pos += 16;
 
        //IMEI
        byte[] imeiBytes = !TextUtils.isEmpty(imei)?imei.getBytes():"".getBytes();
        System.arraycopy(imeiBytes,0,messageBody,pos,imeiBytes.length);
 
        return messageBody;
    }
}