FlowModel.java
2.37 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
package com.viontech.model;
import com.viontech.Application;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import lombok.Getter;
import lombok.Setter;
import java.util.zip.CRC32;
/**
* .
*
* @author 谢明辉
* @date 2020/8/24
*/
@Getter
@Setter
public class FlowModel extends BaseModel {
private final int[] laneNoAndType = new int[16];
private final int[] traffic = new int[16];
private final int[] avgSpeed = new int[16];
private final int[] maxQueueLen = new int[16];
private final int[] occupy = new int[16];
private final int[] avgDistanceBetweenVehicle = new int[16];
private final int[] trafficSupplement = new int[16];
private int serialNum;
private int time;
private int timeDuring;
private byte[] reservedField = new byte[64];
@Override
public void encodeData() {
this.length = 540L;
this.protocol = 0x00040005L;
this.flag = Application.REAL_TIME;
ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
buffer.writeIntLE(serialNum);
buffer.writeIntLE(time);
buffer.writeIntLE(timeDuring);
for (int i : laneNoAndType) {
buffer.writeIntLE(i);
}
for (int i : traffic) {
buffer.writeIntLE(i);
}
for (int i : avgSpeed) {
buffer.writeIntLE(i);
}
for (int i : maxQueueLen) {
buffer.writeIntLE(i);
}
for (int i : occupy) {
buffer.writeIntLE(i);
}
for (int i : avgDistanceBetweenVehicle) {
buffer.writeIntLE(i);
}
for (int i : trafficSupplement) {
buffer.writeIntLE(i);
}
buffer.writeBytes(reservedField);
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);
}
}