Slightly modified version of the SerialGPS library (https://os.mbed.com/teams/components/code/SerialGPS/) to support the BufferedSerial class
SerialGPS.h@3:ebd79e3acf14, 2021-03-02 (annotated)
- Committer:
- runesla
- Date:
- Tue Mar 02 18:27:46 2021 +0100
- Revision:
- 3:ebd79e3acf14
- Parent:
- 2:e7f24389167b
- Child:
- 4:2c76f1ec13a9
simple parsing
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 |
3:ebd79e3acf14 | 28 | #include "BufferedSerial.h" |
runesla |
2:e7f24389167b | 29 | |
runesla |
3:ebd79e3acf14 | 30 | #define MAX_LINELENGTH 255 |
runesla |
3:ebd79e3acf14 | 31 | |
runesla |
2:e7f24389167b | 32 | class SerialGPS |
runesla |
2:e7f24389167b | 33 | { |
runesla |
2:e7f24389167b | 34 | public: |
runesla |
3:ebd79e3acf14 | 35 | SerialGPS(PinName tx, PinName rx, int baud); |
runesla |
0:1a8299deb917 | 36 | |
runesla |
3:ebd79e3acf14 | 37 | SerialGPS(BufferedSerial* serial); |
runesla |
2:e7f24389167b | 38 | |
runesla |
2:e7f24389167b | 39 | /** |
runesla |
3:ebd79e3acf14 | 40 | * Sample the incoming GPS data |
runesla |
3:ebd79e3acf14 | 41 | */ |
runesla |
3:ebd79e3acf14 | 42 | void read(); |
runesla |
3:ebd79e3acf14 | 43 | |
runesla |
3:ebd79e3acf14 | 44 | /** |
runesla |
3:ebd79e3acf14 | 45 | * Send PMTK command to GPS |
runesla |
3:ebd79e3acf14 | 46 | * |
runesla |
3:ebd79e3acf14 | 47 | * @param cmd the PMTK command to send to the GPS module |
runesla |
2:e7f24389167b | 48 | */ |
runesla |
3:ebd79e3acf14 | 49 | void send_command(const char* cmd); |
runesla |
3:ebd79e3acf14 | 50 | |
runesla |
3:ebd79e3acf14 | 51 | /** |
runesla |
3:ebd79e3acf14 | 52 | * GPS fix |
runesla |
3:ebd79e3acf14 | 53 | * |
runesla |
3:ebd79e3acf14 | 54 | * @return true if the GPS module has acquired fix |
runesla |
3:ebd79e3acf14 | 55 | */ |
runesla |
3:ebd79e3acf14 | 56 | bool fix(); |
runesla |
3:ebd79e3acf14 | 57 | |
runesla |
3:ebd79e3acf14 | 58 | /** |
runesla |
3:ebd79e3acf14 | 59 | * The longitude (call sample() to set) |
runesla |
3:ebd79e3acf14 | 60 | * |
runesla |
3:ebd79e3acf14 | 61 | * @return _lat the latitude component |
runesla |
3:ebd79e3acf14 | 62 | */ |
runesla |
3:ebd79e3acf14 | 63 | float get_lon(); |
runesla |
0:1a8299deb917 | 64 | |
runesla |
2:e7f24389167b | 65 | /** |
runesla |
2:e7f24389167b | 66 | * The latitude (call sample() to set) |
runesla |
3:ebd79e3acf14 | 67 | * |
runesla |
3:ebd79e3acf14 | 68 | * @return _lon the longitude component |
runesla |
2:e7f24389167b | 69 | */ |
runesla |
3:ebd79e3acf14 | 70 | float get_lat(); |
runesla |
0:1a8299deb917 | 71 | |
runesla |
2:e7f24389167b | 72 | private: |
runesla |
2:e7f24389167b | 73 | float trunc(float v); |
runesla |
2:e7f24389167b | 74 | void getline(); |
runesla |
3:ebd79e3acf14 | 75 | void set_vals(); |
runesla |
3:ebd79e3acf14 | 76 | char read_char(); |
runesla |
3:ebd79e3acf14 | 77 | |
runesla |
2:e7f24389167b | 78 | BufferedSerial* _gps_p; |
runesla |
2:e7f24389167b | 79 | BufferedSerial& _gps; |
runesla |
3:ebd79e3acf14 | 80 | |
runesla |
3:ebd79e3acf14 | 81 | char _nmea[MAX_LINELENGTH]; |
runesla |
3:ebd79e3acf14 | 82 | bool _fix; |
runesla |
3:ebd79e3acf14 | 83 | |
runesla |
3:ebd79e3acf14 | 84 | float _UTCtime, _lat, _lon; |
runesla |
3:ebd79e3acf14 | 85 | int _lock; |
runesla |
3:ebd79e3acf14 | 86 | char _status, _NS, _EW; |
runesla |
0:1a8299deb917 | 87 | }; |
runesla |
0:1a8299deb917 | 88 | |
runesla |
0:1a8299deb917 | 89 | #endif |