Slightly modified version of the SerialGPS library (https://os.mbed.com/teams/components/code/SerialGPS/) to support the BufferedSerial class
SerialGPS.h@5:cc8f9d7f9bdb, 2021-04-23 (annotated)
- Committer:
- runesla
- Date:
- Fri Apr 23 09:38:08 2021 +0200
- Revision:
- 5:cc8f9d7f9bdb
- Parent:
- 4:2c76f1ec13a9
small fixes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
runesla |
0:1a8299deb917 | 1 | /* mbed GPS Module Library |
runesla |
0:1a8299deb917 | 2 | * Copyright (c) 2008-2010, sford |
runesla |
0:1a8299deb917 | 3 | * Copyright (c) 2013, B.Adryan |
runesla |
0:1a8299deb917 | 4 | * |
runesla |
0:1a8299deb917 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
runesla |
0:1a8299deb917 | 6 | * of this software and associated documentation files (the "Software"), to deal |
runesla |
0:1a8299deb917 | 7 | * in the Software without restriction, including without limitation the rights |
runesla |
0:1a8299deb917 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
runesla |
0:1a8299deb917 | 9 | * copies of the Software, and to permit persons to whom the Software is |
runesla |
0:1a8299deb917 | 10 | * furnished to do so, subject to the following conditions: |
runesla |
0:1a8299deb917 | 11 | * |
runesla |
0:1a8299deb917 | 12 | * The above copyright notice and this permission notice shall be included in |
runesla |
0:1a8299deb917 | 13 | * all copies or substantial portions of the Software. |
runesla |
0:1a8299deb917 | 14 | * |
runesla |
0:1a8299deb917 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
runesla |
0:1a8299deb917 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
runesla |
0:1a8299deb917 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
runesla |
0:1a8299deb917 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
runesla |
0:1a8299deb917 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
runesla |
0:1a8299deb917 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
runesla |
0:1a8299deb917 | 21 | * THE SOFTWARE. |
runesla |
0:1a8299deb917 | 22 | */ |
runesla |
0:1a8299deb917 | 23 | |
runesla |
0:1a8299deb917 | 24 | #ifndef MBED_GPS_H |
runesla |
0:1a8299deb917 | 25 | #define MBED_GPS_H |
runesla |
0:1a8299deb917 | 26 | |
runesla |
2:e7f24389167b | 27 | #include "mbed.h" |
runesla |
4:2c76f1ec13a9 | 28 | #include <cstring> |
runesla |
3:ebd79e3acf14 | 29 | #include "BufferedSerial.h" |
runesla |
2:e7f24389167b | 30 | |
runesla |
3:ebd79e3acf14 | 31 | #define MAX_LINELENGTH 255 |
runesla |
3:ebd79e3acf14 | 32 | |
runesla |
2:e7f24389167b | 33 | class SerialGPS |
runesla |
2:e7f24389167b | 34 | { |
runesla |
2:e7f24389167b | 35 | public: |
runesla |
3:ebd79e3acf14 | 36 | SerialGPS(PinName tx, PinName rx, int baud); |
runesla |
0:1a8299deb917 | 37 | |
runesla |
3:ebd79e3acf14 | 38 | SerialGPS(BufferedSerial* serial); |
runesla |
2:e7f24389167b | 39 | |
runesla |
2:e7f24389167b | 40 | /** |
runesla |
4:2c76f1ec13a9 | 41 | * Read the incoming GPS data |
runesla |
3:ebd79e3acf14 | 42 | */ |
runesla |
3:ebd79e3acf14 | 43 | void read(); |
runesla |
3:ebd79e3acf14 | 44 | |
runesla |
3:ebd79e3acf14 | 45 | /** |
runesla |
3:ebd79e3acf14 | 46 | * Send PMTK command to GPS |
runesla |
3:ebd79e3acf14 | 47 | * |
runesla |
3:ebd79e3acf14 | 48 | * @param cmd the PMTK command to send to the GPS module |
runesla |
2:e7f24389167b | 49 | */ |
runesla |
3:ebd79e3acf14 | 50 | void send_command(const char* cmd); |
runesla |
3:ebd79e3acf14 | 51 | |
runesla |
3:ebd79e3acf14 | 52 | /** |
runesla |
3:ebd79e3acf14 | 53 | * GPS fix |
runesla |
3:ebd79e3acf14 | 54 | * |
runesla |
3:ebd79e3acf14 | 55 | * @return true if the GPS module has acquired fix |
runesla |
3:ebd79e3acf14 | 56 | */ |
runesla |
3:ebd79e3acf14 | 57 | bool fix(); |
runesla |
3:ebd79e3acf14 | 58 | |
runesla |
4:2c76f1ec13a9 | 59 | /** |
runesla |
5:cc8f9d7f9bdb | 60 | * Read one character from the UART interface |
runesla |
5:cc8f9d7f9bdb | 61 | * |
runesla |
5:cc8f9d7f9bdb | 62 | * @return ch the character extracted from the UART interface |
runesla |
5:cc8f9d7f9bdb | 63 | */ |
runesla |
5:cc8f9d7f9bdb | 64 | inline char read_char() |
runesla |
5:cc8f9d7f9bdb | 65 | { |
runesla |
5:cc8f9d7f9bdb | 66 | char ch; |
runesla |
5:cc8f9d7f9bdb | 67 | this->_gps_p->read(&ch, 1); |
runesla |
5:cc8f9d7f9bdb | 68 | return ch; |
runesla |
5:cc8f9d7f9bdb | 69 | } |
runesla |
5:cc8f9d7f9bdb | 70 | |
runesla |
5:cc8f9d7f9bdb | 71 | /** |
runesla |
4:2c76f1ec13a9 | 72 | * Helper function for converting from Decimal Minutes Seconds (DMS) to Decimal Degrees (DD) |
runesla |
4:2c76f1ec13a9 | 73 | * |
runesla |
4:2c76f1ec13a9 | 74 | * @param dms float containing the DMS value |
runesla |
4:2c76f1ec13a9 | 75 | * @return dd the converted value |
runesla |
4:2c76f1ec13a9 | 76 | */ |
runesla |
4:2c76f1ec13a9 | 77 | inline float convert(float dms) |
runesla |
4:2c76f1ec13a9 | 78 | { |
runesla |
4:2c76f1ec13a9 | 79 | float degmin, sec; |
runesla |
4:2c76f1ec13a9 | 80 | sec = modf(dms, °min); |
runesla |
4:2c76f1ec13a9 | 81 | |
runesla |
4:2c76f1ec13a9 | 82 | float deg = (int) degmin / 100; |
runesla |
4:2c76f1ec13a9 | 83 | float min = (int) degmin % 100; |
runesla |
4:2c76f1ec13a9 | 84 | |
runesla |
5:cc8f9d7f9bdb | 85 | float dd = deg + (min / 60.0) + (sec / 3600); |
runesla |
4:2c76f1ec13a9 | 86 | |
runesla |
4:2c76f1ec13a9 | 87 | return dd; |
runesla |
4:2c76f1ec13a9 | 88 | }; |
runesla |
4:2c76f1ec13a9 | 89 | |
runesla |
3:ebd79e3acf14 | 90 | /** |
runesla |
4:2c76f1ec13a9 | 91 | * The longitude (call read() to set) |
runesla |
3:ebd79e3acf14 | 92 | * |
runesla |
3:ebd79e3acf14 | 93 | * @return _lat the latitude component |
runesla |
3:ebd79e3acf14 | 94 | */ |
runesla |
3:ebd79e3acf14 | 95 | float get_lon(); |
runesla |
0:1a8299deb917 | 96 | |
runesla |
2:e7f24389167b | 97 | /** |
runesla |
4:2c76f1ec13a9 | 98 | * The latitude (call read() to set) |
runesla |
3:ebd79e3acf14 | 99 | * |
runesla |
3:ebd79e3acf14 | 100 | * @return _lon the longitude component |
runesla |
2:e7f24389167b | 101 | */ |
runesla |
3:ebd79e3acf14 | 102 | float get_lat(); |
runesla |
0:1a8299deb917 | 103 | |
runesla |
2:e7f24389167b | 104 | private: |
runesla |
2:e7f24389167b | 105 | void getline(); |
runesla |
3:ebd79e3acf14 | 106 | void set_vals(); |
runesla |
3:ebd79e3acf14 | 107 | char read_char(); |
runesla |
3:ebd79e3acf14 | 108 | |
runesla |
2:e7f24389167b | 109 | BufferedSerial* _gps_p; |
runesla |
2:e7f24389167b | 110 | BufferedSerial& _gps; |
runesla |
3:ebd79e3acf14 | 111 | |
runesla |
3:ebd79e3acf14 | 112 | char _nmea[MAX_LINELENGTH]; |
runesla |
3:ebd79e3acf14 | 113 | bool _fix; |
runesla |
3:ebd79e3acf14 | 114 | |
runesla |
3:ebd79e3acf14 | 115 | float _UTCtime, _lat, _lon; |
runesla |
3:ebd79e3acf14 | 116 | int _lock; |
runesla |
3:ebd79e3acf14 | 117 | char _status, _NS, _EW; |
runesla |
0:1a8299deb917 | 118 | }; |
runesla |
0:1a8299deb917 | 119 | |
runesla |
0:1a8299deb917 | 120 | #endif |