FlowModel.java 1.81 KB
package com.viontech.model;

import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.viontech.Application;
import lombok.Getter;
import lombok.Setter;

/**
 * .
 *
 * @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.deviceId = 1;
        this.length = 540L;
        this.protocol = 0x00040005L;
        this.flag = Application.REAL_TIME;

        ByteArrayBuilder builder = new ByteArrayBuilder(Math.toIntExact(this.length - 16));

        builder.appendFourBytes(serialNum);
        builder.appendFourBytes(time);
        builder.appendFourBytes(timeDuring);
        for (int value : laneNoAndType) {
            builder.appendFourBytes(value);
        }
        for (int value : traffic) {
            builder.appendFourBytes(value);
        }
        for (int value : avgSpeed) {
            builder.appendFourBytes(value);
        }
        for (int value : maxQueueLen) {
            builder.appendFourBytes(value);
        }
        for (int value : avgDistanceBetweenVehicle) {
            builder.appendFourBytes(value);
        }
        for (int value : trafficSupplement) {
            builder.appendFourBytes(value);
        }
        builder.write(reservedField);

        this.data = builder.resetAndGetFirstSegment();
    }
}