PDudecoder --- an article written on CodeProject

xiaoxiao2021-03-06  58

Download Source Files - 3.02 KB Download Demo Project - 10.2 KB CodeProject on the original link

Introduction

Wish to develop SMS or EMS Application? What do you read from your mobile? PDU code. PDU is a format Which you send to a phone to send a sms or an EMS. You can Find More in GSM 03.40.

What is a pdu code and how can I decode it?

Let us Take a Simple Look at PDU Code. Here i created a SMS: "Hello, My Pretty World!", In My Siemens M55 Mobile, And Send It To 1861. I Use Hyperterminal To Communicate With My Phone Using At Command Set.

First, I set my character set to uncode:

AT CSCS = "UCS2"

Then i set my preferred message storage to MT:

AT CPMS = "MT"

At Last, I Read All My SMS OUT:

AT cmgl = 4

I find the SMS I Just Created in PDU Format:

0891683108200805F01151048181160000FF16C8329BFD66B5F320B8BC4CA7E741F7B79C4D0E01

Now, I decode it mantly:

08: Length of Service Center Number

91: INDICATE THERE IS A Plus at The Beginning of Service Center Number

683108200805F: Service Center Number: 8613800280500 Note WHEN THE LENGTH

Of Number is an ODD Number, Add F.

11: INDICATE SMS WILL BE SENT.

51: TP-MR MESSAGE REFERENCE, NOT COMMON USED.

04: Length of destination Number. Here 1861.

81: No Plus Here.

8161: Destination Number 1861.

00: TP-PID. SEE GSM 03.40

00: TP-DCS. TP-UD IS Coded by 7bit Charactor Method. See GSM 03.38

FF: TP-VP. Valid Period. Here is infinity.

16: HEX Value Equals to 22. This INDICATES There Are 22 Charactors in TP-UD

C8329BFD66B5F320B8BC4CA7E741F7B79C4D0E01: TP-UD,

Decode it Using 7bit Charactor Method.

HA-HA, NOW You May Know More About PDU Code. Let us Start Our Program.

What is the structure of my pdu decoder?

I created a must inherit class SMS, it provides basic structure a SMS must have For example:. Something relating to service center, first octet, TP_PID, and so on.In this class I provide a must override sub GetOrignalData, this help me to Do Further Work on The Orignal Data from PDU Code. Here Are Also A Few of Shared Functions:

GetString () getdate () spap () getaddress () getsmstype () decodeunicateode90 () decode7bit ()

There Shared Functions Will Be Used Frequently. After SMS Class, I create, EMS_RECEIVED, EMS_SUBMIT, SMS_STATUS_REPORT CLASS That Inherit from SMS Class.

How IT Works?

I Wanded It Like, Once You Create An Instance of One Class with a PDU Code, IT Decodes It Immediately. So, I Wrote Some Code in Every Sub New.

Take SMS_Received, for example:

Sub New (Byval Pducode As String)

TYPE = SMS.SMSTYPE.SMS_RECEIVED

GetorignalData (PDucode)

End Sub

....................

Public overrides sub getorignaldata (Byval Pducode As String)

ScaddressLength = GetByte (PDucode)

SCADDRESSTYPE = GetByte (PDucode)

ScaddressValue = Getdress ((GetString (pducode, (ScaddressLength - 1) * 2))))))))))

FirstOCTET = GetByte (PDucode)

SRCADDRESSLENGTH = GetByte (PDucode)

SRCADDRESSTYPE = GetByte (pducode)

SRCADDRESSLENGTH = SRCADDRESSLENGTH MOD 2

SrcaddressValue = GetDress ((GetString (pducode, srcaddressLength))))

TP_PID = GetByte (PDucode)

TP_DCS = GetByte (PDucode)

TP_SCTS = Getdate (Pducode, 14))

TP_UDL = GetByte (PDucode)

TP_UD = GetString (Pducode, TP_UDL * 2)

End Sub

It is so easy to write some code like this after you read GSM 03.40. Shared Function Here Helps Me Get What I Want, A Byte OR A String or Even You Get Something from PDU Code, IT Will Be Got rid of from the PDU code. This seemed like a good way after I failed to control the position of what PDU code I should get, because every time, the shared functions started from the beginning of PDU code.In EMS, I write a function TO GET INFORMATION Element from PDU Code And A Structure To Store IT.

Public structure infolex

Public Identifier as Byte

Public Length as Byte

Public Data As String

End structure

Shared function getie (Byval IECode As String) AS Infoelem ()

DIM TMP As String = IECode, T as integer = 0

Dim Result () AS Infoelem

Do Until IECode = ""

Redim Preserve Result (T)

WITH RESULT (T)

.Identifier = GetByte (IECode)

.Length = getByte (IECODE)

.DATA = getString (IECode, .length * 2)

End with

T = 1

Loop

Return RESULT

END FUNCTION

Maybe, My Class Is Not The Best, But IT Works Well :).

How Can I Use this class?

If you know what the type of PDU code is, you simply create an instance of a certain type in SMS or EMS. But when you do not know the type, you use shared function GetSMSType to get the type. Then according to the type Create a certain instance of sms class, it is decoded automaticly.

STILL DON't KNOW? Sorry for My Poor English, Run My Program and See My Code, You Will Know It Better.

Are there some bugs?

Sorry, I Don't Find Bugs When I Decode PDU Code from Siemens M55 Mobile and Nokia 8xxx Mobile, I Think the Will Be No Bugs. If You Find Some, please contact me. Thanks!

Some Useful Documents and Sites

GSM 03.40 ETSI (This Site Provides GSM Documents) .Contact ME and make Friends with me

My email: hesicong@mail.sc.cninfo.net; hesicong@126.com. My QQ (ONLY IN China): 3828890. My MSN: hesicong@mail.sc.cninfo.net. My homepage. My 9cbs blog. In The end, thanks for using these classes!

转载请注明原文地址:https://www.9cbs.com/read-113325.html

New Post(0)