BehaviorModel.java 3.37 KB
package com.viontech.model;

import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.viontech.Application;
import com.viontech.utils.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * .
 *
 * @author 谢明辉
 * @date 2020/8/24
 */
@Getter
@Setter
public class BehaviorModel extends BaseModel {

    private final byte[] licensePlateText = new byte[16];
    private final byte[] recordingPath = new byte[128];
    private final byte[] eventLocation = new byte[32];
    private final byte[] eventSnapshotPath = new byte[128];
    private int serialNum;
    private int recordingStartSecond;
    private int recordingStartMillisecond;
    private int recordingEndSecond;
    private int recordingEndMillisecond;
    private int eventStartSecond;
    private int eventStartMillisecond;
    private int eventEndSecond;
    private int eventEndMillisecond;
    private int eventCode;
    private int laneNo;
    private int pictureSize;
    private int pictureWidth;
    private int pictureHeight;
    private int x;
    private int y;
    private int vehicleType;
    private int color1;
    private int speed;
    private int direction;
    private int color2;
    private int color3;
    private int color1Weights;
    private int color2Weights;
    private int color3Weights;
    private int vehicleCategory;
    private int reservedField;
    private int recordingDuration;
    private int faceWidth;
    private int faceHeight;
    private byte[] reservedField2 = new byte[24];
    private byte[] picture;


    @Override
    public void encodeData() {
        this.length = 16L + 448L + picture.length;
        this.protocol = 0x00040006L;
        this.flag = Application.REAL_TIME;
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
        buffer.writeIntLE(serialNum);
        buffer.writeIntLE(recordingStartSecond);
        buffer.writeIntLE(recordingStartMillisecond);
        buffer.writeIntLE(recordingEndSecond);
        buffer.writeIntLE(recordingEndMillisecond);
        buffer.writeIntLE(eventStartSecond);
        buffer.writeIntLE(eventStartMillisecond);
        buffer.writeIntLE(eventEndSecond);
        buffer.writeIntLE(eventEndMillisecond);
        buffer.writeIntLE(laneNo);
        buffer.writeIntLE(pictureSize);
        buffer.writeIntLE(pictureWidth);
        buffer.writeIntLE(pictureHeight);
        buffer.writeIntLE(x);
        buffer.writeIntLE(y);
        buffer.writeBytes(licensePlateText);
        buffer.writeBytes(recordingPath);
        buffer.writeIntLE(vehicleType);
        buffer.writeIntLE(color1);
        buffer.writeIntLE(speed);
        buffer.writeIntLE(direction);
        buffer.writeBytes(eventLocation);
        buffer.writeBytes(eventSnapshotPath);
        buffer.writeIntLE(color2);
        buffer.writeIntLE(color3);
        buffer.writeIntLE(color1Weights);
        buffer.writeIntLE(color2Weights);
        buffer.writeIntLE(color3Weights);
        buffer.writeIntLE(vehicleCategory);
        buffer.writeIntLE(reservedField);
        buffer.writeIntLE(recordingDuration);
        buffer.writeIntLE(faceWidth);
        buffer.writeIntLE(faceHeight);
        buffer.writeBytes(reservedField2);
        buffer.writeBytes(picture);

        this.data = new byte[buffer.readableBytes()];
        buffer.readBytes(this.data);
        buffer.release();
    }
}