QRSS Rx Network receiver. A receiver to sample a segment of RF spectrum and send this data to a server for further processing and display. NXP mbed Design Challenge entry (Honorable Mention). Published in Circuit Cellar, Feb 2012

Dependencies:   NetServices mbed DNSResolver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gps.h Source File

gps.h

00001 /*---------------------------------------------------------------------------
00002 
00003     QRSS Receiver Application
00004         
00005     by Clayton ZL3TKA/VK1TKA
00006     clayton@isnotcrazy.com
00007 
00008     Header File for GPS Module
00009 
00010 ---------------------------------------------------------------------------*/
00011 #ifndef _GPS_H
00012 #define _GPS_H
00013 
00014 #include "mbed.h"
00015 
00016 // Definitions
00017 
00018 #define GPS_FIELDLEN        20
00019 #define GPS_LINELENGTH      200
00020 #define GPS_MSGTIMEOUT      3000        // GPS message timeout (mSecs)
00021 #define GPS_PULSETIMEOUT    1500        // GPS pulse timeout (mSecs)
00022 
00023 // comments
00024 
00025 // Macros
00026 
00027 //
00028 // Classes
00029 //
00030 
00031 //---------------------------------------------------------------------------
00032 //
00033 //  GPS Module Class
00034 //
00035 class TGPSController
00036 {
00037     // create/destroy
00038     public:
00039         TGPSController();
00040         ~TGPSController() {}
00041 
00042     // public type - GPS data
00043     public:
00044         typedef struct _gpsdata
00045         {
00046             int32_t     iGPSQuality;
00047             int32_t     iGPSSatellites;
00048             int32_t     iGPSTimeSeconds;
00049             int32_t     iGPSLatMicroDegrees;
00050             int32_t     iGPSLongMicroDegrees;
00051             int32_t     iGPSAltitudeMeters;
00052         } TGPSData;
00053 
00054     // local type - for parsing message numbers
00055     private:
00056         typedef struct _parsenumber
00057         {
00058             uint32_t    uiNumber;
00059             int         iNumberLen;
00060             int         iNumberSign;
00061             int         iNumberDecimals;
00062         } TParsedNum;
00063 
00064     // API
00065     public:
00066         // Initi8alise routine
00067         void Init();
00068 
00069         // Processing routine
00070         void Poll();
00071 
00072         // Return the last line from the GPS
00073         const char * LastLine()
00074             { return szLastLine; }
00075         
00076         // indicate a new last line has been received from the GPS unit
00077         //  Self resetting
00078         bool NewLine()
00079             {
00080                 bool bRet = bNewLine;
00081                 bNewLine = false;
00082                 return bRet;
00083             }
00084 
00085         // Get GPS Data
00086         //  Returns status value (0=offline)
00087         int GPSData( TGPSData &GPSDat )
00088             { GPSDat = GPSRecord;
00089               return GPSDat.iGPSQuality; }
00090 
00091     // Private methods
00092     private:
00093         // callback on 1PPS rising edge
00094         void PPSPulse();
00095 
00096         // Parse a number
00097         bool ParseNumber( char cChr );
00098         void ResetNumber();
00099 
00100         // Parse data from the GPS
00101         //  Return true if a completed valid sentence is received
00102         bool ParseData( char cChr );
00103 
00104         //  Process the data from the GPS message
00105         //      Returns 0 if all data is good, or an error code
00106         //      Call after a valid ParseData has occurred
00107         int ProcessGPSData();
00108 
00109     // data
00110     private:
00111         // 1PPS pin
00112         DigitalIn   PPSInput;
00113 
00114         // GPS Serial Port
00115         Serial      GPSPort;
00116         
00117         // GPS Status LED
00118         DigitalOut  GPSUpLED;
00119 
00120         // Interrupt on 1PPS pulse
00121         InterruptIn PPSEvent;        
00122         
00123         // 1PPS flag and captured timer registers
00124         bool        bPulsed;
00125         uint32_t    uiPPSCapture;
00126         uint32_t    uiLOscCapture;
00127 
00128         // GPS data timeout timer
00129         Timer       GPSMsgTimeout;
00130         Timer       GPSPulseTimeout;
00131 
00132         // Parsing data and resulting values
00133         int         iParseState;
00134         TParsedNum  ParseNum;
00135         char        cCharacter;
00136         
00137         // last line variables
00138         char        szCurrentLine[GPS_LINELENGTH+1];
00139         char        szLastLine[GPS_LINELENGTH+1];
00140         bool        bNewLine;
00141 
00142         // GPS message data - raw data from message
00143         TParsedNum  GPSTime;
00144         TParsedNum  GPSLatitude;
00145         char        GPSLatNS;
00146         TParsedNum  GPSLongitude;
00147         char        GPSLongEW;
00148         TParsedNum  GPSQuality;
00149         TParsedNum  GPSSatellites;
00150         TParsedNum  GPSDOP;
00151         TParsedNum  GPSAltitude;
00152         char        GPSAltType;
00153         TParsedNum  GPSHeight;
00154         char        GPSHeightType;
00155         uint8_t     ucMsgChecksum;
00156         uint8_t     ucFinalChecksum;
00157         uint8_t     ucChecksum;
00158 
00159         // Final GPS info (validated)        
00160         TGPSData    GPSRecord;
00161 };
00162 
00163 // declare the GPS module
00164 extern TGPSController GPSModule;
00165 
00166 #endif
00167 
00168 //---------------------------------------------------------------------------
00169 //  END
00170 //---------------------------------------------------------------------------
00171