GetPkgStateResponse.java
4.92 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package com.sunvote.cmd.state;
import com.sunvote.cmd.ICmd;
import java.io.ByteArrayOutputStream;
/**
* Created by Elvis on 2017/8/21.
* Email:Eluis@psunsky.com
* 版权所有:长沙中天电子设计开发有限公司
* Description:平板模块键盘投票功能模块
*/
public class GetPkgStateResponse extends StateBaseCmd {
public static final byte CMD = 0x15;
private byte cmd;
private byte[] key1 = new byte[2];
private byte[] key2 = new byte[2];
private byte[] key3 = new byte[2];
private byte[] key4 = new byte[2];
private byte[] key5 = new byte[2];
private byte[] key6 = new byte[2];
private byte[] key7 = new byte[2];
private byte[] key8 = new byte[2];
private byte[] key9 = new byte[2];
private byte[] key10 = new byte[2];
private byte[] keyOther = new byte[3];
public byte getCmd() {
return cmd;
}
public void setCmd(byte cmd) {
this.cmd = cmd;
}
public byte[] getKey1() {
return key1;
}
public void setKey1(byte[] key1) {
this.key1 = key1;
}
public byte[] getKey2() {
return key2;
}
public void setKey2(byte[] key2) {
this.key2 = key2;
}
public byte[] getKey3() {
return key3;
}
public void setKey3(byte[] key3) {
this.key3 = key3;
}
public byte[] getKey4() {
return key4;
}
public void setKey4(byte[] key4) {
this.key4 = key4;
}
public byte[] getKey5() {
return key5;
}
public void setKey5(byte[] key5) {
this.key5 = key5;
}
public byte[] getKeyOther() {
return keyOther;
}
public void setKeyOther(byte[] keyOther) {
this.keyOther = keyOther;
}
@Override
public byte[] toBytes() {
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
try {
byteOutputStream.write(cmd);
byteOutputStream.write(key1);
byteOutputStream.write(key2);
byteOutputStream.write(key3);
byteOutputStream.write(key4);
byteOutputStream.write(key5);
byteOutputStream.write(key6);
byteOutputStream.write(key7);
byteOutputStream.write(key8);
byteOutputStream.write(key9);
byteOutputStream.write(key10);
byteOutputStream.write(keyOther);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
return byteOutputStream.toByteArray();
}
}
@Override
public ICmd parseCmd(byte[] source, int start) {
cmd = source[start];
key1[0] = source[start + 1];
key1[1] = source[start + 2];
key2[0] = source[start + 3];
key2[1] = source[start + 4];
key3[0] = source[start + 5];
key3[1] = source[start + 6];
key4[0] = source[start + 7];
key4[1] = source[start + 8];
key5[0] = source[start + 9];
key5[1] = source[start + 10];
key6[0] = source[start + 11];
key6[1] = source[start + 12];
key7[0] = source[start + 13];
key7[1] = source[start + 14];
key8[0] = source[start + 15];
key8[1] = source[start + 16];
key9[0] = source[start + 17];
key9[1] = source[start + 18];
key10[0] = source[start + 19];
key10[1] = source[start + 20];
keyOther[0] = source[start + 21];
keyOther[1] = source[start + 22];
keyOther[2] = source[start + 23];
return this;
}
public boolean containsKeyId(byte[] keyId){
if(compareBytes(keyId,key1)){
return true;
}
if(compareBytes(keyId,key2)){
return true;
}
if(compareBytes(keyId,key3)){
return true;
}
if(compareBytes(keyId,key4)){
return true;
}
if(compareBytes(keyId,key5)){
return true;
}
if(compareBytes(keyId,key6)){
return true;
}
if(compareBytes(keyId,key7)){
return true;
}
if(compareBytes(keyId,key8)){
return true;
}
if(compareBytes(keyId,key9)){
return true;
}
if(compareBytes(keyId,key10)){
return true;
}
return false;
}
private static boolean compareBytes(byte[] byte1, byte[] byte2) {
if (byte1 != null && byte2 != null) {
if (byte1.length != byte2.length) {
return false;
}
for (int i = 0; i < byte1.length; i++) {
if (byte1[i] != byte2[i]) {
return false;
}
}
return true;
}
return false;
}
public static GetPkgStateResponse parseRequest(byte[] bytes, int length) {
GetPkgStateResponse response = new GetPkgStateResponse();
response.parseCmd(bytes);
return response;
}
}