package com.its.pis.xnettcp.vds.protocol;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

@Slf4j
@Getter
public class VdsResFrameHead {

    public static int SIZE = 9;

    private byte  dle;
    private byte  stx;
    private short groupNo;
    private short controllerNo;
    private byte  opCode;
    private byte  status1;
    private byte  status2;

    public VdsResFrameHead(byte[] headBytes) {
        if (headBytes != null && headBytes.length >= SIZE) {
            ByteBuffer byteBuffer = ByteBuffer.wrap(headBytes);
            byteBuffer.order(VdsProtocol.byteOrder);
            this.dle = byteBuffer.get();
            this.stx = byteBuffer.get();
            this.groupNo = byteBuffer.getShort();
            this.controllerNo = byteBuffer.getShort();
            this.opCode = byteBuffer.get();
            this.status1 = byteBuffer.get();
            this.status2 = byteBuffer.get();
        }
        else {
            log.error("VdsResFrameHead: create failed, headBytes error");
        }

    }
}
