GPS BETTER DATA
RMC PARSED DATA
I manipulated the code a bit, most likely making some mistakes, but i parsed the data now that I realized for the purpose of the Tsunameter location RMC better fits my needs.
// import the serial library:
import processing.serial.*;
int utc = 0; // UTC Time
float latitude = 0.0; // the longitude reading in degrees
String northSouth; // north or south?
float longitude = 0.0; // the longitude reading in degrees
String eastWest; // east or west?
float speed = 0.0; // the speed over ground
float course = 0.0; // the course over ground
int date = 0;
float magnetic = 0.0;
int linefeed = 10; // linefeed in ASCII
int carriageReturn = 13; // carriage return in ASCII
Serial myPort; // The serial port
void setup() {
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[2], 4800);
// read bytes into a buffer until you get a carriage return (ASCII 13):
myPort.bufferUntil(carriageReturn);
}
void draw() {
// not doing anything here
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
// print it:
parseString(myString);
}
}
//Then replace println(myString); above with parseString(myString);
//Then add this method at the end of the program:
void parseString(String serialString) {
// split the string at the commas
//and convert the sections into integers:
String items[] = (split(serialString, ','));
// if the first item in the sentence is our identifier, parse the rest:
if (items[0].equals("$GPRMC") == true) {
// move the items from the string into the variables:
utc = int(items[1]);
latitude = float(items[3]);
northSouth = items[4];
longitude = float(items[5]);
eastWest = items[6];
speed = float(items[7]);
course = float(items[8]);
date = int(items[9]);
magnetic = float (items[10]);
//println (UTC + latitude + northSouth + longitude + eastWest + speed + course + date + magnetic);
println ("UTC:" + utc + "," + "LATITUDE:" + latitude + northSouth + "," + "LONGITUDE:" + longitude + eastWest + "," + "SPEED:" + speed + "," + "COURSE:" + course + "," + "DATE:" + date + ","
+ "MAGNETIC:" + magnetic);
}
}
And here is the result:
