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

📄 sms.vb

📁 vc实现串口收发短信
💻 VB
📖 第 1 页 / 共 4 页
字号:
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Public Property TP_Validity_Period() As ENUM_TP_VALID_PERIOD
                Get
                    Return TP_VP
                End Get
                Set(ByVal Value As ENUM_TP_VALID_PERIOD)
                    TP_VP = Value
                End Set
            End Property

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <value></value>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Public Overridable Property TP_User_Data() As String
                Get
                    Return TP_UD
                End Get
                Set(ByVal Value As String)
                    Select Case TP_DCS
                        Case Is = ENUM_TP_DCS.DefaultAlphabet
                            TP_UDL = Value.Length
                            TP_UD = Encode7Bit(Value)
                        Case Is = ENUM_TP_DCS.UCS2
                            TP_UDL = Value.Length * 2
                            TP_UD = EncodeUCS2(Value)
                        Case Else
                            TP_UD = Value
                    End Select
                End Set
            End Property
#End Region

#Region "Functions"
            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="Content"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Private Function CheckForEncoding(ByVal Content As String) As SMS.ENUM_TP_DCS
                Dim i As Integer
                For i = 1 To Content.Length
                    If Asc(Mid(Content, i, 1)) < 0 Then
                        Return SMS.ENUM_TP_DCS.UCS2
                    End If
                Next
                Return SMS.ENUM_TP_DCS.DefaultAlphabet
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Public Overridable Function GetSMSPDUCode() As String
                Dim PDUCode As String
                'Check User Data Length
                If TP_DCS = ENUM_TP_DCS.DefaultAlphabet Then
                    If TP_UD.Length > 280 Then Throw New Exception("User Data is TOO LONG for SMS")
                End If
                If TP_DCS = ENUM_TP_DCS.UCS2 Then
                    If TP_UD.Length > 280 Then Throw New Exception("User Data is TOO LONG for SMS")
                End If
                'Make PDUCode
                PDUCode = SC_Number
                PDUCode += FirstOctet()
                PDUCode += Format(TP_MR, "X2")
                PDUCode += TP_DA
                PDUCode += Format(TP_PID, "X2")
                PDUCode += Format(CByte(TP_DCS), "X2")
                PDUCode += Format(CByte(TP_VP), "X2")
                PDUCode += Format(CInt(TP_UDL), "X2")
                PDUCode += TP_UD
                Return PDUCode
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Private Function FirstOctet() As String
                Return ByteToHex(CByte(TP_MTI + TP_VPF + TP_SRR + TP_UDHI))
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="aByte"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function ByteToHex(ByVal aByte As Byte) As String
                Dim result As String
                result = Format(aByte, "X2")
                Return result
            End Function

#Region "Enocode7Bit"
            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="Content"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function Encode7Bit(ByVal Content As String) As String
                'Prepare
                Dim CharArray As Char() = Content.ToCharArray
                Dim c As Char
                Dim t As String
                For Each c In CharArray
                    t = CharTo7Bits(c) + t
                Next
                'Add "0"
                Dim i As Integer
                If (t.Length Mod 8) <> 0 Then
                    For i = 1 To 8 - (t.Length Mod 8)
                        t = "0" + t
                    Next
                End If
                'Split into 8bits
                Dim result As String
                For i = t.Length - 8 To 0 Step -8
                    result = result + BitsToHex(Mid(t, i + 1, 8))
                Next
                Return result
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="Bits"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function BitsToHex(ByVal Bits As String) As String
                'Convert 8Bits to Hex String
                Dim i, v As Integer
                For i = 0 To Bits.Length - 1
                    v = v + CInt(Val(Mid(Bits, i + 1, 1)) * 2 ^ (7 - i))
                Next
                Dim result As String
                result = Format(v, "X2")
                Return result
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="c"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function CharTo7Bits(ByVal c As Char) As String
                If c = "@" Then Return "0000000"
                Dim Result As String
                Dim i As Integer
                For i = 0 To 6
                    If (Asc(c) And CLng(2 ^ i)) > 0 Then
                        Result = "1" + Result
                    Else
                        Result = "0" + Result
                    End If
                Next
                Return Result
            End Function
#End Region

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="Content"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function EncodeUCS2(ByVal Content As String) As String
                Dim i, j, v As Integer
                Dim Result, t As String
                For i = 1 To Content.Length
                    v = AscW(Mid(Content, i, 4))
                    t = Format(v, "X4")
                    Result += t
                Next
                Return Result
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <param name="TwoBitStr"></param>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Protected Function Swap(ByRef TwoBitStr As String) As String
                'Swap two bit like "EF" TO "FE"
                Dim c() As Char = TwoBitStr.ToCharArray
                Dim t As Char
                t = c(0)
                c(0) = c(1)
                c(1) = t
                Return (c(0) + c(1)).ToString
            End Function
#End Region
        End Class

        ''' -----------------------------------------------------------------------------
        ''' Project	 : SMS Solution
        ''' Class	 : SMS.Encoder.ConcatenatedShortMessage
        ''' 
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[AMDXP2500]	2005-7-25	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Class ConcatenatedShortMessage
            Inherits SMS
            Private TotalMessages As Integer

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Public Function GetEMSPDUCode() As String()
                Select Case TP_DCS
                    Case ENUM_TP_DCS.UCS2
                        TotalMessages = (CInt(TP_UD.Length / 4)) \ 66 + CInt(((TP_UD.Length / 4 Mod 66) = 0))
                    Case ENUM_TP_DCS.DefaultAlphabet
                        TotalMessages = (TP_UD.Length \ 266) - CInt((TP_UD.Length Mod 266) = 0)
                End Select

                Dim Result(TotalMessages) As String
                Dim tmpTP_UD As String
                Dim i As Integer
                TP_UDHI = CByte(2 ^ 6)
                Dim Reference As Integer = CInt(Rnd(1) * 65536)   '16bit Reference Number 'See 3GPP Document
                For i = 0 To TotalMessages
                    Select Case TP_DCS
                        Case ENUM_TP_DCS.UCS2
                            tmpTP_UD = Mid(TP_UD, i * 66 * 4 + 1, 66 * 4)
                            'When TP_UDL is odd, the max length of an Unicode string in PDU code is 66 Charactor.See [3GPP TS 23.040 V6.5.0 (2004-09] 9.2.3.24.1
                        Case ENUM_TP_DCS.DefaultAlphabet
                            tmpTP_UD = Mid(TP_UD, i * 133 * 2 + 1, 133 * 2)
                    End Select
                    Result(i) = SC_Number
                    Result(i) += FirstOctet()
                    Result(i) += Format(TP_MR, "X2")
                    'Next segement TP_MR must be increased
                    'TP_MR += 1
                    Result(i) += TP_DA
                    Result(i) += Format(CInt(TP_PID), "X2")
                    Result(i) += Format(CInt(TP_DCS), "X2")
                    Result(i) += Format(CInt(TP_VP), "X2")
                    If TP_DCS = ENUM_TP_DCS.UCS2 Then
                        TP_UDL = CInt(tmpTP_UD.Length / 2 + 6 + 1) '6:IE
                    End If
                    If TP_DCS = ENUM_TP_DCS.DefaultAlphabet Then
                        TP_UDL = CInt(Fix((tmpTP_UD.Length + 7 * 2) * 4 / 7))   '6:length of IE
                        ''#################################
                        ''still problem here:
                        ''when the charcter is several times of 7 of the last message, tp_udl will not correct!
                        ''to correct this problem i write some code below. that's may not perfect solution.
                        ''#################################
                        'If i = TotalMessages And ((tmpTP_UD.Length Mod 14) = 0) Then
                        '    tp_udl -= 1
                        'End If
                    End If
                    Result(i) += Format(TP_UDL, "X2")
                    Result(i) += "060804" 'TP_UDHL and some of Concatenated message
                    Result(i) += Format(Reference, "X4")
                    Result(i) += Format(TotalMessages + 1, "X2")
                    Result(i) += Format(i + 1, "X2")
                    Result(i) += tmpTP_UD
                Next
                Return Result
            End Function

            ''' -----------------------------------------------------------------------------
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <returns></returns>
            ''' <remarks>
            ''' </remarks>
            ''' <history>
            ''' 	[AMDXP2500]	2005-7-25	Created
            ''' </history>
            ''' -----------------------------------------------------------------------------
            Private Function FirstOctet() As String
                Return ByteToHex(CByte(TP_MTI + TP_VPF + TP_SRR + TP_UDHI))
            End Function
        End Class
    End Namespace
End Namespace

⌨️ 快捷键说明

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