Changeset - ac84ccb03606
[Not reviewed]
default
0 1 0
mkanning@CL-SEC241-10.cedarville.edu - 13 years ago 2012-11-20 11:53:40
mkanning@CL-SEC241-10.cedarville.edu
More updates to GPS parser
1 file changed with 16 insertions and 5 deletions:
0 comments (0 inline, 0 general)
master/master/lib/trackuinoGPS/gpsMKa.c
Show inline comments
 
/*
 
* gpsMKa.c
 
*
 
* Created: 11/15/2012 12:02:38 PM
 
*  Author: mkanning
 
*/
 
#include <stdbool.h>
 
#include <avr/io.h>
 
#include "gpsMKa.h"
 

	
 
// holds the byte ALREADY PARSED. includes starting character
 
int bytesReceived = 0;
 

	
 
//data (and checksum) of most recent transmission
 
char data[16];
 

	
 
//used to skip over bytes during parse
 
int skipBytes = 0;
 

	
 
//used to index data arrays during data collection
 
int numBytes = 0;
 

	
 
//variables to store data from transmission
 
//least significant digit is stored at location 0 of arrays
 
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 latitude[8];	//lllll.lla
 
uint8_t longitude[8];	//yyyyy.yya
 
uint8_t quality;		//quality for GGA and validity for RMC
 
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;		//xx
 

	
 

	
 
// transmission state machine
 
enum decodeState {
 
	//shared fields
 
	INITIALIZE=0,
 
	GET_TYPE,
 
	GPS_CHECKSUM,	//need to find out how this is calculated/compared
 
	//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,
 
	GGA_CHECKSUM,
 
	RMC_TIME
 
	//RMC data fields
 
	RMC_TIME,
 
	RMC_WARNING,
 
	RMC_LATITUDE,
 
	RMC_LONGITUDE,
 
	RMC_KNOTS,
 
	RMC_COURSE,
 
	RMC_DATE,
 
	RMC_MAG_VERIATION,
 
	
 
}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
 
	{
 
		bytesReceived = 1; //resets transmission if '$' is found
 
		decodeState = GET_TYPE;
 
		numBytes = 0;
 
	}
 
	
 
	//parse transmission type
 
	else if (decodeState == GET_TYPE)
 
	{
 
		if (bytesReceived == 4 ) //check 4th byte
 
		{
 
			tramsmissionType = byte;
 
		}
 
		
 
		if(byte = ',') //end of type data
 
		{
 
			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)
 
	{
0 comments (0 inline, 0 general)