earth
2008-08-14 09:30:13 UTC
Hello,
I am using a variation of the gsm at command set to control a device
(sorry cannot say specifically).
First off I find there is no consistency in the protocol format when
the device sends data to me. Some commands are ended with crcrOKcr
(cr = carriage return + newline), some are crcr, some are just cr and
some are just carriage return with no newline. Then the number of cr
differs if the data was sent unsolicited.
Next there are responses prefixed with an 'at' and unsolicited
responses without.
I wondered what peoples stragegies were to parsing the stream of data
from a device? Currently my parser is built around a state machine.
It compares incomming data with possible strings. When it recongnises
a response idenitifier it sets the state to waiting for the parameters
of that response. Because I have a different state for each response
I can look for the data in the format specific to that response and I
can handle the wide variety of formats that the data is sent in.
However its not elegant.
Thanks,
Richard
I am using a variation of the gsm at command set to control a device
(sorry cannot say specifically).
First off I find there is no consistency in the protocol format when
the device sends data to me. Some commands are ended with crcrOKcr
(cr = carriage return + newline), some are crcr, some are just cr and
some are just carriage return with no newline. Then the number of cr
differs if the data was sent unsolicited.
Next there are responses prefixed with an 'at' and unsolicited
responses without.
I wondered what peoples stragegies were to parsing the stream of data
from a device? Currently my parser is built around a state machine.
It compares incomming data with possible strings. When it recongnises
a response idenitifier it sets the state to waiting for the parameters
of that response. Because I have a different state for each response
I can look for the data in the format specific to that response and I
can handle the wide variety of formats that the data is sent in.
However its not elegant.
Thanks,
Richard