Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data. New feature, added Mbed/LPC17xx RTC synchronisation

Dependents:   SatGPS AntiTheftGPS FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM GPS-Lora ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GPS_VTG.cpp Source File

GPS_VTG.cpp

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 #include "GPS_VTG.h"
00024 #include <math.h>
00025 
00026 GPS_VTG::GPS_VTG() 
00027 {
00028     _velocity_knots = 0;
00029     _velocity_kph = 0;
00030     _track_true = 0;    
00031     _track_mag = 0;    
00032 }
00033 
00034 GPS_VTG *
00035 GPS_VTG::vtg(GPS_VTG *n)
00036 {
00037     if (n == NULL) n = new GPS_VTG;
00038     
00039     n->_velocity_knots = _velocity_knots;
00040     n->_velocity_kph   = _velocity_kph;
00041     n->_track_true     = _track_true;
00042     n->_track_mag      = _track_mag;
00043     
00044     return n;    
00045 }
00046 
00047 void 
00048 GPS_VTG::nmea_vtg(char *s)
00049 {
00050     char *token;
00051     int  token_counter = 0;
00052     char *vel_knots = (char *)NULL;
00053     char *vel_kph   = (char *)NULL;
00054     char *trk_t  = (char *)NULL;
00055     char *trk_m  = (char *)NULL;
00056     
00057     token = strtok(s, ",");
00058     while (token) {
00059         switch (token_counter) {
00060             case 5:  vel_knots = token; break;
00061             case 7:  vel_kph   = token; break;
00062             case 1:  trk_t     = token; break;
00063             case 3:  trk_m     = token; break;            
00064         }
00065         token = strtok((char *)NULL, ",");
00066         token_counter++;
00067     }
00068     
00069     if (trk_t)     { _track_true     = atof(trk_t);     }
00070     if (trk_m)     { _track_mag      = atof(trk_m);     }    
00071     if (vel_knots) { _velocity_knots = atof(vel_knots); }
00072     if (vel_kph)   { _velocity_kph   = atof(vel_kph);   }    
00073 }
00074