BehaviorModel.java 3.38 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 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.deviceId = 1;
        this.length = 16L + 448L + picture.length;
        this.protocol = 0x00040006L;
        this.flag = Application.REAL_TIME;

        ByteArrayBuilder builder = new ByteArrayBuilder(Math.toIntExact(this.length - 16));
        builder.appendFourBytes(serialNum);
        builder.appendFourBytes(recordingStartSecond);
        builder.appendFourBytes(recordingStartMillisecond);
        builder.appendFourBytes(recordingEndSecond);
        builder.appendFourBytes(recordingEndMillisecond);
        builder.appendFourBytes(eventStartSecond);
        builder.appendFourBytes(eventStartMillisecond);
        builder.appendFourBytes(eventEndSecond);
        builder.appendFourBytes(eventEndMillisecond);
        builder.appendFourBytes(laneNo);
        builder.appendFourBytes(pictureSize);
        builder.appendFourBytes(pictureWidth);
        builder.appendFourBytes(pictureHeight);
        builder.appendFourBytes(x);
        builder.appendFourBytes(y);
        builder.write(licensePlateText);
        builder.write(recordingPath);
        builder.appendFourBytes(vehicleType);
        builder.appendFourBytes(color1);
        builder.appendFourBytes(speed);
        builder.appendFourBytes(direction);
        builder.write(eventLocation);
        builder.write(eventSnapshotPath);
        builder.appendFourBytes(color2);
        builder.appendFourBytes(color3);
        builder.appendFourBytes(color1Weights);
        builder.appendFourBytes(color2Weights);
        builder.appendFourBytes(color3Weights);
        builder.appendFourBytes(vehicleCategory);
        builder.appendFourBytes(reservedField);
        builder.appendFourBytes(recordingDuration);
        builder.appendFourBytes(faceWidth);
        builder.appendFourBytes(faceHeight);
        builder.write(reservedField2);
        builder.write(picture);
        this.data = builder.resetAndGetFirstSegment();
    }
}