Skip to content

Instantly share code, notes, and snippets.

@ibanezmatt13
Last active December 25, 2015 09:29
Show Gist options
  • Save ibanezmatt13/6954770 to your computer and use it in GitHub Desktop.
Save ibanezmatt13/6954770 to your computer and use it in GitHub Desktop.
char NMEA_string[70] = "";
char buffer = 0;
int n = 0;
int state = 0;
while (1){
buffer = Serial.read(); // Read Character
switch(state){
case 0: // Waiting for a $
if (buffer == '$'){
state=1;
n=0;
memset(NMEA_string,0,70); // Clear NMEA_sentence
NMEA_string[n++]=buffer;
}
break;
case 1: // Got a string
if (buffer == '\r'){ // End of string
// Parse the string
state=0;
} else {
NMEA_string[n++]=buffer;
}
if (buffer >=68) { // Stop at 68 (69 chars) so there's still a NULL at the end.
printf("Error: NMEA_sentence has overflown (%s)\n", NMEA_sentence);
state=0;
}
break;
} // Close switch
} // Close while
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment