A year ago, I wrote two articles, "sending and receiving short messages through serial ports (I) and (I)", discussing Te (PC, single chip microcomputer system, etc) use the extended at command to control the basic method of sending and receiving short messages by me (mobile phone, GSM module, etc. The method for receiving or reading short messages is proactive query. Te sends the "at + cmgl" command, and me outputs the received and stored short messages. This is in line with the AT Instruction Set spirit: I have a question and a question. However, in practical application, it is found that this method has some disadvantages:
Me receives and stores the message, and then transmits it to the Te when it is queried. There will always be a delay in the middle. The latency depends on the query interval.
After this command is sent, no matter whether or not there are many messages in me, the final "OK" must be received after a long delay of Te ". The complete process generally lasts 5-10 seconds.
This article introduces a method to receive short messages in real time through the serial port. When me receives a message, it sends a notification to te or forwards the message directly to te. Compared with the query mechanism, it is similar to the interrupt mechanism.
First, briefly describe the concept of Short Message class: according to the specified storage location, short messages are divided into four categories: Class 0-3. You can also choose not to specify a class (no class), which is processed by me according to the default settings and stored in the memory or SIM card. In the TP-DCS bytes of the tpdu, when the bit7-bit4 is 00x1, 01x1, 1111, The bit1-bit0 points out the message's class:
00-Class 0: display only, not store
01-Class 1: stored in me memory
02-Class 2: stored in SIM card
03-Class 3: directly transmitted to te
Generally, GSM Modem supports an "at + cnmi" command, which can be used to set how to handle a short message when it arrives: it is only stored in the specified memory (easy to lose/non-easy). It is stored first and then notified to the Te, or directly forwarded to the Te.
The "at + cnmi" command syntax is
AT+CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,<bfr>]]]]]
Mode-notification method:
0-Te is not notified.
1-only notify the Te when the data line is idle; otherwise, the Te is not notified.
2-Notification te. When the data line is occupied, it is buffered first, and then notified when the data line is idle.
3-Notification te. When the data line is occupied, the notification is sent together.
MT-message storage or direct forwarding to te:
0-store to the default memory location (including class 3)
1-store it in the default memory location and send a notification to te (including class 3)
2-for Class 2, store the message to the SIM card and send a notification to te; for other classes, directly forward the message to te
3-for Class 3, messages are directly forwarded to te; for other classes, the same as Mt = 1
For the meanings of BM, DS, and BFR, see the relevant standard documentation. Generally, you do not need to care about them.
In the specific implementation of the program, it is relatively simple to use mode = 2, MT = 1. For all types of short messages, you only need to use the "at + cmgr" command to read the message content after receiving the "+ cmti" notification sent by me. The communication process between TE and me is as follows:
(Initialization) at + cnmi =? (View supported settings) + cnmi: (0-2), (0-3), (, 3) OK at + cnmi? (View the current settings) + cnmi:, 0 OK at + cnmi = (set to mode = 2, MT = 1) OK at + cnmi? (Check the current settings) + cnmi:, 0 OK (after a while, a message arrives) + cmti "me", 8 (notification: messages are already stored in the me memory, with the serial number 8) at + cmgr = 8 (read 8th messages) + cmgr: 8, deleting at + cmgd = 8 (delete 8th messages) OK
Another method is mode = 2 and Mt = 2. In this way, messages are not stored except Class 2 and are directly forwarded to te. It is complicated to process message notifications and content. However, if the sender is also controlled by the program, only messages of no class or Class 1 can be sent, which is not stored in the receiver's me memory (generally flash memory, non-volatile, it will certainly extend its service life. The communication process between TE and me is as follows:
At + cnmi = (set to mode = 2, MT = 2) OK (after a while, a message arrives) + CMT:, success
[Related resources]
3GPP Official Website: www.3gpp.org
Kernel studio: www.kernelstudio.com
First Release: 2004-02-26
Last revised: