BehaviorModel.java
3.97 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
package com.viontech.model;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.viontech.Application;
import com.viontech.utils.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import lombok.Getter;
import lombok.Setter;
import java.util.zip.CRC32;
/**
* .
*
* @author 谢明辉
* @date 2020/8/24
*/
@Getter
@Setter
public class BehaviorModel extends BaseModel {
private final byte[] licensePlateText = new byte[16];
private final byte[] recordingPath = new byte[128];
private final byte[] eventLocation = new byte[32];
private final byte[] eventSnapshotPath = new byte[128];
private int serialNum;
private int recordingStartSecond;
private int recordingStartMillisecond;
private int recordingEndSecond;
private int recordingEndMillisecond;
private int eventStartSecond;
private int eventStartMillisecond;
private int eventEndSecond;
private int eventEndMillisecond;
private int eventCode;
private int laneNo;
private int pictureSize;
private int pictureWidth;
private int pictureHeight;
private int x;
private int y;
private int vehicleType;
private int color1;
private int speed;
private int direction;
private int color2;
private int color3;
private int color1Weights;
private int color2Weights;
private int color3Weights;
private int vehicleCategory;
private int reservedField;
private int recordingDuration;
private int faceWidth;
private int faceHeight;
private byte[] reservedField2 = new byte[24];
private byte[] picture;
@Override
public void encodeData() {
this.length = 16L + 448L + picture.length + 4;
this.protocol = 0x00040006L;
this.flag = Application.REAL_TIME;
ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
buffer.writeIntLE(serialNum);
buffer.writeIntLE(recordingStartSecond);
buffer.writeIntLE(recordingStartMillisecond);
buffer.writeIntLE(recordingEndSecond);
buffer.writeIntLE(recordingEndMillisecond);
buffer.writeIntLE(eventStartSecond);
buffer.writeIntLE(eventStartMillisecond);
buffer.writeIntLE(eventEndSecond);
buffer.writeIntLE(eventEndMillisecond);
buffer.writeIntLE(eventCode);
buffer.writeIntLE(laneNo);
buffer.writeIntLE(pictureSize);
buffer.writeIntLE(pictureWidth);
buffer.writeIntLE(pictureHeight);
buffer.writeIntLE(x);
buffer.writeIntLE(y);
buffer.writeBytes(licensePlateText);
buffer.writeBytes(recordingPath);
buffer.writeIntLE(vehicleType);
buffer.writeIntLE(color1);
buffer.writeIntLE(speed);
buffer.writeIntLE(direction);
buffer.writeBytes(eventLocation);
buffer.writeBytes(eventSnapshotPath);
buffer.writeIntLE(color2);
buffer.writeIntLE(color3);
buffer.writeIntLE(color1Weights);
buffer.writeIntLE(color2Weights);
buffer.writeIntLE(color3Weights);
buffer.writeIntLE(vehicleCategory);
buffer.writeIntLE(reservedField);
buffer.writeIntLE(recordingDuration);
buffer.writeIntLE(faceWidth);
buffer.writeIntLE(faceHeight);
buffer.writeBytes(reservedField2);
buffer.writeBytes(picture);
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
buffer.release();
int count = bytes.length;
// crc32
CRC32 crc32 = new CRC32();
crc32.update(bytes);
int value = (int) crc32.getValue();
for (int i = 0; i < count; i++) {
bytes[i] = (byte) (bytes[i] ^ 0x94);
}
this.data = new byte[count + 4];
System.arraycopy(bytes, 0, data, 0, count);
this.data[count++] = (byte) value;
this.data[count++] = (byte) (value >> 8);
this.data[count++] = (byte) (value >> 16);
this.data[count] = (byte) (value >> 24);
}
}