I'm developing a software that manages a GSM modem (actually it's a SIM900 from SimCom).
So I need to implement an AT parser. At first it appears a simple thing to do: the host microcontroller sends an AT command and waits for an answer usually ending with
The problem arises with unsolicited result codes (URC) that are asyncronous messages transmitted from the modem at any time (such as messages that signals the arrival of an incoming SMS or a RING).
I discovered those messages can be concatenated to the answer of a previous AT command: the first character of the URC could appear immediately after the last character of the answer of a previous AT command.
I know the application layer can break the incoming stream of characters from modem into messages, parsing the content, knowing all the possible expected answers and URC.
Anyway I think this is complicated so I'm thinking of a low-level (driver level) mechanism that is sufficiently generic.
I tried to search for something similar, but without success. Any suggestions?