TrafficModel.java
5.47 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
package com.viontech.model;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.zip.CRC32;
/**
* 发送车牌记录,包含电警记录
*
* @author 谢明辉
* @date 2020/8/21
*/
@Getter
@Setter
@Accessors(chain = true)
public class TrafficModel extends BaseModel {
/** 车牌文字 */
private final byte[] plateText = new byte[16];
/** 经过地点 */
private final byte[] routeLocation = new byte[32];
/** 录像路径 */
private final byte[] videoPath = new byte[128];
/** 第一张照片路径 */
private final byte[] picturePath = new byte[128];
/** 序列号 */
private int serialNum;
/** 识别车牌时间(秒) */
private int discernTime;
/** 识别车牌时间(毫秒) */
private int discernMillisecondTime;
/** 车牌类型 */
private int plateType;
/** 车牌识别可靠度 */
private int confidence;
/** 车道 */
private int lane;
/** 车辆类型 */
private int vehicleType;
/** 图片大小宽高 */
private int secondPictureSize;
private int secondPictureWidth;
private int secondPictureHeight;
private int firstPictureSize;
private int firstPictureWidth;
private int firstPictureHeight;
/** 车牌在第一张图片两种 左上右下 位置 */
private int patternLeft;
private int patternTop;
private int patternRight;
private int patternBottom;
/** 车身颜色 */
private int color;
/** 车速 */
private int speed;
/** 方向 */
private int direction;
/** 厂商标志 */
private int manufacturerLogo;
/** 三个预留位 */
private int reservedField;
private int reservedField2;
private int reservedField3;
/** 车型细分 */
private int vehicleCategory;
/** 车牌结构 1单行2双行3其他 */
private int plateStructure;
/** 违章类型 */
private int illegalType;
/** 预留位 */
private int reservedField4;
/** 第二张图片抓拍时间 */
private int secondPictureTime;
private int secondPictureMillisecondTime;
/** 红灯开始时间 */
private int redLightBeginTime;
private int redLightBeginMillisecondTime;
/** 红灯结束时间 */
private int redLightEndTime;
private int redLightEndMillisecondTime;
/** 限速值 */
private int speedLimit;
/** 超速抓拍值 */
private int overSpeedThreshold;
/** 预留字段 */
private byte[] reservedField5 = new byte[4];
/** picture1 */
private byte[] picture1 = new byte[0];
/** picture2 */
private byte[] picture2 = new byte[0];
@Override
public void encodeData() {
this.protocol = 0x00020004L;
this.length = 16L + 452L + picture1.length + picture2.length + 4;
ByteArrayBuilder builder = new ByteArrayBuilder(Math.toIntExact(this.length - 16 - 4));
builder.appendFourBytes(serialNum);
builder.appendFourBytes(discernTime);
builder.appendFourBytes(discernMillisecondTime);
builder.write(plateText);
builder.appendFourBytes(plateType);
builder.appendFourBytes(confidence);
builder.appendFourBytes(lane);
builder.appendFourBytes(vehicleType);
builder.appendFourBytes(secondPictureSize);
builder.appendFourBytes(secondPictureWidth);
builder.appendFourBytes(secondPictureHeight);
builder.appendFourBytes(firstPictureSize);
builder.appendFourBytes(firstPictureWidth);
builder.appendFourBytes(firstPictureHeight);
builder.appendFourBytes(patternLeft);
builder.appendFourBytes(patternTop);
builder.appendFourBytes(patternRight);
builder.appendFourBytes(patternBottom);
builder.appendFourBytes(color);
builder.appendFourBytes(speed);
builder.appendFourBytes(direction);
builder.appendFourBytes(manufacturerLogo);
builder.write(routeLocation);
builder.write(videoPath);
builder.write(picturePath);
builder.appendFourBytes(reservedField);
builder.appendFourBytes(reservedField2);
builder.appendFourBytes(reservedField3);
builder.appendFourBytes(vehicleCategory);
builder.appendFourBytes(plateStructure);
builder.appendFourBytes(illegalType);
builder.appendFourBytes(reservedField4);
builder.appendFourBytes(secondPictureTime);
builder.appendFourBytes(secondPictureMillisecondTime);
builder.appendFourBytes(redLightBeginTime);
builder.appendFourBytes(redLightBeginMillisecondTime);
builder.appendFourBytes(redLightEndTime);
builder.appendFourBytes(redLightEndMillisecondTime);
builder.appendFourBytes(speedLimit);
builder.appendFourBytes(overSpeedThreshold);
builder.write(reservedField5);
builder.write(picture1);
builder.write(picture2);
byte[] bytes = builder.resetAndGetFirstSegment();
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 >> 24);
this.data[count++] = (byte) (value >> 16);
this.data[count++] = (byte) (value >> 8);
this.data[count] = (byte) value;
}
}