Changeset - 0062f8daffe7
[Not reviewed]
default
0 9 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-10 21:58:42
ethanzonca@CL-ENS241-08.cedarville.edu
GPS parser now functional, APRS is now broadcasted with possibly correct position information
9 files changed with 318 insertions and 84 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -16,13 +16,13 @@
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
 
#define BOARDTEMP_ADDR 0x90
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (led.c, used throughout code)
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
@@ -59,18 +59,24 @@
 
// Circular serial buffer size. Must be at least MAX_CMD_LEN + 5
 
#define BUFFER_SIZE 32 
 
 
// Public broadcast address
 
#define BROADCAST_ADDR 0 
 
 
 
// --------------------------------------------------------------------------
 
// GPS config (xxx.c)
 
// --------------------------------------------------------------------------
 
#define NMEABUFFER_SIZE 150
 
 
// --------------------------------------------------------------------------
 
// USART config (serial.c)
 
// --------------------------------------------------------------------------
 
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 4800
 
#define USART1_BAUDRATE 115200
 
 
 
// --------------------------------------------------------------------------
 
// AX.25 config (ax25.c)
 
// --------------------------------------------------------------------------
 

	
 
@@ -109,13 +115,13 @@
 
// APRS comment: this goes in the comment portion of the APRS message. You
 
// might want to keep this short. The longer the packet, the more vulnerable
 
// it is to noise.
 
#define APRS_COMMENT    "CedarvilleUniversity HAB"
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 10000
 
#define APRS_TRANSMIT_PERIOD 5000
 

	
 

	
 
// --------------------------------------------------------------------------
 
// Logger config (logger.c)
 
// --------------------------------------------------------------------------
 
master/master/lib/afsk.c
Show inline comments
 
@@ -201,13 +201,14 @@ void afsk_send(const uint8_t *buffer, in
 
	afsk_packet = buffer;
 
}
 

	
 

	
 
void afsk_setup() 
 
{
 
	
 
	DDRA |= 0b00100000;
 
	DDRD |= 0b10000000;
 
	// Source timer2 from clkIO (datasheet p.164)
 
	ASSR &= ~(_BV(EXCLK) | _BV(AS2));
 

	
 
	// Set fast PWM mode with TOP = 0xff: WGM22:0 = 3  (p.150)
 
	TCCR2A |= _BV(WGM21) | _BV(WGM20);
 
	TCCR2B &= ~_BV(WGM22);
 
@@ -219,16 +220,8 @@ void afsk_setup()
 
	TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20);
 
	
 
	// Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163)
 
	//TIMSK2 |= _BV(TOIE2);
 
	TIMSK2 |= 0b00000001;
 
	
 
	// FIXME TODO
 
	DDRD = 0xff;
 
	PORTD = 0xff;
 
	
 
	// todo: init radio, maybe in main
 
	
 
	
 
	
 
	while(afsk_busy());
 
}
 
\ No newline at end of file
master/master/lib/aprs.c
Show inline comments
 
@@ -10,12 +10,13 @@
 
 *
 
 */
 
 
#include "../config.h"
 
#include "aprs.h"
 
#include "ax25.h"
 
#include "trackuinoGPS/gpsMKa.h"
 
#include <stdio.h>
 

	
 
const char *gps_aprs_lat = "39.74744N";
 
const char *gps_aprs_lon = "-83.81249W";
 
const char *gps_time = "081533/";
 
float gps_altitude = 123.5;
 
@@ -43,35 +44,39 @@ void aprs_send()
 
  };
 

	
 
	// emz: modified this to get the size of the first address rather than the size of the struct itself, which fails
 
  ax25_send_header(addresses, sizeof(addresses)/sizeof(addresses[0]));
 
  ax25_send_byte('/');                // Report w/ timestamp, no APRS messaging. $ = NMEA raw data
 
  // ax25_send_string("021709z");     // 021709z = 2nd day of the month, 17:09 zulu (UTC/GMT)
 
  ax25_send_string(gps_time);         // 170915 = 17h:09m:15s zulu (not allowed in Status Reports)
 
  ax25_send_string(get_timestamp());         // 170915 = 17h:09m:15s zulu (not allowed in Status Reports)
 
  ax25_send_byte('h');
 
  ax25_send_string(gps_aprs_lat);     // Lat: 38deg and 22.20 min (.20 are NOT seconds, but 1/100th of minutes)
 
  ax25_send_string(get_latitude());     // Lat: 38deg and 22.20 min (.20 are NOT seconds, but 1/100th of minutes)
 
  ax25_send_byte('/');                // Symbol table
 
  ax25_send_string(gps_aprs_lon);     // Lon: 000deg and 25.80 min
 
  ax25_send_string(get_longitude());     // Lon: 000deg and 25.80 min
 
  ax25_send_byte('O');                // Symbol: O=balloon, -=QTH
 
  snprintf(temp, 4, "%03d", (int)(gps_course + 0.5)); 
 
  ax25_send_string(temp);             // Course (degrees)
 
  ax25_send_byte('/');                // and
 
  snprintf(temp, 4, "%03d", (int)(gps_speed + 0.5));
 
  ax25_send_string(temp);             // speed (knots)
 
  //snprintf(temp, 4, "%03d", (int)(gps_speed + 0.5));
 
  ax25_send_string(get_speedKnots());             // speed (knots)
 
  
 
  /*
 
  ax25_send_string("/A=");            // Altitude (feet). Goes anywhere in the comment area
 
  snprintf(temp, 7, "%06ld", (long)(meters_to_feet(gps_altitude) + 0.5));
 
  ax25_send_string(temp);
 
  ax25_send_string("/Ti=");
 
  snprintf(temp, 6, "%d", 122);//sensors_int_lm60()); -- PUT SENSOR DATA HERE
 
  ax25_send_string(temp);
 
  ax25_send_string("/Te=");
 
  snprintf(temp, 6, "%d", 123);//sensors_ext_lm60());
 
  ax25_send_string(temp);
 
  ax25_send_string("/V=");
 
  snprintf(temp, 6, "%d", 123);//sensors_vin());
 
  ax25_send_string(temp);
 
  */
 
  
 
  ax25_send_byte(' ');
 
  ax25_send_string(APRS_COMMENT);     // Comment
 
  ax25_send_footer();
 

	
 
  ax25_flush_frame();                 // Tell the modem to go
 
}
master/master/lib/looptime.c
Show inline comments
 
@@ -17,14 +17,12 @@
 
#include <util/delay.h>
 
 
volatile uint32_t millis = 0; // Milliseconds since initialization
 

	
 
void time_setup() 
 
{
 
	DDRA = 0xff;
 
	
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
	TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well)
 
	TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64
 
	TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts
master/master/lib/serial.c
Show inline comments
 
@@ -33,18 +33,14 @@ void serial0_setup() {
 
	
 
	UCSR0B |= (1 << RXCIE0); // Enable interrupt
 
	
 
	//UCSR0A |= (1<<RXC0);
 
}
 
 
volatile uint8_t charTest;
 
 
ISR(USART1_RX_vect)
 
{
 
	serial1_sendChar(UDR1);
 
}
 
 
 
void serial1_setup() {
 
//PROVEN in test project
 
 
	/* Enable receiver and transmitter */
 
	UCSR1B |= (1<<RXEN1)|(1<<TXEN1); // Enable rx/tx
master/master/lib/trackuinoGPS/gpsMKa.c
Show inline comments
 
@@ -4,16 +4,37 @@
 
* Created: 11/15/2012 12:02:38 PM
 
*  Author: mkanning
 
*/
 
 
#include <stdbool.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "gpsMKa.h"
 
#include "../serial.h"
 
#include "../../config.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;
 
 

	
 
/*
 
volatile uint8_t charTest;
 
ISR(USART1_RX_vect)
 
{
 
	serial0_sendChar(UDR1);
 
	
 
}*/
 

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

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

	
 
@@ -22,31 +43,52 @@ 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[5];
 
uint8_t timestamp[9];	//hhmmss.ss
 
uint8_t latitude[8];	//lllll.lla
 
uint8_t longitude[8];	//yyyyy.yyb
 
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[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
 
char tramsmissionType[7];
 

	
 
char timestamp[12];	//hhmmss.ss
 
char* get_timestamp() {
 
	return timestamp;
 
}
 
	
 
char latitude[14];	//lllll.lla
 
char* get_latitude() {
 
	return latitude;
 
}
 

	
 
char longitude[14];	//yyyyy.yyb
 
char* get_longitude() {
 
	return longitude;
 
}
 

	
 

	
 
char quality;		//quality for GGA and validity for RMC
 
char numSatellites[3];
 
char hdop[6];		//xx.x
 
char altitude[10];	//xxxxxx.x
 
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 datestamp[9];	//ddmmyy
 
char variation[9];	//xxx.xb
 
int calculatedChecksum;
 
int receivedChecksum;
 

	
 
char convertBuf1[15];
 
char convertBuf2[15];
 

	
 
// 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
 
@@ -71,356 +113,515 @@ enum decodeState {
 
	RMC_DATE,
 
	RMC_MAG_VARIATION,
 
	
 
}decodeState;
 

	
 

	
 
char debugBuff[128];
 

	
 
ISR(USART1_RX_vect)
 
{
 
	nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = UDR1;
 
	nmeaBufferDataPosition = (nmeaBufferDataPosition + 1) % NMEABUFFER_SIZE;
 
	//serial0_sendChar(UDR1);
 
	//snprintf(debugBuff, 32, "GPS: bdp: %d, bpp: %d decodestate: %u \r\n", nmeaBufferDataPosition, nmeaBufferParsePosition, decodeState);
 
	//serial0_sendString((debugBuff));
 
}
 

	
 

	
 
// Could inline if program space available
 
static void setParserState(uint8_t state)
 
{
 
	decodeState = state;
 
 
	
 
	// If resetting, clear vars
 
	if(state == INITIALIZE)
 
	{
 
		calculatedChecksum = 0;
 
	}
 
	
 
	// Every time we change state, we have parsed a byte
 
	nmeaBufferParsePosition = (nmeaBufferParsePosition + 1) % NMEABUFFER_SIZE;
 
}
 

	
 

	
 

	
 
//// MKa GPS transmission parser START
 
void parse_gps_transmission(void){
 
	
 
	// Pull byte off of the buffer
 
	char byte = 'a';// serial1_readChar();
 
	char byte;
 
	
 
	while(nmeaBufferDataPosition != nmeaBufferParsePosition) {
 
		
 
		byte = nmeaBuffer[nmeaBufferParsePosition];
 
		
 
		//snprintf(debugBuff, 64, "GPSParse: byte [%c] decodestate: %u bp: %u pp: %u\r\n",  byte, decodeState, nmeaBufferDataPosition, nmeaBufferParsePosition);
 
		//serial0_sendString((debugBuff));
 
	
 
	if(byte == '$') //start of transmission sentence
 
		if(decodeState == INITIALIZE) //start of transmission sentence
 
	{
 
		decodeState = GET_TYPE;
 
			if(byte == '$') {
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found $\r\n");
 
				#endif
 
				
 
				setParserState(GET_TYPE);
 
		numBytes = 0; //prep for next phases
 
		skipBytes = 0;
 
		calculatedChecksum = 0;
 
	}
 
	
 
			else {
 
				setParserState(INITIALIZE);
 
			}
 
		}
 
	
 
	//parse transmission type
 
	else if (decodeState == GET_TYPE)
 
	{
 
		tramsmissionType[numBytes] = byte;
 
		numBytes++;
 
		
 
			#ifdef DEBUG_NMEA
 
			serial0_sendString("stored a type byte\r\n");
 
			#endif
 
			
 
		if(byte == ',') //end of this data type
 
		{
 
				tramsmissionType[5] = 0x00;
 
				
 
			if (tramsmissionType[2] == 'G' &&
 
			tramsmissionType[3] == 'G' &&
 
			tramsmissionType[4] == 'A')
 
			{
 
				decodeState = GGA_TIME;
 
					setParserState(GGA_TIME);
 
					numBytes = 0;
 
			}
 
			else if (tramsmissionType[2] == 'R' &&
 
			tramsmissionType[3] == 'M' &&
 
			tramsmissionType[4] == 'C')
 
			{
 
				decodeState = RMC_TIME;
 
					setParserState(RMC_TIME);
 
					numBytes = 0;
 
			}
 
			else //this is an invalid transmission type
 
			{
 
				decodeState = INITIALIZE;
 
					setParserState(INITIALIZE);
 
			}
 
		}
 
			else {
 
				// continue
 
				setParserState(GET_TYPE);
 
			}
 
			
 
	}
 
	
 
	///parses GGA transmissions START
 
	/// $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*xx
 
	//timestamp
 
	else if (decodeState == GGA_TIME)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_LATITUDE;
 
				timestamp[6] = 0x00; // Cut off at 6 for APRS
 
				serial0_sendString("time byte DONE\r\n");
 
				setParserState(GGA_LATITUDE);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			timestamp[numBytes] = byte; //adjust number of bytes to fit array
 
				//#ifdef DEBUG_NMEA
 
				serial0_sendString("found GGA time byte\r\n");
 
				//#endif
 
				
 
				setParserState(GGA_TIME);
 
				timestamp[numBytes] = byte; //byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	
 
	//latitude
 
	else if (decodeState == GGA_LATITUDE)
 
	{
 
		if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat skip byte\r\n");
 
				#endif
 
				
 
			skipBytes = 1;
 
				setParserState(GGA_LATITUDE);
 
		}
 
		else if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_LONGITUDE;
 
				
 
				latitude[numBytes] = 0x00; // null terminate
 
				
 
				
 
				// First 2 bytes
 
				//convertBuf1[0] = latitude[0];
 
				//convertBuf1[1] = latitude[1];
 
				//convertBuf1[2] = '\0';
 
				//strncpy(convertBuf2, latitude, 7);
 
				//convertBuf2[7] = '\0';
 
				
 
				
 
				setParserState(GGA_LONGITUDE);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat byte\r\n");
 
				#endif
 
				
 
			latitude[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_LATITUDE);
 
		}
 
	}
 
	
 
	//longitude
 
	else if (decodeState == GGA_LONGITUDE)
 
	{
 
		if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found long skip byte\r\n");
 
				#endif
 
				
 
			skipBytes = 1;
 
				setParserState(GGA_LONGITUDE);
 
		}
 
		else if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_QUALITY;
 
				longitude[numBytes] = 0x00;
 
				setParserState(GGA_QUALITY);
 
			numBytes = 0; //prep for next phase of parse
 
			skipBytes = 0;
 
		}
 
		else //store data
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found long byte\r\n");
 
				#endif
 
				
 
			longitude[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_LONGITUDE);
 
		}
 
	}
 
	
 
	//GGA quality
 
	else if (decodeState == GGA_QUALITY)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_SATELLITES;
 
				setParserState(GGA_SATELLITES);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found quality byte\r\n");
 
				#endif
 
				
 
			quality = byte; //maybe reset if invalid data ??
 
				setParserState(GGA_QUALITY);
 
		}
 
	}
 
	
 
	//number of satellites
 
	else if (decodeState == GGA_SATELLITES)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_HDOP;
 
				numSatellites[numBytes] = 0x00;
 
				setParserState(GGA_HDOP);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
			numSatellites[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_SATELLITES);
 
		}
 
	}
 
	
 
	//HDOP
 
	else if (decodeState == GGA_HDOP)
 
	{
 
		if (byte == ',' ) //end of this data type
 
		{
 
			decodeState = GGA_ALTITUDE;
 
				hdop[numBytes] = 0x00;
 
				setParserState(GGA_ALTITUDE);
 
			numBytes = 0; //prep for next phase of parse
 
			skipBytes = 0;
 
		}
 
		else //store data
 
		{
 
			hdop[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_HDOP);
 
		}
 
	}
 
	
 
	//altitude
 
	else if (decodeState == GGA_ALTITUDE)
 
	{
 
		if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
			skipBytes = 1;
 
				setParserState(GGA_ALTITUDE);
 
		}
 
		else if(byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_WGS84;
 
				altitude[numBytes] = 0x00;
 
				setParserState(GGA_WGS84);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
			altitude[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_ALTITUDE);
 
		}
 
	}
 
	
 
	//WGS84 Height
 
	else if (decodeState == GGA_WGS84)
 
	{
 
		if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
			skipBytes = 1;
 
				setParserState(GGA_WGS84);
 
		}
 
		else if(byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_LAST_UPDATE;
 
				wgs84Height[numBytes] = 0x00;
 
				setParserState(GGA_LAST_UPDATE);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			wgs84Height[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_WGS84);
 
		}
 
	}
 
	
 
	//last GGA DGPS update
 
	else if (decodeState == GGA_LAST_UPDATE)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = GGA_STATION_ID;
 
				lastUpdated[numBytes] = 0x00;
 
				setParserState(GGA_STATION_ID);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data - this should be blank
 
		{
 
			lastUpdated[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_LAST_UPDATE);
 
		}
 
	}
 
	
 
	//GGA DGPS station ID
 
	else if (decodeState == GGA_STATION_ID)
 
	{
 
		if (byte == ',' || byte == '*') //end of this data type
 
		{
 
			decodeState = GPS_CHECKSUM;
 
				stationID[numBytes] = 0x00;
 
				setParserState(GPS_CHECKSUM);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data - this should be blank
 
		{
 
			stationID[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(GGA_STATION_ID);
 
		}
 
	}
 
	///parses GGA transmissions END
 
	
 
	/// $GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
 
	///parses RMC transmissions
 
	//time
 
		// emz: commented setter, GMC time better?
 
	else if(decodeState == RMC_TIME)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_VALIDITY;
 
				//timestamp[numBytes] = 0x00;
 
				setParserState(RMC_VALIDITY);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
			timestamp[numBytes] = byte; //adjust number of bytes to fit array
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found time byte\r\n");
 
				#endif
 
				
 
				//timestamp[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(RMC_TIME);
 
		}
 
	}
 
	
 
	//validity
 
		// not needed? dupe gga
 
	else if(decodeState == RMC_VALIDITY)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_LATITUDE;
 
				setParserState(RMC_LATITUDE);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			quality = byte;
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found valid byte\r\n");
 
				#endif
 
				
 
				//quality = byte;
 
			numBytes++;
 
				setParserState(RMC_VALIDITY);
 
		}
 
	}
 
	
 
	//latitude
 
		//latitude RMC (we don't need this, commented out setter)
 
	else if(decodeState == RMC_LATITUDE)
 
	{
 
		if (byte == ',' && skipBytes == 1) //discard this byte
 
			if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat skip byte\r\n");
 
				#endif
 
				
 
			skipBytes = 1; 
 
				setParserState(RMC_LATITUDE);
 
		}
 
		else if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_LONGITUDE;
 
				setParserState(RMC_LONGITUDE);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			latitude[numBytes]= byte; //adjust number of bytes to fit array
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat byte\r\n");
 
				#endif
 
				
 
				//latitude[numBytes]= byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(RMC_LATITUDE);
 
		}
 
	}
 
	
 
	//longitude
 
		//longitude RMC (we don't need this, commented out setter)
 
	else if(decodeState == RMC_LONGITUDE)
 
	{
 
		if (byte == ',' && skipBytes == 1) //discard this byte
 
			if (byte == ',' && skipBytes == 0) //discard this byte
 
		{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found long byte\r\n");
 
				#endif
 
				
 
			skipBytes = 1; 
 
				setParserState(RMC_LONGITUDE);
 
		}
 
		else if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_KNOTS;
 
				setParserState(RMC_KNOTS);
 
			skipBytes = 0;
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
			longitude[numBytes]= byte; //adjust number of bytes to fit array
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found long byte\r\n");
 
				#endif
 
				
 
				//longitude[numBytes]= byte; //adjust number of bytes to fit array
 
			numBytes++;
 
				setParserState(RMC_LONGITUDE);
 
		}
 
	}
 
	
 
	//knots
 
	else if(decodeState == RMC_KNOTS)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_COURSE;
 
				knots[numBytes] = 0x00;
 
				setParserState(RMC_COURSE);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
				setParserState(RMC_KNOTS);
 
			knots[numBytes]= byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	
 
	//course
 
	else if(decodeState == RMC_COURSE)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_DATE;
 
				course[numBytes] = 0x00;
 
				setParserState(RMC_DATE);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
				setParserState(RMC_COURSE);
 
			course[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	
 
	//date
 
	else if(decodeState == RMC_DATE)
 
	{
 
		if (byte == ',') //end of this data type
 
		{
 
			decodeState = RMC_MAG_VARIATION;
 
				datestamp[numBytes] = 0x00;
 
				setParserState(RMC_MAG_VARIATION);
 
			skipBytes = 0; //prep for next phase of parse
 
			numBytes = 0;
 
		}
 
		else //store data
 
		{
 
				setParserState(RMC_DATE);
 
			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
 
		{
 
			decodeState = GPS_CHECKSUM;
 
				variation[numBytes] = 0x00;
 
				setParserState(GPS_CHECKSUM);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
				setParserState(RMC_MAG_VARIATION);
 
			variation[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
	///parses RMC transmissions END
 
	
 
@@ -438,29 +639,39 @@ void parse_gps_transmission(void){
 
				
 
			}
 
			else
 
			{
 
				
 
			}
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("OMG GOT TO CHECKSUM!\r\n");
 
				#endif
 
			
 
			decodeState = INITIALIZE;
 
				snprintf(debugBuff, 128, "\r\n\r\ntype: %s tstamp: %s lat: %s lon: %s speed: %s hdop: %s course: %s \r\n\r\n",
 
				tramsmissionType,timestamp,latitude,longitude,knots,hdop, course);
 
				serial0_sendString((debugBuff));
 
				setParserState(INITIALIZE);
 
			numBytes = 0; //prep for next phase of parse
 
		}
 
		else //store data
 
		{
 
				setParserState(GPS_CHECKSUM);
 
			checksum[numBytes] = byte; //adjust number of bytes to fit array
 
			numBytes++;
 
		}
 
	}
 
		else {
 
			setParserState(INITIALIZE);
 
		}
 
	
 
	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
master/master/lib/trackuinoGPS/gpsMKa.h
Show inline comments
 
@@ -9,7 +9,12 @@
 
#ifndef GPSMKA_H_
 
#define GPSMKA_H_
 
#define GGA_MESSAGE
 
#define RMC_MESSAGE
 
#define UKN_MESSAGE
 
 
char* get_longitude();
 
char* get_latitude();
 
char* get_timestamp();
 
char* get_speedKnots();
 
 
#endif /* GPSMKA_H_ */
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -21,16 +21,20 @@
 
#include <stdbool.h>
 

	
 
#include "lib/serial.h"
 
#include "lib/aprs.h"
 
#include "lib/afsk.h"
 
#include "lib/led.h"
 
//#include "lib/logger.h"
 
#include "lib/logger.h"
 
#include "lib/watchdog.h"
 
//!
 
#include "lib/sd/sd_raw_config.h"
 

	
 
#include "lib/trackuinoGPS/gpsMKa.h"
 

	
 
#include "lib/i2c.h"
 
#include "lib/boardtemp.h"
 

	
 
#include "lib/looptime.h"
 
#include "lib/slavesensors.h"
 
#include "lib/serparser.h"
 
#include "lib/sensordata.h"
 

	
 
void micro_setup() 
 
@@ -52,29 +56,31 @@ int main(void)
 
	
 
	serial0_setup();
 
	_delay_ms(10);
 
	
 
	serial1_setup();
 
	
 
	i2c_init(); // for board temp
 

	
 
	sensordata_setup(); // must happen before sensors/logger/afsk
 
	slavesensors_setup();
 
	logger_setup();
 
	
 
	afsk_setup();
 

	
 
	serial0_sendString("\r\n\r\n---------------------------------\r\n");
 
	serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
 
	serial0_sendString("---------------------------------\r\n\r\n");
 
	serial0_sendString("\f\r\n\r\Hello.\r\n\r\n");
 
	serial0_sendString("\f\r\n\rHello.\r\n\r\n");
 
	
 
	led_on(LED_POWER);
 
	led_off(LED_SIDEBOARD);
 

	
 
	
 
	// Buffer for string operations
 
	char logbuf[16];
 
	char logbuf[32];
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	
 
@@ -122,26 +128,30 @@ int main(void)
 
			lastLedCycle = time_millis();	
 
		}
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			
 
			led_on(LED_STATUS);
 
			snprintf(logbuf, 16, "%lu,%d,\r\n", time_millis(), sensordata_get(HUMIDITY));
 
			sensors_readBoardTemp(); // i2c read, 400k
 
			snprintf(logbuf, 32, "%lu,%d,%uF\r\n", time_millis(), sensordata_get(HUMIDITY), sensors_getBoardTemp());
 
			logger_log(logbuf);
 
			//serial0_sendString("Logging: ");
 
			//serial0_sendString(logbuf);
 
			led_off(LED_STATUS);
 
			
 
			lastLog = time_millis();
 
		}		
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			
 
			
 
			serial0_sendString(":: APRS Periodic\r\n");
 
			
 
			while(afsk_busy());
 
			aprs_send(); // non-blocking
 
			
 
			//serial0_sendString("Initiating APRS transmission...\r\n");
 
@@ -158,13 +168,11 @@ int main(void)
 
			
 
			lastAprsBroadcast = time_millis();
 
		}			
 
		
 

	
 
		parseResult = serparser_parse();
 
		
 

	
 
		slavesensors_process(parseResult);
 

	
 
		parse_gps_transmission();
 
		wdt_reset();
 
    }
 
}
 
\ No newline at end of file
master/master/master.cproj
Show inline comments
 
@@ -129,12 +129,24 @@
 
    <Compile Include="lib\ax25.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\ax25.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\boardtemp.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\boardtemp.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\i2c.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\i2c.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
0 comments (0 inline, 0 general)