The GSM module supports sending and receiving SMS messages in two modes: The text mode and the PDU (protocol description unit) mode. The text mode can only send Common ascill characters, and images and ringtones must be sent, other encoded characters (such as Chinese) must adopt the PDU mode.
In PDU mode, three encoding methods can be used to encode the content to be sent.
Are 7-bit, 8-bit, 16-bit, and 7-bit encoding used to send Common ascill characters. 8-bit encoding is usually used to send data information, slices, and ringtones,
The 16-bit encoding is used to send Unicode characters. The maximum number of characters that can be sent by the three encodings is 160,140 and 70. To send a Chinese text message, use the Unicode encoding in PDU mode. The specific steps are described as follows:
(1) Conversion from gb2321 encoding to unicode encoding.
● Functions provided by the operating system (some systems do not provide functions, such as deltaos ).
● Manual query.
(2) Unicode to 16-bit encoding conversion.
● After the Unicode code is obtained, it must be converted to the 16-bit code of the PDU before it can be correctly sent.
● In this conversion process, the 0xffff mark at the beginning of Unicode encoding should be removed. The content after 0xffff is the real UNICODE character.
●
Unicode is a dual-byte. If the system uses little-Endian In the byte order, that is to say, the system first saves the low level before storing the high level. For example
Unicode encoding is 0x4e2d. It is stored in 2d4e. It must be converted to a 16-bit encoding sequence. If it is a big-Endian (big-Endian), this system
System, you do not need to switch.
● Correctly calculate the 16-bit encoded message body length. The PDU Specification includes the message body itself.
● Correctly set type, TP-MR, TP-PID, TP-VP, in the following PDU format, in turn set to: 11,00, 01 (above are hexadecimal numbers ).
(3) form a standard sending package. SMS sending Process Analysis
The processor sends and receives the AT command to the serial port to form a communication loop with the GSM module. The at command is used to perform basic operations on the GSM module. The at command used to send text messages is shown in table 1.
The text mode and protocol data unit mode (PDU, protocol data
Unit ). Most mobile phones do not support the text mode, but only the PDU mode. In PDU mode, the text message is sent in hexadecimal encoding. The encoding consists of three parts: the service center number and the receiver.
The mobile phone number and text message content, such as the "hello" text message PDU code is like this (where XYZ is the specific number of the mobile phone number ):
The significance of 0011000b8131258698yxfz000801044f60597d is shown in table 2.
Table 1 AT commands used to send text messages
At command |
Function |
Example |
At + cmgf |
Set the text message format, 0 = PDU mode (default), 1 = text mode |
At + cmgf = 0 |
At + csca |
Obtain the service center number |
At + csca? |
At + cmgs |
Send at + cmgs = YYY; where YYY is the decimal length of tpdu |
At + cmgs = 19 |
Received ">" |
Send text message content after response |
|
Table 2 sending data analysis
Receiving number |
Text message content |
00 11 00 0b 8131208698 yxfz |
000801 04 4f605970 |
00: SCA writes at 00, the application's default service center address, which is written with the at + csca command 11: PDU Type 00: TP-MR to indicate Mr Message Reference 0b: 81 characters of the receiving number: indicates the domestic code 31258698 yxfz: the length of the receiving number encoding is an odd number, and "F" is appended to the end of each two bytes for location exchange, that is, 13526889xyz |
00: TP-PID protocol 08: TP-DCS data encoding method 01: TP-VP validity period 04: udl User Data Length, expressed in hexadecimal format 4f60597d: Text message content unicode encoding |
If the message is sent successfully, the serial port returns the following results:
+ Cmgs: X here is a number.