Dependencies:   mbed

Committer:
pd0wm
Date:
Tue Sep 27 19:46:30 2011 +0000
Revision:
0:bec310bde899

        

Who changed what in which revision?

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