Changeset - 84e25f7efd5a
[Not reviewed]
default
0 1 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-04-18 21:51:21
ethanzonca@CL-ENS241-08.cedarville.edu
Fixed issue where get_latitudeTrimmed() and get_latitudeLSBs() and associated longitude function returned the same results due to buffer sharing and compiler optimization.
1 file changed with 16 insertions and 14 deletions:
0 comments (0 inline, 0 general)
master/master/lib/gps.c
Show inline comments
 
/*
 
 * Master Firmware: NMEA Parser
 
 *
 
 * This file is part of OpenTrack.
 
 *
 
 * OpenTrack is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * OpenTrack is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with OpenTrack. If not, see <http://www.gnu.org/licenses/>.
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 

	
 
#include <stdbool.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "gps.h"
 
#include "serial.h"
 
#include "../config.h"
 
#include "led.h"
 
#include "logger.h"
 

	
 
// Circular buffer for incoming data
 
uint8_t nmeaBuffer[NMEABUFFER_SIZE];
 

	
 
// Location of parser in the buffer
 
uint8_t nmeaBufferParsePosition = 0;
 

	
 
// Location of receive byte interrupt in the buffer
 
volatile uint16_t nmeaBufferDataPosition = 0;
 

	
 
// 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
 
char tramsmissionType[7];
 

	
 
char timestamp[12];	//hhmmss.ss
 
char* get_timestamp() 
 
{
 
	return timestamp;
 
}
 
	
 
char latitude[14];	//lllll.lla
 
char latitudeTmp[8];
 
char latitudeTmpTRIM[8];
 
char latitudeTmpLSB[4];
 
char* get_latitudeTrimmed() 
 
{
 
	strncpy(latitudeTmp, &latitude[0], 7);
 
	latitudeTmp[7] = 0x00;
 
	return latitudeTmp;
 
	strncpy(latitudeTmpTRIM, &latitude[0], 7);
 
	latitudeTmpTRIM[7] = 0x00;
 
	return latitudeTmpTRIM;
 
}
 
char* get_latitudeLSBs()
 
{
 
	strncpy(latitudeTmp, &latitude[7], 3);
 
	latitudeTmp[3] = 0x00;
 
	return latitudeTmp;
 
	strncpy(latitudeTmpLSB, &latitude[7], 3);
 
	latitudeTmpLSB[3] = 0x00;
 
	return latitudeTmpLSB;
 
}
 

	
 
char longitude[14];	//yyyyy.yyb
 
char longitudeTmp[9];
 
char longitudeTmpTRIM[9];
 
char longitudeTmpLSB[4];
 

	
 
char* get_longitudeTrimmed() 
 
{
 
	strncpy(longitudeTmp, &longitude[0], 8);
 
	longitudeTmp[8] = 0x00;
 
	return longitudeTmp;
 
	strncpy(longitudeTmpTRIM, &longitude[0], 8);
 
	longitudeTmpTRIM[8] = 0x00;
 
	return longitudeTmpTRIM;
 
}
 
char* get_longitudeLSBs()
 
{
 
	strncpy(longitudeTmp, &longitude[8], 3);
 
	longitudeTmp[3] = 0x00;
 
	return longitudeTmp;
 
	strncpy(longitudeTmpLSB, &longitude[8], 3);
 
	longitudeTmpLSB[3] = 0x00;
 
	return longitudeTmpLSB;
 
}
 

	
 
char quality;		//quality for GGA and validity for RMC
 
char numSatellites[4];
 
char* get_sv() 
 
{
 
	return numSatellites;
 
}
 

	
 
char hdop[6];		//xx.x
 
char* get_hdop() 
 
{
 
	return hdop;
 
}
 

	
 
char altitude[10];	//xxxxxx.x
 
char* get_gpsaltitude()
 
{
 
	return altitude;
 
}
 

	
 
char wgs84Height[8];	//sxxx.x
 
char lastUpdated[8];	//blank - included for testing
 
char stationID[8];	//blank - included for testing
 
char checksum[3];	//xx
 

	
 
char knots[8];		//xxx.xx
 
char* get_speedKnots() 
 
{
 
	return knots;
 
}
 

	
 
char course[8];		//xxx.x
 
char* get_course() 
 
{
 
	return course;
 
}
 
	
 
char dayofmonth[9];	//ddmmyy
 
char* get_dayofmonth() 
 
{
 
	return dayofmonth;
 
}
 

	
 

	
 
bool gps_hadfix = false;
 

	
 
bool gps_hasfix() 
 
{
 
	bool hasFix = get_latitudeTrimmed()[0] != 0x00;
 
	
 
	if(hasFix && !gps_hadfix) {
 
		info_log_msg("Acquired GPS fix");
 
	}
 
	else if(!hasFix && gps_hadfix) {
 
		info_log_msg("Lost GPS fix");
 
	}
 
	
 
	gps_hadfix = hasFix;
 
	return hasFix;
 
}
 

	
 
char variation[9];	//xxx.xb
 
int calculatedChecksum;
 
int receivedChecksum;
 

	
 
// transmission state machine
 
enum decodeState {
 
	//shared fields
 
	INITIALIZE=0,
 
	GET_TYPE,
 
	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
 
	RMC_TIME,
 
	RMC_VALIDITY,
 
	RMC_LATITUDE,
 
	RMC_LONGITUDE,
 
	RMC_KNOTS,
 
	RMC_COURSE,
 
	RMC_DATE,
 
	RMC_MAG_VARIATION,
 
	
 
}decodeState;
 

	
 

	
0 comments (0 inline, 0 general)