d

Dependencies:   BME280 DOGS102 DS1820 MMA845x_timmeh MTS-Serial libmDot_Australia915Mhz mbed-rtos mbed

Fork of mDot_TTN_OTAA_Node by Thing Innovations

Committer:
1994timmeh
Date:
Wed Jan 11 04:12:39 2017 +0000
Revision:
17:55ea4f38710b
Thing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1994timmeh 17:55ea4f38710b 1 /**
1994timmeh 17:55ea4f38710b 2 * @file GpsParser.h
1994timmeh 17:55ea4f38710b 3 * @brief NEMA String to Packet Parser - NEMA strings to compact packet data
1994timmeh 17:55ea4f38710b 4 * @author Tim Barr
1994timmeh 17:55ea4f38710b 5 * @version 1.0
1994timmeh 17:55ea4f38710b 6 * @see http://www.kh-gps.de/nmea.faq
1994timmeh 17:55ea4f38710b 7 * @see http://www.catb.org/gpsd/NMEA.html
1994timmeh 17:55ea4f38710b 8 * @see http://www.skytraq.com.tw/products/Venus638LPx_PB_v3.pdf
1994timmeh 17:55ea4f38710b 9 *
1994timmeh 17:55ea4f38710b 10 * Copyright (c) 2015
1994timmeh 17:55ea4f38710b 11 *
1994timmeh 17:55ea4f38710b 12 * Licensed under the Apache License, Version 2.0 (the "License");
1994timmeh 17:55ea4f38710b 13 * you may not use this file except in compliance with the License.
1994timmeh 17:55ea4f38710b 14 * You may obtain a copy of the License at
1994timmeh 17:55ea4f38710b 15 *
1994timmeh 17:55ea4f38710b 16 * http://www.apache.org/licenses/LICENSE-2.0
1994timmeh 17:55ea4f38710b 17 *
1994timmeh 17:55ea4f38710b 18 * Unless required by applicable law or agreed to in writing, software
1994timmeh 17:55ea4f38710b 19 * distributed under the License is distributed on an "AS IS" BASIS,
1994timmeh 17:55ea4f38710b 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1994timmeh 17:55ea4f38710b 21 * See the License for the specific language governing permissions and
1994timmeh 17:55ea4f38710b 22 * limitations under the License.
1994timmeh 17:55ea4f38710b 23 *
1994timmeh 17:55ea4f38710b 24 */
1994timmeh 17:55ea4f38710b 25
1994timmeh 17:55ea4f38710b 26 #ifndef GPSPARSER_H
1994timmeh 17:55ea4f38710b 27 #define GPSPARSER_H
1994timmeh 17:55ea4f38710b 28
1994timmeh 17:55ea4f38710b 29 #include "mbed.h"
1994timmeh 17:55ea4f38710b 30 #include "rtos.h"
1994timmeh 17:55ea4f38710b 31 #include "MTSSerial.h"
1994timmeh 17:55ea4f38710b 32 #include <string>
1994timmeh 17:55ea4f38710b 33 #include <vector>
1994timmeh 17:55ea4f38710b 34 #include <ctime>
1994timmeh 17:55ea4f38710b 35 #include "MTSLog.h"
1994timmeh 17:55ea4f38710b 36 #define START_THREAD 1
1994timmeh 17:55ea4f38710b 37
1994timmeh 17:55ea4f38710b 38 using namespace mts;
1994timmeh 17:55ea4f38710b 39
1994timmeh 17:55ea4f38710b 40 class GPSPARSER
1994timmeh 17:55ea4f38710b 41 {
1994timmeh 17:55ea4f38710b 42 public:
1994timmeh 17:55ea4f38710b 43
1994timmeh 17:55ea4f38710b 44 /**
1994timmeh 17:55ea4f38710b 45 * @typedef struct latitude
1994timmeh 17:55ea4f38710b 46 * @brief latitude degrees, minutes, seconds structure
1994timmeh 17:55ea4f38710b 47 * range of degrees : 0 to 90 signed (negative degrees is South)
1994timmeh 17:55ea4f38710b 48 * range of minutes : 0 to 60 unsigned
1994timmeh 17:55ea4f38710b 49 * Range of seconds : 0-9999 unsigned or 1/10000 of a minute.
1994timmeh 17:55ea4f38710b 50 * Multiply by 6 and divide or modulus by 1000 to get seconds and fractional seconds
1994timmeh 17:55ea4f38710b 51 */
1994timmeh 17:55ea4f38710b 52 typedef struct{int8_t degrees; uint8_t minutes; uint16_t seconds;} latitude;
1994timmeh 17:55ea4f38710b 53
1994timmeh 17:55ea4f38710b 54 /**
1994timmeh 17:55ea4f38710b 55 * @typedef struct longitude
1994timmeh 17:55ea4f38710b 56 * @brief longitude degrees, minutes, seconds structure negative degrees is West
1994timmeh 17:55ea4f38710b 57 * range of degrees : 0 to 180 signed (negative degrees is West)
1994timmeh 17:55ea4f38710b 58 * range of minutes : 0 to 60 unsigned
1994timmeh 17:55ea4f38710b 59 * Range of seconds : 0-9999 unsigned or 1/10000 of a minute.
1994timmeh 17:55ea4f38710b 60 * Multiply by 6 and divide or modulus by 1000 to get seconds and fractional seconds
1994timmeh 17:55ea4f38710b 61 */
1994timmeh 17:55ea4f38710b 62 typedef struct{int16_t degrees; uint8_t minutes; uint16_t seconds;} longitude;
1994timmeh 17:55ea4f38710b 63
1994timmeh 17:55ea4f38710b 64 /**
1994timmeh 17:55ea4f38710b 65 * @typdef satellite_prn
1994timmeh 17:55ea4f38710b 66 * @brief satellite prn list, up to 12 valid
1994timmeh 17:55ea4f38710b 67 */
1994timmeh 17:55ea4f38710b 68 typedef uint8_t satellite_prn[12];
1994timmeh 17:55ea4f38710b 69
1994timmeh 17:55ea4f38710b 70 /** Create the GPSPARSER object
1994timmeh 17:55ea4f38710b 71 * @param uart - an MTSSerial object
1994timmeh 17:55ea4f38710b 72 * @param led - an NCP5623B led controller object
1994timmeh 17:55ea4f38710b 73 */
1994timmeh 17:55ea4f38710b 74 GPSPARSER(MTSSerial *uart);
1994timmeh 17:55ea4f38710b 75
1994timmeh 17:55ea4f38710b 76 /** destroy the GPSPARSER object
1994timmeh 17:55ea4f38710b 77 */
1994timmeh 17:55ea4f38710b 78 ~GPSPARSER(void);
1994timmeh 17:55ea4f38710b 79
1994timmeh 17:55ea4f38710b 80 /** GPS device detected
1994timmeh 17:55ea4f38710b 81 * @return boolean whether GPS device detected
1994timmeh 17:55ea4f38710b 82 */
1994timmeh 17:55ea4f38710b 83 bool gpsDetected(void);
1994timmeh 17:55ea4f38710b 84
1994timmeh 17:55ea4f38710b 85 /** get longitude structure
1994timmeh 17:55ea4f38710b 86 * @return last valid NEMA string longitude data
1994timmeh 17:55ea4f38710b 87 */
1994timmeh 17:55ea4f38710b 88 longitude getLongitude(void);
1994timmeh 17:55ea4f38710b 89
1994timmeh 17:55ea4f38710b 90 /** get latitude structure
1994timmeh 17:55ea4f38710b 91 * @return last valid NEMA string latitude data
1994timmeh 17:55ea4f38710b 92 */
1994timmeh 17:55ea4f38710b 93 latitude getLatitude(void);
1994timmeh 17:55ea4f38710b 94
1994timmeh 17:55ea4f38710b 95 /** get timestamp structure
1994timmeh 17:55ea4f38710b 96 * @return last valid NEMA string time and date data
1994timmeh 17:55ea4f38710b 97 * uses tm struc from ctime standard library
1994timmeh 17:55ea4f38710b 98 */
1994timmeh 17:55ea4f38710b 99 struct tm getTimestamp(void);
1994timmeh 17:55ea4f38710b 100
1994timmeh 17:55ea4f38710b 101 /** get GPS Lock status
1994timmeh 17:55ea4f38710b 102 * @return boolean of last valid NEMA string lock status data
1994timmeh 17:55ea4f38710b 103 */
1994timmeh 17:55ea4f38710b 104 bool getLockStatus(void);
1994timmeh 17:55ea4f38710b 105
1994timmeh 17:55ea4f38710b 106 /** get GPS Fix status
1994timmeh 17:55ea4f38710b 107 * @return last valid NEMA Fix status data
1994timmeh 17:55ea4f38710b 108 * 1 = no fix
1994timmeh 17:55ea4f38710b 109 * 2 = 2D fix - latitude, longitude, time only valid
1994timmeh 17:55ea4f38710b 110 * 3 = 3D fix - all data valid
1994timmeh 17:55ea4f38710b 111 */
1994timmeh 17:55ea4f38710b 112 uint8_t getFixStatus(void);
1994timmeh 17:55ea4f38710b 113
1994timmeh 17:55ea4f38710b 114 /** get GPS Fix qualty
1994timmeh 17:55ea4f38710b 115 * @return last valid NEMA string Fix Quality data
1994timmeh 17:55ea4f38710b 116 * 0 = invalid
1994timmeh 17:55ea4f38710b 117 * 1 = GPS fix (SPS)
1994timmeh 17:55ea4f38710b 118 * 2 = DGPS fix
1994timmeh 17:55ea4f38710b 119 * 3 = PPS fix
1994timmeh 17:55ea4f38710b 120 * 4 = Real Time Kinematic
1994timmeh 17:55ea4f38710b 121 * 5 = Float RTK
1994timmeh 17:55ea4f38710b 122 * 6 = estimated (dead reckoning) (2.3 feature)
1994timmeh 17:55ea4f38710b 123 * 7 = Manual input mode
1994timmeh 17:55ea4f38710b 124 * 8 = Simulation mode
1994timmeh 17:55ea4f38710b 125 */
1994timmeh 17:55ea4f38710b 126 uint8_t getFixQuality(void);
1994timmeh 17:55ea4f38710b 127
1994timmeh 17:55ea4f38710b 128 /** get number of visible satellites
1994timmeh 17:55ea4f38710b 129 * @return last valid NEMA string number of satellites visible
1994timmeh 17:55ea4f38710b 130 */
1994timmeh 17:55ea4f38710b 131 uint8_t getNumSatellites(void);
1994timmeh 17:55ea4f38710b 132
1994timmeh 17:55ea4f38710b 133 /** get calculated altitude
1994timmeh 17:55ea4f38710b 134 * @return last valid NEMA string altitude data in meters
1994timmeh 17:55ea4f38710b 135 */
1994timmeh 17:55ea4f38710b 136 int16_t getAltitude(void);
1994timmeh 17:55ea4f38710b 137
1994timmeh 17:55ea4f38710b 138 /** Read NEMA sentences from specified serial port and call specific sentence parser
1994timmeh 17:55ea4f38710b 139 */
1994timmeh 17:55ea4f38710b 140 int readNemaSentence (void);
1994timmeh 17:55ea4f38710b 141
1994timmeh 17:55ea4f38710b 142 char rmc_buf[100];
1994timmeh 17:55ea4f38710b 143
1994timmeh 17:55ea4f38710b 144 private:
1994timmeh 17:55ea4f38710b 145
1994timmeh 17:55ea4f38710b 146 std::string _nema_buff;
1994timmeh 17:55ea4f38710b 147 bool _gps_detected;
1994timmeh 17:55ea4f38710b 148 latitude _gps_latitude;
1994timmeh 17:55ea4f38710b 149 longitude _gps_longitude;
1994timmeh 17:55ea4f38710b 150 struct tm _timestamp;
1994timmeh 17:55ea4f38710b 151 bool _gps_status;
1994timmeh 17:55ea4f38710b 152 uint8_t _fix_status;
1994timmeh 17:55ea4f38710b 153 uint8_t _fix_quality;
1994timmeh 17:55ea4f38710b 154 uint8_t _num_satellites;
1994timmeh 17:55ea4f38710b 155 satellite_prn _satellite_prn;
1994timmeh 17:55ea4f38710b 156 int16_t _msl_altitude;
1994timmeh 17:55ea4f38710b 157
1994timmeh 17:55ea4f38710b 158 MTSSerial *_gps_uart;
1994timmeh 17:55ea4f38710b 159 Thread _getSentenceThread;
1994timmeh 17:55ea4f38710b 160 // NCP5623B* _led;
1994timmeh 17:55ea4f38710b 161 int8_t _led_state;
1994timmeh 17:55ea4f38710b 162 Ticker _tick;
1994timmeh 17:55ea4f38710b 163 bool _tick_running;
1994timmeh 17:55ea4f38710b 164 Mutex _mutex;
1994timmeh 17:55ea4f38710b 165
1994timmeh 17:55ea4f38710b 166 /** Start sentence parser thread
1994timmeh 17:55ea4f38710b 167 *
1994timmeh 17:55ea4f38710b 168 */
1994timmeh 17:55ea4f38710b 169 static void startSentenceThread (void const *p);
1994timmeh 17:55ea4f38710b 170
1994timmeh 17:55ea4f38710b 171 /** Parse GGA NEMA sentence
1994timmeh 17:55ea4f38710b 172 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 173 */
1994timmeh 17:55ea4f38710b 174 uint8_t parseGGA(char *nema_buf);
1994timmeh 17:55ea4f38710b 175
1994timmeh 17:55ea4f38710b 176 /** Parse GSA NEMA sentence
1994timmeh 17:55ea4f38710b 177 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 178 */
1994timmeh 17:55ea4f38710b 179 uint8_t parseGSA(char *nema_buf);
1994timmeh 17:55ea4f38710b 180
1994timmeh 17:55ea4f38710b 181 /** Parse GSV NEMA sentence
1994timmeh 17:55ea4f38710b 182 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 183 */
1994timmeh 17:55ea4f38710b 184 uint8_t parseGSV(char *nema_buf);
1994timmeh 17:55ea4f38710b 185
1994timmeh 17:55ea4f38710b 186 /** Parse RMC NEMA sentence
1994timmeh 17:55ea4f38710b 187 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 188 */
1994timmeh 17:55ea4f38710b 189 uint8_t parseRMC(char *nema_buf);
1994timmeh 17:55ea4f38710b 190
1994timmeh 17:55ea4f38710b 191 /** Parse VTG NEMA sentence
1994timmeh 17:55ea4f38710b 192 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 193 */
1994timmeh 17:55ea4f38710b 194 uint8_t parseVTG(char *nema_buf);
1994timmeh 17:55ea4f38710b 195
1994timmeh 17:55ea4f38710b 196 /** Parse GLL NEMA sentence
1994timmeh 17:55ea4f38710b 197 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 198 */
1994timmeh 17:55ea4f38710b 199 uint8_t parseGLL(char *nema_buff);
1994timmeh 17:55ea4f38710b 200
1994timmeh 17:55ea4f38710b 201 /** Parse ZDA NEMA sentence
1994timmeh 17:55ea4f38710b 202 * @return status of parser attempt
1994timmeh 17:55ea4f38710b 203 */
1994timmeh 17:55ea4f38710b 204 uint8_t parseZDA(char *nema_buff);
1994timmeh 17:55ea4f38710b 205
1994timmeh 17:55ea4f38710b 206 void blinker();
1994timmeh 17:55ea4f38710b 207
1994timmeh 17:55ea4f38710b 208 };
1994timmeh 17:55ea4f38710b 209 #endif