Changeset - 6a57c40fdde2
[Not reviewed]
default
0 2 0
mkanning@CL-SEC241-10.cedarville.edu - 13 years ago 2012-11-15 11:39:24
mkanning@CL-SEC241-10.cedarville.edu
gps.c and gps.h changes
2 files changed with 10 insertions and 5 deletions:
0 comments (0 inline, 0 general)
master/master/lib/trackuinoGPS/gps.c
Show inline comments
 
@@ -37,101 +37,97 @@ typedef void (*t_nmea_parser)(const char
 

	
 

	
 

	
 

	
 
// Module constants
 
static const t_nmea_parser unk_parsers[] = {
 
	parse_sentence_type,    // $GPxxx
 
};
 

	
 
static const t_nmea_parser gga_parsers[] = {
 
	NULL,             // $GPGGA
 
	parse_time,       // Time
 
	NULL,             // Latitude
 
	NULL,             // N/S
 
	NULL,             // Longitude
 
	NULL,             // E/W
 
	NULL,             // Fix quality
 
	NULL,             // Number of satellites
 
	NULL,             // Horizontal dilution of position
 
	parse_altitude,   // Altitude
 
	NULL,             // "M" (mean sea level)
 
	NULL,             // Height of GEOID (MSL) above WGS84 ellipsoid
 
	NULL,             // "M" (mean sea level)
 
	NULL,             // Time in seconds since the last DGPS update
 
	NULL              // DGPS station ID number
 
};
 

	
 
static const t_nmea_parser rmc_parsers[] = {
 
	NULL,             // $GPRMC
 
	parse_time,       // Time
 
	parse_status,     // A=active, V=void
 
	parse_lat,        // Latitude,
 
	parse_lat_hemi,   // N/S
 
	parse_lon,        // Longitude
 
	parse_lon_hemi,   // E/W
 
	parse_speed,      // Speed over ground in knots
 
	parse_course,     // Track angle in degrees (true)
 
	NULL,             // Date (DDMMYY)
 
	NULL,             // Magnetic variation
 
	NULL              // E/W
 
};
 

	
 

	
 

	
 
static const int NUM_OF_UNK_PARSERS = (sizeof(unk_parsers) / sizeof(t_nmea_parser));
 
static const int NUM_OF_GGA_PARSERS = (sizeof(gga_parsers) / sizeof(t_nmea_parser));
 
static const int NUM_OF_RMC_PARSERS = (sizeof(rmc_parsers) / sizeof(t_nmea_parser));
 

	
 
enum t_sentence_type {
 
	SENTENCE_UNK,
 
	SENTENCE_GGA,
 
	SENTENCE_RMC
 
};
 

	
 

	
 
// Module variables
 
static t_sentence_type sentence_type = SENTENCE_UNK;
 
static bool at_checksum = false;
 
static unsigned char our_checksum = '$';
 
static unsigned char their_checksum = 0;
 
static char token[16];
 
static int num_tokens = 0;
 
static unsigned int offset = 0;
 
static bool active = false;
 
static char gga_time[7] = "", rmc_time[7] = "";
 
static char new_time[7];
 
static uint32_t new_seconds;
 
static float new_lat;
 
static float new_lon;
 
static char new_aprs_lat[9];
 
static char new_aprs_lon[10];
 
static float new_course;
 
static float new_speed;
 
static float new_altitude;
 

	
 
// Public (extern) variables, readable from other modules
 
char gps_time[7];       // HHMMSS
 
uint32_t gps_seconds = 0;   // seconds after midnight
 
float gps_lat = 0;
 
float gps_lon = 0;
 
char gps_aprs_lat[9];
 
char gps_aprs_lon[10];
 
float gps_course = 0;
 
float gps_speed = 0;
 
float gps_altitude = 0;
 

	
 
// Module functions
 
/// convert hex to binary ??
 
unsigned char from_hex(char a)
 
{
 
	if (a >= 'A' && a <= 'F'){
 
		return a - 'A' + 10;
 
	}else if (a >= 'a' && a <= 'f'){
 
		return a - 'a' + 10;
 
	}else if (a >= '0' && a <= '9'){
 
		return a - '0';
 
	}else{
 
		return 0;
 
	}
 
}
 

	
 
/// determine what type of message is being sent ??
 
@@ -211,107 +207,109 @@ void parse_lon(const char *token)
 
		degs[1] = token[1];
 
		degs[2] = token[2];
 
		degs[3] = '\0';
 
		new_lon = atof(degs) + atof(token + 3) / 60;
 
	}
 
	// APRS-ready longitude
 
	strncpy(new_aprs_lon, token, 8);
 
	new_aprs_lon[8] = '\0';
 
}
 

	
 
/// if this is hemisphere it is not needed
 
void parse_lon_hemi(const char *token)
 
{
 
	if (token[0] == 'W'){
 
		new_lon = -new_lon;
 
	}
 
	new_aprs_lon[8] = token[0];
 
	new_aprs_lon[9] = '\0';
 
}
 

	
 
/// we do not need to record speed
 
void parse_speed(const char *token)
 
{
 
	new_speed = atof(token);
 
}
 

	
 
/// we do not need to record course
 
void parse_course(const char *token)
 
{
 
	new_course = atof(token);
 
}
 

	
 
/// will use this to validate pressure readings
 
void parse_altitude(const char *token)
 
{
 
	new_altitude = atof(token);
 
}
 

	
 

	
 
//
 
// Exported functions
 
//
 
/// void zeroing of data. presumably to be called at start
 
void gps_setup() {
 
	strcpy(gps_time, "000000");
 
	strcpy(gps_aprs_lat, "0000.00N");
 
	strcpy(gps_aprs_lon, "00000.00E");
 
}
 

	
 
/// MKa GPS transmission parser
 
void parse_gps_transmission(char c){
 
	// i think c is the most recent character of transmission and is constantly 
 
	// tested if terminal character. if terminal then do parse on previous transmission.
 
	 
 
	// $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx
 
	if(c == '\n') //end of transmission sentence. may need more checks
 
	{
 
				
 
	}
 
}
 

	
 
/// process gps transmission 
 
bool gps_decode(char c)
 
{
 
	int ret = false;
 

	
 
	switch(c) {
 
		case '\r':
 
		case '\n': // End of sentence
 
			if (num_tokens && our_checksum == their_checksum) { ///checksum is valid (good transmission)
 
				#ifdef DEBUG_GPS
 
				Serial.print(" (OK!) ");
 
				Serial.print(millis());
 
				#endif
 
				// Return a valid position only when we have two rmc and gga
 
				// messages with the same timestamp.
 
				switch (sentence_type) {
 
					case SENTENCE_UNK:
 
						break;    // Keeps gcc happy
 
					case SENTENCE_GGA:
 
						strcpy(gga_time, new_time);
 
						break;
 
					case SENTENCE_RMC:
 
						strcpy(rmc_time, new_time);
 
						break;
 
				}
 

	
 
				// Valid position scenario:
 
				//
 
				// 1. The timestamps of the two previous GGA/RMC sentences must match.
 
				//
 
				// 2. We just processed a known (GGA/RMC) sentence. Suppose the
 
				//    contrary: after starting up this module, gga_time and rmc_time
 
				//    are both equal (they're both initialized to ""), so (1) holds
 
				//    and we wrongly report a valid position.
 
				//
 
				// 3. The GPS has a valid fix. For some reason, the Venus 634FLPX
 
				//    reports 24 deg N, 121 deg E (the middle of Taiwan) until a valid
 
				//    fix is acquired:
 
				//
 
				//    $GPGGA,120003.000,2400.0000,N,12100.0000,E,0,00,0.0,0.0,M,0.0,M,,0000*69 (OK!)
 
				//    $GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30 (OK!)
 
				//    $GPRMC,120003.000,V,2400.0000,N,12100.0000,E,000.0,000.0,280606,,,N*78 (OK!)
 
				//    $GPVTG,000.0,T,,M,000.0,N,000.0,K,N*02 (OK!)
 

	
 
				if (sentence_type != SENTENCE_UNK &&      // Known sentence?
 
				strcmp(gga_time, rmc_time) == 0 &&    // RMC/GGA times match?
 
				active) {                             // Valid fix?
 
					// Atomically merge data from the two sentences
master/master/lib/trackuinoGPS/gps.h
Show inline comments
 
/* trackuino copyright (C) 2010  EA5HAV Javi
 
 *
 
 * This program is free software; you can redistribute it and/or
 
 * modify it under the terms of the GNU General Public License
 
 * as published by the Free Software Foundation; either version 2
 
 * of the License, or (at your option) any later version.
 
 *
 
 * This program 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 General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 */
 

	
 
#ifndef __GPS_H__
 
#define __GPS_H__
 

	
 
#include <stdint.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <stdbool.h>
 

	
 
extern char gps_time[7];       // HHMMSS
 
extern uint32_t gps_seconds;   // seconds after midnight
 
extern char gps_date[7];       // DDMMYY
 
extern float gps_lat;
 
extern float gps_lon;
 
extern char gps_aprs_lat[9];
 
extern char gps_aprs_lon[10];
 
extern float gps_course;
 
extern float gps_speed;
 
extern float gps_altitude;
 

	
 

	
 

	
 
void gps_setup();
 
bool gps_decode(char c);
 

	
 
#endif
 
enum t_sentence_type {
 
	SENTENCE_UNK,
 
	SENTENCE_GGA,
 
	SENTENCE_RMC
 
};
 
\ No newline at end of file
0 comments (0 inline, 0 general)