4 pins(vcc,gnd,tx,rx)
Dependents: frdm_k64f_serialgps Low_Power_Long_Distance_IR_Vision_Robot Low_Power_Long_Distance_IR_Vision_Robot
Fork of GPS by
Revision 2:7350eda5fa8c, committed 2016-08-12
- Comitter:
- sampleCode
- Date:
- Fri Aug 12 08:14:08 2016 +0000
- Parent:
- 1:1d60e6a0ffd9
- Commit message:
- k64f+neo-6mGPS
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 |
diff -r 1d60e6a0ffd9 -r 7350eda5fa8c GPS.cpp --- a/GPS.cpp Sat Nov 02 16:17:58 2013 +0000 +++ b/GPS.cpp Fri Aug 12 08:14:08 2016 +0000 @@ -20,24 +20,26 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - + #include "GPS.h" -GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) { - _gps.baud(Baud); +GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) +{ + _gps.baud(Baud); longitude = 0.0; - latitude = 0.0; + latitude = 0.0; } -int GPS::sample() { - char ns, ew, unit; +int GPS::sample() +{ + int lock; - while(1) { + while(1) { getline(); // Check if it is a GPGGA msg (matches both locked and non-locked msg) - if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &sats, &hdop, &alt, &unit, &geoid) >= 1) { + if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &sats, &hdop, &alt, &unit, &geoid) >= 1) { if(!lock) { time = 0.0; longitude = 0.0; @@ -45,29 +47,28 @@ sats = 0; hdop = 0.0; alt = 0.0; - geoid = 0.0; + geoid = 0.0; return 0; } else { //GPGGA format according http://aprs.gids.nl/nmea/#gga // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d), - // hdop (float), altitude (float), M, geoid (float), M, , , + // hdop (float), altitude (float), M, geoid (float), M, , , //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D - - if(ns == 'S') { latitude *= -1.0; } - if(ew == 'W') { longitude *= -1.0; } - float degrees = trunc(latitude / 100.0f); - float minutes = latitude - (degrees * 100.0f); - latitude = degrees + minutes / 60.0f; - degrees = trunc(longitude / 100.0f * 0.01f); - minutes = longitude - (degrees * 100.0f); - longitude = degrees + minutes / 60.0f; + + //format utc time to beijing time,add 8 time zone + time = time + 80000.00f; + hour = int(time) / 10000; + minute = (int(time) % 10000) / 100; + seconed = int(time) % 100; + return 1; } } } } -float GPS::trunc(float v) { +float GPS::trunc(float v) +{ if(v < 0.0) { v*= -1.0; v = floor(v); @@ -78,7 +79,8 @@ return v; } -void GPS::getline() { +void GPS::getline() +{ while(_gps.getc() != '$'); // wait for the start of a line for(int i=0; i<256; i++) { msg[i] = _gps.getc();
diff -r 1d60e6a0ffd9 -r 7350eda5fa8c GPS.h --- a/GPS.h Sat Nov 02 16:17:58 2013 +0000 +++ b/GPS.h Fri Aug 12 08:14:08 2016 +0000 @@ -42,9 +42,18 @@ */ int sample(); + + /** Beijig time format(shi,fen,miao) **/ + int hour; + int minute; + int seconed; + /** The longitude (call sample() to set) */ float longitude; - + + /** display north/south, east/west unit**/ + char ns, ew, unit; + /** The latitude (call sample() to set) */ float latitude; @@ -74,6 +83,7 @@ float trunc(float v); void getline(); + //create a serial object Serial _gps; };