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.
SerialGPS.h
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 #ifndef MBED_GPS_H 00025 #define MBED_GPS_H 00026 00027 #include "mbed.h" 00028 #include <cstring> 00029 #include "BufferedSerial.h" 00030 00031 #define MAX_LINELENGTH 255 00032 00033 class SerialGPS 00034 { 00035 public: 00036 SerialGPS(PinName tx, PinName rx, int baud); 00037 00038 SerialGPS(BufferedSerial* serial); 00039 00040 /** 00041 * Read the incoming GPS data 00042 */ 00043 void read(); 00044 00045 /** 00046 * Send PMTK command to GPS 00047 * 00048 * @param cmd the PMTK command to send to the GPS module 00049 */ 00050 void send_command(const char* cmd); 00051 00052 /** 00053 * GPS fix 00054 * 00055 * @return true if the GPS module has acquired fix 00056 */ 00057 bool fix(); 00058 00059 /** 00060 * Read one character from the UART interface 00061 * 00062 * @return ch the character extracted from the UART interface 00063 */ 00064 inline char read_char() 00065 { 00066 char ch; 00067 this->_gps_p->read(&ch, 1); 00068 return ch; 00069 } 00070 00071 /** 00072 * Helper function for converting from Decimal Minutes Seconds (DMS) to Decimal Degrees (DD) 00073 * 00074 * @param dms float containing the DMS value 00075 * @return dd the converted value 00076 */ 00077 inline float convert(float dms) 00078 { 00079 float degmin, sec; 00080 sec = modf(dms, °min); 00081 00082 float deg = (int) degmin / 100; 00083 float min = (int) degmin % 100; 00084 00085 float dd = deg + (min / 60.0) + (sec / 3600); 00086 00087 return dd; 00088 }; 00089 00090 /** 00091 * The longitude (call read() to set) 00092 * 00093 * @return _lat the latitude component 00094 */ 00095 float get_lon(); 00096 00097 /** 00098 * The latitude (call read() to set) 00099 * 00100 * @return _lon the longitude component 00101 */ 00102 float get_lat(); 00103 00104 private: 00105 void getline(); 00106 void set_vals(); 00107 char read_char(); 00108 00109 BufferedSerial* _gps_p; 00110 BufferedSerial& _gps; 00111 00112 char _nmea[MAX_LINELENGTH]; 00113 bool _fix; 00114 00115 float _UTCtime, _lat, _lon; 00116 int _lock; 00117 char _status, _NS, _EW; 00118 }; 00119 00120 #endif
Generated on Fri Jul 29 2022 21:51:07 by
1.7.2