Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SatGPS AntiTheftGPS FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM GPS-Lora ... more
Revision 6:64771e31464e, committed 2011-04-21
- Comitter:
- AjK
- Date:
- Thu Apr 21 14:06:17 2011 +0000
- Parent:
- 5:7f130f85d5a4
- Commit message:
- 1.16 See ChangeLog.c
Changed in this revision
--- a/ChangeLog.c Wed Apr 20 09:15:07 2011 +0000
+++ b/ChangeLog.c Thu Apr 21 14:06:17 2011 +0000
@@ -82,5 +82,11 @@
* Added the new feature that allows the library to set the Mbed RTC
to the GPS/UTC time. This ensures the RTC is kept up to date with
the latest GPS aquired time (syncs once each minute).
-
+
+1.16 - 21/04/2011
+
+ * Added the ability for an application to request a copy of a NMEA sentence
+ before it gets processed (mangled).
+ See setRmc(), setGga(), setVtg() and setUkn().
+
*/
--- a/GPS.cpp Wed Apr 20 09:15:07 2011 +0000
+++ b/GPS.cpp Thu Apr 21 14:06:17 2011 +0000
@@ -28,6 +28,12 @@
_lastByte = 0;
+ _gga = (char *)NULL;
+
+ _rmc = (char *)NULL;
+
+ _vtg = (char *)NULL;
+
switch(_uidx) {
case 1: _base = LPC_UART1; break;
case 2: _base = LPC_UART2; break;
@@ -120,6 +126,8 @@
void
GPS::ticktock(void)
{
+ int i;
+
// Increment the time structure by 1/100th of a second.
++theTime;
@@ -127,18 +135,45 @@
if (process_required) {
char *s = buffer[active_buffer == 0 ? 1 : 0];
if (!strncmp(s, "$GPRMC", 6)) {
+ if (_rmc) {
+ for(i = 0; s[i] != '\n'; i++) {
+ _rmc[i] = s[i];
+ }
+ _rmc[i++] = '\n'; _rmc[i] = '\0';
+ }
theTime.nmea_rmc(s);
cb_rmc.call();
if (!_ppsInUse) theTime.fractionalReset();
}
else if (!strncmp(s, "$GPGGA", 6)) {
+ if (_gga) {
+ for(int i = 0; s[i] != '\n'; i++) {
+ _gga[i] = s[i];
+ }
+ _gga[i++] = '\n'; _gga[i] = '\0';
+ }
thePlace.nmea_gga(s);
cb_gga.call();
}
else if (!strncmp(s, "$GPVTG", 6)) {
+ if (_vtg) {
+ for(int i = 0; s[i] != '\n'; i++) {
+ _vtg[i] = s[i];
+ }
+ _vtg[i++] = '\n'; _vtg[i] = '\0';
+ }
theVTG.nmea_vtg(s);
cb_vtg.call();
}
+ else {
+ if (_ukn) {
+ for(int i = 0; s[i] != '\n'; i++) {
+ _ukn[i] = s[i];
+ }
+ _ukn[i++] = '\n'; _ukn[i] = '\0';
+ cb_ukn.call();
+ }
+ }
process_required = false;
}
--- a/GPS.h Wed Apr 20 09:15:07 2011 +0000
+++ b/GPS.h Thu Apr 21 14:06:17 2011 +0000
@@ -697,6 +697,80 @@
//! A callback object for the NMEA RMS message processed signal user API.
FunctionPointer cb_vtg;
+ //! Attach a user callback function to the unknown NMEA message.
+ /**
+ * Attach a user callback object/method to call when an unknown NMEA packet.
+ *
+ * @code
+ * class FOO {
+ * public:
+ * void myCallback(void);
+ * };
+ *
+ * GPS gps(NC, p9);
+ * Foo foo;
+ *
+ * gps.attach_ukn(foo, &FOO::myCallback);
+ *
+ * @endcode
+ *
+ * @ingroup API
+ * @param tptr pointer to the object to call the member function on
+ * @param mptr pointer to the member function to be called
+ */
+ template<typename T>
+ void attach_ukn(T* tptr, void (T::*mptr)(void)) { cb_ukn.attach(tptr, mptr); }
+
+ //! Attach a user callback function to the unknown NMEA message.
+ /**
+ * Attach a user callback function pointer to call when an unknown NMEA.
+ *
+ * @code
+ * void myCallback(void) { ... }
+ *
+ * GPS gps(NC, p9);
+ * Foo foo;
+ *
+ * gps.attach_ukn(&myCallback);
+ *
+ * @endcode
+ *
+ * @ingroup API
+ * @param fptr Callback function pointer.
+ */
+ void attach_ukn(void (*fptr)(void)) { cb_ukn.attach(fptr); }
+
+ //! A callback object for the NMEA RMS message processed signal user API.
+ FunctionPointer cb_ukn;
+
+ /**
+ * Set's the GGA string memory pointer.
+ * @param s char pointer ti string.
+ * @return char s passed in.
+ */
+ char * setGga(char *s) { _gga = s; return s; }
+
+ /**
+ * Set's the RMC string memory pointer.
+ * @param s char pointer ti string.
+ * @return char s passed in.
+ */
+ char * setRmc(char *s) { _rmc = s; return s; };
+
+ /**
+ * Set's the VTG string memory pointer.
+ * @param s char pointer ti string.
+ * @return char s passed in.
+ */
+ char * setVtg(char *s) { _vtg = s; return s; };
+
+ /**
+ * Set's the UKN string memory pointer.
+ * @param s char pointer ti string.
+ * @return char s passed in.
+ */
+ char * setUkn(char *s) { _ukn = s; return s; };
+
//! Set the baud rate the GPS module is using.
/**
* Set the baud rate of the serial port
@@ -762,6 +836,11 @@
//! Used to record the previous byte received.
char _lastByte;
+ char *_gga;
+ char *_rmc;
+ char *_vtg;
+ char *_ukn;
+
//! Used for debugging.
bool _nmeaOnUart0;
};
--- a/example1.cpp Wed Apr 20 09:15:07 2011 +0000
+++ b/example1.cpp Thu Apr 21 14:06:17 2011 +0000
@@ -12,6 +12,11 @@
// your GPS module to.
GPS gps(NC, GPSRX);
+char rmc[GPS_BUFFER_LEN];
+char gga[GPS_BUFFER_LEN];
+char vtg[GPS_BUFFER_LEN];
+char ukn[GPS_BUFFER_LEN];
+
// 0.1 second flash of LED2
DigitalOut led2(LED2);
Timeout t2;
@@ -40,6 +45,14 @@
// can read the messages.
pc.baud(PCBAUD);
+ // Tell MODGPS "we want copies of the NMEA sentences". When a callback
+ // is made our buffers will contain a copy of the last received sentence
+ // before it was processed/destroyed.
+ gps.setRmc(rmc);
+ gps.setGga(gga);
+ gps.setVtg(vtg);
+ gps.setUkn(ukn);
+
// SET THIS.
// Most GPS modules use 9600,8,n,1 so that's what
// we default to here. Ensure your GPS module matches