Skip to content

Commit 6bcf2de

Browse files
Read sms in unsynchronized mode (#33)
* Update arduino-cli binary filename The arduino-cli binary filename was recently changed, which broke CI builds: mv: cannot stat ‘arduino-cli-*-linux64’: No such file or directory * Enable SMS read in unsynch mode * Fix typo * Fix name change of binary * Ensure initialization of sms data end index * Handle sender number correctly * Keep track of start of SMS AT response * Clear buffer * Clarify header comment * Adjust _smsDataEndIndex to point at end of SMS * Revert smscharset additions * Rewrite to save memory * Let the available() method advance to next sms as before * Simplify by removing smsIndexStart Co-authored-by: per1234 <[email protected]>
1 parent 86b4d24 commit 6bcf2de

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/NB_SMS.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ int NB_SMS::endSMS()
109109

110110
int NB_SMS::available()
111111
{
112-
if (_incomingBuffer.length() != 0) {
113-
int nextMessageIndex = _incomingBuffer.indexOf("\r\n+CMGL: ");
112+
int nextMessageIndex = _incomingBuffer.indexOf("+CMGL: ");
114113

115-
if (nextMessageIndex != -1) {
116-
_incomingBuffer.remove(0, nextMessageIndex + 2);
117-
} else {
118-
_incomingBuffer = "";
119-
}
114+
if (nextMessageIndex != -1) {
115+
_incomingBuffer.remove(0, nextMessageIndex);
116+
} else {
117+
_incomingBuffer = "";
120118
}
121119

122120
if (_incomingBuffer.length() == 0) {
@@ -141,9 +139,12 @@ int NB_SMS::available()
141139
}
142140

143141
if (_incomingBuffer.startsWith("+CMGL: ")) {
142+
143+
_incomingBuffer.remove(0, 7);
144+
144145
_smsDataIndex = _incomingBuffer.indexOf('\n') + 1;
145146

146-
_smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: ");
147+
_smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: ",_smsDataIndex);
147148
if (_smsDataEndIndex == -1) {
148149
_smsDataEndIndex = _incomingBuffer.length() - 1;
149150
}
@@ -207,13 +208,12 @@ int NB_SMS::peek()
207208

208209
void NB_SMS::flush()
209210
{
210-
int smsIndexStart = _incomingBuffer.indexOf(' ');
211211
int smsIndexEnd = _incomingBuffer.indexOf(',');
212212

213-
if (smsIndexStart != -1 && smsIndexEnd != -1) {
213+
if (smsIndexEnd != -1) {
214214
while (MODEM.ready() == 0);
215215

216-
MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(smsIndexStart + 1, smsIndexEnd).c_str());
216+
MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(0, smsIndexEnd).c_str());
217217

218218
if (_synch) {
219219
MODEM.waitForResponse(55000);

0 commit comments

Comments
 (0)