TrafficModel.java
5.54 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
package com.viontech.model;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.sun.xml.internal.stream.util.BufferAllocator;
import com.viontech.Application;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
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.deviceId = 1;
this.protocol = 0x00020004L;
this.length = 16L + 452L + picture1.length + picture2.length + 4;
this.flag = Application.REAL_TIME;
ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
buffer.writeIntLE(serialNum);
buffer.writeIntLE(discernTime);
buffer.writeIntLE(discernMillisecondTime);
buffer.writeBytes(plateText);
buffer.writeIntLE(plateType);
buffer.writeIntLE(confidence);
buffer.writeIntLE(lane);
buffer.writeIntLE(vehicleType);
buffer.writeIntLE(secondPictureSize);
buffer.writeIntLE(secondPictureWidth);
buffer.writeIntLE(secondPictureHeight);
buffer.writeIntLE(firstPictureSize);
buffer.writeIntLE(firstPictureWidth);
buffer.writeIntLE(firstPictureHeight);
buffer.writeIntLE(patternLeft);
buffer.writeIntLE(patternTop);
buffer.writeIntLE(patternRight);
buffer.writeIntLE(patternBottom);
buffer.writeIntLE(color);
buffer.writeIntLE(speed);
buffer.writeIntLE(direction);
buffer.writeIntLE(manufacturerLogo);
buffer.writeBytes(routeLocation);
buffer.writeBytes(videoPath);
buffer.writeBytes(picturePath);
buffer.writeIntLE(reservedField);
buffer.writeIntLE(reservedField2);
buffer.writeIntLE(reservedField3);
buffer.writeIntLE(vehicleCategory);
buffer.writeIntLE(plateStructure);
buffer.writeIntLE(illegalType);
buffer.writeIntLE(reservedField4);
buffer.writeIntLE(secondPictureTime);
buffer.writeIntLE(secondPictureMillisecondTime);
buffer.writeIntLE(redLightBeginTime);
buffer.writeIntLE(redLightBeginMillisecondTime);
buffer.writeIntLE(redLightEndTime);
buffer.writeIntLE(redLightEndMillisecondTime);
buffer.writeIntLE(speedLimit);
buffer.writeIntLE(overSpeedThreshold);
buffer.writeBytes(reservedField5);
buffer.writeBytes(picture1);
buffer.writeBytes(picture2);
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 >> 24);
this.data[count++] = (byte) (value >> 16);
this.data[count++] = (byte) (value >> 8);
this.data[count] = (byte) value;
}
}