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.
Revision 0:94c22ada3c5a, committed 2012-07-01
- Comitter:
- JST2011
- Date:
- Sun Jul 01 15:14:45 2012 +0000
- Commit message:
- *Fixed calculation around longitude
Changed in this revision
| GPS.cpp | Show annotated file Show diff for this revision Revisions of this file |
| GPS.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.cpp Sun Jul 01 15:14:45 2012 +0000
@@ -0,0 +1,92 @@
+#include "GPS.h"
+
+GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
+ _gps.baud(4800);
+ _gps.printf("$PSRF103,2,0,0,1*26\r\n");
+ _gps.printf("$PSRF103,3,0,0,1*27\r\n");
+ _gps.printf("$PSRF103,4,0,0,1*20\r\n");
+ flag_gps_get = 0;
+ flag_gps_getend = 0;
+ _gps.attach(this,&GPS::sample,Serial::RxIrq);
+ count = 0;
+ flag_gga = 0;
+}
+
+void GPS::sample() {
+ getline();
+ if(flag_gps_getend){
+ if(sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &_time, &_latitude, &_ns, &_longitude, &_ew, &_lock) >= 1) {
+ flag_gga = 1;
+ strcpy(gga,msg);
+ float degrees = floor(_latitude / 100.0f);
+ float minutes = _latitude - (degrees * 100.0f);
+ _latitude = degrees + minutes / 60.0f;
+ degrees = floor(_longitude / 100.0f);
+ minutes = _longitude - (degrees * 100.0f);
+ _longitude = degrees + minutes /60.0f;
+ }
+ flag_gps_getend = 0;
+ }
+}
+
+char* GPS::getGGA(){
+ if(flag_gga){
+// strcpy(gga,msg);
+ flag_gga = 0;
+ }
+ return gga;
+}
+
+float GPS::longitude(){
+ return _longitude;
+}
+
+float GPS::latitude(){
+ return _latitude;
+}
+
+float GPS::time(){
+ return _time;
+}
+
+int GPS::ns(){
+ int d;
+ if(_ns == 'N'){
+ d = 1;
+ }else{
+ d = -1;
+ }
+ return d;
+}
+
+int GPS::ew(){
+ int d;
+ if(_ew == 'E'){
+ d = 1;
+ }else{
+ d = -1;
+ }
+ return d;
+}
+
+int GPS::lock(){
+ return _lock;
+}
+
+void GPS::getline() {
+ char temp;
+ temp = _gps.getc();
+ if(temp == '$'){
+ flag_gps_get = 1;
+ count = 0;
+ }
+ if(flag_gps_get){
+ msg[count] = temp;
+ if(temp == '\r'){
+ msg[count] = '\0';
+ flag_gps_getend = 1;
+ flag_gps_get = 0;
+ }
+ count ++;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.h Sun Jul 01 15:14:45 2012 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+#ifndef MBED_GPS_H
+#define MBED_GPS_H
+class GPS {
+public:
+ GPS(PinName tx, PinName rx);
+ char* getGGA();
+ float longitude();
+ float latitude();
+ float time();
+ int ns();
+ int ew();
+ int lock();
+private:
+ void sample();
+ void getline();
+ Serial _gps;
+ char msg[128],gga[128];
+ float _longitude;
+ float _latitude;
+ float _time;
+ char _ns, _ew;
+ int _lock;
+ int flag_gps_get;
+ int flag_gps_getend;
+ int count;
+ int flag_gga;
+};
+#endif
\ No newline at end of file