Вопрос

I'm looking for some guidelines how to properly parse response data received from GSM module. I'm using uBlox SARA-G350. Documentation states:

Information responses:
<CR><LF><text><CR><LF>

Result codes:
<CR><LF><verbose code><CR><LF>

If the command line is successfully performed, the string "OK" (<CR><LF>OK<CR><LF>)
is sent, otherwise "ERROR".

It might looks everything simple. We should read each sentence from <CR><LF> to <CR><LF> but...

  • data may become in chunks
  • response may contains doubled <CR><LF>OK<CR><LF> (see example below)

Example - sms message sent to gsm module:

"Hi. Is IT
OK
"

After CMGL module respond (this is how end of sequence of returned data might looks like):

Hi. Is IT<CR><LF>
OK<CR><LF>
<CR><LF>
OK<CR><LF>

As you can see we have doubled <CR><LF>OK<CR><LF>.

How do I know that I have whole sentence and should stop reading data from module and do parsing received data?

How AT parser should behave in situation like this?

Where I can find some guidelines how to properly parse incoming response data from gsm module?

Это было полезно?

Решение

I found it. My bad assumption was that sms message can contain CrLf within. This is not true (at least for uBlox SARA-G350). All CrLf within some text received from module are replaced to Lf.

Thanks to that I can know that end of sentence will be when one of the next combinations arrives:

  • <CR><LF>OK<CR><LF>
  • <CR><LF>ERROR<CR><LF>
  • <CR><LF> >

The last one is prompt sign for sms sending command.

Другие советы

Your question is interesting because the standards in large avoid saying what should happen if the text returned should contain something that resembles a final result code. V.250 specifies in 5.7.3 Information text formats for test commands only that the DCE should not generate false positives in breaking up long lines of response text, but does not explicitly forbid ever generating false positives... See also this answer for related discussion around responses from AT+CMGL.

So to answer your question, you must assume this is implementation defined behaviour.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top