RockDawg
YaBB Newbies
Offline
Posts: 1
GPS logging function
Nov 29th , 2009, 9:22pm
Hi everyone, I wrote a program that parses serial data from EM-406 GPS receiver with a GPS evaluation board, but I am stuck though. I am unable to save a .txt with the parsed GPS data continuously. Like below: $GPGGA,023030.116,3409.0176,N,11814.8322,W,1,03,7.9,179.4,M,-33.3,M,,0000*6A I want to be able to save like a logging function. My program so far. import processing.serial.*; //serial port read library Serial com7; String data; Float Latitude1 = 0.0; String Latitude; String NorSindicator; Float Longitude1 = 0.0; String Longitude; String EorWindicator; String Satellites; String Altitude; String gpsdata; void setup(){ size(800,200); //window size PFont myFont = createFont(PFont.list()[2],16); // font type textFont(myFont); noStroke(); smooth(); println(Serial.list()); // displays port numbers for program com7 = new Serial(this, Serial.list()[4], 4800); // serial read setup com7.bufferUntil('\r'); // library buffer } void draw(){ background(0); fill(255); // window display textAlign(LEFT); text(" Latitude: " + Latitude + " Longitude: " + Longitude, 20,30); text(" Position: " + NorSindicator + " " + EorWindicator, 20,50); text("Satellites Used: "+ Satellites, 20,70); text(" Altitude: "+ Altitude + " Meters", 20,90); text(" GPS unparsed: "+ gpsdata, 20,110); } // function reads the gps data and sends it to the parsing function void serialEvent(Serial com7) { String data = com7.readStringUntil('\n'); if( data != null) { println(data); parseString(data); } } //parsing function void parseString (String serialString) { //sets up an array and splits the gps info by comma String items[] = split(serialString,','); if(items[0].equals("$GPGGA")) { //looks for the GPGGA info getGGA(items); } } //this function assigns the variables //to array elements that have been parsed void getGGA(String[] gpsinfo){ //if (gpsinfo[1].equals("A")){ Latitude1 = float(gpsinfo[2])/100.0; Latitude = nfs(Latitude1, 3,2); NorSindicator = gpsinfo[3]; Longitude1 = float( gpsinfo[4])/100.0; Longitude = nfs(Longitude1, 3,2); EorWindicator = gpsinfo[5]; Satellites = gpsinfo[7]; Altitude = gpsinfo[9]; gpsdata = join(gpsinfo,","); } I've used the saveStrings() haven't been able to figure it out. Any Help would be appreciated.