diff --git a/src/NB_SMS.cpp b/src/NB_SMS.cpp index 20c2025..efe11e6 100644 --- a/src/NB_SMS.cpp +++ b/src/NB_SMS.cpp @@ -111,14 +111,12 @@ int NB_SMS::endSMS() int NB_SMS::available() { - if (_incomingBuffer.length() != 0) { - int nextMessageIndex = _incomingBuffer.indexOf("\r\n+CMGL: "); + int nextMessageIndex = _incomingBuffer.indexOf("+CMGL: "); - if (nextMessageIndex != -1) { - _incomingBuffer.remove(0, nextMessageIndex + 2); - } else { - _incomingBuffer = ""; - } + if (nextMessageIndex != -1) { + _incomingBuffer.remove(0, nextMessageIndex); + } else { + _incomingBuffer = ""; } if (_incomingBuffer.length() == 0) { @@ -142,9 +140,12 @@ int NB_SMS::available() } if (_incomingBuffer.startsWith("+CMGL: ")) { + + _incomingBuffer.remove(0, 7); + _smsDataIndex = _incomingBuffer.indexOf('\n') + 1; - _smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: "); + _smsDataEndIndex = _incomingBuffer.indexOf("\r\n+CMGL: ",_smsDataIndex); if (_smsDataEndIndex == -1) { _smsDataEndIndex = _incomingBuffer.length() - 1; } @@ -208,13 +209,12 @@ int NB_SMS::peek() void NB_SMS::flush() { - int smsIndexStart = _incomingBuffer.indexOf(' '); int smsIndexEnd = _incomingBuffer.indexOf(','); - if (smsIndexStart != -1 && smsIndexEnd != -1) { + if (smsIndexEnd != -1) { while (MODEM.ready() == 0); - MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(smsIndexStart + 1, smsIndexEnd).c_str()); + MODEM.sendf("AT+CMGD=%s", _incomingBuffer.substring(0, smsIndexEnd).c_str()); if (_synch) { MODEM.waitForResponse(55000);