Message0205.java 1.59 KB
package com.bsth.socket.protocol;

import com.bsth.util.ConvertUtil;

/**
 * @author Hill
 * 车辆位置数据
 */
public class Message0205 implements IMessageBody02 {

	/**
	 * 信息类型
	 * 默认应该为0x05
	 */
	private byte infoType;

	/**
	 * 定位状态
	 * 位0 0有效 1无效
	 * 位1 0北纬 1南纬
	 * 位2 0东经 1西经
	 * 位3-7 保留
	 */
	private byte locationState;

	/**
	 * 经度
	 * 分辨率0.000001
	 */
	private int lon;

	/**
	 * 纬度
	 * 分辨率0.000001
	 */
	private int lat;

	@Override
	public void read(byte[] bytes, int idx) {
		// TODO Auto-generated method stub
		infoType = bytes[idx]; idx++;
		locationState = bytes[idx]; idx++;
		lon = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
		lat = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
	}

	@Override
	public int getByteLen() {
		return 10;
	}

	public byte getInfoType() {
		return infoType;
	}

	public void setInfoType(byte infoType) {
		this.infoType = infoType;
	}

	public byte getLocationState() {
		return locationState;
	}

	public void setLocationState(byte locationState) {
		this.locationState = locationState;
	}

	public int getLon() {
		return lon;
	}

	public void setLon(int lon) {
		this.lon = lon;
	}

	public int getLat() {
		return lat;
	}

	public void setLat(int lat) {
		this.lat = lat;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(" 信息类型: ").append(String.format("%02x", infoType))
		.append(" 定位状态: ").append(locationState)
		.append(" 经度: ").append(lon)
		.append(" 纬度: ").append(lat);

		return sb.toString();
	}
}