Skip to content

Instantly share code, notes, and snippets.

@indrora
Created July 4, 2013 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indrora/5923924 to your computer and use it in GitHub Desktop.
Save indrora/5923924 to your computer and use it in GitHub Desktop.
// Lower end of ASCII printable (space)
#define ASCII_PRINT_LOWER = 0x20
// replace.
char[] want_kind = "$GPXXX";
int want_idx = 0;
void loop()
{
/* stuff to keep strobing happy */
// if we have serial data
if(Serial.available())
{
// check to see if it's what we want
// if idx = 0, want_kind[idx] = $
// if we get $, we go on, looking for G..
if(Serial.read() == want_kind[want_idx])
want_idx++; // the stanza we're going to get looks kinda like what we want.
else
{
// the stanza we are going to get is NOT what we want.
want_idx = 0;
// eat anything until we get a newline, or anything that's less than
// the lower end of ASCII's printable region.
while(Serial.Read() > ASCII_PRINT_LOWER ) ;
}
if(want_idx == sizeof(want_kind)-1)
{
// we have the stanza we want.
// parse it as we need
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment