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

import com.viontech.Application;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
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.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 : avgDistanceBetweenVehicle) {
            buffer.writeIntLE(i);
        }
        for (int i : trafficSupplement) {
            buffer.writeIntLE(i);
        }
        buffer.writeBytes(reservedField);
        this.data = new byte[buffer.readableBytes()];
        buffer.readBytes(this.data);
        buffer.release();
    }
}