Message0207.java
6.79 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.bsth.socket.protocol;
import com.bsth.constant.Constant;
import com.bsth.util.ConvertUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @author Hill
* 报警数据
*/
public class Message0207 implements IMessageBody02 {
/**
* 信息类型
* 默认应该为0x07
*/
private byte infoType;
/**
* 最高警报等级 0-3(亦可自定义)
* 0 无故障
* 1 级故障,不影响车辆行驶的故障
* 2 级故障,影响车辆性能,需驾驶员限制行驶的故障
* 3 级故障,停车待援
* 0xfe 异常
* 0xff 无效
*/
private byte maxAlarmLevel;
/**
* 通用报警标志
* 0位 0正常 1温度差异 1位 电池高温 2位 车载储能装置类型过压 3位 车载储能装置类型欠压
* 4位 SOC低 5位 单体电池过压 6位 单体电池欠压 7位 SOC过高
* 8位 SOC跳变 9位 可充电储能系统不匹配 10位 电池单体一致性差 11位 绝缘
* 12位 DC-DC温度 13位 制动系统 14位 DC-DC状态 15位 驱动电机控制器温度
* 16位 高压互锁状态 17位 驱动电机温度 18位 车载储能装置类型过充
* 19-31位 保留
*/
private int commonAlarmFlag;
/**
* 储能装置数量 0-252
* N1
* 0xfe 异常
* 0xff 无效
*/
private byte energyStorageDeviceQuantity;
/**
* 储能装置报警情况(自定义)
* N1 * 4
*/
private int[] esdAlarms;
/**
* 驱动电机数量 0-252
* N2
* 0xfe 异常
* 0xff 无效
*/
private byte electricMotorQuantity;
/**
* 驱动电机报警情况(自定义)
* N2 * 4
*/
private int[] emAlarms;
/**
* 发动机数量 0-252
* N3
* 0xfe 异常
* 0xff 无效
*/
private byte engineQuantity;
/**
* 发动机报警情况(自定义)
* N3 * 4
*/
private int[] engineAlarms;
/**
* 其它故障 0-252
* N4
* 0xfe 异常
* 0xff 无效
*/
private byte otherQuantity;
/**
* 扩展故障详细
*/
private List<Trouble> troubleList = new ArrayList<>();
@Override
public void read(byte[] bytes, int idx) {
// TODO Auto-generated method stub
infoType = bytes[idx]; idx++;
maxAlarmLevel = bytes[idx]; idx++;
commonAlarmFlag = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
energyStorageDeviceQuantity = bytes[idx]; idx++;
int count = energyStorageDeviceQuantity & Constant.BYTE_INT;
if (count == 0xFE || count == 0xFF) {
count = 0;
}
esdAlarms = new int[count];
for (int i = 0;i < count;i++) {
esdAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
}
electricMotorQuantity = bytes[idx]; idx++;
count = electricMotorQuantity & Constant.BYTE_INT;
if (count == 0xFE || count == 0xFF) {
count = 0;
}
emAlarms = new int[count];
for (int i = 0;i < count;i++) {
emAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
}
engineQuantity = bytes[idx]; idx++;
count = engineQuantity & Constant.BYTE_INT;
if (count == 0xFE || count == 0xFF) {
count = 0;
}
engineAlarms = new int[count];
for (int i = 0;i < count;i++) {
engineAlarms[i] = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
}
otherQuantity = bytes[idx]; idx++;
count = otherQuantity & Constant.BYTE_INT;
if (count == 0xFF) {
count = 0;
}
if (idx + count * Trouble.BYTE_LEN < bytes.length - 1) {
for (int i = 0;i < count;i ++) {
Trouble trouble = new Trouble();
trouble.read(bytes, idx); idx += Trouble.BYTE_LEN;
troubleList.add(trouble);
}
} else {
throw new IllegalArgumentException("异常的扩展故障数据");
}
}
@Override
public int getByteLen() {
return 10 + (esdAlarms.length + emAlarms.length + engineAlarms.length + troubleList.size()) * 4;
}
public byte getInfoType() {
return infoType;
}
public void setInfoType(byte infoType) {
this.infoType = infoType;
}
public byte getMaxAlarmLevel() {
return maxAlarmLevel;
}
public void setMaxAlarmLevel(byte maxAlarmLevel) {
this.maxAlarmLevel = maxAlarmLevel;
}
public int getCommonAlarmFlag() {
return commonAlarmFlag;
}
public void setCommonAlarmFlag(int commonAlarmFlag) {
this.commonAlarmFlag = commonAlarmFlag;
}
public byte getEnergyStorageDeviceQuantity() {
return energyStorageDeviceQuantity;
}
public void setEnergyStorageDeviceQuantity(byte energyStorageDeviceQuantity) {
this.energyStorageDeviceQuantity = energyStorageDeviceQuantity;
}
public int[] getEsdAlarms() {
return esdAlarms;
}
public void setEsdAlarms(int[] esdAlarms) {
this.esdAlarms = esdAlarms;
}
public byte getElectricMotorQuantity() {
return electricMotorQuantity;
}
public void setElectricMotorQuantity(byte electricMotorQuantity) {
this.electricMotorQuantity = electricMotorQuantity;
}
public int[] getEmAlarms() {
return emAlarms;
}
public void setEmAlarms(int[] emAlarms) {
this.emAlarms = emAlarms;
}
public byte getEngineQuantity() {
return engineQuantity;
}
public void setEngineQuantity(byte engineQuantity) {
this.engineQuantity = engineQuantity;
}
public int[] getEngineAlarms() {
return engineAlarms;
}
public void setEngineAlarms(int[] engineAlarms) {
this.engineAlarms = engineAlarms;
}
public byte getOtherQuantity() {
return otherQuantity;
}
public void setOtherQuantity(byte otherQuantity) {
this.otherQuantity = otherQuantity;
}
public List<Trouble> getTroubleList() {
return troubleList;
}
public void setTroubleList(List<Trouble> troubleList) {
this.troubleList = troubleList;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" 信息类型: ").append(String.format("%02x", infoType))
.append(" 最大报警级别: ").append(maxAlarmLevel)
.append(" 通用报警标志: ").append(commonAlarmFlag)
.append(" 储能设备报警数: ").append(energyStorageDeviceQuantity)
.append(" 电机报警数: ").append(electricMotorQuantity)
.append(" 发动机报警数: ").append(engineQuantity)
.append(" 其它报警数: ").append(otherQuantity)
.append(" 自定义报警详情: ");
for (Trouble trouble : troubleList) {
sb.append(trouble.toString());
}
return sb.toString();
}
public static class Trouble {
private final static int BYTE_LEN = 4;
/**
* 故障类型
*/
private byte type;
/**
* 故障代码
*/
private short code;
/**
* 故障级别
*/
private byte level;
public void read(byte[] bytes, int idx) {
type = bytes[idx]; idx++;
code = (short) ConvertUtil.bytes2int(bytes, idx, 2); idx += 2;
level = bytes[idx]; idx++;
}
public byte getType() {
return type;
}
public void setType(byte type) {
this.type = type;
}
public short getCode() {
return code;
}
public void setCode(short code) {
this.code = code;
}
public byte getLevel() {
return level;
}
public void setLevel(byte level) {
this.level = level;
}
@Override
public String toString() {
return String.format("%02x%04x%02x\n", type, code, level);
}
}
}