# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-01-10 21:58:42 # Node ID 0062f8daffe7ce8ba9103465e0f6f7b3f68c6a28 # Parent e5c11279c2a031ff0b6570d8ccca42b3f8d6fbf2 GPS parser now functional, APRS is now broadcasted with possibly correct position information diff --git a/master/master/config.h b/master/master/config.h --- a/master/master/config.h +++ b/master/master/config.h @@ -19,7 +19,7 @@ #define F_CPU 11059200 #define MODULE_ID '1' - +#define BOARDTEMP_ADDR 0x90 // -------------------------------------------------------------------------- // Error Codes config (led.c, used throughout code) @@ -62,12 +62,18 @@ // 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 // -------------------------------------------------------------------------- @@ -112,7 +118,7 @@ #define APRS_COMMENT "CedarvilleUniversity HAB" // Transmit the APRS sentence every X milliseconds -#define APRS_TRANSMIT_PERIOD 10000 +#define APRS_TRANSMIT_PERIOD 5000 // -------------------------------------------------------------------------- diff --git a/master/master/lib/afsk.c b/master/master/lib/afsk.c --- a/master/master/lib/afsk.c +++ b/master/master/lib/afsk.c @@ -204,7 +204,8 @@ void afsk_send(const uint8_t *buffer, in void afsk_setup() { - + DDRA |= 0b00100000; + DDRD |= 0b10000000; // Source timer2 from clkIO (datasheet p.164) ASSR &= ~(_BV(EXCLK) | _BV(AS2)); @@ -222,13 +223,5 @@ void afsk_setup() //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 diff --git a/master/master/lib/aprs.c b/master/master/lib/aprs.c --- a/master/master/lib/aprs.c +++ b/master/master/lib/aprs.c @@ -13,6 +13,7 @@ #include "../config.h" #include "aprs.h" #include "ax25.h" +#include "trackuinoGPS/gpsMKa.h" #include const char *gps_aprs_lat = "39.74744N"; @@ -46,17 +47,19 @@ void aprs_send() 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); @@ -69,6 +72,8 @@ void aprs_send() 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(); diff --git a/master/master/lib/looptime.c b/master/master/lib/looptime.c --- a/master/master/lib/looptime.c +++ b/master/master/lib/looptime.c @@ -20,8 +20,6 @@ volatile uint32_t millis = 0; // Millise void time_setup() { - DDRA = 0xff; - // Generic microcontroller config options OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler diff --git a/master/master/lib/serial.c b/master/master/lib/serial.c --- a/master/master/lib/serial.c +++ b/master/master/lib/serial.c @@ -36,12 +36,8 @@ void serial0_setup() { //UCSR0A |= (1< #include +#include #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; @@ -25,25 +46,46 @@ 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 @@ -74,390 +116,559 @@ enum decodeState { }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; - if(byte == '$') //start of transmission sentence - { - decodeState = GET_TYPE; - numBytes = 0; //prep for next phases - skipBytes = 0; - calculatedChecksum = 0; - } + 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(decodeState == INITIALIZE) //start of transmission sentence + { + 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++; - - if(byte == ',') //end of this data type + //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') + { + setParserState(GGA_TIME); + numBytes = 0; + } + else if (tramsmissionType[2] == 'R' && + tramsmissionType[3] == 'M' && + tramsmissionType[4] == 'C') + { + setParserState(RMC_TIME); + numBytes = 0; + } + else //this is an invalid transmission type + { + 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 (tramsmissionType[2] == 'G' && - tramsmissionType[3] == 'G' && - tramsmissionType[4] == 'A') + if (byte == ',') //end of this data type + { + 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 + { + //#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 + { + + 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 { - decodeState = GGA_TIME; + #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 (tramsmissionType[2] == 'R' && - tramsmissionType[3] == 'M' && - tramsmissionType[4] == 'C') + else if (byte == ',') //end of this data type + { + 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 + { + setParserState(GGA_SATELLITES); + numBytes = 0; //prep for next phase of parse + } + else //store data { - decodeState = RMC_TIME; + #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 + { + 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); } - else //this is an invalid transmission type + } + + //HDOP + else if (decodeState == GGA_HDOP) + { + if (byte == ',' ) //end of this data type + { + hdop[numBytes] = 0x00; + setParserState(GGA_ALTITUDE); + numBytes = 0; //prep for next phase of parse + skipBytes = 0; + } + else //store data { - decodeState = INITIALIZE; + 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 + { + 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); } } - } - - ///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; - skipBytes = 0; //prep for next phase of parse - numBytes = 0; - } - else //store data - { - timestamp[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; - } - } - - //latitude - else if (decodeState == GGA_LATITUDE) - { - if (byte == ',' && skipBytes == 0) //discard this byte - { - skipBytes = 1; - } - else if (byte == ',') //end of this data type - { - decodeState = GGA_LONGITUDE; - skipBytes = 0; //prep for next phase of parse - numBytes = 0; - } - else //store data - { - latitude[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; - } - } - - //longitude - else if (decodeState == GGA_LONGITUDE) - { - if (byte == ',' && skipBytes == 0) //discard this byte - { - skipBytes = 1; - } - else if (byte == ',') //end of this data type - { - decodeState = GGA_QUALITY; - numBytes = 0; //prep for next phase of parse - skipBytes = 0; - } - else //store data - { - longitude[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; - } - } - - //GGA quality - else if (decodeState == GGA_QUALITY) - { - if (byte == ',') //end of this data type - { - decodeState = GGA_SATELLITES; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - quality = byte; //maybe reset if invalid data ?? - } - } - //number of satellites - else if (decodeState == GGA_SATELLITES) - { - if (byte == ',') //end of this data type - { - decodeState = GGA_HDOP; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - numSatellites[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; - } - } - - //HDOP - else if (decodeState == GGA_HDOP) - { - if (byte == ',' ) //end of this data type - { - decodeState = 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++; - } - } - - //altitude - else if (decodeState == GGA_ALTITUDE) - { - if (byte == ',' && skipBytes == 0) //discard this byte - { - skipBytes = 1; - } - else if(byte == ',') //end of this data type + //WGS84 Height + else if (decodeState == GGA_WGS84) { - decodeState = GGA_WGS84; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - altitude[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; + if (byte == ',' && skipBytes == 0) //discard this byte + { + skipBytes = 1; + setParserState(GGA_WGS84); + } + else if(byte == ',') //end of this data type + { + 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); + } } - } - //WGS84 Height - else if (decodeState == GGA_WGS84) - { - if (byte == ',' && skipBytes == 0) //discard this byte - { - skipBytes = 1; - } - else if(byte == ',') //end of this data type + //last GGA DGPS update + else if (decodeState == GGA_LAST_UPDATE) { - decodeState = 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++; + if (byte == ',') //end of this data type + { + 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); + } } - } - //last GGA DGPS update - else if (decodeState == GGA_LAST_UPDATE) - { - if (byte == ',') //end of this data type - { - decodeState = GGA_STATION_ID; - numBytes = 0; //prep for next phase of parse - } - else //store data - this should be blank + //GGA DGPS station ID + else if (decodeState == GGA_STATION_ID) { - lastUpdated[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; - } - } - - //GGA DGPS station ID - else if (decodeState == GGA_STATION_ID) - { - if (byte == ',' || byte == '*') //end of this data type - { - decodeState = 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++; + if (byte == ',' || byte == '*') //end of this data type + { + 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 + ///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 - else if(decodeState == RMC_TIME) - { - if (byte == ',') //end of this data type - { - decodeState = RMC_VALIDITY; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - timestamp[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; + /// $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 + { + //timestamp[numBytes] = 0x00; + setParserState(RMC_VALIDITY); + numBytes = 0; //prep for next phase of parse + } + else //store data + { + #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 - else if(decodeState == RMC_VALIDITY) - { - if (byte == ',') //end of this data type - { - decodeState = RMC_LATITUDE; - skipBytes = 0; //prep for next phase of parse - numBytes = 0; - } - else //store data - { - quality = byte; - numBytes++; + //validity + // not needed? dupe gga + else if(decodeState == RMC_VALIDITY) + { + if (byte == ',') //end of this data type + { + setParserState(RMC_LATITUDE); + skipBytes = 0; //prep for next phase of parse + numBytes = 0; + } + else //store data + { + #ifdef DEBUG_NMEA + serial0_sendString("found valid byte\r\n"); + #endif + + //quality = byte; + numBytes++; + setParserState(RMC_VALIDITY); + } } - } - //latitude - else if(decodeState == RMC_LATITUDE) - { - if (byte == ',' && skipBytes == 1) //discard this byte - { - skipBytes = 1; - } - else if (byte == ',') //end of this data type - { - decodeState = 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 - numBytes++; + //latitude RMC (we don't need this, commented out setter) + else if(decodeState == RMC_LATITUDE) + { + 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 + { + setParserState(RMC_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(RMC_LATITUDE); + } } - } - //longitude - else if(decodeState == RMC_LONGITUDE) - { - if (byte == ',' && skipBytes == 1) //discard this byte - { - skipBytes = 1; - } - else if (byte == ',') //end of this data type - { - decodeState = RMC_KNOTS; - skipBytes = 0; - numBytes = 0; - } - else //store data - { - longitude[numBytes]= byte; //adjust number of bytes to fit array - numBytes++; + //longitude RMC (we don't need this, commented out setter) + else if(decodeState == RMC_LONGITUDE) + { + 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 + { + setParserState(RMC_KNOTS); + skipBytes = 0; + numBytes = 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(RMC_LONGITUDE); + } } - } - //knots - else if(decodeState == RMC_KNOTS) - { - if (byte == ',') //end of this data type - { - decodeState = RMC_COURSE; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - knots[numBytes]= byte; //adjust number of bytes to fit array - numBytes++; + //knots + else if(decodeState == RMC_KNOTS) + { + if (byte == ',') //end of this data type + { + 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; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - course[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; + //course + else if(decodeState == RMC_COURSE) + { + if (byte == ',') //end of this data type + { + 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; - skipBytes = 0; //prep for next phase of parse - numBytes = 0; - } - else //store data - { - datestamp[numBytes] = byte; //adjust number of bytes to fit array - numBytes++; + //date + else if(decodeState == RMC_DATE) + { + if (byte == ',') //end of this data type + { + 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; - numBytes = 0; //prep for next phase of parse - } - else //store data - { - variation[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 + { + 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 + ///parses RMC transmissions END - //checksum - else if (decodeState == GPS_CHECKSUM) - { - if (numBytes == 2) //end of data - terminating character ?? + //checksum + else if (decodeState == GPS_CHECKSUM) { - //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) + 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 - { + } + else + { + } + #ifdef DEBUG_NMEA + serial0_sendString("OMG GOT TO CHECKSUM!\r\n"); + #endif + + 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 } - - decodeState = INITIALIZE; - numBytes = 0; //prep for next phase of parse - } - else //store data + 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 '*' { - 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 diff --git a/master/master/lib/trackuinoGPS/gpsMKa.h b/master/master/lib/trackuinoGPS/gpsMKa.h --- a/master/master/lib/trackuinoGPS/gpsMKa.h +++ b/master/master/lib/trackuinoGPS/gpsMKa.h @@ -12,4 +12,9 @@ #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 diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -24,10 +24,14 @@ #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" @@ -55,23 +59,25 @@ int main(void) 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; @@ -125,8 +131,10 @@ int main(void) // 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); @@ -139,6 +147,8 @@ int main(void) // Periodic: APRS transmission if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) { + + serial0_sendString(":: APRS Periodic\r\n"); while(afsk_busy()); @@ -161,10 +171,8 @@ int main(void) parseResult = serparser_parse(); - - slavesensors_process(parseResult); - + parse_gps_transmission(); wdt_reset(); } } \ No newline at end of file diff --git a/master/master/master.cproj b/master/master/master.cproj --- a/master/master/master.cproj +++ b/master/master/master.cproj @@ -132,6 +132,18 @@ compile + + compile + + + compile + + + compile + + + compile + compile