25.5. Syntax of the
+CMGS AT Command in SMS PDU Mode
In
SMS PDU mode, the syntax of the +CMGS AT command is:
+CMGS=TPDU_length<CR>SMSC_number_and_TPDU<Ctrl+z>
Before
we discuss each of the parameters, let's see an example that gives
you some idea of how an actual command line should look like:
AT+CMGS=42<CR>07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
The
TPDU_length Parameter
The
first parameter of the +CMGS AT command, TPDU_length, specifies the
length (in octets. 1 octet = 8 bits) of the TPDU (Transfer Protocol
Data Unit) assigned to the SMSC_number_and_TPDU parameter. In the
earlier example command line, the value assigned to the
SMSC_number_and_TPDU parameter is:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
It
can be divided into two parts. The following part is the TPDU:
01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
The
TPDU is coded in hexadecimal format. Each character represents 4
bits, i.e. 1/2 octet. The TPDU has 84 characters and so there are
totally 42 octets. That's why the value assigned to the TPDU_length
parameter is 42.
The
<CR> Character
<CR>,
which represents the carriage return character, follows the
TPDU_length parameter.
When the GSM/GPRS modem or mobile phone receives the carriage return
character, it will send back a prompt formed by these four
characters: the carriage return character, the linefeed character,
the ">" character and the space character. If you don't
understand what this means, don't worry. This should be clear to you
when you see the example in the section "Example
Demonstrating How to Use the +CMGS AT Command to Send SMS Text
Messages in SMS PDU Mode".
The
SMSC_number_and_TPDU Parameter
The
second parameter of the +CMGS AT command, SMSC_number_and_TPDU,
specifies the SMSC number and the TPDU in hexadecimal format.
Entering the <Esc>
character will cancel the +CMGS AT command. If you don't
understand what this means, see the example in the section "Example
Demonstrating How to Use the +CMGS AT Command to Send SMS Text
Messages in SMS PDU Mode".
The
<Ctrl+z> Character
When
you finish entering the value for the SMSC_number_and_TPDU
parameter, you have to enter the <Ctrl+z>
character to mark the end of the value. The GSM/GPRS modem or mobile
phone will then attempt to send the SMS message to the SMS center.
25.5.1. Some
Explanation about the Coding of the SMSC_number_and_TPDU Parameter
Value of the +CMGS AT Command
This
section provides some explanation about the coding of the
SMSC_number_and_TPDU
parameter value of the +CMGS AT command. Let's consider the
SMSC_number_and_TPDU
parameter value in the earlier example command line:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
The
above value can be divided into two parts, as shown below. The first
part contains information about the SMSC to be used for sending the
SMS message. The second part is the TPDU.
07915892000000F0
01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
25.5.1.1. The
SMSC Part
The
SMSC part can be further divided into three sub-fields, like this:
07
91 5892000000F0
The
First Sub-field: Length of the Second and Third Sub-fields
The
first sub-field specifies the length in octets of the following two
sub-fields. There are 14 hexadecimal digits in "915892000000F0"
and each hexadecimal digit represents 4 bits. So, there are totally 7
octets. That's why the value of the first sub-field is 0x07.
The
Second Sub-field: Type of SMSC Number
The
second sub-field specifies the type of the SMSC number assigned to
the third sub-field. Two values are
commonly used. They are 0x81 (129 in decimal) and 0x91 (145 in
decimal):
0x81.
It means the SMSC number is formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163) but it is not sure
whether the SMSC number is an international number, a national
number or a number of other types. For example, suppose the SMSC
number provided to you by the mobile network operator for sending
SMS messages is "+85290000000". If the value of the second
sub-field is 0x81, the SMSC number assigned to the third sub-field
can be either "85290000000" (country code included) or
"90000000" (country code omitted).
0x91.
It means the SMSC number is formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163) and it is an
international number. For example, suppose the SMSC number provided
to you by the mobile network operator for sending SMS messages is
"+85290000000". If the value of the second sub-field is
0x91, the SMSC number assigned to the third sub-field should be
"85290000000".
The
Third Sub-field: SMSC Number
The
third sub-field specifies the SMSC number for sending the SMS
message. 0x5892000000F0 represents the phone number +85290000000.
Here's how the value 0x5892000000F0 is obtained:
Starting
from the left, group the digits of the phone number 85290000000 into
pairs, like this: 85 29 00 00 00 0.
As
the last group has only one digit, we add an "F" to make
up a pair. The result is 85 29 00 00 00 0F.
Swap
the digits in each pair and you will get 58 92 00 00 00 F0.
Note
It
is possible to tell the GSM/GPRS modem or mobile phone to use the
SMSC number specified by the AT command +CSCA (command name in text:
Service Centre Address) for sending SMS messages. Just assign the
value 0x00 to the first sub-field and omit the second and third
sub-fields, i.e. the SMSC part becomes:
00
25.5.1.2. The TPDU
Part (SMS-SUBMIT TPDU)
The
TPDU part can be divided into nine sub-fields, as shown below. This
is a TPDU of the type SMS-SUBMIT.
01
00 0B 91 5892214365F7 00 00 21
493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
The
First Sub-field: First Octet of the TPDU
The
first sub-field is the first octet of the TPDU. It tells the GSM/GPRS
modem or mobile phone several things:
the
type of the TPDU
whether
the SMSC should reject duplicated TPDUs
whether
a validity period exists in the TPDU, and the format of the validity
period if it exists
whether
a reply path is requested
whether
a user data header exists in the TPDU
whether
a status report is requested from the SMSC
The
value 0x01 means:
the
type of the TPDU is SMS-SUBMIT
the
SMSC should not reject duplicated TPDUs
no
validity period exists in the TPDU
no
reply path is requested
no
user data header exists in the TPDU
no
status report is requested from the SMSC
The
Second Sub-field: Message Reference Number
The
second sub-field specifies the message reference number. It is an
integer in the range from 0 to 255. The value 0x00 tells the GSM/GPRS
modem or mobile phone to assign a message reference number to the SMS
message automatically.
The
Third Sub-field: Length of the Destination Phone Number
The
third sub-field specifies the length
in digits of the destination phone number. The destination phone
number specified in the fifth sub-field is
"+85291234567", which has 11 digits. Thus, the value of the
third sub-field is 0x0B (i.e. 11 in decimal).
The
Fourth Sub-field: Type of the Destination Phone Number
The
fourth sub-field specifies the type of the destination phone number
assigned to the fifth sub-field. Two
values are commonly used. They are 0x81 (129 in decimal) and 0x91
(145 in decimal):
0x81.
It means the destination phone number is formatted using the typical
ISDN / telephony numbering plan (ITU E.164/E.163) but it is not sure
whether the destination phone number is an international number, a
national number or a number of other types. For example, suppose you
want to send an SMS message to the phone number "+85291234567".
If the value of the fourth sub-field is 0x81, the destination phone
number assigned to the fifth sub-field can be either
"85291234567" (country code included) or "91234567"
(country code omitted).
0x91.
It means the destination phone number is formatted using the typical
ISDN / telephony numbering plan (ITU E.164/E.163) and it is an
international number. For example, suppose you want to send an SMS
message to the phone number "+85291234567". If the value
of the fourth sub-field is 0x91, the destination phone number
assigned to the fifth sub-field should be
"85291234567".
The
Fifth Sub-field: Destination Phone Number
The
fifth sub-field specifies the destination phone number. The value
0x5892214365F7 represents the phone number +85291234567. Here's how
the value 0x5892214365F7 is obtained:
Starting
from the left, group the digits of the phone number 85291234567 into
pairs, like this: 85 29 12 34 56 7.
As
the last group has only one digit, we add an "F" to make
up a pair. The result is 85 29 12 34 56 7F.
Swap
the digits in each pair and you will get 58 92 21 43 65 F7.
The
Sixth Sub-field: Protocol Identifier
The
sixth sub-field specifies the protocol identifier. Its value should
be 0x00 for normal cases.
The
Seventh Sub-field: Data Coding Scheme
The
seventh sub-field specifies the data coding scheme. With 0x00, we
inform the GSM/GPRS modem or mobile phone that the text in the SMS
message body is encoded according to the "GSM 7-bit default
alphabet" text coding scheme.
The
Eighth Sub-field: Length of the SMS Message Body
The
eighth sub-field specifies the length of the SMS message body in
septets (1 septet = 7 bits). The value 0x21 means there are 33
septets (or characters, since each character is represented by 7 bits
according to the "GSM 7-bit default alphabet" text coding
scheme) in the SMS message body.
The
Ninth Sub-field: SMS Message Body
The
ninth sub-field specifies the SMS message body. The value
0x493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
represents the text message "It is easy to send text messages.".
Below shows how the hexadecimal value is obtained:
Encode
the SMS text message "It is easy to send text messages."
according to the character set "GSM 7-bit default alphabet".
For example, 0x49 is used to represent the first character "I"
in the SMS text message, 0x74 is used to represent the second
character "t", etc. To find the code representing a
certain character, see "Appendix:
GSM 7-bit Default Alphabet Table (with Character Codes of ISO 8859
Latin 1)" of this SMS tutorial.
After
encoding, the SMS text message "It is easy to send text
messages." becomes:
49
74 20 69 73 20 65 61 73 79 20 74 6F 20 73 65 6E 64 20 74 65 78 74 20
6D 65 73 73 61 67 65 73 2E
With
the character set "GSM 7-bit default alphabet", each
character is represented by 7 bits. If the SMS text message is
encoded as above, 1 bit is wasted in every octet. To prevent this
from happening, the SMS specification requires us to pack the 7-bit
characters in octets. The packing process is described below:
The
binary representation of the first character is 1001001. Since the
most significant bit of the first octet is unused, we fill it by
the least significant bit of the second character, which is 0. (The
binary representation of the second character is 1110100.)
As a result, the first octet contains the binary value 01001001,
which is 0x49 in hexadecimal format.
As
the least significant bit of the second character has been moved to
the first octet, the second octet now contains the binary value
111010 and the two bits at the leftmost position of the second
octet is unused. We fill them by the two least significant bits of
the third character, which are both 0. (The binary representation
of the third character is 0100000.) As a result, the
second octet contains 00111010, which is 0x3A in
hexadecimal format.
Similarly,
since the two least significant bits of the third character have
been moved to the second octet, the third octet now contains the
binary value 01000 and the three bits at the leftmost position of
the third octet is unused. So, we fill them by the three least
significant bits of the fourth character, which are 0, 0 and 1.
(The binary representation of the fourth character is 1101001.)
Now the third octet contains the binary value 00101000,
which is 0x28 in hexadecimal format.
The
packing process continues. This is illustrated in the following
table.
|
|
Bit 7
|
Bit 6
|
Bit 5
|
Bit 4
|
Bit 3
|
Bit 2
|
Bit 1
|
Bit 0
|
|
|
|
Octet 1
|
0
|
1
|
0
|
0
|
1
|
0
|
0
|
1
|
=
|
0x49
|
|
Octet 2
|
0
|
0
|
1
|
1
|
1
|
0
|
1
|
0
|
=
|
0x3A
|
|
Octet 3
|
0
|
0
|
1
|
0
|
1
|
0
|
0
|
0
|
=
|
0x28
|
|
Octet 4
|
0
|
0
|
1
|
1
|
1
|
1
|
0
|
1
|
=
|
0x3D
|
|
Octet 5
|
0
|
0
|
0
|
0
|
0
|
1
|
1
|
1
|
=
|
0x07
|
|
Octet 6
|
1
|
0
|
0
|
1
|
0
|
1
|
0
|
1
|
=
|
0x95
|
|
Octet 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