Click here to Skip to main content
15,893,663 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.8K   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

 
GeneralEncoder/Decoder Pin
Member 30541152-Nov-09 23:25
Member 30541152-Nov-09 23:25 
GeneralRe: Encoder/Decoder Pin
uncleR18-Nov-09 1:19
uncleR18-Nov-09 1:19 
GeneralRe: Encoder/Decoder Pin
ummarbhutta21-Nov-09 4:49
ummarbhutta21-Nov-09 4:49 
GeneralRe: Encoder/Decoder Pin
Member 305411522-Nov-09 22:44
Member 305411522-Nov-09 22:44 
GeneralRe: Encoder/Decoder Pin
ohinCZ24-Nov-09 0:02
ohinCZ24-Nov-09 0:02 
GeneralRe: Encoder/Decoder Pin
Member 305411525-Nov-09 8:17
Member 305411525-Nov-09 8:17 
GeneralUpdated version of this library Pin
ummarbhutta18-Oct-09 8:03
ummarbhutta18-Oct-09 8:03 
GeneralSuggestion/Doubts about receiving long SMS Pin
faber7517-Oct-09 0:17
faber7517-Oct-09 0:17 
Hi, wonderful and helpful code.
I'm building an app that may receive lengthy messages and i have a few doubts.
I can recognize they are lengthy checking bool InParts and i can get current number with Part.
I can't get the total number of parts, because you use the 3rd header byte (that should contain the total parts number) for the InPartsID.
Is there something i'm missing ?
I changed your code for the InPartsID excluding _userDataHeader[3] from the evaluation, renamed the Part property to PartCurrent and created the property PartTotal as

    public int InPartsID
    {
        get
        {
            if (!InParts)
                return 0;

            return (_userDataHeader[2] << 8); // was return (_userDataHeader[2] << 8) + _userDataHeader[3];
        }
    }

    public int PartTotal
    {
        get
        {
            if (!InParts)
                return 0;

            return _userDataHeader[3];
        }
    }

public int PartCurrent
{
    get
    {
        if (!InParts)
        return 0;

        return _userDataHeader[4];
    }
}


In the tests that i'm doing is running just fine but PDU 'syntax' is new to me and i fear i'm missing something.
Sounds good to you ?

Thanks again for your code and for any suggestions you may give,
Fabrizio
Generalhi Pin
Member 108861211-Oct-09 19:58
Member 108861211-Oct-09 19:58 
GeneralRe: hi Pin
Eduard Gomolyako11-Oct-09 23:30
Eduard Gomolyako11-Oct-09 23:30 
QuestionOpen Source Project Pin
KillerTiger20-May-09 10:37
KillerTiger20-May-09 10:37 
AnswerRe: Open Source Project Pin
Eduard Gomolyako20-May-09 19:33
Eduard Gomolyako20-May-09 19:33 
GeneralSending sms [modified] Pin
tprimus8-Feb-09 21:31
tprimus8-Feb-09 21:31 
GeneralRe: Sending sms Pin
Member 47650628-Feb-09 22:37
Member 47650628-Feb-09 22:37 
GeneralRe: Sending sms [modified] Pin
Member 47650628-Feb-09 23:08
Member 47650628-Feb-09 23:08 
GeneralRe: Sending sms [modified] Pin
tprimus9-Feb-09 6:48
tprimus9-Feb-09 6:48 
GeneralRe: Sending sms [modified] Pin
tprimus9-Feb-09 8:54
tprimus9-Feb-09 8:54 
GeneralRe: Sending sms Pin
nkachanov9-Feb-09 19:33
nkachanov9-Feb-09 19:33 
GeneralRe: Sending sms [modified] Pin
tprimus9-Feb-09 21:04
tprimus9-Feb-09 21:04 
AnswerRe: Sending sms Pin
nkachanov10-Feb-09 18:45
nkachanov10-Feb-09 18:45 
GeneralRe: Sending sms Pin
tprimus10-Feb-09 21:19
tprimus10-Feb-09 21:19 
Generalbug, I guess Pin
nkachanov5-Feb-09 2:01
nkachanov5-Feb-09 2:01 
GeneralStill the long message Problem Pin
cam.artem4-Feb-09 21:34
cam.artem4-Feb-09 21:34 
GeneralRe: Still the long message Problem Pin
nkachanov5-Feb-09 2:55
nkachanov5-Feb-09 2:55 
GeneralRe: Still the long message Problem Pin
cam.artem5-Feb-09 18:10
cam.artem5-Feb-09 18:10 

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.