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
gps.h@0:82ff15078322, 2012-01-25 (annotated)
- Committer:
- claytong
- Date:
- Wed Jan 25 20:32:53 2012 +0000
- Revision:
- 0:82ff15078322
1.0 (initial public release)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
claytong | 0:82ff15078322 | 1 | /*--------------------------------------------------------------------------- |
claytong | 0:82ff15078322 | 2 | |
claytong | 0:82ff15078322 | 3 | QRSS Receiver Application |
claytong | 0:82ff15078322 | 4 | |
claytong | 0:82ff15078322 | 5 | by Clayton ZL3TKA/VK1TKA |
claytong | 0:82ff15078322 | 6 | clayton@isnotcrazy.com |
claytong | 0:82ff15078322 | 7 | |
claytong | 0:82ff15078322 | 8 | Header File for GPS Module |
claytong | 0:82ff15078322 | 9 | |
claytong | 0:82ff15078322 | 10 | ---------------------------------------------------------------------------*/ |
claytong | 0:82ff15078322 | 11 | #ifndef _GPS_H |
claytong | 0:82ff15078322 | 12 | #define _GPS_H |
claytong | 0:82ff15078322 | 13 | |
claytong | 0:82ff15078322 | 14 | #include "mbed.h" |
claytong | 0:82ff15078322 | 15 | |
claytong | 0:82ff15078322 | 16 | // Definitions |
claytong | 0:82ff15078322 | 17 | |
claytong | 0:82ff15078322 | 18 | #define GPS_FIELDLEN 20 |
claytong | 0:82ff15078322 | 19 | #define GPS_LINELENGTH 200 |
claytong | 0:82ff15078322 | 20 | #define GPS_MSGTIMEOUT 3000 // GPS message timeout (mSecs) |
claytong | 0:82ff15078322 | 21 | #define GPS_PULSETIMEOUT 1500 // GPS pulse timeout (mSecs) |
claytong | 0:82ff15078322 | 22 | |
claytong | 0:82ff15078322 | 23 | // comments |
claytong | 0:82ff15078322 | 24 | |
claytong | 0:82ff15078322 | 25 | // Macros |
claytong | 0:82ff15078322 | 26 | |
claytong | 0:82ff15078322 | 27 | // |
claytong | 0:82ff15078322 | 28 | // Classes |
claytong | 0:82ff15078322 | 29 | // |
claytong | 0:82ff15078322 | 30 | |
claytong | 0:82ff15078322 | 31 | //--------------------------------------------------------------------------- |
claytong | 0:82ff15078322 | 32 | // |
claytong | 0:82ff15078322 | 33 | // GPS Module Class |
claytong | 0:82ff15078322 | 34 | // |
claytong | 0:82ff15078322 | 35 | class TGPSController |
claytong | 0:82ff15078322 | 36 | { |
claytong | 0:82ff15078322 | 37 | // create/destroy |
claytong | 0:82ff15078322 | 38 | public: |
claytong | 0:82ff15078322 | 39 | TGPSController(); |
claytong | 0:82ff15078322 | 40 | ~TGPSController() {} |
claytong | 0:82ff15078322 | 41 | |
claytong | 0:82ff15078322 | 42 | // public type - GPS data |
claytong | 0:82ff15078322 | 43 | public: |
claytong | 0:82ff15078322 | 44 | typedef struct _gpsdata |
claytong | 0:82ff15078322 | 45 | { |
claytong | 0:82ff15078322 | 46 | int32_t iGPSQuality; |
claytong | 0:82ff15078322 | 47 | int32_t iGPSSatellites; |
claytong | 0:82ff15078322 | 48 | int32_t iGPSTimeSeconds; |
claytong | 0:82ff15078322 | 49 | int32_t iGPSLatMicroDegrees; |
claytong | 0:82ff15078322 | 50 | int32_t iGPSLongMicroDegrees; |
claytong | 0:82ff15078322 | 51 | int32_t iGPSAltitudeMeters; |
claytong | 0:82ff15078322 | 52 | } TGPSData; |
claytong | 0:82ff15078322 | 53 | |
claytong | 0:82ff15078322 | 54 | // local type - for parsing message numbers |
claytong | 0:82ff15078322 | 55 | private: |
claytong | 0:82ff15078322 | 56 | typedef struct _parsenumber |
claytong | 0:82ff15078322 | 57 | { |
claytong | 0:82ff15078322 | 58 | uint32_t uiNumber; |
claytong | 0:82ff15078322 | 59 | int iNumberLen; |
claytong | 0:82ff15078322 | 60 | int iNumberSign; |
claytong | 0:82ff15078322 | 61 | int iNumberDecimals; |
claytong | 0:82ff15078322 | 62 | } TParsedNum; |
claytong | 0:82ff15078322 | 63 | |
claytong | 0:82ff15078322 | 64 | // API |
claytong | 0:82ff15078322 | 65 | public: |
claytong | 0:82ff15078322 | 66 | // Initi8alise routine |
claytong | 0:82ff15078322 | 67 | void Init(); |
claytong | 0:82ff15078322 | 68 | |
claytong | 0:82ff15078322 | 69 | // Processing routine |
claytong | 0:82ff15078322 | 70 | void Poll(); |
claytong | 0:82ff15078322 | 71 | |
claytong | 0:82ff15078322 | 72 | // Return the last line from the GPS |
claytong | 0:82ff15078322 | 73 | const char * LastLine() |
claytong | 0:82ff15078322 | 74 | { return szLastLine; } |
claytong | 0:82ff15078322 | 75 | |
claytong | 0:82ff15078322 | 76 | // indicate a new last line has been received from the GPS unit |
claytong | 0:82ff15078322 | 77 | // Self resetting |
claytong | 0:82ff15078322 | 78 | bool NewLine() |
claytong | 0:82ff15078322 | 79 | { |
claytong | 0:82ff15078322 | 80 | bool bRet = bNewLine; |
claytong | 0:82ff15078322 | 81 | bNewLine = false; |
claytong | 0:82ff15078322 | 82 | return bRet; |
claytong | 0:82ff15078322 | 83 | } |
claytong | 0:82ff15078322 | 84 | |
claytong | 0:82ff15078322 | 85 | // Get GPS Data |
claytong | 0:82ff15078322 | 86 | // Returns status value (0=offline) |
claytong | 0:82ff15078322 | 87 | int GPSData( TGPSData &GPSDat ) |
claytong | 0:82ff15078322 | 88 | { GPSDat = GPSRecord; |
claytong | 0:82ff15078322 | 89 | return GPSDat.iGPSQuality; } |
claytong | 0:82ff15078322 | 90 | |
claytong | 0:82ff15078322 | 91 | // Private methods |
claytong | 0:82ff15078322 | 92 | private: |
claytong | 0:82ff15078322 | 93 | // callback on 1PPS rising edge |
claytong | 0:82ff15078322 | 94 | void PPSPulse(); |
claytong | 0:82ff15078322 | 95 | |
claytong | 0:82ff15078322 | 96 | // Parse a number |
claytong | 0:82ff15078322 | 97 | bool ParseNumber( char cChr ); |
claytong | 0:82ff15078322 | 98 | void ResetNumber(); |
claytong | 0:82ff15078322 | 99 | |
claytong | 0:82ff15078322 | 100 | // Parse data from the GPS |
claytong | 0:82ff15078322 | 101 | // Return true if a completed valid sentence is received |
claytong | 0:82ff15078322 | 102 | bool ParseData( char cChr ); |
claytong | 0:82ff15078322 | 103 | |
claytong | 0:82ff15078322 | 104 | // Process the data from the GPS message |
claytong | 0:82ff15078322 | 105 | // Returns 0 if all data is good, or an error code |
claytong | 0:82ff15078322 | 106 | // Call after a valid ParseData has occurred |
claytong | 0:82ff15078322 | 107 | int ProcessGPSData(); |
claytong | 0:82ff15078322 | 108 | |
claytong | 0:82ff15078322 | 109 | // data |
claytong | 0:82ff15078322 | 110 | private: |
claytong | 0:82ff15078322 | 111 | // 1PPS pin |
claytong | 0:82ff15078322 | 112 | DigitalIn PPSInput; |
claytong | 0:82ff15078322 | 113 | |
claytong | 0:82ff15078322 | 114 | // GPS Serial Port |
claytong | 0:82ff15078322 | 115 | Serial GPSPort; |
claytong | 0:82ff15078322 | 116 | |
claytong | 0:82ff15078322 | 117 | // GPS Status LED |
claytong | 0:82ff15078322 | 118 | DigitalOut GPSUpLED; |
claytong | 0:82ff15078322 | 119 | |
claytong | 0:82ff15078322 | 120 | // Interrupt on 1PPS pulse |
claytong | 0:82ff15078322 | 121 | InterruptIn PPSEvent; |
claytong | 0:82ff15078322 | 122 | |
claytong | 0:82ff15078322 | 123 | // 1PPS flag and captured timer registers |
claytong | 0:82ff15078322 | 124 | bool bPulsed; |
claytong | 0:82ff15078322 | 125 | uint32_t uiPPSCapture; |
claytong | 0:82ff15078322 | 126 | uint32_t uiLOscCapture; |
claytong | 0:82ff15078322 | 127 | |
claytong | 0:82ff15078322 | 128 | // GPS data timeout timer |
claytong | 0:82ff15078322 | 129 | Timer GPSMsgTimeout; |
claytong | 0:82ff15078322 | 130 | Timer GPSPulseTimeout; |
claytong | 0:82ff15078322 | 131 | |
claytong | 0:82ff15078322 | 132 | // Parsing data and resulting values |
claytong | 0:82ff15078322 | 133 | int iParseState; |
claytong | 0:82ff15078322 | 134 | TParsedNum ParseNum; |
claytong | 0:82ff15078322 | 135 | char cCharacter; |
claytong | 0:82ff15078322 | 136 | |
claytong | 0:82ff15078322 | 137 | // last line variables |
claytong | 0:82ff15078322 | 138 | char szCurrentLine[GPS_LINELENGTH+1]; |
claytong | 0:82ff15078322 | 139 | char szLastLine[GPS_LINELENGTH+1]; |
claytong | 0:82ff15078322 | 140 | bool bNewLine; |
claytong | 0:82ff15078322 | 141 | |
claytong | 0:82ff15078322 | 142 | // GPS message data - raw data from message |
claytong | 0:82ff15078322 | 143 | TParsedNum GPSTime; |
claytong | 0:82ff15078322 | 144 | TParsedNum GPSLatitude; |
claytong | 0:82ff15078322 | 145 | char GPSLatNS; |
claytong | 0:82ff15078322 | 146 | TParsedNum GPSLongitude; |
claytong | 0:82ff15078322 | 147 | char GPSLongEW; |
claytong | 0:82ff15078322 | 148 | TParsedNum GPSQuality; |
claytong | 0:82ff15078322 | 149 | TParsedNum GPSSatellites; |
claytong | 0:82ff15078322 | 150 | TParsedNum GPSDOP; |
claytong | 0:82ff15078322 | 151 | TParsedNum GPSAltitude; |
claytong | 0:82ff15078322 | 152 | char GPSAltType; |
claytong | 0:82ff15078322 | 153 | TParsedNum GPSHeight; |
claytong | 0:82ff15078322 | 154 | char GPSHeightType; |
claytong | 0:82ff15078322 | 155 | uint8_t ucMsgChecksum; |
claytong | 0:82ff15078322 | 156 | uint8_t ucFinalChecksum; |
claytong | 0:82ff15078322 | 157 | uint8_t ucChecksum; |
claytong | 0:82ff15078322 | 158 | |
claytong | 0:82ff15078322 | 159 | // Final GPS info (validated) |
claytong | 0:82ff15078322 | 160 | TGPSData GPSRecord; |
claytong | 0:82ff15078322 | 161 | }; |
claytong | 0:82ff15078322 | 162 | |
claytong | 0:82ff15078322 | 163 | // declare the GPS module |
claytong | 0:82ff15078322 | 164 | extern TGPSController GPSModule; |
claytong | 0:82ff15078322 | 165 | |
claytong | 0:82ff15078322 | 166 | #endif |
claytong | 0:82ff15078322 | 167 | |
claytong | 0:82ff15078322 | 168 | //--------------------------------------------------------------------------- |
claytong | 0:82ff15078322 | 169 | // END |
claytong | 0:82ff15078322 | 170 | //--------------------------------------------------------------------------- |
claytong | 0:82ff15078322 | 171 |