如何在内存有限的嵌入式系统上使用 AT 读取短信? [英] How to read SMS using AT on an embedded system with limited memory?
问题描述
我正在开发一款嵌入式软件,该软件还通过 AT 协议与调制解调器进行通信.现在我想阅读消息,但我的内存容量出现问题.可能是有多个消息给我,并且使用 AT 命令集,我将它们一次全部返回.我没有足够的内存来存储它们来处理它们(我只有 1KB 左右).
请参阅此处的示例:http://www.smssolutions.net/tutorials/gsm/receivesmsat/>
我发送AT+CMGL="ALL"
.然后我会得到类似的东西:
+CMGL: 1,"REC UNREAD","+31625012354",,"07/07/05,09:55:16+08"测试消息 1+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"测试消息2好的
这里的问题是消息可能包含某些指令,这些指令会触发某些操作,这些操作可能需要一段时间才能执行.在此期间,用于从调制解调器接收数据的缓冲区可能(将)溢出.另一方面,我没有内存容量先将所有消息读入内存以防止缓冲区溢出,然后从内存中处理它们.
另一种方法是使用 AT+CMGR=2
读取一条消息,只返回一条消息:
+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"测试消息2好的
但是,要使其正常工作,我需要知道存储位置(在上面的示例中为 2).
直觉告诉我先运行AT+CMGL
,解析数据,只保留存储位置,然后用AT+一一请求解析(删除)CMGR
.
但是,我想获得第二意见.我对 AT 和嵌入式软件还没有那么熟悉,所以也许我忽略了一些东西.
发送 AT+CMGL="ALL"
并保存第一条消息直到返回.忽略所有其他数据,直到您收到 OK
,表明调制解调器已完成.处理完第一条消息后,通过发送AT+CMGD=
(其中是第一条消息的编号)将其删除.重复.
是的,它有点丑,但效果很好.
I'm developing a piece of embedded software, which also communicates with a modem through the AT protocol. Now I want to read messages, but I have come across a problem with my memory capacity. It could be that there are multiple messages for me, and using the AT command set, I get them returned all at once. I do not have the memory capacity to store them all to process them (I only have 1KB or so).
See the examples here: http://www.smssolutions.net/tutorials/gsm/receivesmsat/
I send AT+CMGL="ALL"
. I then get back something like:
+CMGL: 1,"REC UNREAD","+31625012354",,"07/07/05,09:55:16+08"
Test message 1
+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"
Test message 2
OK
The problem here is that the message can contain certain directives, which trigger certain actions, which might take a while to execute. During that time, the buffer for receiving data from the modem can (will) overflow. On the other hand, I do not have the memory capacity to first read ALL the messages into memory to prevent the buffer overflow, and then process them from memory.
An alternative is reading a single message, with AT+CMGR=2
, getting back just one message:
+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"
Test message 2
OK
However, for this to work, I need know the storage location (2 in the above example).
My gut feeling tells me to first run AT+CMGL
, parsing the data and only keeping the storage locations, then requesting and parsing (and deleting) them one by one with AT+CMGR
.
However, I would like to receive a second opinion. I'm not that experienced with AT nor with embedded software yet, so perhaps I'm overlooking something.
Send AT+CMGL="ALL"
and save the first message up to the return. Ignore all other data until you receive OK
, indicating that the modem is done. After processing the first message, delete it by sending AT+CMGD=<NUM>
(where is the number of the first message). Repeat.
Yes, it's kind of ugly, but it works fine.
这篇关于如何在内存有限的嵌入式系统上使用 AT 读取短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!