package cn.net.cpzslibs.prot.handset;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;

import cn.net.cpzslibs.prot.ProtBase;
import cn.net.cpzslibs.prot.SocketCreate;

/**
 * 汽车入库
 * 
 * @author zwj 2015-9-1
 */
public class Prot30CarRuku extends ProtBase {
	private final short iTaskCode30 = 30;
	// 任务号30： 汽配模式生产入库时，标已经入库，iErrCode=0xFFCE
	public final int errCode = 0xFFCE;

	/**
	 * 单标的时候，start和end一致 <br/>
	 * 2015-9-1下午12:56:18
	 * 
	 * @param create
	 * @param startLabel
	 * @param endLabel
	 * @param productId
	 * @throws SocketTimeoutException
	 * @throws IOException
	 */
	public void dealProt(SocketCreate create, String startLabel, String endLabel, String productId)
			throws SocketTimeoutException, IOException {
		dealProt(create, Long.valueOf(startLabel), Long.valueOf(endLabel), Long.valueOf(productId));
	}
	public void dealProt(SocketCreate create, long iStartLabel, long iEndLabel, long iProductId)
			throws SocketTimeoutException, IOException {
		sendProt(create.getDos(), iTaskCode30, iStartLabel, iEndLabel, iProductId);
		recProt(create.getDis(), iTaskCode30);
	}

	private void recProt(DataInputStream dis, short iTaskCode) throws IOException {
		recHeader(dis);
		recFFFF(dis, iTaskCode);
	}

	private void sendProt(DataOutputStream dos, short iTaskCode, long iStartLabel, long iEndLabel, long iProductId)
			throws SocketTimeoutException, IOException {
		short iBodySize = countBodySize(iStartLabel, iEndLabel, iProductId);
		sendHeader(dos, iTaskCode, iBodySize);
		sendiLabel(dos, iStartLabel);
		sendiLabel(dos, iEndLabel);
		sendiProductId(dos, iProductId);
		sendCheckCode(dos);
	}
}
