Bibliothèque pur gps, trame NMEA, conversion des coordonnées au format WSG84
Dependencies: mbed
Fork of GPSINT by
GPSINT.h@0:f3a7d716faea, 2014-11-01 (annotated)
- Committer:
- jebradshaw
- Date:
- Sat Nov 01 13:27:11 2014 +0000
- Revision:
- 0:f3a7d716faea
- Child:
- 1:c266b90b4c74
GPSINT serial receive interrupt library for parsing GPS NMEA messages
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jebradshaw | 0:f3a7d716faea | 1 | /* GPSINT.h |
jebradshaw | 0:f3a7d716faea | 2 | * Copyright (c) 2014, jbradshaw (20141101) |
jebradshaw | 0:f3a7d716faea | 3 | * |
jebradshaw | 0:f3a7d716faea | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
jebradshaw | 0:f3a7d716faea | 5 | * of this software and associated documentation files (the "Software"), to deal |
jebradshaw | 0:f3a7d716faea | 6 | * in the Software without restriction, including without limitation the rights |
jebradshaw | 0:f3a7d716faea | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
jebradshaw | 0:f3a7d716faea | 8 | * copies of the Software, and to permit persons to whom the Software is |
jebradshaw | 0:f3a7d716faea | 9 | * furnished to do so, subject to the following conditions: |
jebradshaw | 0:f3a7d716faea | 10 | * |
jebradshaw | 0:f3a7d716faea | 11 | * The above copyright notice and this permission notice shall be included in |
jebradshaw | 0:f3a7d716faea | 12 | * all copies or substantial portions of the Software. |
jebradshaw | 0:f3a7d716faea | 13 | * |
jebradshaw | 0:f3a7d716faea | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
jebradshaw | 0:f3a7d716faea | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
jebradshaw | 0:f3a7d716faea | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
jebradshaw | 0:f3a7d716faea | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
jebradshaw | 0:f3a7d716faea | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jebradshaw | 0:f3a7d716faea | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
jebradshaw | 0:f3a7d716faea | 20 | * THE SOFTWARE. |
jebradshaw | 0:f3a7d716faea | 21 | */ |
jebradshaw | 0:f3a7d716faea | 22 | |
jebradshaw | 0:f3a7d716faea | 23 | /* This GPSINT library class retrieves, parses, and updates variables using |
jebradshaw | 0:f3a7d716faea | 24 | a serial receive interrupt. The library was written using the Trimble |
jebradshaw | 0:f3a7d716faea | 25 | Copernicus II moduls bus should work on any NMEA 4800 baud output device. |
jebradshaw | 0:f3a7d716faea | 26 | The relatively slow 4800 baud allows for plenty of processing time during |
jebradshaw | 0:f3a7d716faea | 27 | byte receptions in the interrupt. Using the mbed LPC 100MHz unit, it takes |
jebradshaw | 0:f3a7d716faea | 28 | about 340us to process, and parse the 2 default GPGGA and GPZTG strings.*/ |
jebradshaw | 0:f3a7d716faea | 29 | |
jebradshaw | 0:f3a7d716faea | 30 | #include "mbed.h" |
jebradshaw | 0:f3a7d716faea | 31 | |
jebradshaw | 0:f3a7d716faea | 32 | #ifndef GPSINT_H |
jebradshaw | 0:f3a7d716faea | 33 | #define GPSINT_H |
jebradshaw | 0:f3a7d716faea | 34 | |
jebradshaw | 0:f3a7d716faea | 35 | #define PI (3.14159265359) |
jebradshaw | 0:f3a7d716faea | 36 | #define GPSBUFSIZE 256 // GPS buffer size |
jebradshaw | 0:f3a7d716faea | 37 | |
jebradshaw | 0:f3a7d716faea | 38 | /** |
jebradshaw | 0:f3a7d716faea | 39 | * GPSINT Class. |
jebradshaw | 0:f3a7d716faea | 40 | */ |
jebradshaw | 0:f3a7d716faea | 41 | |
jebradshaw | 0:f3a7d716faea | 42 | class GPSINT{ |
jebradshaw | 0:f3a7d716faea | 43 | public: |
jebradshaw | 0:f3a7d716faea | 44 | /** |
jebradshaw | 0:f3a7d716faea | 45 | * Constructor. |
jebradshaw | 0:f3a7d716faea | 46 | * @param gps - Serial port pins attached to the gps |
jebradshaw | 0:f3a7d716faea | 47 | */ |
jebradshaw | 0:f3a7d716faea | 48 | GPSINT(PinName tx, PinName rx); |
jebradshaw | 0:f3a7d716faea | 49 | int nmea_validate(char *nmeastr); |
jebradshaw | 0:f3a7d716faea | 50 | void parseGPSString(char *GPSstrParse); |
jebradshaw | 0:f3a7d716faea | 51 | void GPSSerialRecvInterrupt(void); |
jebradshaw | 0:f3a7d716faea | 52 | float nmea_to_dec(float deg_coord, char nsew); |
jebradshaw | 0:f3a7d716faea | 53 | float calc_course_to(float pointLat, float pontLong); |
jebradshaw | 0:f3a7d716faea | 54 | double calc_dist_to_mi(float pointLat, float pontLong); |
jebradshaw | 0:f3a7d716faea | 55 | double calc_dist_to_ft(float pointLat, float pontLong); |
jebradshaw | 0:f3a7d716faea | 56 | double calc_dist_to_km(float pointLat, float pontLong); |
jebradshaw | 0:f3a7d716faea | 57 | double calc_dist_to_m(float pointLat, float pontLong); |
jebradshaw | 0:f3a7d716faea | 58 | |
jebradshaw | 0:f3a7d716faea | 59 | // GPSINT variables |
jebradshaw | 0:f3a7d716faea | 60 | char GPSbuf[GPSBUFSIZE]; // Receive buffer. |
jebradshaw | 0:f3a7d716faea | 61 | char Temp_GPSbuf[GPSBUFSIZE];// Receive buffer. |
jebradshaw | 0:f3a7d716faea | 62 | char GPSidx; // Read by background, written by Int Handler. |
jebradshaw | 0:f3a7d716faea | 63 | int GPSstate; //set when successful GPS string is received |
jebradshaw | 0:f3a7d716faea | 64 | |
jebradshaw | 0:f3a7d716faea | 65 | // calculated values |
jebradshaw | 0:f3a7d716faea | 66 | float dec_longitude; |
jebradshaw | 0:f3a7d716faea | 67 | float dec_latitude; |
jebradshaw | 0:f3a7d716faea | 68 | float altitude_ft; |
jebradshaw | 0:f3a7d716faea | 69 | |
jebradshaw | 0:f3a7d716faea | 70 | // GGA - Global Positioning System Fixed Data |
jebradshaw | 0:f3a7d716faea | 71 | float nmea_longitude; |
jebradshaw | 0:f3a7d716faea | 72 | float nmea_latitude; |
jebradshaw | 0:f3a7d716faea | 73 | float utc_time; |
jebradshaw | 0:f3a7d716faea | 74 | char ns, ew; |
jebradshaw | 0:f3a7d716faea | 75 | int lock; |
jebradshaw | 0:f3a7d716faea | 76 | int satelites; |
jebradshaw | 0:f3a7d716faea | 77 | float hdop; |
jebradshaw | 0:f3a7d716faea | 78 | float msl_altitude; |
jebradshaw | 0:f3a7d716faea | 79 | char msl_units; |
jebradshaw | 0:f3a7d716faea | 80 | |
jebradshaw | 0:f3a7d716faea | 81 | // RMC - Recommended Minimmum Specific GNS Data |
jebradshaw | 0:f3a7d716faea | 82 | char rmc_status; |
jebradshaw | 0:f3a7d716faea | 83 | float speed_k; |
jebradshaw | 0:f3a7d716faea | 84 | float course_d; |
jebradshaw | 0:f3a7d716faea | 85 | int date; |
jebradshaw | 0:f3a7d716faea | 86 | |
jebradshaw | 0:f3a7d716faea | 87 | // GLL |
jebradshaw | 0:f3a7d716faea | 88 | char gll_status; |
jebradshaw | 0:f3a7d716faea | 89 | |
jebradshaw | 0:f3a7d716faea | 90 | // VTG - Course over ground, ground speed |
jebradshaw | 0:f3a7d716faea | 91 | float course_t; // ground speed true |
jebradshaw | 0:f3a7d716faea | 92 | char course_t_unit; |
jebradshaw | 0:f3a7d716faea | 93 | float course_m; // magnetic |
jebradshaw | 0:f3a7d716faea | 94 | char course_m_unit; |
jebradshaw | 0:f3a7d716faea | 95 | char speed_k_unit; |
jebradshaw | 0:f3a7d716faea | 96 | float speed_km; // speek km/hr |
jebradshaw | 0:f3a7d716faea | 97 | char speed_km_unit; |
jebradshaw | 0:f3a7d716faea | 98 | private: |
jebradshaw | 0:f3a7d716faea | 99 | Serial _gps; |
jebradshaw | 0:f3a7d716faea | 100 | }; |
jebradshaw | 0:f3a7d716faea | 101 | |
jebradshaw | 0:f3a7d716faea | 102 | #endif /* GPSINT_H */ |