⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triarea.java

📁 中国移动定位引擎的客户端
💻 JAVA
字号:
/**
* <p>Title: Smgp协议解析</p>
* <p>Description: SMGW 向MSP 下发短消息的操作包</p>
* <p>Company: 福富软件 </p>
* @author chenxin
* @version 1.0 $Date 2007-07-05
*/
package ffcs.lbp.le.message;

import java.io.IOException;
import java.nio.ByteBuffer;

import ffcs.lbp.MessageParseException;
import ffcs.lbp.le.message.tlv.TLVTable;
import ffcs.lbp.le.message.tlv.Tag;

public class TriArea extends LeMessage {



	private TLVTable IsdnRange=null;
	private int Interval; 	
	private long  StartTime	;
	private long  StopTime	;
	private int Duration;
	private TLVTable LocType=null;
	

	

	private int lenInterval=4;
	private int lenStartTime=4;
	private int lenStopTime=4;
	private int lenDuration=4;
	private int lenMessageBody= lenInterval+lenStartTime
								+ lenStopTime + lenDuration;
	
	
	public TriArea() {
        super(CycLoc);
    }
	
	
	
	
	
	public int getBodyLength() {
	    int len = lenMessageBody ;
	    if (IsdnRange!=null){
			len+=IsdnRange.getLength();
		}
        if (LocType!=null){
			len+=LocType.getLength();
		}
        
        return len;
        
        
        
    }
	
	
	/**
     * 读取协议包的包体
     * @param buf ByteBuffer
     * @throws MessageParseException
     * @return boolean
     */
    protected boolean readBody(ByteBuffer buf) throws
            LeProtocolException{
    	int body_length=super.getPackLength()-HEADER_LENGTH;
      	int tag_IsdnRange=buf.getInt();
    	int len_IsdnRange=buf.getInt();
    	if (len_IsdnRange>0){

    	    byte[] byteTmp=new byte[len_IsdnRange];
			buf.get(byteTmp);
			//0x00000004表示IsdnRange
/*			这里可能会有个bug,包体结构是这样的
			IsdnRange	TLV String	N*36
			Interval 	int			4
			StartTime	long		4
			StopTime	long		4
			Duration	int			4
			可选参数(以下都是tlv字段)
			LocType	unsigned int	4
			此处程序通过判断Tag==0x00000004,来确定TLV是否结束
*/
			while(buf.getInt()==0x00000004&&buf.getInt()!=0){
			    byteTmp=new byte[buf.getInt(buf.position()-1)];
				buf.get(byteTmp);
				}
			int Interval_start=buf.position()-8;//此时的pos为Interval的开始位置
			buf.flip();
			byte[] bytetemp=new byte[Interval_start];
			buf.get(bytetemp);
			IsdnRange = new TLVTable();
			IsdnRange.readFrom(byteTmp,0,Interval_start);
			Interval=buf.getInt();
			StartTime=buf.getLong();
			StopTime=buf.getLong();
			Duration=buf.getInt();
			//下面判断是否有可选参数LocType
			int l=super.getPackLength()-getBodyLength();
	      	if (l>0){

	    	    byte[] OptionTemp=new byte[l];
				buf.get(OptionTemp);
				LocType = new TLVTable();
				LocType.readFrom(byteTmp,0,l);
		
	    	}
    	}


    	return true;
    }


    /**
     * 读取协议包的包体
     * @param buf ByteBuffer
     * @return boolean
     */
    protected  boolean writeBody(ByteBuffer buf){
    	

    	return true;
    }

    /**
     * Convert this packet to a String. Not to be interpreted programmatically,
     * it's just dead handy for debugging!
     */
    public String toString() {

        StringBuffer sb=new StringBuffer("CycLoc:");
	    sb.append(super.toString());
	    
	    sb.append("IsdnRange");
        sb.append("=");
        sb.append(IsdnRange.toString());
        sb.append(" ");
        
        sb.append("Interval");
        sb.append("=");
        sb.append(Interval);
        sb.append(" ");
        
        sb.append("StartTime");
        sb.append("=");
        sb.append(StartTime);
        sb.append(" ");
        
        sb.append("StopTime");
        sb.append("=");
        sb.append(StopTime);
        sb.append(" ");
        
        sb.append("Duration");
        sb.append("=");
        sb.append(Duration);
        sb.append(" ");
        
        sb.append("LocType");
        sb.append("=");
        sb.append(LocType.toString());
        sb.append(" ");

        
        return sb.toString();
        
    }





	public int getDuration() {
		return Duration;
	}





	public void setDuration(int duration) {
		Duration = duration;
	}





	public int getInterval() {
		return Interval;
	}





	public void setInterval(int interval) {
		Interval = interval;
	}





	public TLVTable getIsdnRange() {
		return IsdnRange;
	}





	public void setIsdnRange(TLVTable isdnRange) {
		IsdnRange = isdnRange;
	}





	public TLVTable getLocType() {
		return LocType;
	}





	public void setLocType(TLVTable locType) {
		LocType = locType;
	}





	public long getStartTime() {
		return StartTime;
	}





	public void setStartTime(long startTime) {
		StartTime = startTime;
	}





	public long getStopTime() {
		return StopTime;
	}





	public void setStopTime(long stopTime) {
		StopTime = stopTime;
	}
	
	
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -