博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SMS,EMS PDU Code Decoder 短信PDU格式解码器
阅读量:4554 次
发布时间:2019-06-08

本文共 15068 字,大约阅读时间需要 50 分钟。

None.gif
'
==========================================================
None.gif'
                    SMS,EMS Decoder
None.gif'
                      2005-2-20
None.gif'
1.Description
None.gif'
   This class decode a SMS or EMS PDU code to a certain
None.gif'
class. You can use it in your software to read SMSs and 
None.gif'
EMSs. All of this is done under GSM 03.40. I tested it
None.gif'
on my SIEMENS M55 and NOKIA 8xxx and it works well.
None.gif'
2.Useage 
None.gif'
   If you know what type of PDU code, you can create a 
None.gif'
new instance of class like DIM s as SMS(myPDUCode)
None.gif'
When instance is created, you read its public variable 
None.gif'
to get what you want.
None.gif'
   When TP_DCS=0, PDU code is coded from 7bit 
None.gif'
charactor (see GSM 03.38), use shared function 
None.gif'
Deocde7Bit to decode it.
None.gif'
   When TP_DCS=8, PDU code is coded from Unicode
None.gif'
charactor (see GSM 03.38), use shared funtion
None.gif'
DecodeUnicode to decode it.
None.gif'
3.Bugs
None.gif'
   So far in my tests I found none.
None.gif'
4.When you use it
None.gif'
   You can freely use it or modify it in your program,
None.gif'
but when you find bugs or improved it please publish it
None.gif'
or send one copy to me. Thanks
None.gif'
5.About me
None.gif'
   I am writting a program which can list folders and 
None.gif'
files in SIEMENS M55 mobile phone. It can also read
None.gif'
and send SMS,EMS. Some documents are hard to find on
None.gif'
internet, but I keep on my mind to study it and finally
None.gif'
I found it is full of interests.
None.gif'
    I like freedom, so'I exchange my ideas with all of 
None.gif'
the world. It is so happy that you can use my classes!
None.gif'
   In the end, sorry for my poor english.
None.gif'
6.Contact me
None.gif'
   Email:hesicong@mail.sc.cninfo.net
None.gif'
   QQ:38288890
None.gif'
   Homepage:http://dream-world.nease.net (Chinese)
None.gif'
   Thanks for using it!
None.gif'
                       ----By HESICONG
None.gif'
None.gif'
Revision:
None.gif'
   2004-10-29:
None.gif'
       Fix bug in decode "@" charactor.
None.gif'
       Add functions in "decode 7 bit code to english" region
None.gif'
   2005-2-20:
None.gif'
       Final version released. Fixed minor bugs. 
None.gif
None.gif
Imports
 System.text
ExpandedBlockStart.gifContractedBlock.gif
Namespace SMS
Namespace SMS
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Namespace DecoderNamespace Decoder
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public MustInherit Class SMSBaseClass SMSBase
InBlock.gif            
'Note all of following various with TP_ can be found in GSM 03.40
InBlock.gif
            Public SCAddressLength As Byte  'Service Center Address length
InBlock.gif
            Public SCAddressType As Byte    'Service Center Type[See GSM 03.40]
InBlock.gif
            Public SCAddressValue As String 'Service Center nuber
InBlock.gif
            Public FirstOctet As Byte       'See GSM 03.40
InBlock.gif
InBlock.gif            
Public TP_PID As Byte
InBlock.gif            
Public TP_DCS As Byte
InBlock.gif            
Public TP_UDL As Byte
InBlock.gif            
Public TP_UD As String
InBlock.gif            
Public Text As String
InBlock.gif            
Public Type As SMSType
InBlock.gif            
Public UserData As String
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Enum SMSTypeEnum SMSType
InBlock.gif                SMS_RECEIVED 
= 0
InBlock.gif                SMS_STATUS_REPORT 
= 2
InBlock.gif                SMS_SUBMIT 
= 1
InBlock.gif                EMS_RECEIVED 
= 64 'It is "Reserved" on my phone??
InBlock.gif
                EMS_SUBMIT = 65
ExpandedSubBlockEnd.gif            
End Enum
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public MustOverride Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif
InBlock.gif            
'Get a byte from PDU string
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function GetByte()Function GetByte(ByRef PDUCode As StringAs Byte
InBlock.gif                
Dim r As Byte = Val("&H" + Mid(PDUCode, 12))
InBlock.gif                PDUCode 
= Mid(PDUCode, 3)
InBlock.gif                
Return r
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
InBlock.gif            
'Get a string of certain length
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function GetString()Function GetString(ByRef PDUCode As StringByVal Length As IntegerAs String
InBlock.gif                
Dim r As String = Mid(PDUCode, 1, Length)
InBlock.gif                PDUCode 
= Mid(PDUCode, Length + 1)
InBlock.gif                
Return r
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
InBlock.gif            
'Get date from SCTS format
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function GetDate()Function GetDate(ByRef SCTS As StringAs Date
InBlock.gif                
Dim yearmonthdayhourminutesecond, timezone As Integer
InBlock.gif
InBlock.gif                
year = Val(Swap(GetString(SCTS, 2))) + 2000
InBlock.gif                
month = Val(Swap(GetString(SCTS, 2)))
InBlock.gif                
day = Val(Swap(GetString(SCTS, 2)))
InBlock.gif                
hour = Val(Swap(GetString(SCTS, 2)))
InBlock.gif                
minute = Val(Swap(GetString(SCTS, 2)))
InBlock.gif                
second = Val(Swap(GetString(SCTS, 2)))
InBlock.gif                timezone 
= Val(Swap(GetString(SCTS, 2)))
InBlock.gif
InBlock.gif                
Dim result As New Date(yearmonthdayhourminutesecond)
InBlock.gif                
Return result
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
InBlock.gif            
'Swap two bit
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function Swap()Function Swap(ByRef TwoBitStr As StringAs String
InBlock.gif                
Dim c() As Char = TwoBitStr.ToCharArray
InBlock.gif                
Dim t As Char
InBlock.gif                t 
= c(0)
InBlock.gif                c(
0= c(1)
InBlock.gif                c(
1= t
InBlock.gif                
Return (c(0+ c(1)).ToString
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
InBlock.gif            
'Get phone address
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function GetAddress()Function GetAddress(ByRef Address As StringAs String
InBlock.gif                
Dim tmpChar As Char() = Address.ToCharArray
InBlock.gif                
Dim i As Integer, result As String
InBlock.gif                
For i = 0 To tmpChar.GetUpperBound(0Step 2
InBlock.gif                    result 
+= Swap(tmpChar(i) + tmpChar(i + 1))
InBlock.gif                
Next
InBlock.gif                
If InStr(result, "F"Then result = Mid(result, 1, result.Length - 1)
InBlock.gif                
Return result
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Shared Function GetSMSType()Function GetSMSType(ByVal PDUCode As StringAs SMSBase.SMSType
InBlock.gif                
'Get first october
InBlock.gif
                Dim FirstOctet As Byte
InBlock.gif                
Dim L As Integer = SMSBase.GetByte(PDUCode)
InBlock.gif                SMSBase.GetByte(PDUCode)
InBlock.gif                SMSBase.GetString(PDUCode, (L 
- 1* 2)
InBlock.gif                FirstOctet 
= SMSBase.GetByte(PDUCode)
InBlock.gif                
'[Chinese]取得特征码
InBlock.gif
                '[Chinese]取得基本码 最后两个bit + 是否有header作为标记
InBlock.gif
                'Get base code. Use last 2 bit and whether there's a header as remark
InBlock.gif
                Dim t1 As Integer = FirstOctet And 3 '00000011
InBlock.gif
                Dim t2 As Integer = FirstOctet And 64 '01000000
InBlock.gif
                '[Chinese]特别处理
InBlock.gif
                If t1 = 3 And t2 = 64 Then Return SMSBase.SMSType.EMS_SUBMIT
InBlock.gif                
Return t1 + t2
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
InBlock.gif            
'Deoce a unicode string
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function DecodeUnicode()Function DecodeUnicode(ByVal strUnicode As StringAs String
InBlock.gif                
Dim Code As String
InBlock.gif                
Dim i, j As Integer
InBlock.gif                
Dim c() As String       'temp
InBlock.gif
                ReDim c(strUnicode.Length / 4)     '2 Byte a Unicode char
InBlock.gif
InBlock.gif                
For j = 0 To strUnicode.Length \ 4 - 1
InBlock.gif                    
Dim d() As Char = strUnicode.ToCharArray(j * 44)
InBlock.gif                    c(j) 
= "&H" & CType(d, String)
InBlock.gif                    c(j) 
= ChrW(Val(c(j)))
InBlock.gif                    Code 
+= c(j)
InBlock.gif                
Next
InBlock.gif                
Return Code
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
'Deocde 7Bit to english#Region "'Deocde 7Bit to english"
InBlock.gif            
'2004-10-29:Region added
InBlock.gif
            'Fixed decode "@" charactor
InBlock.gif
            'I use a new method, it is easily to understand but look much longer than before.
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function InvertHexString()Function InvertHexString(ByVal HexString As StringAs String
InBlock.gif                
'For example:
InBlock.gif
                '123456
InBlock.gif
                '===>
InBlock.gif
                '563412
InBlock.gif
                Dim Result As New StringBuilder
InBlock.gif                
Dim i As Integer
InBlock.gif                
For i = HexString.Length - 2 To 0 Step -2
InBlock.gif                    Result.Append(HexString.Substring(i, 
2))
InBlock.gif                
Next
InBlock.gif                
Return Result.ToString
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Shared Function ByteToBinary()Function ByteToBinary(ByVal Dec As ByteAs String
InBlock.gif                
Dim Result As String
InBlock.gif                
Dim Temp As Byte = Dec
InBlock.gif                
Do
InBlock.gif                    Result 
= (Temp Mod 2& Result
InBlock.gif                    
If Temp = 1 Or Temp = 0 Then Exit Do
InBlock.gif                    Temp 
= Temp \ 2
InBlock.gif                
Loop
InBlock.gif                Result 
= Result.PadLeft(8"0")
InBlock.gif                
Return Result
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Shared Function BinaryToInt()Function BinaryToInt(ByVal Binary As StringAs Integer
InBlock.gif                
Dim Result As Integer
InBlock.gif                
Dim i As Integer
InBlock.gif                
For i = 0 To Binary.Length - 1
InBlock.gif                    Result 
= Result + Val(Binary.Substring(Binary.Length - i - 11)) * 2 ^ i
InBlock.gif                
Next
InBlock.gif                
Return Result
ExpandedSubBlockEnd.gif            
End Function
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Shared Function Decode7Bit()Function Decode7Bit(ByVal str7BitCode As StringByVal charCount As IntegerAs String
InBlock.gif                
Dim Inv7BitCode As String = InvertHexString(str7BitCode)
InBlock.gif                
Dim Binary As String
InBlock.gif                
Dim Result As String
InBlock.gif                
Dim i As Integer
InBlock.gif                
For i = 0 To Inv7BitCode.Length - 1 Step 2
InBlock.gif                    Binary 
+= ByteToBinary(Val("&H" & Inv7BitCode.Substring(i, 2)))
InBlock.gif                
Next
InBlock.gif                
Dim Temp As Integer
InBlock.gif                
For i = 1 To charCount
InBlock.gif                    Temp 
= BinaryToInt(Binary.Substring(Binary.Length - i * 77))
InBlock.gif                    
'There is a problem:
InBlock.gif
                    '"@" charactor is decoded to binary "0000000", but its Ascii Code is 64!!
InBlock.gif
                    'Don't know what to do with it,maybe it is a bug!
InBlock.gif
                    If Temp = 0 Then Temp = 64
InBlock.gif                    Result 
= Result + ChrW(Temp)
InBlock.gif                
Next
InBlock.gif                
Return (Result)
ExpandedSubBlockEnd.gif            
End Function
ExpandedSubBlockEnd.gif
#End Region
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class SMS_RECEIVEDClass SMS_RECEIVED
InBlock.gif            
Inherits SMSBase
InBlock.gif            
Public SrcAddressLength As Byte
InBlock.gif            
Public SrcAddressType As Byte
InBlock.gif            
Public SrcAddressValue As String
InBlock.gif            
Public TP_SCTS As Date
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                Type 
= SMSBase.SMSType.SMS_RECEIVED
InBlock.gif                GetOrignalData(PDUCode)
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Overrides Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif                SCAddressLength 
= GetByte(PDUCode)
InBlock.gif                SCAddressType 
= GetByte(PDUCode)
InBlock.gif                SCAddressValue 
= GetAddress((GetString(PDUCode, (SCAddressLength - 1* 2)))
InBlock.gif                FirstOctet 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                SrcAddressLength 
= GetByte(PDUCode)
InBlock.gif                SrcAddressType 
= GetByte(PDUCode)
InBlock.gif                SrcAddressLength 
+= SrcAddressLength Mod 2
InBlock.gif                SrcAddressValue 
= GetAddress((GetString(PDUCode, SrcAddressLength)))
InBlock.gif
InBlock.gif
InBlock.gif                TP_PID 
= GetByte(PDUCode)
InBlock.gif                TP_DCS 
= GetByte(PDUCode)
InBlock.gif                TP_SCTS 
= GetDate(GetString(PDUCode, 14))
InBlock.gif                TP_UDL 
= GetByte(PDUCode)
InBlock.gif                TP_UD 
= GetString(PDUCode, TP_UDL * 2)
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class SMS_SUBMITClass SMS_SUBMIT
InBlock.gif            
Inherits SMSBase
InBlock.gif            
Public TP_MR As Byte
InBlock.gif            
Public DesAddressLength As Byte
InBlock.gif            
Public DesAddressType As Byte
InBlock.gif            
Public DesAddressValue As String
InBlock.gif            
Public TP_VP As Byte
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                Type 
= SMSBase.SMSType.SMS_SUBMIT
InBlock.gif                GetOrignalData(PDUCode)
ExpandedSubBlockEnd.gif            
End Sub
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Overrides Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif                SCAddressLength 
= GetByte(PDUCode)
InBlock.gif                SCAddressType 
= GetByte(PDUCode)
InBlock.gif                SCAddressValue 
= GetAddress((GetString(PDUCode, (SCAddressLength - 1* 2)))
InBlock.gif                FirstOctet 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                TP_MR 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                DesAddressLength 
= GetByte(PDUCode)
InBlock.gif                DesAddressType 
= GetByte(PDUCode)
InBlock.gif                DesAddressLength 
+= DesAddressLength Mod 2
InBlock.gif                DesAddressValue 
= GetAddress((GetString(PDUCode, DesAddressLength)))
InBlock.gif
InBlock.gif                TP_PID 
= GetByte(PDUCode)
InBlock.gif                TP_DCS 
= GetByte(PDUCode)
InBlock.gif                TP_VP 
= GetByte(PDUCode)
InBlock.gif                TP_UDL 
= GetByte(PDUCode)
InBlock.gif                TP_UD 
= GetString(PDUCode, TP_UDL * 2)
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class EMS_RECEIVEDClass EMS_RECEIVED
InBlock.gif            
Inherits SMS_RECEIVED
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Structure InfoElemStructure InfoElem       'See document "How to create EMS"
InBlock.gif
                Public Identifier As Byte
InBlock.gif                
Public Length As Byte
InBlock.gif                
Public Data As String
ExpandedSubBlockEnd.gif            
End Structure
InBlock.gif            
Public TP_UDHL As Byte
InBlock.gif
InBlock.gif            
Public IE() As InfoElem
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                
MyBase.New(PDUCode)
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Overrides Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif                SCAddressLength 
= GetByte(PDUCode)
InBlock.gif                SCAddressType 
= GetByte(PDUCode)
InBlock.gif                SCAddressValue 
= GetAddress(GetString(PDUCode, (SCAddressLength - 1* 2))
InBlock.gif                FirstOctet 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                SrcAddressLength 
= GetByte(PDUCode)
InBlock.gif                SrcAddressType 
= GetByte(PDUCode)
InBlock.gif                SrcAddressLength 
+= SrcAddressLength Mod 2
InBlock.gif                SrcAddressValue 
= GetAddress((GetString(PDUCode, SrcAddressLength)))
InBlock.gif
InBlock.gif                TP_PID 
= GetByte(PDUCode)
InBlock.gif                TP_DCS 
= GetByte(PDUCode)
InBlock.gif                TP_SCTS 
= GetDate(GetString(PDUCode, 14))
InBlock.gif                TP_UDL 
= GetByte(PDUCode)
InBlock.gif                TP_UDHL 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                IE 
= GetIE(GetString(PDUCode, TP_UDHL * 2))
InBlock.gif
InBlock.gif                TP_UD 
= GetString(PDUCode, TP_UDL * 2)
ExpandedSubBlockEnd.gif            
End Sub
InBlock.gif
InBlock.gif            
'Get Informat Elements 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            Shared Function GetIE()Function GetIE(ByVal IECode As StringAs InfoElem()
InBlock.gif                
Dim tmp As String = IECode, t As Integer = 0
InBlock.gif                
Dim result() As InfoElem
InBlock.gif                
Do Until IECode = ""
InBlock.gif
                    ReDim Preserve result(t)
InBlock.gif                    
With result(t)
InBlock.gif                        .Identifier 
= GetByte(IECode)
InBlock.gif                        .Length 
= GetByte(IECode)
InBlock.gif                        .Data 
= GetString(IECode, .Length * 2)
InBlock.gif                    
End With
InBlock.gif                    t 
+= 1
InBlock.gif                
Loop
InBlock.gif                
Return result
ExpandedSubBlockEnd.gif            
End Function
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class EMS_SUBMITClass EMS_SUBMIT
InBlock.gif            
Inherits SMS_SUBMIT
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                
MyBase.New(PDUCode)
InBlock.gif                Type 
= SMSBase.SMSType.EMS_SUBMIT
ExpandedSubBlockEnd.gif            
End Sub
InBlock.gif
InBlock.gif            
Public TP_UDHL As Byte
InBlock.gif
InBlock.gif            
Public IE() As EMS_RECEIVED.InfoElem
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Overrides Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif                SCAddressLength 
= GetByte(PDUCode)
InBlock.gif                SCAddressType 
= GetByte(PDUCode)
InBlock.gif                SCAddressValue 
= GetAddress(GetString(PDUCode, (SCAddressLength - 1* 2))
InBlock.gif                FirstOctet 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                TP_MR 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                DesAddressLength 
= GetByte(PDUCode)
InBlock.gif                DesAddressType 
= GetByte(PDUCode)
InBlock.gif                DesAddressLength 
+= DesAddressLength Mod 2
InBlock.gif                DesAddressValue 
= GetAddress(GetString(PDUCode, DesAddressLength))
InBlock.gif
InBlock.gif                TP_PID 
= GetByte(PDUCode)
InBlock.gif                TP_DCS 
= GetByte(PDUCode)
InBlock.gif                TP_VP 
= GetByte(PDUCode)
InBlock.gif                TP_UDL 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                TP_UDHL 
= GetByte(PDUCode)
InBlock.gif                IE 
= EMS_RECEIVED.GetIE(GetString(PDUCode, TP_UDHL * 2))
InBlock.gif
InBlock.gif                TP_UD 
= GetString(PDUCode, TP_UDL * 2)
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class SMS_STATUS_REPORTClass SMS_STATUS_REPORT
InBlock.gif            
Inherits SMS_RECEIVED
InBlock.gif            
Public TP_MR As Byte
InBlock.gif            
Public TP_DP As Date
InBlock.gif            
Public Status As EnumStatus
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Enum EnumStatusEnum EnumStatus
InBlock.gif                Success 
= 0
InBlock.gif                NotSend 
= 96
InBlock.gif                NoResponseFromSME 
= 98
ExpandedSubBlockEnd.gif            
End Enum
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                
MyBase.New(PDUCode)
InBlock.gif                Type 
= SMSBase.SMSType.SMS_STATUS_REPORT
ExpandedSubBlockEnd.gif            
End Sub
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Overrides Sub GetOrignalData()Sub GetOrignalData(ByVal PDUCode As String)
InBlock.gif                SCAddressLength 
= GetByte(PDUCode)
InBlock.gif                SCAddressType 
= GetByte(PDUCode)
InBlock.gif                SCAddressValue 
= GetAddress(GetString(PDUCode, (SCAddressLength - 1* 2))
InBlock.gif
InBlock.gif                FirstOctet 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                TP_MR 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                SrcAddressLength 
= GetByte(PDUCode)
InBlock.gif                SrcAddressType 
= GetByte(PDUCode)
InBlock.gif                SrcAddressLength 
+= SrcAddressLength Mod 2
InBlock.gif                SrcAddressValue 
= GetAddress(GetString(PDUCode, SrcAddressLength))
InBlock.gif
InBlock.gif                TP_SCTS 
= GetDate(GetString(PDUCode, 14))
InBlock.gif                TP_DP 
= GetDate(GetString(PDUCode, 14))
InBlock.gif
InBlock.gif                Status 
= GetByte(PDUCode)
InBlock.gif
InBlock.gif                
'Status report do not have content so I set it a zero length string
InBlock.gif
                TP_UD = ""
ExpandedSubBlockEnd.gif
            End Sub
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Class PDUDecoderClass PDUDecoder
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Structure BaseInfoStructure BaseInfo
InBlock.gif                
Public SourceNumber As String
InBlock.gif                
Public DestinationNumber As String
InBlock.gif                
Public ReceivedDate As Date
InBlock.gif                
Public Text As String
InBlock.gif                
Public Type As SMS.Decoder.SMSBase.SMSType
InBlock.gif                
Public EMSTotolPiece As Integer
InBlock.gif                
Public EMSCurrentPiece As Integer
InBlock.gif                
Public StatusFromReport As SMS_STATUS_REPORT.EnumStatus
InBlock.gif
InBlock.gif                
Public DestinationReceivedDate
ExpandedSubBlockEnd.gif            
End Structure
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Sub New()Sub New(ByVal PDUCode As String)
InBlock.gif                Decode(PDUCode)
ExpandedSubBlockEnd.gif            
End Sub
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
Public Shared Function Decode()Function Decode(ByVal PDUCode As StringAs BaseInfo
InBlock.gif                
Dim Result As BaseInfo
InBlock.gif                
Try
InBlock.gif                    
Dim s As Object
InBlock.gif                    
Dim T As SMSBase.SMSType = SMSBase.GetSMSType(PDUCode)
InBlock.gif                    Result.Type 
= T
InBlock.gif                    
Select Case T
InBlock.gif                        
Case SMSBase.SMSType.EMS_RECEIVED
InBlock.gif                            s 
= New EMS_RECEIVED(PDUCode)
InBlock.gif                            Result.SourceNumber 
= s.SrcAddressValue
InBlock.gif
InBlock.gif                            
If s.SrcAddressType = &H91 Then Result.SourceNumber = "+" + Result.SourceNumber
InBlock.gif
InBlock.gif                            Result.ReceivedDate 
= s.TP_SCTS
InBlock.gif
InBlock.gif                            
If Not (s.IE Is NothingThen
InBlock.gif                                
Dim Data As String = s.IE(0).Data
InBlock.gif                                Result.EMSTotolPiece 
= CInt(Mid(Data, 52))
InBlock.gif                                Result.EMSCurrentPiece 
= CInt(Mid(Data, 72))
InBlock.gif                            
End If
InBlock.gif
InBlock.gif                        
Case SMSBase.SMSType.SMS_RECEIVED
InBlock.gif                            s 
= New SMS_RECEIVED(PDUCode)
InBlock.gif                            Result.SourceNumber 
= s.SrcAddressValue
InBlock.gif                            
If s.SrcAddressType = &H91 Then Result.SourceNumber = "+" + Result.SourceNumber
InBlock.gif                            Result.ReceivedDate 
= s.TP_SCTS
InBlock.gif
InBlock.gif                        
Case SMSBase.SMSType.EMS_SUBMIT
InBlock.gif                            s 
= New EMS_SUBMIT(PDUCode)
InBlock.gif
InBlock.gif                            Result.DestinationNumber 
= s.DesAddressValue
InBlock.gif                            
If s.DesAddressType = &H91 Then Result.DestinationNumber = "+" + Result.DestinationNumber
InBlock.gif                            
If Not (s.IE Is NothingThen
InBlock.gif                                
Dim Data As String = s.IE(0).Data
InBlock.gif                                Result.EMSTotolPiece 
= CInt(Mid(Data, 52))
InBlock.gif                                Result.EMSCurrentPiece 
= CInt(Mid(Data, 72))
InBlock.gif                            
End If
InBlock.gif
InBlock.gif                        
Case SMSBase.SMSType.SMS_SUBMIT
InBlock.gif                            s 
= New SMS_SUBMIT(PDUCode)
InBlock.gif                            Result.DestinationNumber 
= s.DesAddressValue
InBlock.gif                            
If s.DesAddressType = &H91 Then Result.DestinationNumber = "+" + Result.DestinationNumber
InBlock.gif
InBlock.gif                        
Case SMSBase.SMSType.SMS_STATUS_REPORT
InBlock.gif                            s 
= New SMS_STATUS_REPORT(PDUCode)
InBlock.gif                            Result.SourceNumber 
= s.SrcAddressValue
InBlock.gif                            
If s.SrcAddressType = &H91 Then Result.SourceNumber = "+" + Result.SourceNumber
InBlock.gif                            Result.ReceivedDate 
= s.TP_SCTS
InBlock.gif                            Result.DestinationReceivedDate 
= s.TP_DP()
InBlock.gif                            Result.StatusFromReport 
= s.status
InBlock.gif                        
Case Else
InBlock.gif                            
Stop
InBlock.gif                    
End Select
InBlock.gif                    
'###########################
InBlock.gif
                    'Correct when s is SMS type, no TP_UDL is found.
InBlock.gif
                    'Note:Only EMS has the TP_UDHL and TP_UDH see 3GPP TS 23.040 V6.5.0 (2004-09)
InBlock.gif
                    '###########################
InBlock.gif
                    If s.tp_DCS = 0 Then
InBlock.gif                        
If T = SMSBase.SMSType.SMS_RECEIVED Or T = SMSBase.SMSType.SMS_STATUS_REPORT Or T = SMSBase.SMSType.SMS_SUBMIT Then
InBlock.gif                            
'#############################
InBlock.gif
                            'add a parameter
InBlock.gif
                            '############################
InBlock.gif
                            Result.Text = s.decode7bit(s.tp_UD, s.TP_UDL)
InBlock.gif                        
End If
InBlock.gif
InBlock.gif                        
If T = SMSBase.SMSType.EMS_RECEIVED Or T = SMSBase.SMSType.EMS_SUBMIT Then
InBlock.gif                            Result.Text 
= s.decode7bit(s.tp_ud, s.tp_udl - 8 * (1 + s.tp_udhl) / 7)
InBlock.gif                        
End If
InBlock.gif                    
Else
InBlock.gif                        Result.Text 
= s.DecodeUnicode(s.TP_UD)
InBlock.gif                    
End If
InBlock.gif                
Catch err As Exception
InBlock.gif                    Result.Text 
= "PDU解码错误:" & PDUCode
InBlock.gif                
End Try
InBlock.gif                
Return Result
ExpandedSubBlockEnd.gif            
End Function
ExpandedSubBlockEnd.gif        
End Class
InBlock.gif
ExpandedSubBlockEnd.gif    
End Namespace
ExpandedBlockEnd.gif
End Namespace
None.gif
None.gif

转载于:https://www.cnblogs.com/hesicong/archive/2005/08/03/207044.html

你可能感兴趣的文章
SQL优化:重新编译存储过程和表
查看>>
PCB“有铅”工艺将何去何从?
查看>>
Solr环境搭建
查看>>
垂直居中的几种实现方法
查看>>
UILabel标签文字过长时的显示方式
查看>>
H5离线缓存机制-manifest
查看>>
比较:I/O成员函数getline() 与 get()(第二种用法)的用法异同
查看>>
201671010118 2016-2017-2《Java程序设计》 第十一周学习心得
查看>>
Get Sauce(状压DP)
查看>>
Office2007 升级到 office2010
查看>>
SpringBoot整合Hibernate
查看>>
PPT1 例2
查看>>
extern外部方法使用C#简单例子
查看>>
血液循环结构
查看>>
SQL Server统计数据库中表个数、视图个数、存储过程个数
查看>>
设计模式:观察者模式
查看>>
课程总结
查看>>
openstack新建虚机、网络、路由时候对应的ovs网桥的变化
查看>>
linux 编译运行c文件
查看>>
Scrapy的学习和使用
查看>>