Changeset - e5c11279c2a0
[Not reviewed]
default
0 1 0
mkanning@CL-ENS241-10.cedarville.edu - 12 years ago 2013-01-10 15:03:18
mkanning@CL-ENS241-10.cedarville.edu
checksum calculator and comparator for NMEA
1 file changed with 22 insertions and 4 deletions:
0 comments (0 inline, 0 general)
master/master/lib/trackuinoGPS/gpsMKa.c
Show inline comments
 
@@ -33,31 +33,32 @@ uint8_t quality;		//quality for GGA and 
 
uint8_t numSatellites[2];
 
uint8_t hdop[4];		//xx.x
 
uint8_t altitude[8];	//xxxxxx.x
 
uint8_t wgs84Height[6];	//sxxx.x
 
uint8_t lastUpdated[6];	//blank - included for testing
 
uint8_t stationID[6];	//blank - included for testing
 
uint8_t checksum[2];	//xx
 
uint8_t knots[5];		//xxx.xx
 
uint8_t course[5];		//xxx.x
 
uint8_t datestamp[6];	//ddmmyy
 
uint8_t variation[6];	//xxx.xb
 
int calculatedChecksum;
 
int receivedChecksum;
 

	
 
// transmission state machine
 
enum decodeState {
 
	//shared fields
 
	INITIALIZE=0,
 
	GET_TYPE,
 
	GPS_CHECKSUM,	//need to find out how this is calculated/compared
 
	GPS_CHECKSUM,	//XOR of all the bytes between the $ and the * (not including the delimiters themselves), written in hexadecimal
 
	//GGA data fields
 
	GGA_TIME,
 
	GGA_LATITUDE,
 
	GGA_LONGITUDE,
 
	GGA_QUALITY,
 
	GGA_SATELLITES,
 
	GGA_HDOP,
 
	GGA_ALTITUDE,
 
	GGA_WGS84,
 
	GGA_LAST_UPDATE,
 
	GGA_STATION_ID,
 
	//RMC data fields
 
@@ -401,50 +402,67 @@ void parse_gps_transmission(void){
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			datestamp[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	
 
	//magnetic variation
 
	else if(decodeState == RMC_MAG_VARIATION)
 
	{
 
		if (byte == ',') //end of this data type
 
		if (byte == '*') //end of this data type
 
		{
 
			decodeState = GPS_CHECKSUM;
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
			variation[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	///parses RMC transmissions END
 
	
 
	
 
	//checksum
 
	else if (decodeState == GPS_CHECKSUM)
 
	{
 
		if (numBytes == 2) //end of data - terminating character ??
 
		{
 
			//checksum calculator for testing http://www.hhhh.org/wiml/proj/nmeaxor.html
 
			//TODO: must determine what to do with correct and incorrect messages
 
			receivedChecksum = checksum[0] + (checksum[1]*16);	//convert bytes to int
 
			if(calculatedChecksum==receivedChecksum)
 
			{
 
				
 
			}
 
			else
 
			{
 
				
 
			}
 
			
 
			decodeState = INITIALIZE;
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
			checksum[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	
 
	//input byte into running checksum
 
	XORbyteWithChecksum(byte);
 
	if (decodeState!=GPS_CHECKSUM && decodeState!=INITIALIZE)	//want bytes between '$' and '*'
 
	{
 
		//input byte into running checksum
 
		XORbyteWithChecksum(byte);
 
	}
 
	
 

	
 
}
 
/// MKa GPS transmission parser END
 

	
 
void XORbyteWithChecksum(uint8_t byte){
 
	calculatedChecksum ^= (int)byte; //this may need to be re-coded
 
}
 

	
0 comments (0 inline, 0 general)