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
Fork of MODGPS by
GPS_VTG.cpp@2:8aa059e7d8b1, 2011-04-15 (annotated)
- Committer:
- AjK
- Date:
- Fri Apr 15 12:23:52 2011 +0000
- Revision:
- 2:8aa059e7d8b1
- Child:
- 3:28a1b60b0f37
1.12 See ChangeLog.c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 2:8aa059e7d8b1 | 1 | /* |
AjK | 2:8aa059e7d8b1 | 2 | Copyright (c) 2010 Andy Kirkham |
AjK | 2:8aa059e7d8b1 | 3 | |
AjK | 2:8aa059e7d8b1 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
AjK | 2:8aa059e7d8b1 | 5 | of this software and associated documentation files (the "Software"), to deal |
AjK | 2:8aa059e7d8b1 | 6 | in the Software without restriction, including without limitation the rights |
AjK | 2:8aa059e7d8b1 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
AjK | 2:8aa059e7d8b1 | 8 | copies of the Software, and to permit persons to whom the Software is |
AjK | 2:8aa059e7d8b1 | 9 | furnished to do so, subject to the following conditions: |
AjK | 2:8aa059e7d8b1 | 10 | |
AjK | 2:8aa059e7d8b1 | 11 | The above copyright notice and this permission notice shall be included in |
AjK | 2:8aa059e7d8b1 | 12 | all copies or substantial portions of the Software. |
AjK | 2:8aa059e7d8b1 | 13 | |
AjK | 2:8aa059e7d8b1 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
AjK | 2:8aa059e7d8b1 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
AjK | 2:8aa059e7d8b1 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
AjK | 2:8aa059e7d8b1 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
AjK | 2:8aa059e7d8b1 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AjK | 2:8aa059e7d8b1 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
AjK | 2:8aa059e7d8b1 | 20 | THE SOFTWARE. |
AjK | 2:8aa059e7d8b1 | 21 | */ |
AjK | 2:8aa059e7d8b1 | 22 | |
AjK | 2:8aa059e7d8b1 | 23 | #include "GPS_VTG.h" |
AjK | 2:8aa059e7d8b1 | 24 | |
AjK | 2:8aa059e7d8b1 | 25 | GPS_VTG::GPS_VTG() |
AjK | 2:8aa059e7d8b1 | 26 | { |
AjK | 2:8aa059e7d8b1 | 27 | _velocity_knots = 0; |
AjK | 2:8aa059e7d8b1 | 28 | _velocity_kph = 0; |
AjK | 2:8aa059e7d8b1 | 29 | _track_true = 0; |
AjK | 2:8aa059e7d8b1 | 30 | _track_mag = 0; |
AjK | 2:8aa059e7d8b1 | 31 | } |
AjK | 2:8aa059e7d8b1 | 32 | |
AjK | 2:8aa059e7d8b1 | 33 | GPS_VTG * |
AjK | 2:8aa059e7d8b1 | 34 | GPS_VTG::vtg(GPS_VTG *n) |
AjK | 2:8aa059e7d8b1 | 35 | { |
AjK | 2:8aa059e7d8b1 | 36 | if (n == NULL) n = new GPS_VTG; |
AjK | 2:8aa059e7d8b1 | 37 | |
AjK | 2:8aa059e7d8b1 | 38 | do { |
AjK | 2:8aa059e7d8b1 | 39 | memcpy(n, this, sizeof(GPS_VTG)); |
AjK | 2:8aa059e7d8b1 | 40 | } |
AjK | 2:8aa059e7d8b1 | 41 | while (memcmp(n, this, sizeof(GPS_VTG))); |
AjK | 2:8aa059e7d8b1 | 42 | return n; |
AjK | 2:8aa059e7d8b1 | 43 | } |
AjK | 2:8aa059e7d8b1 | 44 | |
AjK | 2:8aa059e7d8b1 | 45 | void |
AjK | 2:8aa059e7d8b1 | 46 | GPS_VTG::nmea_vtg(char *s) |
AjK | 2:8aa059e7d8b1 | 47 | { |
AjK | 2:8aa059e7d8b1 | 48 | char *token; |
AjK | 2:8aa059e7d8b1 | 49 | int token_counter = 0; |
AjK | 2:8aa059e7d8b1 | 50 | char *vel_knots = (char *)NULL; |
AjK | 2:8aa059e7d8b1 | 51 | char *vel_kph = (char *)NULL; |
AjK | 2:8aa059e7d8b1 | 52 | char *trk_t = (char *)NULL; |
AjK | 2:8aa059e7d8b1 | 53 | char *trk_m = (char *)NULL; |
AjK | 2:8aa059e7d8b1 | 54 | |
AjK | 2:8aa059e7d8b1 | 55 | token = strtok(s, ","); |
AjK | 2:8aa059e7d8b1 | 56 | while (token) { |
AjK | 2:8aa059e7d8b1 | 57 | switch (token_counter) { |
AjK | 2:8aa059e7d8b1 | 58 | case 5: vel_knots = token; break; |
AjK | 2:8aa059e7d8b1 | 59 | case 7: vel_kph = token; break; |
AjK | 2:8aa059e7d8b1 | 60 | case 1: trk_t = token; break; |
AjK | 2:8aa059e7d8b1 | 61 | case 3: trk_m = token; break; |
AjK | 2:8aa059e7d8b1 | 62 | } |
AjK | 2:8aa059e7d8b1 | 63 | token = strtok((char *)NULL, ","); |
AjK | 2:8aa059e7d8b1 | 64 | token_counter++; |
AjK | 2:8aa059e7d8b1 | 65 | } |
AjK | 2:8aa059e7d8b1 | 66 | |
AjK | 2:8aa059e7d8b1 | 67 | if (vel_knots) { _velocity_knots = atof(vel_knots); } |
AjK | 2:8aa059e7d8b1 | 68 | if (vel_kph) { _velocity_kph = atof(vel_kph); } |
AjK | 2:8aa059e7d8b1 | 69 | if (trk_t) { _track_true = atof(trk_t); } |
AjK | 2:8aa059e7d8b1 | 70 | if (trk_m) { _track_mag = atof(trk_m); } |
AjK | 2:8aa059e7d8b1 | 71 | } |
AjK | 2:8aa059e7d8b1 | 72 |