Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#

Library for Decode/Encode SMS PDU

Rate me:
Please Sign up or sign in to vote.
4.74/5 (49 votes)
18 Oct 2012CPOL 759.5K   26.6K   128   192
Library for decoding and encoding mobile short messages to/from SMS protocol data unit

Last Updates

You can find some community fixes mentioned on comments section on Project Home at Google Code[^].

Introduction

The smspdulib library is intended for more transparent interaction with SMS PDU. This thought over hierarchy of classes will allow you to create new classes for other types of short messages using the realized base functionality.

At present, the following types of short messages are supported: status report, SMS (with long (large) SMS parts support).

Hierarchy of Classes

Classes hierarchy

Enums

Sample Code

This example shows you how to decode PDU.

C#
SMSType smsType = SMSBase.GetSMSType(pduSource);
switch (smsType) {
    case SMSType.SMS:
        SMS sms = new SMS();
        SMS.Fetch(sms, ref pduSource);
        //Use instance of SMS class here
        break;
    case SMSType.StatusReport:
        SMSStatusReport statusReport = new SMSStatusReport();
        SMSStatusReport.Fetch(statusReport, ref pduSource);
        //Use instance of SMSStatusReport class here
        break;
}

This example show you how to encode SMS to PDU.

C#
SMS sms = new SMS();
sms.Direction = SMSDirection.Submited;
sms.PhoneNumber = "+74951234567";
sms.ValidityPeriod = new TimeSpan(4, 0, 0, 0);
sms.Message = "Me message here!";
string pduSource = sms.Compose(SMS.SMSEncoding.UCS2);

Useful Links

Updated

  • Updated Decode7bit method: Fixed some bugs (see comments)
  • PopDate method now doesn't recognize time zone because some phones send strange stuff

Please help me find more detailed specification of PDU format and TP-SCTS format.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: PDU Parsing Pin
Eduard Gomolyako25-Oct-07 5:22
Eduard Gomolyako25-Oct-07 5:22 
AnswerRe: PDU Parsing Pin
yateee25-Oct-07 23:24
yateee25-Oct-07 23:24 
GeneralRe: PDU Parsing Pin
Eduard Gomolyako25-Oct-07 23:58
Eduard Gomolyako25-Oct-07 23:58 
GeneralPDUHelper Pin
petr_rehor7-Sep-07 2:42
petr_rehor7-Sep-07 2:42 
GeneralRe: PDUHelper Pin
Eduard Gomolyako9-Sep-07 9:27
Eduard Gomolyako9-Sep-07 9:27 
GeneralRe: PDUHelper Pin
mcampo10-Apr-08 23:17
mcampo10-Apr-08 23:17 
GeneralRe: PDUHelper Pin
Eduard Gomolyako10-Apr-08 23:46
Eduard Gomolyako10-Apr-08 23:46 
GeneralDelivery report problem [modified] Pin
kospanov2-Sep-07 18:00
kospanov2-Sep-07 18:00 
I compose and send SMS via modem as shown,

SMSPDULib.SMS sms = new SMSPDULib.SMS();
sms.PhoneNumber = "77057231750";
sms.StatusReportIndication = true;
sms.Message = "some msg";
sms.Direction = SMSDirection.Submited;
sms.ValidityPeriod = new TimeSpan(0, 0, 1, 0);

but delivery reports has strange format:
00040B917750271357F01F1970903090552500020020.

This report decoded as:

Service center number:
Service center time stamp: 03.09.2007 9:55:52
Message reference #: 0
Direction: Received
Phone number: +77057231750
Status report indication: False
Message:

But cell phone recognize this as report correctlly.
Whats wrong?





-- modified at 12:55 Monday 3rd September, 2007

For all.
We`re sorry for this russian dialog.
There is no bag in this library, problem with cell phones Motorola, that not fully compliant with the standart. Motorolas phones transform delivery reports to its own format, just simple sms with no needed information (such as status, msg id, etc.
AnswerRe: Delivery report problem Pin
Eduard Gomolyako2-Sep-07 22:35
Eduard Gomolyako2-Sep-07 22:35 
GeneralRe: Delivery report problem Pin
kospanov2-Sep-07 23:02
kospanov2-Sep-07 23:02 
AnswerRe: Delivery report problem Pin
Eduard Gomolyako3-Sep-07 0:57
Eduard Gomolyako3-Sep-07 0:57 
GeneralRe: Delivery report problem Pin
kospanov3-Sep-07 1:26
kospanov3-Sep-07 1:26 
GeneralRe: Delivery report problem Pin
Eduard Gomolyako3-Sep-07 1:31
Eduard Gomolyako3-Sep-07 1:31 
AnswerRe: Delivery report problem Pin
Eduard Gomolyako3-Sep-07 1:35
Eduard Gomolyako3-Sep-07 1:35 
GeneralRe: Delivery report problem Pin
kospanov3-Sep-07 1:42
kospanov3-Sep-07 1:42 
GeneralRe: Delivery report problem Pin
Eduard Gomolyako3-Sep-07 1:57
Eduard Gomolyako3-Sep-07 1:57 
GeneralRe: Delivery report problem Pin
kospanov3-Sep-07 4:24
kospanov3-Sep-07 4:24 
GeneralRe: Delivery report problem Pin
Eduard Gomolyako3-Sep-07 4:43
Eduard Gomolyako3-Sep-07 4:43 
GeneralRe: Delivery report problem Pin
kospanov3-Sep-07 6:55
kospanov3-Sep-07 6:55 
QuestionPicture SMS? Pin
Rick S16-Aug-07 14:00
Rick S16-Aug-07 14:00 
AnswerRe: Picture SMS? Pin
Eduard Gomolyako22-Aug-07 2:45
Eduard Gomolyako22-Aug-07 2:45 
GeneralArabic Text Pin
nonintrusive24-Jul-07 7:56
nonintrusive24-Jul-07 7:56 
QuestionPerdida de caracteres Pin
C#Mikha9-Jul-07 6:58
C#Mikha9-Jul-07 6:58 
GeneralMMS Pin
Shakeel Mumtaz1-Jul-07 0:42
Shakeel Mumtaz1-Jul-07 0:42 
GeneralRe: MMS Pin
Eduard Gomolyako1-Jul-07 7:23
Eduard Gomolyako1-Jul-07 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.