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

📄 pdumms.java

📁 首先在串口上连接一个或者多个MODEL(简单的说就是可以收发短信的手机)
💻 JAVA
字号:

public class PduMMS extends PduData{
	    
	   protected String WDPheader;//无线寻址信息协议

	   protected String WSP;//Wireless session protocol
	   
	   protected String MMSheader;
	   //ud context   WDPheader
	   protected int UDHL; //user data header length
	   private   int  IEID;//information Element identifier 05=port address 16bit
	   private   int  IEL;//information element length
	   protected int DestPort;
	   protected int OrigPort;   
	  // WSP
	   protected int TransactionID;
	   protected int PDUType;
	   protected int WSPLen;
	   protected String ContentType;
	   protected int PushFlag;
	   protected int XWapAppID;//X-Wap-Application-ID
	   
	protected void DecodeWSP() throws Exception
	  {
		String hex=WSP;
		int pos=0;
		String ct=hex.substring(pos,pos+(WSPLen-4)*2); pos=pos+(WSPLen-4)*2;
		ContentType=PduUtil.Hex2AnsiMsg(ct).trim();
		int by=PduUtil.ReadByte(hex, pos);pos=pos+2;
		if(by==0xB4)  PushFlag=PduUtil.ReadByte(hex, pos);  
		pos=pos+2;
		by=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
		if(by==0xAF)  XWapAppID=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
	  }
	   //MMS Header
	   protected int   XMmsMsgType; //X-Mms-Message-Type :m-notification-ind
	   protected String MMSTransactionID;//X-Mms-Transaction-ID
	   protected int    MMSVer;//MMS-Version 90=1.0
	   protected String MMSContentURL;//Content-Location
	   protected int    ExpiryType;  //Expiry格式,81 relative
	   protected int    ExpirySecs;  //expiry delta-secs;
	   protected String From;     //address-present-token;
	   protected int    MMSClass;   //msg-class : 82 info
	   protected int    MMSSize;   //msg-size

protected void DecodeMMSHeader() throws Exception
	{
		String hex=MMSheader;
		int pos=0;
		int token=PduUtil.ReadByte(hex, pos);
		pos=pos+2; //X-MMS-Message-Type
		if(token==0x8C) XMmsMsgType=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
		
		token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;//TransactionID 0x98
		if(token==0x98) MMSTransactionID=PduUtil.Hex2ASC(hex.substring(pos));
		pos=pos+MMSTransactionID.length()*2+2;//00
		
		token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;//0x8D MMS-Version
		if(token==0x8D) MMSVer=PduUtil.ReadByte(hex, pos);
	    pos=pos+2;
	   
	    
	    token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;//Content-Location
	   	if(token==0x83)  MMSContentURL=PduUtil.Hex2ASC(hex.substring(pos));
	    pos=pos+MMSContentURL.length()*2+2;

        token=PduUtil.ReadByte(hex, pos);
		pos=pos+2; //Expiry
		if(token==0x88)
		{
		   int dl=PduUtil.ReadByte(hex, pos);
		   pos=pos+2;
		   token=PduUtil.ReadByte(hex, pos);
		   pos=pos+2;
		   if(token==0x81) //Relative token
		   {
			  ExpirySecs=Integer.parseInt(hex.substring(pos,pos+dl*2-4),16);
		  	 }
			pos=pos+(dl-1)*2;
		}
	    
		token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;//89 From Len AddressToken
		if(token==0x89)
		{
			int addLen=PduUtil.ReadByte(hex, pos);
			pos=pos+2;
			token=PduUtil.ReadByte(hex, pos);//address present token
			pos=pos+2;
			if(token==0x80) // 
				From=PduUtil.Hex2AnsiMsg(hex.substring(pos,pos+addLen*2-2)).trim();
		    pos=pos+addLen*2-2;
		}
		
		//8A Msg-Class
	    token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
		if(token==0x8A)	MMSClass=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
		
		//8E Msg-Size
	    token=PduUtil.ReadByte(hex, pos);
		pos=pos+2;
		if(token==0x8E) MMSSize=PduUtil.ReadWord(hex, pos);
	    
	}
	 public PduMMS(PduSms mainBody) throws Exception
	    {
	    	super(mainBody);
	    }
	 
	  protected void DecodeWDP() throws Exception
	  {//从WDPheader读取各个字段
		  String hex=WDPheader;
		  int pos=0;
		  IEID=PduUtil.ReadByte(hex, pos);
	      pos=pos+2;
	      IEL=PduUtil.ReadByte(hex, pos);
	      pos=pos+2;
	      DestPort=PduUtil.ReadWord(hex, pos);
	      pos=pos+4;
	      OrigPort=PduUtil.ReadWord(hex, pos);
	      pos=pos+4;
   
	  }

	  protected void DecodeSMS()  throws Exception 
	    {
		  int pos=0;
		  String hex=MainBody.UD;
		  UDHL= PduUtil.ReadByte(hex, pos);
		  pos=pos+2;
		  WDPheader=hex.substring(pos, pos+UDHL*2);
	      pos=pos+UDHL*2;
	      DecodeWDP();
	      //wsp
	      TransactionID=PduUtil.ReadByte(hex, pos); pos=pos+2;
		  PDUType=PduUtil.ReadByte(hex, pos); pos=pos+2;
		  WSPLen=PduUtil.ReadByte(hex, pos);  pos=pos+2;
	      WSP=hex.substring(pos, pos+WSPLen*2); pos=pos+WSPLen*2;
          DecodeWSP();
          
	      //MMSHeader
	      MMSheader=hex.substring(pos);
	      DecodeMMSHeader();
	      Msg=WDPtoString()+"\r\n"+WSPtoString()+"\r\n"+MMSHeader();
	    }
	  protected String WDPtoString()
	  {
		  String str=new String();
		  str="无线寻址目标端口="+DestPort+"  源端口="+ OrigPort;
		  return str;
	  }
	  protected String WSPtoString()
	  {
		  String str=new String();
		  str="无线会协议内容类型="+ContentType;
		  str=str+" 会话ID="+TransactionID;
		  str=str+" Push标志= "+PushFlag;
		  str=str+" PDU类型="+PDUType;
		  str=str+" X-Wap应用程序ID="+XWapAppID;
		  return str;
	  }
	  protected String MMSHeader()
	  {
		  return "彩信头:从"+From+"发来彩信,URL="+ MMSContentURL+"  彩信大小="+MMSSize;
		  
		  
	  }
	 
}

⌨️ 快捷键说明

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