package com.its.pis.xnetudp.protocol;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class CENTER_VDS_RES_STOPIMAGE extends CENTER_COMM_MESSAGE {

	public static int STOP_IMAGE_RES_HEAD_SIZE = 14;

	private int    VDS_CTLR_NMBR;                      /* VDS 제어기 ID */
	private byte   cameraNo;                           /* 카메라 번호 */
	private byte   error;                              /* 오류코드 : 0x00 이 아니면 오류 */
	private short  total;
	private short  current;
	private int    size;
	private byte[] data;

	public CENTER_VDS_RES_STOPIMAGE(int vdsCtlrNmbr, int cameraNo, int error, int total, int current, int size) {
		int pktLen = (STOP_IMAGE_RES_HEAD_SIZE + size);
		setSendId((byte) CENTER_COMM_DEFINE.INT_ID_VDS_SERVER);
		setRecvId((byte) CENTER_COMM_DEFINE.INT_ID_MAIN_OPER);
		setTotalFrame((byte)1);
		setCurrentFrame((byte)1);
		setMsgSeq((byte)0x00);
		setOpCode((byte) CENTER_COMM_DEFINE.INT_OP_VDS_STOP_IMAGE_RES);
		setLength(pktLen);

		this.VDS_CTLR_NMBR = vdsCtlrNmbr;
		this.cameraNo = (byte)cameraNo;
		this.error = (byte)error;
		this.total = (short)total;
		this.current = (short)current;
		this.size = size;
	}

	public void setData(byte[] data) {
		this.data = data;
	}
	@Override
	public ByteBuffer getBuffer() {
		ByteBuffer byteBuffer = ByteBuffer.allocate(CENTER_COMM_MESSAGE.CENTER_HEADER_SIZE + getLength());
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);

		byteBuffer.put(getSendId());
		byteBuffer.put(getRecvId());
		byteBuffer.put(getTotalFrame());
		byteBuffer.put(getCurrentFrame());
		byteBuffer.put(getMsgSeq());
		byteBuffer.put(getOpCode());
		byteBuffer.putShort((short)getLength());

		byteBuffer.putInt(this.VDS_CTLR_NMBR);
		byteBuffer.put(this.cameraNo);
		byteBuffer.put(this.error);
		byteBuffer.putShort(this.total);
		byteBuffer.putShort(this.current);
		byteBuffer.putInt(this.size);
		byteBuffer.put(this.data);

		return byteBuffer;
	}

}
