Click here to Skip to main content
15,898,222 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 761K   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: Which SMS server are you using? Pin
Eduard Gomolyako23-Oct-06 3:23
Eduard Gomolyako23-Oct-06 3:23 
GeneralRe: Which SMS server are you using? Pin
Rajib Bahar23-Oct-06 5:06
Rajib Bahar23-Oct-06 5:06 
GeneralRe: Which SMS server are you using? Pin
Eduard Gomolyako23-Oct-06 5:13
Eduard Gomolyako23-Oct-06 5:13 
GeneralRe: Which SMS server are you using? Pin
Rajib Bahar23-Oct-06 5:15
Rajib Bahar23-Oct-06 5:15 
AnswerRe: Which SMS server are you using? Pin
Eduard Gomolyako23-Oct-06 5:30
Eduard Gomolyako23-Oct-06 5:30 
GeneralThanks! Pin
Ladislav Soukup17-Oct-06 6:48
Ladislav Soukup17-Oct-06 6:48 
GeneralRe: Thanks! Pin
Eduard Gomolyako19-Oct-06 5:25
Eduard Gomolyako19-Oct-06 5:25 
GeneralRe: Thanks! Pin
Ladislav Soukup8-Dec-06 0:13
Ladislav Soukup8-Dec-06 0:13 
OK, I have found one BUG(?). I have several messages, that Your lib can't parse Frown | :(
PDU received from SMS gate...
0791246030500200440C91246030828930000060218080239440A00500039E020182E8B71AA427CBC3F6741B640DCF4169D07C5D87A7DD75D0529E9FD3DF6697755C968741EA79B90DB2E7D1F2303B0C5297D5E9311A34248641ECF49CBECE83DC61D0FAED1E97E574D0BC0CAAEB41EDF718442FCFD36D50183446D3CBEC30489C1FA341F6F01C047FC3E5EF799A0E0AEB416477790E9AA741F43AC89E47CBEB20785D4DAE83EC

When I try to parse this, I get error:

System.ArgumentOutOfRangeException: Hodnota StartIndex nemůže být menší než nula.
Název parametru: startIndex
   v System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
   v System.String.Substring(Int32 startIndex, Int32 length)
   v SMSPDULib.SMSBase.Decode7bit(String source, Int32 length) v C:\Documents and Settings\soukup\Dokumenty\Visual Studio 2005\Projects\SMS_PDU_decode_test\SMS_PDU_decode_test\SMSBase.cs:řádek 68
   v SMSPDULib.SMS.Fetch(SMS sms, String& source) v C:\Documents and Settings\soukup\Dokumenty\Visual Studio 2005\Projects\SMS_PDU_decode_test\SMS_PDU_decode_test\SMS.cs:řádek 205
   v SMS_PDU_decode_test.Form1.btn_PDUdecode_Click(Object sender, EventArgs e) v C:\Documents and Settings\soukup\Dokumenty\Visual Studio 2005\Projects\SMS_PDU_decode_test\SMS_PDU_decode_test\Form1.cs:řádek 35


Can You please try to decode this PDU? Problem may by in characters used in SMS (czech). I can't find the it Frown | :(
BTW: Sorry for czech exception text Wink | ;)
GeneralInteresting article Pin
Abbas_Riazi16-Oct-06 13:25
professionalAbbas_Riazi16-Oct-06 13:25 
GeneralRe: Interesting article Pin
Eduard Gomolyako17-Oct-06 1:29
Eduard Gomolyako17-Oct-06 1:29 

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.