分享
 
 
 

PDUDecoder ---我在CodeProject上写的一篇文章

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

[/url][url=http://www.codeproject.com/useritems/PDUDecoder/SMS.zip]Download source files - 4 Kb

Download demo project - 12 Kb

Introduction

Wish to develop SMS or EMS application? What you read from your mobile? PDU code.

PDU is a format which you send to 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 Unicode:

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 we decode it manually.

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 this 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 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 relate 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:

GetByte(),GetString(),GetDate(),Swap(),GetAddress(),GetSMSType(),DecodeUnicode90,Decode7Bit()

There shared functions will be used frequently.

After SMS class, I create SMS_RECEIVED,SMS_SUBMIT,EMS_RECEIVED,EMS_SUBMIT,SMS_STATUS_REPORT class that inherits from SMS class.

How it works?

I want once you created an instance of one class with a PDU code, it decode it immediately. So I write 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

The sub GetOrignalData get original data from PDU code. This is one decode a received SMS's PDU code.

Public Overrides Sub GetOrignalData(ByVal PDUCode As String)

SCAddressLength = GetByte(PDUCode)

SCAddressType = GetByte(PDUCode)

SCAddressValue = GetAddress((GetString(PDUCode, (SCAddressLength - 1) * 2)))

FirstOctet = GetByte(PDUCode)

SrcAddressLength = GetByte(PDUCode)

SrcAddressType = GetByte(PDUCode)

SrcAddressLength += SrcAddressLength Mod 2

SrcAddressValue = GetAddress((GetString(PDUCode, SrcAddressLength)))

TP_PID = GetByte(PDUCode)

TP_DCS = GetByte(PDUCode)

TP_SCTS = GetDate(GetString(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 a date. Note that when you get something from PDU code, it will be got rid of from PDU code. This is a good way after I failed to control the position of what PDU code I should get, because every time the shared functions start 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 InfoElem

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, you simply create an instance of a certain type in SMS or EMS.

But when you don't know the type, you use shared function GetSMSType to get the type.

Then according to the type, create certain instance of SMS class, it decoded automatically.

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 there will be no bugs. If you find some, please contact me. Thanks!

Some useful documents and sites.

GSM 03.40:http://webapp.etsi.org/exchangefolder/gsmts_0340v050300p.pdf

ETSI:http://www.etsi.org (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):38288890

My MSN:hesicong@mail.sc.cninfo.net

My homepage:http://hesicong2004.vip.myrice.com

My CSDN blog:http://blog.csdn.net/hesicong

In the end, thanks for using these classes!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有