'#########################################
'SMS/EMS Encoder
'Write by Hesicong
'Last Edited:2005/2/20
'Until now no bug found here.
'Contact:
' Email:
' hesicong@mail.sc.cninfo.net
' or
' 38288890@qq.com
' HomePage:
' http://dream-world.nease.net
'Thanks for using my code
'#########################################
Namespace SMSNamespace SMS
Namespace EncoderNamespace Encoder
Public Class SMSClass SMS
Enums#Region "Enums"
Public Enum ENUM_TP_VPFEnum ENUM_TP_VPF
Relative_Format = 16 'b4=1 b3=0
End Enum
Public Enum ENUM_TP_SRIEnum ENUM_TP_SRI
Request_SMS_Report = 32
No_SMS_Report = 0
End Enum
Public Enum ENUM_TP_DCSEnum ENUM_TP_DCS
DefaultAlphabet = 0
UCS2 = 8
End Enum
Public Enum ENUM_TP_VALID_PERIODEnum ENUM_TP_VALID_PERIOD
OneHour = 11 '0 to 143:(TP-VP+1)*5Min
ThreeHours = 29
SixHours = 71
TwelveHours = 143
OneDay = 167
OneWeek = 196
Maximum = 255
End Enum
#End Region
Private Data#Region "Private Data"
Protected SC_Number As String 'Note the plus!
Protected TP_MTI As Byte = 1
Protected TP_RD As Byte = 0
Protected TP_VPF As Byte = 16
Protected TP_UDHI As Byte
Protected TP_SRR As Byte
Protected TP_MR As Integer
Protected TP_DA As String
Protected TP_PID As Byte
Protected TP_DCS As Byte
Protected TP_VP As Byte
Protected TP_UDL As Integer
Protected TP_UD As String
#End Region
Properties#Region "Properties"
Public Property ServiceCenterNumber()Property ServiceCenterNumber() As String
Get
Return SC_Number
End Get
Set(ByVal Value As String)
'Convert an ServiceCenterNumber to PDU Code
If InStr(Value, "+") Then
SC_Number = "91"
Else
SC_Number = "81"
End If
Value = Mid(Value, 2)
Dim i As Integer
If (Value.Length Mod 2) = 1 Then
Value += "F"
End If
For i = 1 To Value.Length Step 2
SC_Number += Swap(Mid(Value, i, 2))
Next
SC_Number = ByteToHex((SC_Number.Length - 2) / 2 + 1) + SC_Number
End Set
End Property
Public Property TP_Status_Report_Request()Property TP_Status_Report_Request() As ENUM_TP_SRI
Get
Return TP_SRR
End Get
Set(ByVal Value As ENUM_TP_SRI)
TP_SRR = Value
End Set
End Property
Public Property TP_Message_Reference()Property TP_Message_Reference() As Integer
Get
Return TP_MR
End Get
Set(ByVal Value As Integer)
TP_MR = Value
End Set
End Property
Public Property TP_Destination_Address()Property TP_Destination_Address() As String
Get
Return TP_DA
End Get
Set(ByVal Value As String)
TP_DA = ""
If InStr(Value, "+") Then
TP_DA += "91"
Else
TP_DA += "81"
End If
Value = Value.Replace("+", "")
TP_DA = Format(Value.Length, "X2") + TP_DA
Dim i As Integer
If (Value.Length Mod 2) = 1 Then
Value += "F"
End If
For i = 1 To Value.Length Step 2
TP_DA += Swap(Mid(Value, i, 2))
Next
End Set
End Property
Public Property TP_Data_Coding_Scheme()Property TP_Data_Coding_Scheme() As ENUM_TP_DCS
Get
Return TP_DCS
End Get
Set(ByVal Value As ENUM_TP_DCS)
TP_DCS = Value
End Set
End Property
Public Property TP_Validity_Period()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
Public Overridable Property TP_User_Data()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
Functions#Region "Functions"
Public Shared Function CheckForEncoding()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
Public Overridable Function GetSMSPDUCode()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(TP_DCS, "X2")
PDUCode += Format(TP_VP, "X2")
PDUCode += Format(TP_UDL, "X2")
'SMS/EMS Encoder
'Write by Hesicong
'Last Edited:2005/2/20
'Until now no bug found here.
'Contact:
' Email:
' hesicong@mail.sc.cninfo.net
' or
' 38288890@qq.com
' HomePage:
' http://dream-world.nease.net
'Thanks for using my code
'#########################################
Namespace SMSNamespace SMS
Namespace EncoderNamespace Encoder
Public Class SMSClass SMS
Enums#Region "Enums"
Public Enum ENUM_TP_VPFEnum ENUM_TP_VPF
Relative_Format = 16 'b4=1 b3=0
End Enum
Public Enum ENUM_TP_SRIEnum ENUM_TP_SRI
Request_SMS_Report = 32
No_SMS_Report = 0
End Enum
Public Enum ENUM_TP_DCSEnum ENUM_TP_DCS
DefaultAlphabet = 0
UCS2 = 8
End Enum
Public Enum ENUM_TP_VALID_PERIODEnum ENUM_TP_VALID_PERIOD
OneHour = 11 '0 to 143:(TP-VP+1)*5Min
ThreeHours = 29
SixHours = 71
TwelveHours = 143
OneDay = 167
OneWeek = 196
Maximum = 255
End Enum
#End Region
Private Data#Region "Private Data"
Protected SC_Number As String 'Note the plus!
Protected TP_MTI As Byte = 1
Protected TP_RD As Byte = 0
Protected TP_VPF As Byte = 16
Protected TP_UDHI As Byte
Protected TP_SRR As Byte
Protected TP_MR As Integer
Protected TP_DA As String
Protected TP_PID As Byte
Protected TP_DCS As Byte
Protected TP_VP As Byte
Protected TP_UDL As Integer
Protected TP_UD As String
#End Region
Properties#Region "Properties"
Public Property ServiceCenterNumber()Property ServiceCenterNumber() As String
Get
Return SC_Number
End Get
Set(ByVal Value As String)
'Convert an ServiceCenterNumber to PDU Code
If InStr(Value, "+") Then
SC_Number = "91"
Else
SC_Number = "81"
End If
Value = Mid(Value, 2)
Dim i As Integer
If (Value.Length Mod 2) = 1 Then
Value += "F"
End If
For i = 1 To Value.Length Step 2
SC_Number += Swap(Mid(Value, i, 2))
Next
SC_Number = ByteToHex((SC_Number.Length - 2) / 2 + 1) + SC_Number
End Set
End Property
Public Property TP_Status_Report_Request()Property TP_Status_Report_Request() As ENUM_TP_SRI
Get
Return TP_SRR
End Get
Set(ByVal Value As ENUM_TP_SRI)
TP_SRR = Value
End Set
End Property
Public Property TP_Message_Reference()Property TP_Message_Reference() As Integer
Get
Return TP_MR
End Get
Set(ByVal Value As Integer)
TP_MR = Value
End Set
End Property
Public Property TP_Destination_Address()Property TP_Destination_Address() As String
Get
Return TP_DA
End Get
Set(ByVal Value As String)
TP_DA = ""
If InStr(Value, "+") Then
TP_DA += "91"
Else
TP_DA += "81"
End If
Value = Value.Replace("+", "")
TP_DA = Format(Value.Length, "X2") + TP_DA
Dim i As Integer
If (Value.Length Mod 2) = 1 Then
Value += "F"
End If
For i = 1 To Value.Length Step 2
TP_DA += Swap(Mid(Value, i, 2))
Next
End Set
End Property
Public Property TP_Data_Coding_Scheme()Property TP_Data_Coding_Scheme() As ENUM_TP_DCS
Get
Return TP_DCS
End Get
Set(ByVal Value As ENUM_TP_DCS)
TP_DCS = Value
End Set
End Property
Public Property TP_Validity_Period()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
Public Overridable Property TP_User_Data()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
Functions#Region "Functions"
Public Shared Function CheckForEncoding()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
Public Overridable Function GetSMSPDUCode()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(TP_DCS, "X2")
PDUCode += Format(TP_VP, "X2")
PDUCode += Format(TP_UDL, "X2")