Click here to Skip to main content
15,905,967 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 762.2K   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: 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 
GeneralRead Long SMS Pin
minori_aoi15-Jun-07 18:05
minori_aoi15-Jun-07 18:05 
GeneralRe: Read Long SMS Pin
Adam Page16-Oct-07 22:43
Adam Page16-Oct-07 22:43 
GeneralMoreMessagesToSend Pin
PapaDoener3-May-07 2:38
PapaDoener3-May-07 2:38 
Hi thx for this great tool! I've been trying to implement the multipart message option but no luck so far.

I want to use the UCS2 since we in Denmark has a lot of special chars æøå etc.
<= 70 chars everything works like a charm.

I've added:

if (UserDataStartsWithHeader)
_pduType = (byte) (_pduType | 0x40);

to the ComposePDUType method on the SMSBase.

If i send this to my phone i recieve a lot of square boxes in two messages. I guess I am missing something.
One thing that i have not figured out yet is the length of the header and the insertion of the header in the Message text. Are there some kind of header length max? how should the octet length be calculated (header.length/2?) and transformed into hex(05 = 5 octets)

Right now i am using the first 10 chars of the message as the header and i am writing their length as 05 octets. After that i paste the header into every message i send and transforms header(10 chars) and message(70 chars) to PDU which i send to the modem.
Any help would be highly appriciated and rewarded with a ½ L of brown sugarwater.
General7bits continued Pin
pa_duch29-Apr-07 8:33
pa_duch29-Apr-07 8:33 
GeneralEncode7Bit [modified] Pin
pa_duch27-Apr-07 15:26
pa_duch27-Apr-07 15:26 
Questionserialport (.net 2.0) & infrared Pin
rimobul27-Apr-07 12:46
rimobul27-Apr-07 12:46 
AnswerRe: serialport (.net 2.0) & infrared Pin
Eduard Gomolyako30-Apr-07 5:30
Eduard Gomolyako30-Apr-07 5:30 
GeneralCan't decode sms sent from siemens M65 Pin
zaven12-Mar-07 7:57
zaven12-Mar-07 7:57 
GeneralLonger messages Pin
TheManDK17-Feb-07 7:16
TheManDK17-Feb-07 7:16 
GeneralRe: Longer messages Pin
Eduard Gomolyako17-Feb-07 8:08
Eduard Gomolyako17-Feb-07 8:08 
GeneralRe: Longer messages Pin
Treca3-Mar-07 6:19
Treca3-Mar-07 6:19 
GeneralRe: Longer messages Pin
Eduard Gomolyako3-Mar-07 9:23
Eduard Gomolyako3-Mar-07 9:23 
GeneralRe: Longer messages Pin
Treca3-Mar-07 11:23
Treca3-Mar-07 11:23 
GeneralRe: Longer messages Pin
Eduard Gomolyako3-Mar-07 12:25
Eduard Gomolyako3-Mar-07 12:25 
GeneralRe: Longer messages Pin
zaven12-Mar-07 8:32
zaven12-Mar-07 8:32 
GeneralBUG!!!!! can u answer it really helps me... Pin
Umairarain14-Feb-07 2:21
Umairarain14-Feb-07 2:21 
GeneralRe: BUG!!!!! can u answer it really helps me... Pin
Eduard Gomolyako19-Feb-07 5:07
Eduard Gomolyako19-Feb-07 5:07 
GeneralBUG: 7bit Long SMS Pin
Ladislav Soukup16-Jan-07 3:39
Ladislav Soukup16-Jan-07 3:39 
AnswerRe: BUG: 7bit Long SMS Pin
Eduard Gomolyako19-Feb-07 5:10
Eduard Gomolyako19-Feb-07 5:10 
GeneralUsing a Webservice Pin
xaml.net13-Jan-07 2:04
xaml.net13-Jan-07 2:04 

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.