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.
Fork of NEO-6m-GPS by
GPS.cpp
00001 /* mbed GPS Module Library 00002 * Copyright (c) 2008-2010, sford 00003 * Copyright (c) 2013, B.Adryan 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #include "GPS.h" 00025 00026 GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx) 00027 { 00028 _gps.baud(Baud); 00029 longitude = 0.0; 00030 latitude = 0.0; 00031 } 00032 00033 int GPS::sample() 00034 { 00035 00036 int lock; 00037 00038 while(1) { 00039 00040 getline(); 00041 00042 // Check if it is a GPGGA msg (matches both locked and non-locked msg) 00043 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) { 00044 if(!lock) { 00045 time = 0.0; 00046 longitude = 0.0; 00047 latitude = 0.0; 00048 sats = 0; 00049 hdop = 0.0; 00050 alt = 0.0; 00051 geoid = 0.0; 00052 return 0; 00053 } else { 00054 //GPGGA format according http://aprs.gids.nl/nmea/#gga 00055 // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d), 00056 // hdop (float), altitude (float), M, geoid (float), M, , , 00057 //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D 00058 00059 //format utc time to beijing time,add 8 time zone 00060 time = time + 80000.00f; 00061 hour = int(time) / 10000; 00062 minute = (int(time) % 10000) / 100; 00063 seconed = int(time) % 100; 00064 00065 return 1; 00066 } 00067 } 00068 } 00069 } 00070 00071 float GPS::trunc(float v) 00072 { 00073 if(v < 0.0) { 00074 v*= -1.0; 00075 v = floor(v); 00076 v*=-1.0; 00077 } else { 00078 v = floor(v); 00079 } 00080 return v; 00081 } 00082 00083 void GPS::getline() 00084 { 00085 while(_gps.getc() != '$'); 00086 00087 // wait for the start of a line 00088 for(int i=0; i<256; i++) { 00089 msg[i] = _gps.getc(); 00090 if(msg[i] == '\r') { 00091 msg[i] = 0; 00092 00093 return; 00094 } 00095 } 00096 error("Overflowed message limit"); 00097 }
Generated on Thu Jul 28 2022 06:58:29 by
1.7.2
