FANDOM


Reading a full line of dataEdit

https://gist.github.com/94327/2f51486f19d5eeb96dfc701c7f46821cdeac4e22

  • read it into an array buffer

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257354909

  • another example of an array buffer, with checking number of available bytes

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243608781

  • links to sample code to get and parse NMEA strings

http://www.cs.cf.ac.uk/Dave/C/node19.html

String functions in strings.h

NMEA DataEdit

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 parsingEdit

  • 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 ParsingEdit

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

NotesEdit

It seems that strtok possibly corrupts our string as it processes it? First time through the loop it parses the full string; 2nd time it thinks that only the first token exists/is the full string (returns garbage when it attempts to tokenize beyond the first token)

CodeEdit

 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);

ResultEdit

Ð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 LinksEdit

Serial parsing suggested protocols

A smallish string library

String copy with arduino

String tokenize with arduino

Comparing strings with arduino


NMEAEdit

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