# HG changeset patch # User ethanzonca@CL-SEC241-08.cedarville.edu # Date 2012-11-15 15:50:44 # Node ID e54e67fc99cd6ff8fe06e39140f98f5da667b53c # Parent 94648aa82312e79fb27aeb20be8db33a58f13516 # Parent 2c211b2f6366d61581e2695f97e5a2586476be9a Merge diff --git a/master/master/lib/trackuinoGPS/gpsMKa.c b/master/master/lib/trackuinoGPS/gpsMKa.c --- a/master/master/lib/trackuinoGPS/gpsMKa.c +++ b/master/master/lib/trackuinoGPS/gpsMKa.c @@ -5,9 +5,8 @@ * Author: mkanning */ #include - -// has the transmission started -bool transmissionBegin = false; +#include +#include "gpsMKa.h" // holds the byte ALREADY PARSED. includes starting character int bytesReceived = 0; @@ -15,32 +14,135 @@ int bytesReceived = 0; //data (and checksum) of most recent transmission char data[16]; +//used to skip over bytes during parse +int skipBytes = 0; + +//variables to store data from transmission +uint8_t tramsmissionType; +uint8_t timestamp[9]; //hhmmss.ss +uint8_t latitude[8]; //llll.ll,a +uint8_t longitude[8]; //yyyyy.yy,a +uint8_t quality; +uint8_t numSatellites; +uint8_t hdop; +uint8_t altitude; +uint8_t wgs84Height; +uint8_t lastUpdated; +uint8_t stationID; +uint8_t checksum; + +// transmission state machine +enum decodeState { + INITIALIZE=0, + GET_TYPE, + GGA_TIME, + GGA_LATITUDE, + GGA_LONGITUDE, + GGA_QUALITY, + GGA_SATELLITES, + GGA_HDOP, + GGA_ALTITUDE, + GGA_WGS84, + GGA_LAST_UPDATE, + GGA_STATION_ID, + RMC_TIME +}decodeState; + /// MKa GPS transmission parser START void parse_gps_transmission(void){ + bytesReceived++; // Pull byte off of the buffer char byte = uart_getchar(); // $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx + // ^8 ^18 ^28 if(byte == '$') //start of transmission sentence { - transmissionBegin = true; bytesReceived = 1; //resets transmission if '$' is found + decodeState = GET_TYPE; } - if (transmissionBegin) + //parse transmission type + else if (decodeState == GET_TYPE) { - if (bytesReceived == 3) //check 4th byte + if (bytesReceived == 4 ) //check 4th byte + { + tramsmissionType = byte; + } + + if(byte = ',') //end of type data { - if(byte == ' ') + if (tramsmissionType == 'G') + { + decodeState = GGA_TIME; + } + else if(tramsmissionType == 'R') + { + decodeState = RMC_TIME; //not implemented + } + else { - - } - } + //reset + decodeState = INITIALIZE; + bytesReceived = 0; + } + } + } + + //parse GGA timestamp + else if (decodeState == GGA_TIME) + { + if (byte = ',')//end of timestamp data + { + decodeState = GGA_LATITUDE; + skipBytes = 0; //prep for next phase of parse + } + else //store the byte of timestamp data + { + timestamp[bytesReceived-7] = byte; //adjust number of bytes to fit array + } + } + + //parse GGA latitude data + else if (decodeState == GGA_LATITUDE) + { + if (byte == ',' && skipBytes == 0) //discard this byte + { + skipBytes = 1; + } + else if (byte == ',') //end of latitude data + { + decodeState = GGA_LONGITUDE; + skipBytes = 0; //prep for next phase of parse + } else { + latitude[bytesReceived-17] = byte; //adjust number of bytes to fit array + } + } + + //parse GGA longitude data + else if (decodeState == GGA_LONGITUDE) + { + if (byte == ',' && skipBytes == 0) //discard this byte + { + skipBytes = 1; } - //use a state machine implementation rather than this + else if (byte == ',') //end of latitude data + { + decodeState = GGA_QUALITY; + } + else + { + longitude[bytesReceived-17] = byte; //adjust number of bytes to fit array + } + } + + //parse GGA quality data + else if (decodeState = GGA_QUALITY) + { + quality = byte; } } diff --git a/master/master/lib/trackuinoGPS/gpsMKa.h b/master/master/lib/trackuinoGPS/gpsMKa.h --- a/master/master/lib/trackuinoGPS/gpsMKa.h +++ b/master/master/lib/trackuinoGPS/gpsMKa.h @@ -11,8 +11,5 @@ #define GGA_MESSAGE #define RMC_MESSAGE #define UKN_MESSAGE -// states -#define - #endif /* GPSMKA_H_ */ \ No newline at end of file