Slightly modified version of the SerialGPS library (https://os.mbed.com/teams/components/code/SerialGPS/) to support the BufferedSerial class
SerialGPS.h@4:2c76f1ec13a9, 2021-04-01 (annotated)
- Committer:
- runesla
- Date:
- Thu Apr 01 21:18:48 2021 +0200
- Revision:
- 4:2c76f1ec13a9
- Parent:
- 3:ebd79e3acf14
- Child:
- 5:cc8f9d7f9bdb
addded DMS to DD conversion
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 |
4:2c76f1ec13a9 | 60 | * Helper function for converting from Decimal Minutes Seconds (DMS) to Decimal Degrees (DD) |
runesla |
4:2c76f1ec13a9 | 61 | * |
runesla |
4:2c76f1ec13a9 | 62 | * @param dms float containing the DMS value |
runesla |
4:2c76f1ec13a9 | 63 | * @return dd the converted value |
runesla |
4:2c76f1ec13a9 | 64 | */ |
runesla |
4:2c76f1ec13a9 | 65 | inline float convert(float dms) |
runesla |
4:2c76f1ec13a9 | 66 | { |
runesla |
4:2c76f1ec13a9 | 67 | float degmin, sec; |
runesla |
4:2c76f1ec13a9 | 68 | sec = modf(dms, °min); |
runesla |
4:2c76f1ec13a9 | 69 | |
runesla |
4:2c76f1ec13a9 | 70 | float deg = (int) degmin / 100; |
runesla |
4:2c76f1ec13a9 | 71 | float min = (int) degmin % 100; |
runesla |
4:2c76f1ec13a9 | 72 | |
runesla |
4:2c76f1ec13a9 | 73 | float dd = deg + (min / 60.0) + (sec / 60); |
runesla |
4:2c76f1ec13a9 | 74 | |
runesla |
4:2c76f1ec13a9 | 75 | return dd; |
runesla |
4:2c76f1ec13a9 | 76 | }; |
runesla |
4:2c76f1ec13a9 | 77 | |
runesla |
3:ebd79e3acf14 | 78 | /** |
runesla |
4:2c76f1ec13a9 | 79 | * The longitude (call read() to set) |
runesla |
3:ebd79e3acf14 | 80 | * |
runesla |
3:ebd79e3acf14 | 81 | * @return _lat the latitude component |
runesla |
3:ebd79e3acf14 | 82 | */ |
runesla |
3:ebd79e3acf14 | 83 | float get_lon(); |
runesla |
0:1a8299deb917 | 84 | |
runesla |
2:e7f24389167b | 85 | /** |
runesla |
4:2c76f1ec13a9 | 86 | * The latitude (call read() to set) |
runesla |
3:ebd79e3acf14 | 87 | * |
runesla |
3:ebd79e3acf14 | 88 | * @return _lon the longitude component |
runesla |
2:e7f24389167b | 89 | */ |
runesla |
3:ebd79e3acf14 | 90 | float get_lat(); |
runesla |
0:1a8299deb917 | 91 | |
runesla |
2:e7f24389167b | 92 | private: |
runesla |
2:e7f24389167b | 93 | void getline(); |
runesla |
3:ebd79e3acf14 | 94 | void set_vals(); |
runesla |
3:ebd79e3acf14 | 95 | char read_char(); |
runesla |
3:ebd79e3acf14 | 96 | |
runesla |
2:e7f24389167b | 97 | BufferedSerial* _gps_p; |
runesla |
2:e7f24389167b | 98 | BufferedSerial& _gps; |
runesla |
3:ebd79e3acf14 | 99 | |
runesla |
3:ebd79e3acf14 | 100 | char _nmea[MAX_LINELENGTH]; |
runesla |
3:ebd79e3acf14 | 101 | bool _fix; |
runesla |
3:ebd79e3acf14 | 102 | |
runesla |
3:ebd79e3acf14 | 103 | float _UTCtime, _lat, _lon; |
runesla |
3:ebd79e3acf14 | 104 | int _lock; |
runesla |
3:ebd79e3acf14 | 105 | char _status, _NS, _EW; |
runesla |
0:1a8299deb917 | 106 | }; |
runesla |
0:1a8299deb917 | 107 | |
runesla |
0:1a8299deb917 | 108 | #endif |