Answers of AT commands are parsed using "\r\n" delimiter. In other words, the GSM modem transmits messages starting with "\r\n" and ending with "\r\n".
AT+CMGR answer (read SMS) is strange. It is composed by:
\r\n+CMGR=,,[,][,,,,,,,]\r\n \r\n \r\nOK\r\n
As usual, I parse this answer receiving blocks of characters from modem, ending with delimiter "\r\n".
- The first block (\r\n) is empty.
- The second block (+CMGR=,,[,][,,,,,,,]\r\n) is parsed splitting fields using comma delimiter.
- The third block (\r\n) is the SMS text, except last two characters.
- The fourth block (\r\n) is empty.
- The fifth block (OK\r\n) is the last block that ends the AT+CMGR answer.
This approach is good in most situations. But what happens if field contains \r\n? I tried to send an SMS with newline from my mobile phone and I noticed it is received as a single \n character. So the parsing above works well.
Yesterday my GSM modem received a SMS with true 2-characters \r\n newlines in ! It was a SMS send by the mobile operator and not by a user. Anyway, it's possible to have the with embedded \r\n.
Have you noticed this before on your tests? How do you parse the AT+CMGR answer?