Main Page   Data Structures   File List   Data Fields   Globals  

nmea.c

Go to the documentation of this file.
00001 /*! \file nmea.c \brief NMEA protocol function library. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'nmea.c'
00005 // Title        : NMEA protocol function library
00006 // Author       : Pascal Stang - Copyright (C) 2002
00007 // Created      : 2002.08.27
00008 // Revised      : 2002.08.27
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 #ifndef WIN32
00023     #include <avr/io.h>
00024     #include <avr/signal.h>
00025     #include <avr/interrupt.h>
00026     #include <avr/progmem.h>
00027     #include <string.h>
00028 #endif
00029 
00030 #include "global.h"
00031 #include "buffer.h"
00032 #include "rprintf.h"
00033 #include "uart2.h"
00034 #include "gps.h"
00035 
00036 #include "nmea.h"
00037 
00038 // Program ROM constants
00039 
00040 // Global variables
00041 extern GpsInfoType GpsInfo;
00042 #define BUFFERSIZE 80
00043 u08 NmeaPacket[BUFFERSIZE];
00044 u08 debug;
00045 
00046 void nmeaInit(void)
00047 {
00048     debug = 1;
00049 }
00050 
00051 u08 nmeaProcess(cBuffer* rxBuffer)
00052 {
00053     u08 foundpacket = FALSE;
00054     u08 startFlag = FALSE;
00055     //u08 data;
00056     u08 i,j;
00057 
00058     // process the receive buffer
00059     // go through buffer looking for packets
00060     while(rxBuffer->datalength)
00061     {
00062         // look for a start of NMEA packet
00063         if(bufferGetAtIndex(rxBuffer,0) == '$')
00064         {
00065             // found start
00066             startFlag = TRUE;
00067             // done looking for start
00068             break;
00069         }
00070         else
00071             bufferGetFromFront(rxBuffer);
00072     }
00073     
00074     // if we detected a start, look for end of packet
00075     if(startFlag)
00076     {
00077         for(i=1; i<(rxBuffer->datalength)-1; i++)
00078         {
00079             // check for end of NMEA packet <CR><LF>
00080             if((bufferGetAtIndex(rxBuffer,i) == '\r') && (bufferGetAtIndex(rxBuffer,i+1) == '\n'))
00081             {
00082                 // have a packet end
00083                 // dump initial '$'
00084                 bufferGetFromFront(rxBuffer);
00085                 // copy packet to NmeaPacket
00086                 for(j=0; j<(i-1); j++)
00087                     NmeaPacket[j] = bufferGetFromFront(rxBuffer);
00088                 // dump <CR><LF> from rxBuffer
00089                 bufferGetFromFront(rxBuffer);
00090                 bufferGetFromFront(rxBuffer);
00091 
00092                 if(debug)
00093                 {
00094                     rprintf("Rx NMEA packet type: ");
00095                     rprintfStrLen(NmeaPacket, 0, 5);
00096                     rprintfCRLF();
00097                     rprintfStrLen(NmeaPacket, 6, (i-1)-6);
00098                     rprintfCRLF();
00099                 }
00100                 // found a packet
00101                 // done with this processing session
00102                 foundpacket = TRUE;
00103                 break;
00104             }
00105         }
00106     }
00107 
00108     if(foundpacket)
00109     {
00110         // check message type and process appropriately
00111         if(strncmp(NmeaPacket, "GPGGA", 5))
00112             nmeaProcessGPGGA(NmeaPacket);
00113         else if(strncmp(NmeaPacket, "GPVTG", 5))
00114             nmeaProcessGPVTG(NmeaPacket);
00115     }
00116     return foundpacket;
00117 }
00118 
00119 void nmeaProcessGPGGA(u08* packet)
00120 {
00121     PORTC = ~(1<<0);
00122     
00123 }
00124 
00125 void nmeaProcessGPVTG(u08* packet)
00126 {
00127     PORTC = ~(1<<1);
00128 }
00129 

Generated on Tue Feb 4 20:18:37 2003 for Procyon AVRlib by doxygen1.3-rc2