C # principles and methods for developing terminal text messages

Source: Internet
Author: User

PrinciplesSMS code

In terms of sending and receiving Text messages, there are three modes generated successively by Time: Block Mode, Text Mode based on AT command, PDU Modem Based on AT command, Text Mode is relatively simple, multiple Nokia mobile phones support this mode. Most Siemens mobile phones only support the PDU mode. The PDU mode is a method for sending or receiving SMS messages from mobile phones. The text of Short Messages is transmitted after hexadecimal encoding. Currently, PDU has replaced Block Mode because we mainly discuss the transmission of PDU Mode. Take the Siemens 3508 mobile phone as an example.

SMS is a specification developed by Etsi (GSM 03.40 and GSM 03.38 ). When 7-bits encoding is used, it can send a maximum of 160 characters. However, it is 8-bit encoded and can send a maximum of 140 characters, which is usually not displayed on a mobile phone; it can contain up to 70 characters in 16-bit encoding and is used to display Unicode (UCS2) text information, which can be displayed on most mobile phones. We are talking about UCS2 encoding today. That is to say, a maximum of 70 characters can be sent, whether in English or Chinese.

For example, we want to send the following message to my mobile phone 13715342642. "Hello, Hello! ". Before sending the email, you must be clear that the SMS center number in the SIM card's location is not the SMS center number in your current location. For example, if I am in Shenzhen, the SMS center number in Shenzhen is 8613800755000, even if I am outside China, the SMS center number is still in Shenzhen. We get the following information from the above:

Received mobile phone number: 13715342642
SMS center No.: 8613800755000
Text message content: Hello, Hello!

In actual use, the above information is not executed by the mobile phone, and will be executed only when the mobile phone is encoded. Check the encoded information first:

Bytes

Let me explain it:

08-refers to the length of the SMS center number, that is, the length of (91) + (683104705500f0)

91-indicates the short message center number type. 91 indicates that TON/NPI complies with International/E.164 standards and requires a plus sign before the number. In addition, there are other values, but 91 is the most commonly used.

68310000705500f0-SMS center number. The actual number should be 8613800731500 (the letter F indicates the length minus 1) because the location is slightly processed ). This needs to be modified based on different regions. The preceding (08) + (91) + (6830000705500f0) actually forms a part of the entire text message, which is called the Address of the SMSC ).

11-File Header bytes

00-information type (TP-Message-Reference)

0D-length of the callednumber

91-called Number Type

In actual processing, we usually write 11000D91 into the program, because in China, the data will not change.

683117352446F2-called number. After displacement processing, the actual number is "8613715342642 ". The above (00) + (0D) + (91) + (683117352446F2) constitutes the second part of the Destination Address (TP-Destination-Address) of the entire text message ).

00-Protocol Identification TP-PID, which is generally 00

08-Data encoding Scheme TP-DCS (TP-Data-Coding-Scheme), using the previously mentioned USC2 (16bit) Data Encoding

00-Period TP-VP (TP-Valid-Period)

12-Length TP-UDL (TP-User-Data-Length), that is, 4F60597DFF0C00480065006C006C Length 36/2 = 18 hexadecimal 12

4F60597DFF0C00480065006C006C 006F0021-here is the text message content. The actual content is: "Hello, Hello! "Program implementation, please refer to the PDUdecoding. cs program included in this article.

 

 

 AT command

When talking about AT commands, there is a thick book, which is beyond the scope of our discussion today. Here I will only discuss the several AT commands necessary to send text messages.

The gsm at commands (from GSM07.05) related to SMS are shown in table 1:

 

AT command function AT + CMGC Send an SMS command (Send a short message command) AT + CMGD Delete SMS message (Delete short message of SIM card memory) AT + CMGF Select SMS message formate (Select the Short message format: 0-PDU; 1-text) AT + CMGL List SMS message from preferred store (List the short message PDU/text in the SIM card: 0/"rec unread"-UNREAD, 1/"rec read"-READ, 2/"sto unsent"-to be SENT, 3/"sto sent"-SENT, 4/"ALL"-ALL) AT + CMGR Read SMS message (Read short message) AT + CMGS Send SMS message (Send short message) AT + CMGW Write SMS message to memory (Write short messages to SIM memory) AT + CMSS Send SMS message from storage (Send short messages from SIN | M memory) AT + CNMI New SMS message indications (display New messages) AT + CPMS Preferred SMS message storage (select Short message Memory) AT + csca sms service center address (Short message center address) AT + CSCB Select cell broadcast messages (Select cellular broadcast Message) AT + CSMP Set SMS text mode parameters (Set Short Message text mode parameters) AT + CSMS Select Message Service (Select short Message Service)

Table 1: Related gsm at commands

The following example shows how to use these commands:

Connect your mobile phone to your computer's serial port with the mobile phone data cable and set the baud rate of the serial port to 19200.

1. First, test whether your connection and mobile phone support the AT command. In your serial port debugging program, enter:

AT <press enter>

If "OK" is returned on the screen, it indicates that the computer is connected to the mobile phone normally, so that we can test other AT commands.

2. Set the text message sending format

AT + CMGF = 1 <press enter>

If "OK" is returned on the screen, the current message sending method is PDU. If it is set to TEXT, AT + CMGF = 0 <press enter>

3. send text messages

The sent content and manual number are still the same as those in the encoding. After encoding, the data to be sent is as follows:

Bytes

We use the following command to send

AT + CMGS = 33 <press enter>

If ">" is returned, enter the encoded data above and end with CTRL + Z. Wait a moment and you will see that the return result is OK.

Let's explain why AT + CMGS = 33 is like this:

11000D91683117352446F2000800124F60597D002C00480065006C006C006F0021

The result is obtained by dividing the length of this string by 2. The above string, the SMS center number, and the text message content are obtained. For details, refer to the Decoding Section.

In our previous discussion, a complete text message is sent, as long as three AT commands are executed, AT, AT + CMGS =? , AT + CMGS =? You can. Due to the length, I can only mention so much here. If you want to learn more, you can ask mobile phone manufacturers for the AT Instruction White Paper, which is very detailed.

As mentioned above, we can only prepare for the actual situation. We also need a transmission channel. Based on our needs, we choose to invest the least to achieve convenient serial communication. Note: The serial port is connected to the mobile phone through the data cable, and the AT command is used to send text messages.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.