Message82Cmd.java 1.58 KB
package com.bsth.socket.protocol;

import com.bsth.util.ConvertUtil;
import org.joda.time.DateTime;

import java.nio.ByteBuffer;

/**
 * @author Hill
 * 车载终端控制
 */
public class Message82Cmd implements IMessageBody {

	/**
	 * byte[6]
	 * 数据采集时间
	 */
	private long timestamp;

	/**
	 * 命令ID
	 */
	private byte commandId;

	/**
	 * 命令参数
	 */
	private IMessage82Param message82Param;
	
	@Override
	public void read(byte[] bytes) {
		// TODO Auto-generated method stub

	}
	
	@Override
	public byte[] write() {
		// TODO Auto-generated method stub
		byte[] bytes = new byte[0];
		if (message82Param != null) {
			bytes = message82Param.write();
		}
		ByteBuffer buf = ByteBuffer.allocate(7 + bytes.length);
		buf.put(ConvertUtil.timestamp2bytes(timestamp));
		buf.put(commandId);
		buf.put(bytes);

		return buf.array();
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public byte getCommandId() {
		return commandId;
	}

	public void setCommandId(byte commandId) {
		this.commandId = commandId;
	}

	public IMessage82Param getMessage82Param() {
		return message82Param;
	}

	public void setMessage82Param(IMessage82Param message82Param) {
		this.message82Param = message82Param;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss"))
		.append(" 命令ID:").append(commandId)
		.append(" 命令参数:").append(message82Param);

		return sb.toString();
	}
}