GSM/GPS shield data order and length

Hi,
I've got GSM/GPS shield (the one with SIM908 chip), now I want to implement GPS tracker, it will collect and send the data asynchronously.
Two questions:
1. I've sent a text message to my device. The message is [tt]OK\n\nOK[/tt]. I request all messages with [tt]AT+CMGL="ALL"[/tt] and get something like this:
[quote]
+CMGL: 4,"REC READ","+XXXXXXXXXXX","","14/12/28,05:09:08+12"
OK
OK
OK[/quote]
I can't just parse the data till the latest [tt]OK[/tt] — what if some other command has happened in the meantime? How to know for sure when the command result ends?
2. The second question comes from the first one. When I, for example, call to my device, I read [tt]RING[/tt] from the serial port. What if the call happens during some other command output progress? Will the result be splitted by the [tt]RING[/tt] (or [tt]+CMTI: "SM",2[/tt] or anything else)? And if not — again, how to say when one response ends and when another one begins?
Thanks.
I've got GSM/GPS shield (the one with SIM908 chip), now I want to implement GPS tracker, it will collect and send the data asynchronously.
Two questions:
1. I've sent a text message to my device. The message is [tt]OK\n\nOK[/tt]. I request all messages with [tt]AT+CMGL="ALL"[/tt] and get something like this:
[quote]
+CMGL: 4,"REC READ","+XXXXXXXXXXX","","14/12/28,05:09:08+12"
OK
OK
OK[/quote]
I can't just parse the data till the latest [tt]OK[/tt] — what if some other command has happened in the meantime? How to know for sure when the command result ends?
2. The second question comes from the first one. When I, for example, call to my device, I read [tt]RING[/tt] from the serial port. What if the call happens during some other command output progress? Will the result be splitted by the [tt]RING[/tt] (or [tt]+CMTI: "SM",2[/tt] or anything else)? And if not — again, how to say when one response ends and when another one begins?
Thanks.