lauren cloutier / GPSINT
Committer:
laurencloutier
Date:
Tue Nov 17 22:06:13 2020 +0000
Revision:
0:35125ac3d3f9
assignment 8;

Who changed what in which revision?

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