Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data.

Fork of MODGPS by Andy K

Committer:
xanter
Date:
Sat Sep 29 20:31:31 2018 +0000
Revision:
7:049436bc2225
Parent:
6:64771e31464e
Fixed compiler errors/warnings; Removed hardcode for LPC17xx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:db98027c0bbb 1 /*
AjK 0:db98027c0bbb 2 Copyright (c) 2010 Andy Kirkham
xanter 7:049436bc2225 3
AjK 0:db98027c0bbb 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:db98027c0bbb 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:db98027c0bbb 6 in the Software without restriction, including without limitation the rights
AjK 0:db98027c0bbb 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:db98027c0bbb 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:db98027c0bbb 9 furnished to do so, subject to the following conditions:
xanter 7:049436bc2225 10
AjK 0:db98027c0bbb 11 The above copyright notice and this permission notice shall be included in
AjK 0:db98027c0bbb 12 all copies or substantial portions of the Software.
xanter 7:049436bc2225 13
AjK 0:db98027c0bbb 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:db98027c0bbb 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:db98027c0bbb 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:db98027c0bbb 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:db98027c0bbb 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:db98027c0bbb 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:db98027c0bbb 20 THE SOFTWARE.
AjK 0:db98027c0bbb 21 */
AjK 0:db98027c0bbb 22
AjK 0:db98027c0bbb 23 #ifndef GPS_H
AjK 0:db98027c0bbb 24 #define GPS_H
AjK 0:db98027c0bbb 25
AjK 0:db98027c0bbb 26 #include "mbed.h"
AjK 2:8aa059e7d8b1 27 #include "GPS_VTG.h"
AjK 0:db98027c0bbb 28 #include "GPS_Time.h"
AjK 0:db98027c0bbb 29 #include "GPS_Geodetic.h"
AjK 0:db98027c0bbb 30
AjK 0:db98027c0bbb 31 #define GPS_RBR 0x00
AjK 0:db98027c0bbb 32 #define GPS_THR 0x00
AjK 0:db98027c0bbb 33 #define GPS_DLL 0x00
AjK 0:db98027c0bbb 34 #define GPS_IER 0x04
AjK 0:db98027c0bbb 35 #define GPS_DML 0x04
AjK 0:db98027c0bbb 36 #define GPS_IIR 0x08
AjK 0:db98027c0bbb 37 #define GPS_FCR 0x08
AjK 0:db98027c0bbb 38 #define GPS_LCR 0x0C
AjK 0:db98027c0bbb 39 #define GPS_LSR 0x14
AjK 0:db98027c0bbb 40 #define GPS_SCR 0x1C
AjK 0:db98027c0bbb 41 #define GPS_ACR 0x20
AjK 0:db98027c0bbb 42 #define GPS_ICR 0x24
AjK 0:db98027c0bbb 43 #define GPS_FDR 0x28
AjK 0:db98027c0bbb 44 #define GPS_TER 0x30
AjK 0:db98027c0bbb 45
AjK 0:db98027c0bbb 46 #define GPS_BUFFER_LEN 128
AjK 0:db98027c0bbb 47 #define GPS_TICKTOCK 10000
AjK 0:db98027c0bbb 48
AjK 1:6aec92e77ad2 49 /** @defgroup API The MODGPS API */
AjK 0:db98027c0bbb 50
AjK 0:db98027c0bbb 51 /** GPS module
AjK 1:6aec92e77ad2 52 * @author Andy Kirkham
AjK 0:db98027c0bbb 53 * @see http://mbed.org/cookbook/MODGPS
AjK 0:db98027c0bbb 54 * @see example1.cpp
AjK 0:db98027c0bbb 55 * @see example2.cpp
xanter 7:049436bc2225 56 * @see API
AjK 1:6aec92e77ad2 57 *
AjK 1:6aec92e77ad2 58 * @image html /media/uploads/AjK/gps_interfaces.png "Wiring up the GPS module"
AjK 0:db98027c0bbb 59 *
AjK 0:db98027c0bbb 60 * Example:
AjK 0:db98027c0bbb 61 * @code
AjK 0:db98027c0bbb 62 * #include "mbed.h"
AjK 0:db98027c0bbb 63 * #include "GPS.h"
AjK 0:db98027c0bbb 64 *
AjK 0:db98027c0bbb 65 * DigitalOut led1(LED1);
AjK 0:db98027c0bbb 66 * Serial pc(USBTX, USBRX);
xanter 7:049436bc2225 67 * GPS gps(NC, p10);
AjK 0:db98027c0bbb 68 *
AjK 0:db98027c0bbb 69 * int main() {
AjK 0:db98027c0bbb 70 * GPS_Time t;
AjK 0:db98027c0bbb 71 *
AjK 0:db98027c0bbb 72 * // Wait for the GPS NMEA data to become valid.
AjK 0:db98027c0bbb 73 * while (!gps.isTimeValid()) {
AjK 0:db98027c0bbb 74 * led1 = !led1;
AjK 0:db98027c0bbb 75 * wait(1);
AjK 0:db98027c0bbb 76 * }
AjK 0:db98027c0bbb 77 *
AjK 0:db98027c0bbb 78 * gps.timeNow(&t);
AjK 0:db98027c0bbb 79 *
AjK 0:db98027c0bbb 80 * pc.printf("The time/date is %02d:%02d:%02d %02d/%02d/%04d\r\n",
AjK 0:db98027c0bbb 81 * t.hour, t.minute, t.second, t.day, t.month, t.year);
AjK 0:db98027c0bbb 82 *
AjK 0:db98027c0bbb 83 * // Wait until at least four satellites produce a position fix and a valid quality.
AjK 0:db98027c0bbb 84 * while (gps.numOfSats() < 4 && gps.getGPSquality != 0) {
AjK 0:db98027c0bbb 85 * led1 = !led1;
AjK 0:db98027c0bbb 86 * wait(1);
AjK 0:db98027c0bbb 87 * }
AjK 0:db98027c0bbb 88 *
xanter 7:049436bc2225 89 * pc.printf("Lat = %.4f Lon = %.4f Alt = %.1fkm\r\n",
AjK 0:db98027c0bbb 90 * gps.latitude(), gps.longitude, gps.altitude());
AjK 0:db98027c0bbb 91 *
AjK 0:db98027c0bbb 92 * // Make the LED go steady to indicate we have finished.
AjK 0:db98027c0bbb 93 * led1 = 1;
xanter 7:049436bc2225 94 *
AjK 0:db98027c0bbb 95 * while(1) {}
AjK 0:db98027c0bbb 96 * }
AjK 0:db98027c0bbb 97 * @endcode
AjK 0:db98027c0bbb 98 */
AjK 0:db98027c0bbb 99
xanter 7:049436bc2225 100 class GPS : RawSerial
xanter 7:049436bc2225 101 {
AjK 0:db98027c0bbb 102 public:
xanter 7:049436bc2225 103
AjK 0:db98027c0bbb 104 //! The PPS edge type to interrupt on.
xanter 7:049436bc2225 105 enum ppsEdgeType {
AjK 0:db98027c0bbb 106 ppsRise = 0, /*!< Use the rising edge (default). */
AjK 0:db98027c0bbb 107 ppsFall /*!< Use the falling edge. */
AjK 0:db98027c0bbb 108 };
xanter 7:049436bc2225 109
AjK 0:db98027c0bbb 110 //! GPS constructor.
AjK 0:db98027c0bbb 111 /**
AjK 0:db98027c0bbb 112 * The GPS constructor is used to initialise the GPS object.
AjK 0:db98027c0bbb 113 *
AjK 0:db98027c0bbb 114 * @param tx Usually unused and set to NC
AjK 0:db98027c0bbb 115 * @param rx The RX pin the GPS is connected to, p10, p14( OR p25), p27.
AjK 0:db98027c0bbb 116 * @param name An option name for RPC usage.
AjK 0:db98027c0bbb 117 */
AjK 0:db98027c0bbb 118 GPS(PinName tx, PinName rx, const char *name = NULL);
AjK 0:db98027c0bbb 119
AjK 0:db98027c0bbb 120 //! Is the time reported by the GPS valid.
AjK 0:db98027c0bbb 121 /**
AjK 0:db98027c0bbb 122 * Method used to check the validity of the time the GPS module is reporting.
AjK 0:db98027c0bbb 123 *
AjK 0:db98027c0bbb 124 * @code
AjK 0:db98027c0bbb 125 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 126 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 127 *
AjK 0:db98027c0bbb 128 * if (gps.isTimeValid()) {
AjK 0:db98027c0bbb 129 * // Time is valid :)
AjK 0:db98027c0bbb 130 * }
AjK 0:db98027c0bbb 131 * else {
AjK 0:db98027c0bbb 132 * // Doh, time is not valid :(
AjK 0:db98027c0bbb 133 * )
xanter 7:049436bc2225 134 *
AjK 0:db98027c0bbb 135 * @endcode
AjK 0:db98027c0bbb 136 *
AjK 0:db98027c0bbb 137 * @ingroup API
AjK 0:db98027c0bbb 138 * @return bool true if valid, false otherwise
AjK 0:db98027c0bbb 139 */
xanter 7:049436bc2225 140 bool isTimeValid(void) {
xanter 7:049436bc2225 141 return theTime.status == 'V' ? false : true;
xanter 7:049436bc2225 142 }
xanter 7:049436bc2225 143
AjK 0:db98027c0bbb 144 //! Is the positional fix reported by the GPS valid.
AjK 0:db98027c0bbb 145 /**
AjK 0:db98027c0bbb 146 * Method used to check the validity of the positional data. This method
xanter 7:049436bc2225 147 * returns the GGA field, 0 is "bad, 1 is "ok", etc. See the NMEA GGA
AjK 1:6aec92e77ad2 148 * description for more details.
AjK 1:6aec92e77ad2 149 *
AjK 1:6aec92e77ad2 150 * @code
AjK 1:6aec92e77ad2 151 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 152 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 153 *
AjK 1:6aec92e77ad2 154 * if (gps.getGPSquality() == 0) {
AjK 1:6aec92e77ad2 155 * // The location fix is no good/not accurate :(
AjK 1:6aec92e77ad2 156 * }
AjK 1:6aec92e77ad2 157 * else {
AjK 1:6aec92e77ad2 158 * // All good, can use last fix data.
AjK 1:6aec92e77ad2 159 * )
xanter 7:049436bc2225 160 *
AjK 1:6aec92e77ad2 161 * @endcode
AjK 1:6aec92e77ad2 162 *
AjK 1:6aec92e77ad2 163 * @ingroup API
AjK 0:db98027c0bbb 164 * @return int 0 on no fix, 1... (see NMEA GGA for more details).
AjK 0:db98027c0bbb 165 */
xanter 7:049436bc2225 166 int getGPSquality(void) {
xanter 7:049436bc2225 167 return thePlace.getGPSquality();
xanter 7:049436bc2225 168 }
xanter 7:049436bc2225 169
AjK 0:db98027c0bbb 170 //! How many satellites were used in the last fix.
AjK 0:db98027c0bbb 171 /**
AjK 0:db98027c0bbb 172 * Method returns the number of GPS satellites used on the last fix.
AjK 0:db98027c0bbb 173 *
AjK 0:db98027c0bbb 174 * @code
AjK 0:db98027c0bbb 175 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 176 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 177 *
AjK 0:db98027c0bbb 178 * int sats = gps.numOfSats();
xanter 7:049436bc2225 179 *
AjK 0:db98027c0bbb 180 * @endcode
AjK 0:db98027c0bbb 181 *
AjK 0:db98027c0bbb 182 * @ingroup API
AjK 0:db98027c0bbb 183 * @return int The number of satellites.
AjK 0:db98027c0bbb 184 */
xanter 7:049436bc2225 185 int numOfSats(void) {
xanter 7:049436bc2225 186 return thePlace.numOfSats();
xanter 7:049436bc2225 187 }
xanter 7:049436bc2225 188
AjK 0:db98027c0bbb 189 //! What was the last reported latitude (in degrees)
AjK 0:db98027c0bbb 190 /**
AjK 0:db98027c0bbb 191 * Method returns a double in degrees, positive being North, negative being South.
AjK 0:db98027c0bbb 192 *
AjK 0:db98027c0bbb 193 * @code
AjK 0:db98027c0bbb 194 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 195 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 196 *
AjK 0:db98027c0bbb 197 * double latitude = gps.latitude();
xanter 7:049436bc2225 198 *
AjK 0:db98027c0bbb 199 * @endcode
AjK 0:db98027c0bbb 200 *
AjK 0:db98027c0bbb 201 * @ingroup API
AjK 0:db98027c0bbb 202 * @return double Degrees
AjK 0:db98027c0bbb 203 */
AjK 0:db98027c0bbb 204 double latitude(void);
xanter 7:049436bc2225 205
AjK 0:db98027c0bbb 206 //! What was the last reported longitude (in degrees)
AjK 0:db98027c0bbb 207 /**
AjK 0:db98027c0bbb 208 * Method returns a double in degrees, positive being East, negative being West.
AjK 0:db98027c0bbb 209 *
AjK 0:db98027c0bbb 210 * @code
AjK 0:db98027c0bbb 211 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 212 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 213 *
AjK 0:db98027c0bbb 214 * double logitude = gps.logitude();
xanter 7:049436bc2225 215 *
AjK 0:db98027c0bbb 216 * @endcode
AjK 0:db98027c0bbb 217 *
AjK 0:db98027c0bbb 218 * @ingroup API
AjK 0:db98027c0bbb 219 * @return double Degrees
AjK 0:db98027c0bbb 220 */
AjK 0:db98027c0bbb 221 double longitude(void);
xanter 7:049436bc2225 222
AjK 0:db98027c0bbb 223 //! What was the last reported altitude (in kilometers)
AjK 0:db98027c0bbb 224 /**
AjK 0:db98027c0bbb 225 * Method returns a double in kilometers.
AjK 0:db98027c0bbb 226 *
AjK 0:db98027c0bbb 227 * @code
AjK 0:db98027c0bbb 228 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 229 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 230 *
AjK 0:db98027c0bbb 231 * double altitude = gps.altitude();
xanter 7:049436bc2225 232 *
AjK 0:db98027c0bbb 233 * @endcode
AjK 0:db98027c0bbb 234 *
AjK 0:db98027c0bbb 235 * @ingroup API
AjK 0:db98027c0bbb 236 * @return double Kilometers
AjK 0:db98027c0bbb 237 */
AjK 0:db98027c0bbb 238 double altitude(void);
xanter 7:049436bc2225 239
AjK 0:db98027c0bbb 240 //! What was the last reported altitude/height (in kilometers)
AjK 0:db98027c0bbb 241 /**
AjK 0:db98027c0bbb 242 * @see altitude()
AjK 0:db98027c0bbb 243 *
AjK 0:db98027c0bbb 244 * @code
AjK 0:db98027c0bbb 245 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 246 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 247 *
AjK 0:db98027c0bbb 248 * double height = gps.height();
xanter 7:049436bc2225 249 *
AjK 0:db98027c0bbb 250 * @endcode
AjK 0:db98027c0bbb 251 *
AjK 0:db98027c0bbb 252 * Note, this is identical to altitude()
AjK 0:db98027c0bbb 253 * @see altitude()
AjK 0:db98027c0bbb 254 *
AjK 0:db98027c0bbb 255 * @ingroup API
AjK 0:db98027c0bbb 256 * @return double Kilometers
AjK 0:db98027c0bbb 257 */
xanter 7:049436bc2225 258 double height(void) {
xanter 7:049436bc2225 259 return altitude();
xanter 7:049436bc2225 260 }
xanter 7:049436bc2225 261
AjK 2:8aa059e7d8b1 262 //! Get all vector parameters together.
AjK 2:8aa059e7d8b1 263 /**
AjK 2:8aa059e7d8b1 264 * Pass a pointer to a GPS_VTG object and the current
AjK 2:8aa059e7d8b1 265 * GPS data will be copied into it.
AjK 2:8aa059e7d8b1 266 *
AjK 2:8aa059e7d8b1 267 * @code
AjK 2:8aa059e7d8b1 268 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 269 * GPS gps(NC, p9);
AjK 2:8aa059e7d8b1 270 *
AjK 2:8aa059e7d8b1 271 * // Then get the data...
AjK 2:8aa059e7d8b1 272 * GPS_VTG p;
AjK 2:8aa059e7d8b1 273 * gps.vtg(&p);
AjK 2:8aa059e7d8b1 274 * printf("Speed (knots) = %.4f", p.velocity_knots);
AjK 2:8aa059e7d8b1 275 * printf("Speed (kps) = %.4f", p.velocity_kps);
AjK 2:8aa059e7d8b1 276 * printf("Track (true) = %.4f", p.track_true);
AjK 2:8aa059e7d8b1 277 * printf("Track (mag) = %.4f", p.track_mag);
AjK 2:8aa059e7d8b1 278 *
AjK 2:8aa059e7d8b1 279 * @endcode
AjK 2:8aa059e7d8b1 280 *
AjK 2:8aa059e7d8b1 281 * @ingroup API
AjK 2:8aa059e7d8b1 282 * @param g A GSP_VTG pointer to an existing GPS_VTG object.
AjK 2:8aa059e7d8b1 283 * @return GPS_VTG * The pointer passed in.
AjK 2:8aa059e7d8b1 284 */
AjK 2:8aa059e7d8b1 285 GPS_VTG *vtg(GPS_VTG *g);
xanter 7:049436bc2225 286
AjK 2:8aa059e7d8b1 287 //! Get all vector parameters together.
AjK 2:8aa059e7d8b1 288 /**
AjK 2:8aa059e7d8b1 289 * Get all the vector data at once. For example:-
AjK 2:8aa059e7d8b1 290 *
AjK 2:8aa059e7d8b1 291 * @code
AjK 2:8aa059e7d8b1 292 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 293 * GPS gps(NC, p9);
AjK 2:8aa059e7d8b1 294 *
AjK 2:8aa059e7d8b1 295 * // Then get the data...
AjK 2:8aa059e7d8b1 296 * GPS_VTG *p = gps.vtg();
AjK 2:8aa059e7d8b1 297 * printf("Speed (knots) = %.4f", p->velocity_knots);
AjK 2:8aa059e7d8b1 298 * printf("Speed (kps) = %.4f", p->velocity_kps);
AjK 2:8aa059e7d8b1 299 * printf("Track (true) = %.4f", p->track_true);
xanter 7:049436bc2225 300 * printf("Track (mag) = %.4f", p->track_mag);
AjK 2:8aa059e7d8b1 301 * delete(p); // then remember to delete the object to prevent memory leaks.
AjK 2:8aa059e7d8b1 302 *
AjK 2:8aa059e7d8b1 303 * @endcode
AjK 2:8aa059e7d8b1 304 *
AjK 2:8aa059e7d8b1 305 * @ingroup API
AjK 2:8aa059e7d8b1 306 * @return GPS_Geodetic * A pointer to the data.
AjK 2:8aa059e7d8b1 307 */
xanter 7:049436bc2225 308 GPS_VTG *vtg(void) {
xanter 7:049436bc2225 309 return vtg(NULL);
xanter 7:049436bc2225 310 }
xanter 7:049436bc2225 311
AjK 0:db98027c0bbb 312 //! Get all three geodetic parameters together.
AjK 0:db98027c0bbb 313 /**
AjK 0:db98027c0bbb 314 * Pass a pointer to a GPS_Geodetic object and the current
AjK 0:db98027c0bbb 315 * GPS data will be copied into it.
AjK 0:db98027c0bbb 316 *
AjK 0:db98027c0bbb 317 * @code
AjK 0:db98027c0bbb 318 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 319 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 320 *
AjK 0:db98027c0bbb 321 * // Then get the data...
AjK 0:db98027c0bbb 322 * GPS_Geodetic p;
AjK 0:db98027c0bbb 323 * gps.geodetic(&p);
AjK 0:db98027c0bbb 324 * printf("Latitude = %.4f", p.lat);
AjK 0:db98027c0bbb 325 * printf("Longitude = %.4f", p.lon);
AjK 0:db98027c0bbb 326 * printf("Altitude = %.4f", p.alt);
AjK 0:db98027c0bbb 327 *
AjK 0:db98027c0bbb 328 * @endcode
AjK 0:db98027c0bbb 329 *
AjK 0:db98027c0bbb 330 * @ingroup API
AjK 0:db98027c0bbb 331 * @param g A GSP_Geodetic pointer to an existing GPS_Geodetic object.
AjK 0:db98027c0bbb 332 * @return GPS_Geodetic * The pointer passed in.
AjK 0:db98027c0bbb 333 */
AjK 0:db98027c0bbb 334 GPS_Geodetic *geodetic(GPS_Geodetic *g);
xanter 7:049436bc2225 335
AjK 0:db98027c0bbb 336 //! Get all three geodetic parameters together.
AjK 0:db98027c0bbb 337 /**
AjK 0:db98027c0bbb 338 * Get all the geodetic data at once. For example:-
AjK 0:db98027c0bbb 339 *
AjK 0:db98027c0bbb 340 * @code
AjK 0:db98027c0bbb 341 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 342 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 343 *
AjK 0:db98027c0bbb 344 * // Then get the data...
AjK 0:db98027c0bbb 345 * GPS_Geodetic *p = gps.geodetic();
AjK 0:db98027c0bbb 346 * printf("Latitude = %.4f", p->lat);
AjK 0:db98027c0bbb 347 * delete(p); // then remember to delete the object to prevent memory leaks.
AjK 0:db98027c0bbb 348 *
AjK 0:db98027c0bbb 349 * @endcode
AjK 0:db98027c0bbb 350 *
AjK 0:db98027c0bbb 351 * @ingroup API
AjK 0:db98027c0bbb 352 * @return GPS_Geodetic * A pointer to the data.
AjK 0:db98027c0bbb 353 */
xanter 7:049436bc2225 354 GPS_Geodetic *geodetic(void) {
xanter 7:049436bc2225 355 return geodetic(NULL);
xanter 7:049436bc2225 356 }
xanter 7:049436bc2225 357
AjK 0:db98027c0bbb 358 //! Take a snap shot of the current time.
AjK 0:db98027c0bbb 359 /**
AjK 0:db98027c0bbb 360 * Pass a pointer to a GPS_Time object to get a copy of the current
AjK 0:db98027c0bbb 361 * time and date as reported by the GPS.
AjK 0:db98027c0bbb 362 *
AjK 0:db98027c0bbb 363 * @code
AjK 0:db98027c0bbb 364 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 365 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 366 *
AjK 0:db98027c0bbb 367 * // Then get the data...
AjK 0:db98027c0bbb 368 * GPS_Time t;
AjK 0:db98027c0bbb 369 * gps.timeNow(&t);
AjK 0:db98027c0bbb 370 * printf("Year = %d", t.year);
AjK 0:db98027c0bbb 371 *
AjK 0:db98027c0bbb 372 * @endcode
AjK 0:db98027c0bbb 373 *
AjK 0:db98027c0bbb 374 * @ingroup API
AjK 0:db98027c0bbb 375 * @param n A GPS_Time * pointer to an existing GPS_Time object.
AjK 0:db98027c0bbb 376 * @return GPS_Time * The pointer passed in.
AjK 0:db98027c0bbb 377 */
xanter 7:049436bc2225 378 GPS_Time * timeNow(GPS_Time *n) {
xanter 7:049436bc2225 379 return theTime.timeNow(n);
xanter 7:049436bc2225 380 }
xanter 7:049436bc2225 381
AjK 0:db98027c0bbb 382 //! Take a snap shot of the current time.
AjK 0:db98027c0bbb 383 /**
AjK 0:db98027c0bbb 384 * Pass a pointer to a GPS_Time object to get a copy of the current
AjK 0:db98027c0bbb 385 * time and date as reported by the GPS.
AjK 0:db98027c0bbb 386 *
AjK 0:db98027c0bbb 387 * @code
AjK 0:db98027c0bbb 388 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 389 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 390 *
AjK 0:db98027c0bbb 391 * // Then get the data...
AjK 0:db98027c0bbb 392 * GPS_Time *t = gps.timeNow();
AjK 0:db98027c0bbb 393 * printf("Year = %d", t->year);
AjK 0:db98027c0bbb 394 * delete(t); // Avoid memory leaks.
AjK 0:db98027c0bbb 395 *
AjK 0:db98027c0bbb 396 * @endcode
AjK 0:db98027c0bbb 397 *
AjK 0:db98027c0bbb 398 * @ingroup API
AjK 0:db98027c0bbb 399 * @return GPS_Time * The pointer passed in.
AjK 0:db98027c0bbb 400 */
xanter 7:049436bc2225 401 GPS_Time * timeNow(void) {
xanter 7:049436bc2225 402 GPS_Time *n = new GPS_Time;
xanter 7:049436bc2225 403 return theTime.timeNow(n);
xanter 7:049436bc2225 404 }
xanter 7:049436bc2225 405
AjK 0:db98027c0bbb 406 //! Return the curent day.
AjK 0:db98027c0bbb 407 /**
AjK 0:db98027c0bbb 408 * @code
AjK 0:db98027c0bbb 409 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 410 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 411 *
AjK 0:db98027c0bbb 412 * // Then get the Julain Day Number.
AjK 0:db98027c0bbb 413 * double julianDayNumber = gps.julianDayNumber();
AjK 0:db98027c0bbb 414 *
AjK 0:db98027c0bbb 415 * @endcode
AjK 0:db98027c0bbb 416 *
AjK 0:db98027c0bbb 417 * @ingroup API
AjK 0:db98027c0bbb 418 * @return double The Julian Date as a double.
AjK 0:db98027c0bbb 419 */
xanter 7:049436bc2225 420 double julianDayNumber(void) {
xanter 7:049436bc2225 421 return theTime.julian_day_number();
xanter 7:049436bc2225 422 }
xanter 7:049436bc2225 423
AjK 0:db98027c0bbb 424 //! Return the curent date/time as a Julian date
AjK 0:db98027c0bbb 425 /**
AjK 0:db98027c0bbb 426 * @code
AjK 0:db98027c0bbb 427 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 428 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 429 *
AjK 0:db98027c0bbb 430 * // Then get the Julian Date.
AjK 0:db98027c0bbb 431 * double julianDate = gps.julianDate();
AjK 0:db98027c0bbb 432 *
AjK 0:db98027c0bbb 433 * @endcode
AjK 0:db98027c0bbb 434 *
AjK 0:db98027c0bbb 435 * @ingroup API
AjK 0:db98027c0bbb 436 * @return double The Julian Date as a double.
AjK 0:db98027c0bbb 437 */
xanter 7:049436bc2225 438 double julianDate(void) {
xanter 7:049436bc2225 439 return theTime.julian_date();
xanter 7:049436bc2225 440 }
AjK 0:db98027c0bbb 441
AjK 0:db98027c0bbb 442 //! Get the current sidereal degree angle.
AjK 0:db98027c0bbb 443 /**
AjK 0:db98027c0bbb 444 * @code
AjK 0:db98027c0bbb 445 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 446 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 447 * double sidereal = gps.siderealDegrees();
AjK 0:db98027c0bbb 448 *
AjK 0:db98027c0bbb 449 * @endcode
AjK 0:db98027c0bbb 450 *
AjK 0:db98027c0bbb 451 * @ingroup API
AjK 0:db98027c0bbb 452 * @return double Sidereal degree angle..
AjK 0:db98027c0bbb 453 */
xanter 7:049436bc2225 454 double siderealDegrees(void) {
xanter 7:049436bc2225 455 return theTime.siderealDegrees(&theTime, longitude());
xanter 7:049436bc2225 456 }
xanter 7:049436bc2225 457
AjK 0:db98027c0bbb 458 //! Get the current sidereal hour angle.
AjK 0:db98027c0bbb 459 /**
AjK 0:db98027c0bbb 460 * @code
AjK 0:db98027c0bbb 461 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 462 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 463 * double sidereal = gps.siderealHA();
AjK 0:db98027c0bbb 464 *
AjK 0:db98027c0bbb 465 * @endcode
AjK 0:db98027c0bbb 466 *
AjK 0:db98027c0bbb 467 * @ingroup API
AjK 0:db98027c0bbb 468 * @return double Sidereal degree angle..
AjK 0:db98027c0bbb 469 */
xanter 7:049436bc2225 470 double siderealHA(void) {
xanter 7:049436bc2225 471 return theTime.siderealHA(&theTime, longitude());
xanter 7:049436bc2225 472 }
xanter 7:049436bc2225 473
AjK 0:db98027c0bbb 474 //! Optionally, connect a 1PPS single to an Mbed pin.
AjK 0:db98027c0bbb 475 /**
AjK 0:db98027c0bbb 476 * Optional: If the GPS unit has a 1PPS output, use this to
AjK 0:db98027c0bbb 477 * connect that to our internal ISR. Using the 1PPS increases
AjK 0:db98027c0bbb 478 * the GPS_Time time accuracy from +/-0.25s to +/-0.001s
AjK 0:db98027c0bbb 479 *
AjK 0:db98027c0bbb 480 * @code
AjK 0:db98027c0bbb 481 * // Assuming we have a GPS object previously created...
xanter 7:049436bc2225 482 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 483 *
xanter 7:049436bc2225 484 * gps.ppsAttach(p29); // default to GPS::ppsRise, rising edge.
AjK 0:db98027c0bbb 485 *
AjK 0:db98027c0bbb 486 * // Or...
AjK 0:db98027c0bbb 487 * gps.ppsAttach(p29, GPS::ppsRise); // The default.
AjK 0:db98027c0bbb 488 *
AjK 0:db98027c0bbb 489 * // Or...
AjK 0:db98027c0bbb 490 * gps.ppsAttach(p29, GPS::ppsFall); // If a falling edge.
AjK 0:db98027c0bbb 491 *
AjK 0:db98027c0bbb 492 * @endcode
AjK 0:db98027c0bbb 493 *
AjK 0:db98027c0bbb 494 * <b>Note</b>, before using this function you should attach an actual
AjK 0:db98027c0bbb 495 * callback function using attach_pps()
AjK 0:db98027c0bbb 496 *
AjK 0:db98027c0bbb 497 * @see attach_pps()
AjK 0:db98027c0bbb 498 *
AjK 0:db98027c0bbb 499 * @ingroup API
AjK 0:db98027c0bbb 500 * @param irq A PinName to attach
AjK 0:db98027c0bbb 501 * @param type The type of edge, MAX7456::ppsRise OR MAX7456::ppsFall
AjK 0:db98027c0bbb 502 */
AjK 0:db98027c0bbb 503 void ppsAttach(PinName irq, ppsEdgeType type = ppsRise);
xanter 7:049436bc2225 504
AjK 0:db98027c0bbb 505 //! Remove any 1PPS signal previously attached.
AjK 0:db98027c0bbb 506 void ppsUnattach(void);
xanter 7:049436bc2225 507
AjK 0:db98027c0bbb 508 //! GPS serial receive interrupt handler.
xanter 7:049436bc2225 509 void rx_irq(void);
xanter 7:049436bc2225 510
AjK 0:db98027c0bbb 511 //! GPS pps interrupt handler.
AjK 0:db98027c0bbb 512 void pps_irq(void);
xanter 7:049436bc2225 513
AjK 0:db98027c0bbb 514 //! The RX serial buffer.
AjK 0:db98027c0bbb 515 char buffer[2][GPS_BUFFER_LEN];
xanter 7:049436bc2225 516
AjK 0:db98027c0bbb 517 //! The current "active" buffer, i.e. the buffer the ISR is writing to.
AjK 0:db98027c0bbb 518 int active_buffer;
xanter 7:049436bc2225 519
AjK 0:db98027c0bbb 520 //! The active buffer "in" pointer.
AjK 0:db98027c0bbb 521 int rx_buffer_in;
xanter 7:049436bc2225 522
AjK 0:db98027c0bbb 523 //! Boolean flag set when the "passive" buffer is full and needs processing.
AjK 0:db98027c0bbb 524 bool process_required;
xanter 7:049436bc2225 525
AjK 0:db98027c0bbb 526 //! 10ms Ticker callback.
AjK 0:db98027c0bbb 527 void ticktock(void);
xanter 7:049436bc2225 528
AjK 0:db98027c0bbb 529 //! Attach a user object/method callback function to the PPS signal
AjK 0:db98027c0bbb 530 /**
xanter 7:049436bc2225 531 * Attach a user callback object/method to call when the 1PPS signal activates.
AjK 0:db98027c0bbb 532 *
AjK 0:db98027c0bbb 533 * @code
AjK 0:db98027c0bbb 534 * class FOO {
AjK 0:db98027c0bbb 535 * public:
AjK 0:db98027c0bbb 536 * void myCallback(void);
AjK 0:db98027c0bbb 537 * };
AjK 0:db98027c0bbb 538 *
xanter 7:049436bc2225 539 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 540 * Foo foo;
AjK 0:db98027c0bbb 541 *
AjK 0:db98027c0bbb 542 * gps.attach_pps(foo, &FOO::myCallback);
xanter 7:049436bc2225 543 *
AjK 0:db98027c0bbb 544 * @endcode
AjK 0:db98027c0bbb 545 *
AjK 0:db98027c0bbb 546 * @ingroup API
AjK 0:db98027c0bbb 547 * @param tptr pointer to the object to call the member function on
AjK 0:db98027c0bbb 548 * @param mptr pointer to the member function to be called
AjK 0:db98027c0bbb 549 */
AjK 0:db98027c0bbb 550 template<typename T>
xanter 7:049436bc2225 551 void attach_pps(T* tptr, void (T::*mptr)(void)) {
xanter 7:049436bc2225 552 cb_pps.attach(tptr, mptr);
xanter 7:049436bc2225 553 }
xanter 7:049436bc2225 554
AjK 0:db98027c0bbb 555 //! Attach a user callback function to the PPS signal
AjK 0:db98027c0bbb 556 /**
xanter 7:049436bc2225 557 * Attach a user callback function pointer to call when the 1PPS signal activates.
AjK 0:db98027c0bbb 558 *
AjK 0:db98027c0bbb 559 * @code
AjK 0:db98027c0bbb 560 * void myCallback(void) { ... }
AjK 0:db98027c0bbb 561 *
xanter 7:049436bc2225 562 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 563 * Foo foo;
AjK 0:db98027c0bbb 564 *
AjK 0:db98027c0bbb 565 * gps.attach_pps(&myCallback);
xanter 7:049436bc2225 566 *
AjK 0:db98027c0bbb 567 * @endcode
AjK 0:db98027c0bbb 568 *
AjK 0:db98027c0bbb 569 * @ingroup API
AjK 0:db98027c0bbb 570 * @param fptr Callback function pointer
AjK 0:db98027c0bbb 571 */
xanter 7:049436bc2225 572 void attach_pps(const Callback<void()> & func) {
xanter 7:049436bc2225 573 cb_pps = func;
xanter 7:049436bc2225 574 }
xanter 7:049436bc2225 575
AjK 0:db98027c0bbb 576 //! A callback object for the 1PPS user API.
xanter 7:049436bc2225 577 Callback<void()> cb_pps;
xanter 7:049436bc2225 578
AjK 0:db98027c0bbb 579 //! Attach a user callback function to the NMEA RMC message processed signal.
AjK 0:db98027c0bbb 580 /**
xanter 7:049436bc2225 581 * Attach a user callback object/method to call when an NMEA RMC packet has been processed.
AjK 0:db98027c0bbb 582 *
AjK 0:db98027c0bbb 583 * @code
AjK 0:db98027c0bbb 584 * class FOO {
AjK 0:db98027c0bbb 585 * public:
AjK 0:db98027c0bbb 586 * void myCallback(void);
AjK 0:db98027c0bbb 587 * };
AjK 0:db98027c0bbb 588 *
xanter 7:049436bc2225 589 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 590 * Foo foo;
AjK 0:db98027c0bbb 591 *
AjK 0:db98027c0bbb 592 * gps.attach_rmc(foo, &FOO::myCallback);
xanter 7:049436bc2225 593 *
AjK 0:db98027c0bbb 594 * @endcode
AjK 0:db98027c0bbb 595 *
xanter 7:049436bc2225 596 * @ingroup API
AjK 0:db98027c0bbb 597 * @param tptr pointer to the object to call the member function on
AjK 0:db98027c0bbb 598 * @param mptr pointer to the member function to be called
AjK 0:db98027c0bbb 599 */
AjK 0:db98027c0bbb 600 template<typename T>
xanter 7:049436bc2225 601 void attach_rmc(T* tptr, void (T::*mptr)(void)) {
xanter 7:049436bc2225 602 cb_rmc.attach(tptr, mptr);
xanter 7:049436bc2225 603 }
xanter 7:049436bc2225 604
AjK 0:db98027c0bbb 605 //! Attach a user callback function to the NMEA RMC message processed signal.
AjK 0:db98027c0bbb 606 /**
xanter 7:049436bc2225 607 * Attach a user callback function pointer to call when an NMEA RMC packet has been processed.
AjK 0:db98027c0bbb 608 *
AjK 0:db98027c0bbb 609 * @code
AjK 0:db98027c0bbb 610 * void myCallback(void) { ... }
AjK 0:db98027c0bbb 611 *
xanter 7:049436bc2225 612 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 613 * Foo foo;
AjK 0:db98027c0bbb 614 *
AjK 0:db98027c0bbb 615 * gps.attach_rmc(&myCallback);
xanter 7:049436bc2225 616 *
AjK 0:db98027c0bbb 617 * @endcode
AjK 0:db98027c0bbb 618 *
xanter 7:049436bc2225 619 * @ingroup API
AjK 0:db98027c0bbb 620 * @param fptr Callback function pointer.
AjK 0:db98027c0bbb 621 */
xanter 7:049436bc2225 622 void attach_rmc(const Callback<void()> & func) {
xanter 7:049436bc2225 623 cb_rmc = func;
xanter 7:049436bc2225 624 }
xanter 7:049436bc2225 625
AjK 0:db98027c0bbb 626 //! A callback object for the NMEA RMS message processed signal user API.
xanter 7:049436bc2225 627 Callback<void()> cb_rmc;
xanter 7:049436bc2225 628
AjK 0:db98027c0bbb 629 //! Attach a user callback function to the NMEA GGA message processed signal.
AjK 0:db98027c0bbb 630 /**
xanter 7:049436bc2225 631 * Attach a user callback object/method to call when an NMEA GGA packet has been processed.
AjK 0:db98027c0bbb 632 *
AjK 0:db98027c0bbb 633 * @code
AjK 0:db98027c0bbb 634 * class FOO {
AjK 0:db98027c0bbb 635 * public:
AjK 0:db98027c0bbb 636 * void myCallback(void);
AjK 0:db98027c0bbb 637 * };
AjK 0:db98027c0bbb 638 *
xanter 7:049436bc2225 639 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 640 * Foo foo;
AjK 0:db98027c0bbb 641 *
AjK 0:db98027c0bbb 642 * gps.attach_gga(foo, &FOO::myCallback);
xanter 7:049436bc2225 643 *
AjK 0:db98027c0bbb 644 * @endcode
AjK 0:db98027c0bbb 645 *
xanter 7:049436bc2225 646 * @ingroup API
AjK 0:db98027c0bbb 647 * @param tptr pointer to the object to call the member function on
AjK 0:db98027c0bbb 648 * @param mptr pointer to the member function to be called
AjK 0:db98027c0bbb 649 */
AjK 0:db98027c0bbb 650 template<typename T>
xanter 7:049436bc2225 651 void attach_gga(T* tptr, void (T::*mptr)(void)) {
xanter 7:049436bc2225 652 cb_gga.attach(tptr, mptr);
xanter 7:049436bc2225 653 }
xanter 7:049436bc2225 654
AjK 0:db98027c0bbb 655 //! Attach a user callback function to the NMEA GGA message processed signal.
AjK 0:db98027c0bbb 656 /**
xanter 7:049436bc2225 657 * Attach a user callback function pointer to call when an NMEA GGA packet has been processed.
AjK 0:db98027c0bbb 658 *
AjK 0:db98027c0bbb 659 * @code
AjK 0:db98027c0bbb 660 * void myCallback(void) { ... }
AjK 0:db98027c0bbb 661 *
xanter 7:049436bc2225 662 * GPS gps(NC, p9);
AjK 0:db98027c0bbb 663 * Foo foo;
AjK 0:db98027c0bbb 664 *
AjK 0:db98027c0bbb 665 * gps.attach_gga(&myCallback);
xanter 7:049436bc2225 666 *
AjK 0:db98027c0bbb 667 * @endcode
AjK 0:db98027c0bbb 668 *
xanter 7:049436bc2225 669 * @ingroup API
AjK 0:db98027c0bbb 670 * @param fptr Callback function pointer.
AjK 0:db98027c0bbb 671 */
xanter 7:049436bc2225 672 void attach_gga(const Callback<void()> & func) {
xanter 7:049436bc2225 673 cb_gga = func;
xanter 7:049436bc2225 674 }
xanter 7:049436bc2225 675
AjK 0:db98027c0bbb 676 //! A callback object for the NMEA GGA message processed signal user API.
xanter 7:049436bc2225 677 Callback<void()> cb_gga;
AjK 0:db98027c0bbb 678
AjK 2:8aa059e7d8b1 679
AjK 2:8aa059e7d8b1 680 //! Attach a user callback function to the NMEA VTG message processed signal.
AjK 2:8aa059e7d8b1 681 /**
xanter 7:049436bc2225 682 * Attach a user callback object/method to call when an NMEA VTG packet has been processed.
AjK 2:8aa059e7d8b1 683 *
AjK 2:8aa059e7d8b1 684 * @code
AjK 2:8aa059e7d8b1 685 * class FOO {
AjK 2:8aa059e7d8b1 686 * public:
AjK 2:8aa059e7d8b1 687 * void myCallback(void);
AjK 2:8aa059e7d8b1 688 * };
AjK 2:8aa059e7d8b1 689 *
xanter 7:049436bc2225 690 * GPS gps(NC, p9);
AjK 2:8aa059e7d8b1 691 * Foo foo;
AjK 2:8aa059e7d8b1 692 *
AjK 2:8aa059e7d8b1 693 * gps.attach_vtg(foo, &FOO::myCallback);
xanter 7:049436bc2225 694 *
AjK 2:8aa059e7d8b1 695 * @endcode
AjK 2:8aa059e7d8b1 696 *
xanter 7:049436bc2225 697 * @ingroup API
AjK 2:8aa059e7d8b1 698 * @param tptr pointer to the object to call the member function on
AjK 2:8aa059e7d8b1 699 * @param mptr pointer to the member function to be called
AjK 2:8aa059e7d8b1 700 */
AjK 2:8aa059e7d8b1 701 template<typename T>
xanter 7:049436bc2225 702 void attach_vtg(T* tptr, void (T::*mptr)(void)) {
xanter 7:049436bc2225 703 cb_vtg.attach(tptr, mptr);
xanter 7:049436bc2225 704 }
xanter 7:049436bc2225 705
AjK 2:8aa059e7d8b1 706 //! Attach a user callback function to the NMEA VTG message processed signal.
AjK 2:8aa059e7d8b1 707 /**
xanter 7:049436bc2225 708 * Attach a user callback function pointer to call when an NMEA VTG packet has been processed.
AjK 2:8aa059e7d8b1 709 *
AjK 2:8aa059e7d8b1 710 * @code
AjK 2:8aa059e7d8b1 711 * void myCallback(void) { ... }
AjK 2:8aa059e7d8b1 712 *
xanter 7:049436bc2225 713 * GPS gps(NC, p9);
AjK 2:8aa059e7d8b1 714 * Foo foo;
AjK 2:8aa059e7d8b1 715 *
AjK 2:8aa059e7d8b1 716 * gps.attach_vtg(&myCallback);
xanter 7:049436bc2225 717 *
AjK 2:8aa059e7d8b1 718 * @endcode
AjK 2:8aa059e7d8b1 719 *
xanter 7:049436bc2225 720 * @ingroup API
AjK 2:8aa059e7d8b1 721 * @param fptr Callback function pointer.
AjK 2:8aa059e7d8b1 722 */
xanter 7:049436bc2225 723 void attach_vtg(const Callback<void()> & func) {
xanter 7:049436bc2225 724 cb_vtg = func;
xanter 7:049436bc2225 725 }
xanter 7:049436bc2225 726
AjK 2:8aa059e7d8b1 727 //! A callback object for the NMEA RMS message processed signal user API.
xanter 7:049436bc2225 728 Callback<void()> cb_vtg;
xanter 7:049436bc2225 729
AjK 6:64771e31464e 730 //! Attach a user callback function to the unknown NMEA message.
AjK 6:64771e31464e 731 /**
xanter 7:049436bc2225 732 * Attach a user callback object/method to call when an unknown NMEA packet.
AjK 6:64771e31464e 733 *
AjK 6:64771e31464e 734 * @code
AjK 6:64771e31464e 735 * class FOO {
AjK 6:64771e31464e 736 * public:
AjK 6:64771e31464e 737 * void myCallback(void);
AjK 6:64771e31464e 738 * };
AjK 6:64771e31464e 739 *
xanter 7:049436bc2225 740 * GPS gps(NC, p9);
AjK 6:64771e31464e 741 * Foo foo;
AjK 6:64771e31464e 742 *
AjK 6:64771e31464e 743 * gps.attach_ukn(foo, &FOO::myCallback);
xanter 7:049436bc2225 744 *
AjK 6:64771e31464e 745 * @endcode
AjK 6:64771e31464e 746 *
xanter 7:049436bc2225 747 * @ingroup API
AjK 6:64771e31464e 748 * @param tptr pointer to the object to call the member function on
AjK 6:64771e31464e 749 * @param mptr pointer to the member function to be called
AjK 6:64771e31464e 750 */
AjK 6:64771e31464e 751 template<typename T>
xanter 7:049436bc2225 752 void attach_ukn(T* tptr, void (T::*mptr)(void)) {
xanter 7:049436bc2225 753 cb_ukn.attach(tptr, mptr);
xanter 7:049436bc2225 754 }
xanter 7:049436bc2225 755
AjK 6:64771e31464e 756 //! Attach a user callback function to the unknown NMEA message.
AjK 6:64771e31464e 757 /**
xanter 7:049436bc2225 758 * Attach a user callback function pointer to call when an unknown NMEA.
AjK 6:64771e31464e 759 *
AjK 6:64771e31464e 760 * @code
AjK 6:64771e31464e 761 * void myCallback(void) { ... }
AjK 6:64771e31464e 762 *
xanter 7:049436bc2225 763 * GPS gps(NC, p9);
AjK 6:64771e31464e 764 * Foo foo;
AjK 6:64771e31464e 765 *
AjK 6:64771e31464e 766 * gps.attach_ukn(&myCallback);
xanter 7:049436bc2225 767 *
AjK 6:64771e31464e 768 * @endcode
AjK 6:64771e31464e 769 *
xanter 7:049436bc2225 770 * @ingroup API
AjK 6:64771e31464e 771 * @param fptr Callback function pointer.
AjK 6:64771e31464e 772 */
xanter 7:049436bc2225 773 void attach_ukn(const Callback<void()> & func) {
xanter 7:049436bc2225 774 cb_ukn = func;
xanter 7:049436bc2225 775 }
xanter 7:049436bc2225 776
AjK 6:64771e31464e 777 //! A callback object for the NMEA RMS message processed signal user API.
xanter 7:049436bc2225 778 Callback<void()> cb_ukn;
xanter 7:049436bc2225 779
AjK 6:64771e31464e 780 /**
AjK 6:64771e31464e 781 * Set's the GGA string memory pointer.
AjK 6:64771e31464e 782 * @param s char pointer ti string.
AjK 6:64771e31464e 783 * @return char s passed in.
AjK 6:64771e31464e 784 */
xanter 7:049436bc2225 785 char * setGga(char *s) {
xanter 7:049436bc2225 786 _gga = s;
xanter 7:049436bc2225 787 return s;
xanter 7:049436bc2225 788 }
xanter 7:049436bc2225 789
AjK 6:64771e31464e 790 /**
AjK 6:64771e31464e 791 * Set's the RMC string memory pointer.
AjK 6:64771e31464e 792 * @param s char pointer ti string.
AjK 6:64771e31464e 793 * @return char s passed in.
AjK 6:64771e31464e 794 */
xanter 7:049436bc2225 795 char * setRmc(char *s) {
xanter 7:049436bc2225 796 _rmc = s;
xanter 7:049436bc2225 797 return s;
xanter 7:049436bc2225 798 };
xanter 7:049436bc2225 799
AjK 6:64771e31464e 800 /**
AjK 6:64771e31464e 801 * Set's the VTG string memory pointer.
AjK 6:64771e31464e 802 * @param s char pointer ti string.
AjK 6:64771e31464e 803 * @return char s passed in.
AjK 6:64771e31464e 804 */
xanter 7:049436bc2225 805 char * setVtg(char *s) {
xanter 7:049436bc2225 806 _vtg = s;
xanter 7:049436bc2225 807 return s;
xanter 7:049436bc2225 808 };
xanter 7:049436bc2225 809
AjK 6:64771e31464e 810 /**
AjK 6:64771e31464e 811 * Set's the UKN string memory pointer.
AjK 6:64771e31464e 812 * @param s char pointer ti string.
AjK 6:64771e31464e 813 * @return char s passed in.
AjK 6:64771e31464e 814 */
xanter 7:049436bc2225 815 char * setUkn(char *s) {
xanter 7:049436bc2225 816 _ukn = s;
xanter 7:049436bc2225 817 return s;
xanter 7:049436bc2225 818 };
xanter 7:049436bc2225 819
AjK 0:db98027c0bbb 820 //! Set the baud rate the GPS module is using.
xanter 7:049436bc2225 821 /**
AjK 0:db98027c0bbb 822 * Set the baud rate of the serial port
xanter 7:049436bc2225 823 *
AjK 0:db98027c0bbb 824 * @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.baud
AjK 0:db98027c0bbb 825 *
xanter 7:049436bc2225 826 * @ingroup API
AjK 0:db98027c0bbb 827 * @param baudrate The baudrate to set.
AjK 0:db98027c0bbb 828 */
xanter 7:049436bc2225 829 void baud(int baudrate) {
xanter 7:049436bc2225 830 RawSerial::baud(baudrate);
xanter 7:049436bc2225 831 }
xanter 7:049436bc2225 832
xanter 7:049436bc2225 833 //! Set the serial port format the GPS module is using.
xanter 7:049436bc2225 834 /**
xanter 7:049436bc2225 835 * Set the transmission format used by the Serial port
xanter 7:049436bc2225 836 *
xanter 7:049436bc2225 837 * @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.format
xanter 7:049436bc2225 838 *
xanter 7:049436bc2225 839 * @ingroup API
xanter 7:049436bc2225 840 * @param bits - The number of bits in a word (5-8; default = 8)
xanter 7:049436bc2225 841 * @param parity - The parity used (GPS::None, GPS::Odd, GPS::Even, GPS::Forced1, GPS::Forced0; default = GPS::None)
xanter 7:049436bc2225 842 * @param stop_bits - The number of stop bits (1 or 2; default = 1)
xanter 7:049436bc2225 843 */
xanter 7:049436bc2225 844 void format(int bits, Parity parity, int stop_bits) {
xanter 7:049436bc2225 845 RawSerial::format(bits, parity, stop_bits);
xanter 7:049436bc2225 846 }
xanter 7:049436bc2225 847
xanter 7:049436bc2225 848 //! Send incoming GPS bytes to Uart0
xanter 7:049436bc2225 849 /**
xanter 7:049436bc2225 850 * Send incoming GPS bytes to Uart0
xanter 7:049436bc2225 851 *
xanter 7:049436bc2225 852 * This can be useful for printing out the bytes from the GPS onto
xanter 7:049436bc2225 853 * a the common debug port Uart0. Note, Uart0 should have been setup
xanter 7:049436bc2225 854 * and initialised before switching this on. Also, realistically,
xanter 7:049436bc2225 855 * you should ensure Uart0 has a higher baud rate than that being
xanter 7:049436bc2225 856 * used by the GPS. Sending of bytes to Uart0 is "raw" and should
xanter 7:049436bc2225 857 * only be used to initially gather data and should NOT be used as
xanter 7:049436bc2225 858 * part of the application design. If you need to forward on the
xanter 7:049436bc2225 859 * data you should come up with a proper strategy.
xanter 7:049436bc2225 860 *
xanter 7:049436bc2225 861 * @ingroup API
xanter 7:049436bc2225 862 * @param b - True to send to Uart0, false otherwise
xanter 7:049436bc2225 863 */
xanter 7:049436bc2225 864 void NmeaOnUart0(bool b) {
xanter 7:049436bc2225 865 _nmeaOnUart0 = b;
xanter 7:049436bc2225 866 }
xanter 7:049436bc2225 867
AjK 0:db98027c0bbb 868 protected:
AjK 0:db98027c0bbb 869
AjK 0:db98027c0bbb 870 //! Flag set true when a GPS PPS has been attached to a pin.
xanter 7:049436bc2225 871 bool _ppsInUse;
xanter 7:049436bc2225 872
AjK 0:db98027c0bbb 873 //! An InterruptIn object to "trigger" on the PPS edge.
xanter 7:049436bc2225 874 InterruptIn * _pps;
xanter 7:049436bc2225 875
AjK 0:db98027c0bbb 876 //! A Ticker object called every 10ms.
xanter 7:049436bc2225 877 Ticker * _second100;
xanter 7:049436bc2225 878
AjK 0:db98027c0bbb 879 //! A GPS_Time object used to hold the last parsed time/date data.
xanter 7:049436bc2225 880 GPS_Time theTime;
xanter 7:049436bc2225 881
AjK 0:db98027c0bbb 882 //! A GPS_Geodetic object used to hold the last parsed positional data.
AjK 2:8aa059e7d8b1 883 GPS_Geodetic thePlace;
xanter 7:049436bc2225 884
AjK 2:8aa059e7d8b1 885 //! A GPS_VTG object used to hold vector data.
xanter 7:049436bc2225 886 GPS_VTG theVTG;
xanter 7:049436bc2225 887
AjK 3:28a1b60b0f37 888 //! Used to record the previous byte received.
AjK 3:28a1b60b0f37 889 char _lastByte;
xanter 7:049436bc2225 890
xanter 7:049436bc2225 891 char * _gga;
xanter 7:049436bc2225 892 char * _rmc;
xanter 7:049436bc2225 893 char * _vtg;
xanter 7:049436bc2225 894 char * _ukn;
xanter 7:049436bc2225 895
AjK 3:28a1b60b0f37 896 //! Used for debugging.
xanter 7:049436bc2225 897 bool _nmeaOnUart0;
AjK 0:db98027c0bbb 898 };
AjK 0:db98027c0bbb 899
AjK 0:db98027c0bbb 900 #endif
AjK 0:db98027c0bbb 901