Reading and Parsing Data

=Reading a full line of data= https://gist.github.com/94327/2f51486f19d5eeb96dfc701c7f46821cdeac4e22 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257354909 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243608781 http://www.cs.cf.ac.uk/Dave/C/node19.html
 * read it into an array buffer
 * another example of an array buffer, with checking number of available bytes
 * links to sample code to get and parse NMEA strings

String functions in strings.h

=NMEA Data= NMEA Checksums

NMEA data should have $identifier,data,data,...,data*FF and then a newline, where FF is a checksum Hence, we can check for the newlines, dollar sign, asterisk, and the checksum value to verify the data.

Work on this is being done in reliable_serial_data.pde

Generate a checksum from a command: http://www.hhhh.org/wiml/proj/nmeaxor.html

NMEA checksum discussion

=Handling data after parsing=
 * make this a moving average... remember the oldest data and subtract it.
 * maybe this?
 * to get one, we want a FIFO structure (say of 10 values) that we keep bumping the oldest out, subtracting it from our average, adding the new value to the queue and our average


 * look into extending TinyGPS to include the other data fields needed here; dont quite understand how it goes to the next _term
 * all about NMEA strings

=Debugging Wind Sensor Parsing= We're using strtok to parse data from the wind sensor. This is now working, strtok_parse.pde on dropbox.

Code
strcpy(cp, val); //make a backup copy of the data to parse str1 = strtok(cp, ","); //find location of first ',', and copy everything before it into str1; this will be the type  of command Serial.print("command portion from cp strtok is: "); Serial.println(str1); //Compass if (strcmp(str1, "$PTNTHTM") == 0) { //"$PTNTHTM,285.2,N,-2.4,N,10.7,N,59.1,3844*27" // sscanf(val, "$%7s,%s,%c,%s,%c,%s,%c,%c", str, &head2_string, &head_st, &pitch_string, &pitch_st, &roll_string, &roll_st, &valid); /*printf("Heading is : %f\n", head2_deg); printf("String is : %s\n", str); The %s format in sscanf is defined to read a string until it encounters white space. If you want it to stop on a comma, you should use the %[^,] format. */ // res2 = strtok(NULL, ","); // this will use the cp copied string, since strtok magically remembers which string it was initially referenced to if NULL if used instead of a string result = strtok(val,","); //returns a string section of val up to the first , str=result; // should return $xxxxx identifier result = strtok(NULL,","); //should return 285.2 head2_string = result; //convert to decimals head2_deg = atof(head2_string); roll_deg = atof(roll_string); pitch_deg = atof(pitch_string); // Including these prints causes the strings to be forever printed - they arent terminated properly by sscanf?? Serial.print("Str command portion strtok1 from val: "); Serial.println(str); Serial.print("Heading portion strtok2 from val: "); Serial.println(head2_string);

Result
ÐParses says: valid string, val (full string) is: $PTNTHTM,285.2,N,-2.4,N,10.7,N,V command portion from cp strtok is: $PTNTHTM Str command portion strtok1 from val: $PTNTHTM Heading portion strtok2 from val: 285.2 Parses says: valid string, val (full string) is: $PTNTHTM command portion from cp strtok is: $PTNTHTM Str command portion strtok1 from val: $PTNTHTM Heading portion strtok2 from val: Ê Parses says: valid string, val (full string) is: $PTNTHTM

=External Links= Serial parsing suggested protocols

A smallish string library

String copy with arduino

String tokenize with arduino

Comparing strings with arduino

NMEA
A memory-intensive NMEA parsing library

Less memory-intensive NMEA GPS library, designed for arduino

Very good embedded systems controlling information

Using sscanf vs parsing character by character as TinyGPS does