Receive short messages in real time through the serial port

zhaozj2021-02-16  67

One year ago I have written "Two articles" on "through the serial port (on)", (below) ", discuss the use of extended AT command control ME (mobile, GSM module) on TE (PC, MCU system, etc.) The basic method of sending and receiving short messages. Among them, the receiving / reading short message uses a method of active query. TE sends "At CMGL" instructions, and ME outputs short messages that have been received and stored. This is more in line with the spirit of the AT command: If you ask an answer, a question and answer. But in practical applications, it is found that there is a certain disadvantage:

The Me receives the message and stores it. When the query is transferred to the TE, there will always be a delay in the middle. This delay depends on the query interval. Once the instruction is issued, no matter how many messages are there, there is always a long latency TE to receive the final "OK". The complete process generally lasts for 5-10 seconds. This article describes a method of receiving a short message by serial port "real-time". When ME receives a message, actively issue notification to TE, or forward the message to the TE. Compared to the query mechanism, it is similar to the interrupt mechanism.

First, a short message concept: the short message is divided into Class 0 - 3 according to the specified location. You can also specify a class (No class), and the ME is processed by the default setting, stored in a memory or SIM card. In the TPDU's TP-DCS byte, when bit7-bit4 is 00x1, 01x1, 1111, bit1-bit0 pointers the category of the message:

00 - Class 0: Only displayed, not stored 01 - Class 1: Store in ME memory 02 - Class 2: Store in the SIM card 03 - Class 3: Direct transfer to tegsm modem usually support a "AT CNMI" instruction Can be used to set up when there is a short message to arrive, how to deal with it: only store the specified memory (volatile / non-volatile), first store to notify TE, or forward directly to TE, etc. .

"AT CNMI" instruction syntax

AT CNMI = [ [, [, [, [, ]]]]]]]]]]]]

Mode - Notice:

0 - Do not inform TE. 1 - In the case of the data line, notify TE; otherwise the TE is not notified. 2 - Notify TE. In the case where the data line is occupied, the first buffer is first, and the data line is idle, and then notify. 3 - Notify TE. In the case where the data line is occupied, the notification mix is ​​transmitted together in the data. MT - Message Storage or Forward to TE:

0 - Save to the default memory location (including Class 3) 1 - stored to the default memory location, and send a notification to the TE (including Class 3) 2 - For the Class 2, store it to the SIM card, and send a notification to the TE; Other CLASS, forward the message directly to TE 3 - For Class 3, forward the message directly to TE; for other Class, the meaning of MT = 1BM, DS, BFR, please refer to the relevant standard document. Nea need to care for them.

When implemented in the program, use MODE = 2, MT = 1, relatively simple. For all types of short messages, as long as the " CMTI" notification from the ME is received, the message content is read with the "At CMGR" instruction. The communication process between TE and ME is as follows:

(initialization)

AT CNMI =? (See the range of settings that can be supported)

CNMI: (0-2), (0-3), (0, 2, 3), (0, 1), (0, 1) OK

AT CNMI? (See the current settings)

CNMI: 0, 0, 0, 0, 0

OK

AT CNMI = 2, 1 (set to mod = 2, MT = 1)

OK

AT CNMI? (Then view the current settings)

CNMI: 2, 1, 0, 0

OK

(After a while, there is a message arrival)

CMTI "ME", 8 (Notification: Message has been stored in ME memory, serial number 8)

AT CMGR = 8 (read Article 8 Message)

CMGR: 8, 27

0891683108200505f0240d91683158812764f8000040205211037380074119058341E01

OK

AT CMGD = 8 (Delete Article 8 Message)

OK

There is also a way Mode = 2, MT = 2 is also very interesting. In this way, in addition to the Class 2, the message is not stored, directly forward to TE. There are two cases of writing notifications and content, complex. However, if the sender is also controlled by the program, only the NO Class or Class 1 message, which is not stored in the receiver ME memory (typically flash, non-volatile), will definitely extend its service life. The communication process between TE and ME is as follows:

AT CNMI = 2, 2 (set to mod = 2, MT = 2)

OK

(After a while, there is a message arrival)

CMT:, 26

0891683108200505F0040D91683158812764F8000840205211639180064F60597D0021

[related resources]

3GPP official website: www.3gpp.org Brain Studio (kernel Studio): www.kernelstudio.com

First release: 2004-02-26 Last revision: 2004-02-26

转载请注明原文地址:https://www.9cbs.com/read-23659.html

New Post(0)