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 NemaParser.cpp
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.01
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 *
1994timmeh 17:55ea4f38710b 9 * Copyright (c) 2015
1994timmeh 17:55ea4f38710b 10 *
1994timmeh 17:55ea4f38710b 11 * Licensed under the Apache License, Version 2.0 (the "License");
1994timmeh 17:55ea4f38710b 12 * you may not use this file except in compliance with the License.
1994timmeh 17:55ea4f38710b 13 * You may obtain a copy of the License at
1994timmeh 17:55ea4f38710b 14 *
1994timmeh 17:55ea4f38710b 15 * http://www.apache.org/licenses/LICENSE-2.0
1994timmeh 17:55ea4f38710b 16 *
1994timmeh 17:55ea4f38710b 17 * Unless required by applicable law or agreed to in writing, software
1994timmeh 17:55ea4f38710b 18 * distributed under the License is distributed on an "AS IS" BASIS,
1994timmeh 17:55ea4f38710b 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1994timmeh 17:55ea4f38710b 20 * See the License for the specific language governing permissions and
1994timmeh 17:55ea4f38710b 21 * limitations under the License.
1994timmeh 17:55ea4f38710b 22 *
1994timmeh 17:55ea4f38710b 23 * 09/16/15 TAB V1.01 Changed report rate of GGA and GSA NEMA sentences
1994timmeh 17:55ea4f38710b 24 * 09/22/15 TAB V1.02 Fixed status value for no GPS detected. Increased report rate
1994timmeh 17:55ea4f38710b 25 * of GSV, GGA, and GSA NEMA Sentences
1994timmeh 17:55ea4f38710b 26 *
1994timmeh 17:55ea4f38710b 27 * TODO: Add speed, compass direction, error (DOP) data. Make init more generic
1994timmeh 17:55ea4f38710b 28 */
1994timmeh 17:55ea4f38710b 29
1994timmeh 17:55ea4f38710b 30 #include "GPSPARSER.h"
1994timmeh 17:55ea4f38710b 31
1994timmeh 17:55ea4f38710b 32 using namespace mts;
1994timmeh 17:55ea4f38710b 33
1994timmeh 17:55ea4f38710b 34 GPSPARSER::GPSPARSER(MTSSerial *uart):_getSentenceThread(&GPSPARSER::startSentenceThread,this),
1994timmeh 17:55ea4f38710b 35 _led_state(0),
1994timmeh 17:55ea4f38710b 36 _tick_running(false)
1994timmeh 17:55ea4f38710b 37 {
1994timmeh 17:55ea4f38710b 38 _gps_uart = uart;
1994timmeh 17:55ea4f38710b 39 _gps_uart->baud(9600); //set GPS baud rate here
1994timmeh 17:55ea4f38710b 40
1994timmeh 17:55ea4f38710b 41 _gps_latitude.degrees = 0;
1994timmeh 17:55ea4f38710b 42 _gps_longitude.degrees = 0;
1994timmeh 17:55ea4f38710b 43 _timestamp.tm_sec = 0;
1994timmeh 17:55ea4f38710b 44 _timestamp.tm_min = 0;
1994timmeh 17:55ea4f38710b 45 _timestamp.tm_hour = 0;
1994timmeh 17:55ea4f38710b 46 _timestamp.tm_mday = 0;
1994timmeh 17:55ea4f38710b 47 _timestamp.tm_mon = 0;
1994timmeh 17:55ea4f38710b 48 _timestamp.tm_year = 0;
1994timmeh 17:55ea4f38710b 49 _timestamp.tm_wday = 0;
1994timmeh 17:55ea4f38710b 50 _timestamp.tm_yday = 0;
1994timmeh 17:55ea4f38710b 51 _timestamp.tm_isdst = -1; // time is UTC so no Daylight savings time
1994timmeh 17:55ea4f38710b 52
1994timmeh 17:55ea4f38710b 53 _gps_status = false;
1994timmeh 17:55ea4f38710b 54 _fix_status = 1;
1994timmeh 17:55ea4f38710b 55 _num_satellites =0;
1994timmeh 17:55ea4f38710b 56 _gps_detected = false;
1994timmeh 17:55ea4f38710b 57
1994timmeh 17:55ea4f38710b 58 return;
1994timmeh 17:55ea4f38710b 59 }
1994timmeh 17:55ea4f38710b 60
1994timmeh 17:55ea4f38710b 61 GPSPARSER::~GPSPARSER(void)
1994timmeh 17:55ea4f38710b 62 {
1994timmeh 17:55ea4f38710b 63 if (_gps_detected)
1994timmeh 17:55ea4f38710b 64 _getSentenceThread.terminate();
1994timmeh 17:55ea4f38710b 65 }
1994timmeh 17:55ea4f38710b 66
1994timmeh 17:55ea4f38710b 67 void GPSPARSER::startSentenceThread(void const *p)
1994timmeh 17:55ea4f38710b 68 {
1994timmeh 17:55ea4f38710b 69 GPSPARSER *instance = (GPSPARSER*)p;
1994timmeh 17:55ea4f38710b 70 instance->readNemaSentence();
1994timmeh 17:55ea4f38710b 71 }
1994timmeh 17:55ea4f38710b 72
1994timmeh 17:55ea4f38710b 73 int GPSPARSER::readNemaSentence (void) {
1994timmeh 17:55ea4f38710b 74 // logInfo("===== READING GPS ======\n\r");
1994timmeh 17:55ea4f38710b 75 // this code is specific to the Skytraq Venus GPS chip. This code could be re-written to detect another type of
1994timmeh 17:55ea4f38710b 76 // GPS device. Maybe read serial port for a specific time and detect $GP from NEMA string
1994timmeh 17:55ea4f38710b 77
1994timmeh 17:55ea4f38710b 78 // Sets Skytraq Venus GPS to output GGA,GSA,GSV every 10 seconds, and RMC every second, no ZDA,GLL,VTG
1994timmeh 17:55ea4f38710b 79 // setup string for GPS GGA GSA GSV GLL RMC VTG ZDA cksum
1994timmeh 17:55ea4f38710b 80 char init_gps[16] = {0xA0,0xA1,0x00,0x09,0x08,0x0A,0x0A,0x0A,0x00,0x01,0x00,0x00,0x00,0x03,0x0D,0x0A};
1994timmeh 17:55ea4f38710b 81 char chk_char;
1994timmeh 17:55ea4f38710b 82 uint8_t calc_cksum;
1994timmeh 17:55ea4f38710b 83 uint8_t nema_cksum;
1994timmeh 17:55ea4f38710b 84 char nema_id[2];
1994timmeh 17:55ea4f38710b 85 char nema_str[80];
1994timmeh 17:55ea4f38710b 86 char cksum_str[2];
1994timmeh 17:55ea4f38710b 87
1994timmeh 17:55ea4f38710b 88 // _getSentenceThread.signal_wait(START_THREAD);
1994timmeh 17:55ea4f38710b 89 // logInfo("GPS starting\r\n");
1994timmeh 17:55ea4f38710b 90
1994timmeh 17:55ea4f38710b 91 _gps_uart->rxClear();
1994timmeh 17:55ea4f38710b 92 _gps_uart->write(init_gps, sizeof(init_gps));
1994timmeh 17:55ea4f38710b 93
1994timmeh 17:55ea4f38710b 94 while (! _gps_uart->readable()) {
1994timmeh 17:55ea4f38710b 95 // logInfo("GPS UART NOT READABLE\n\r");
1994timmeh 17:55ea4f38710b 96 osDelay(1000);
1994timmeh 17:55ea4f38710b 97 }
1994timmeh 17:55ea4f38710b 98
1994timmeh 17:55ea4f38710b 99 do {
1994timmeh 17:55ea4f38710b 100 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 101 } while ((chk_char != 0xA0) && (!_gps_uart->rxEmpty()));
1994timmeh 17:55ea4f38710b 102
1994timmeh 17:55ea4f38710b 103 if (chk_char == 0xA0) {
1994timmeh 17:55ea4f38710b 104 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 105 // logInfo("read char %#X\r\n", chk_char);
1994timmeh 17:55ea4f38710b 106 if (chk_char == 0xA1) {
1994timmeh 17:55ea4f38710b 107 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 108 //logInfo("read char %#X\r\n", chk_char);
1994timmeh 17:55ea4f38710b 109 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 110 //logInfo("read char %#X\r\n", chk_char);
1994timmeh 17:55ea4f38710b 111 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 112 //logInfo("read char %#X\r\n", chk_char);
1994timmeh 17:55ea4f38710b 113 if (chk_char == 0x83) {
1994timmeh 17:55ea4f38710b 114 _gps_detected = true;
1994timmeh 17:55ea4f38710b 115 }
1994timmeh 17:55ea4f38710b 116 }
1994timmeh 17:55ea4f38710b 117 }
1994timmeh 17:55ea4f38710b 118
1994timmeh 17:55ea4f38710b 119 // logInfo("GPS detected %s\r\n", _gps_detected ? "true" : "false");
1994timmeh 17:55ea4f38710b 120
1994timmeh 17:55ea4f38710b 121 if (! _gps_detected) {
1994timmeh 17:55ea4f38710b 122 _fix_status = 0;
1994timmeh 17:55ea4f38710b 123 return;
1994timmeh 17:55ea4f38710b 124 }
1994timmeh 17:55ea4f38710b 125
1994timmeh 17:55ea4f38710b 126 if (_gps_uart->readable() > 80) {
1994timmeh 17:55ea4f38710b 127 do {
1994timmeh 17:55ea4f38710b 128 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 129 // logInfo("read char %#X\r\n", chk_char);
1994timmeh 17:55ea4f38710b 130 } while ((chk_char != '$') && (!_gps_uart->rxEmpty()));
1994timmeh 17:55ea4f38710b 131
1994timmeh 17:55ea4f38710b 132 if (chk_char == '$') {
1994timmeh 17:55ea4f38710b 133 _gps_uart->read(nema_id,2);
1994timmeh 17:55ea4f38710b 134 if (strpbrk(nema_id,"GP") != NULL) {
1994timmeh 17:55ea4f38710b 135 uint8_t i = 0;
1994timmeh 17:55ea4f38710b 136 calc_cksum = 0x17; // 8 bit XOR of G and P checksum seed
1994timmeh 17:55ea4f38710b 137 nema_cksum = 0; // initialize nema string checksum
1994timmeh 17:55ea4f38710b 138 memset(nema_str,0x00,80); // clear nema_str array
1994timmeh 17:55ea4f38710b 139 do {
1994timmeh 17:55ea4f38710b 140 _gps_uart->read(chk_char);
1994timmeh 17:55ea4f38710b 141 if ((chk_char != 0x0D) && (chk_char != '*')) {
1994timmeh 17:55ea4f38710b 142 nema_str[i++] = chk_char;
1994timmeh 17:55ea4f38710b 143 calc_cksum ^= chk_char; // 8 bit XOR checksum
1994timmeh 17:55ea4f38710b 144 }
1994timmeh 17:55ea4f38710b 145 if (chk_char == '*') {
1994timmeh 17:55ea4f38710b 146 _gps_uart->read(cksum_str,2);
1994timmeh 17:55ea4f38710b 147 nema_cksum = (uint8_t)strtoul(cksum_str,NULL,16);
1994timmeh 17:55ea4f38710b 148 }
1994timmeh 17:55ea4f38710b 149 } while (( chk_char != 0x0D) && !_gps_uart->rxEmpty());
1994timmeh 17:55ea4f38710b 150
1994timmeh 17:55ea4f38710b 151 // logInfo("STR %s\n", nema_str);
1994timmeh 17:55ea4f38710b 152
1994timmeh 17:55ea4f38710b 153 if (nema_cksum == calc_cksum) {
1994timmeh 17:55ea4f38710b 154 if (strncmp (nema_str,"GGA",3) == 0) {
1994timmeh 17:55ea4f38710b 155 parseGGA(nema_str);
1994timmeh 17:55ea4f38710b 156 } else if (strncmp (nema_str,"GSA",3) == 0) {
1994timmeh 17:55ea4f38710b 157 parseGSA(nema_str);
1994timmeh 17:55ea4f38710b 158 } else if (strncmp (nema_str,"GSV",3) == 0) {
1994timmeh 17:55ea4f38710b 159 parseGSV(nema_str);
1994timmeh 17:55ea4f38710b 160 } else if (strncmp (nema_str,"GLL",3) == 0) {
1994timmeh 17:55ea4f38710b 161 parseGLL(nema_str);
1994timmeh 17:55ea4f38710b 162 } else if (strncmp (nema_str,"RMC",3) == 0) {
1994timmeh 17:55ea4f38710b 163 parseRMC(nema_str);
1994timmeh 17:55ea4f38710b 164 } else if (strncmp (nema_str,"VTG",3) == 0) {
1994timmeh 17:55ea4f38710b 165 parseVTG(nema_str);
1994timmeh 17:55ea4f38710b 166 } else if (strncmp (nema_str,"ZDA",3) == 0) {
1994timmeh 17:55ea4f38710b 167 parseZDA(nema_str);
1994timmeh 17:55ea4f38710b 168 } else {
1994timmeh 17:55ea4f38710b 169 // logInfo("Unknown NEMA String Type\r\n");
1994timmeh 17:55ea4f38710b 170 }
1994timmeh 17:55ea4f38710b 171
1994timmeh 17:55ea4f38710b 172 return 1;
1994timmeh 17:55ea4f38710b 173 } else {
1994timmeh 17:55ea4f38710b 174 // logInfo("NEMA String checksum error %x != %x\r\n",nema_cksum,calc_cksum);
1994timmeh 17:55ea4f38710b 175 return 0;
1994timmeh 17:55ea4f38710b 176 }
1994timmeh 17:55ea4f38710b 177 }
1994timmeh 17:55ea4f38710b 178 } else
1994timmeh 17:55ea4f38710b 179 // logInfo("RX empty before all data read\r\n");
1994timmeh 17:55ea4f38710b 180 return 0;
1994timmeh 17:55ea4f38710b 181 }
1994timmeh 17:55ea4f38710b 182 return 0;
1994timmeh 17:55ea4f38710b 183
1994timmeh 17:55ea4f38710b 184 // if (_led) {
1994timmeh 17:55ea4f38710b 185 // if (_fix_status >= 2) {
1994timmeh 17:55ea4f38710b 186 // if (_tick_running) {
1994timmeh 17:55ea4f38710b 187 // _tick.detach();
1994timmeh 17:55ea4f38710b 188 // _tick_running = false;
1994timmeh 17:55ea4f38710b 189 // }
1994timmeh 17:55ea4f38710b 190 //// _led->setPWM(NCP5623B::LED_3, 8);
1994timmeh 17:55ea4f38710b 191 // } else {
1994timmeh 17:55ea4f38710b 192 // if (! _tick_running) {
1994timmeh 17:55ea4f38710b 193 // _tick.attach(this, &GPSPARSER::blinker, 0.5);
1994timmeh 17:55ea4f38710b 194 // _tick_running = true;
1994timmeh 17:55ea4f38710b 195 // }
1994timmeh 17:55ea4f38710b 196 // }
1994timmeh 17:55ea4f38710b 197 // }
1994timmeh 17:55ea4f38710b 198
1994timmeh 17:55ea4f38710b 199 }
1994timmeh 17:55ea4f38710b 200
1994timmeh 17:55ea4f38710b 201 uint8_t GPSPARSER::parseGGA(char *nema_buf)
1994timmeh 17:55ea4f38710b 202 {
1994timmeh 17:55ea4f38710b 203 char* token_str;
1994timmeh 17:55ea4f38710b 204 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 205
1994timmeh 17:55ea4f38710b 206 _mutex.lock();
1994timmeh 17:55ea4f38710b 207
1994timmeh 17:55ea4f38710b 208 token_str = strtok(nema_buf, ",");
1994timmeh 17:55ea4f38710b 209 // skip timestamp
1994timmeh 17:55ea4f38710b 210 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 211 // skip latitude degrees minutes
1994timmeh 17:55ea4f38710b 212 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 213 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 214 // skip longitude degree minutes
1994timmeh 17:55ea4f38710b 215 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 216 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 217 // read fix quality
1994timmeh 17:55ea4f38710b 218 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 219 _fix_quality = atoi(token_str);
1994timmeh 17:55ea4f38710b 220 // skip number of satellites and horizontal dilution
1994timmeh 17:55ea4f38710b 221 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 222 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 223 // read msl altitude in meters
1994timmeh 17:55ea4f38710b 224 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 225 _msl_altitude = atoi(token_str);
1994timmeh 17:55ea4f38710b 226
1994timmeh 17:55ea4f38710b 227 _mutex.unlock();
1994timmeh 17:55ea4f38710b 228
1994timmeh 17:55ea4f38710b 229 return ret;
1994timmeh 17:55ea4f38710b 230 }
1994timmeh 17:55ea4f38710b 231
1994timmeh 17:55ea4f38710b 232 uint8_t GPSPARSER::parseGSA(char *nema_buf)
1994timmeh 17:55ea4f38710b 233 {
1994timmeh 17:55ea4f38710b 234 char* token_str;
1994timmeh 17:55ea4f38710b 235 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 236
1994timmeh 17:55ea4f38710b 237 _mutex.lock();
1994timmeh 17:55ea4f38710b 238
1994timmeh 17:55ea4f38710b 239 token_str = strtok(nema_buf, ",");
1994timmeh 17:55ea4f38710b 240 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 241 // read fix status
1994timmeh 17:55ea4f38710b 242 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 243 _fix_status = atoi(token_str);
1994timmeh 17:55ea4f38710b 244 // read satellite PRNs
1994timmeh 17:55ea4f38710b 245 for (uint8_t i=0; i<12; i++) {
1994timmeh 17:55ea4f38710b 246 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 247 _satellite_prn[i] = atoi(token_str);
1994timmeh 17:55ea4f38710b 248 }
1994timmeh 17:55ea4f38710b 249
1994timmeh 17:55ea4f38710b 250 _mutex.unlock();
1994timmeh 17:55ea4f38710b 251
1994timmeh 17:55ea4f38710b 252 return ret;
1994timmeh 17:55ea4f38710b 253 }
1994timmeh 17:55ea4f38710b 254
1994timmeh 17:55ea4f38710b 255 uint8_t GPSPARSER::parseGSV(char *nema_buf)
1994timmeh 17:55ea4f38710b 256 {
1994timmeh 17:55ea4f38710b 257 char* token_str;
1994timmeh 17:55ea4f38710b 258 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 259
1994timmeh 17:55ea4f38710b 260 _mutex.lock();
1994timmeh 17:55ea4f38710b 261
1994timmeh 17:55ea4f38710b 262 token_str = strtok(nema_buf, ",");
1994timmeh 17:55ea4f38710b 263 // skip number of sentences and sentence number for now
1994timmeh 17:55ea4f38710b 264 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 265 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 266 // read Number of satellites
1994timmeh 17:55ea4f38710b 267 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 268 _num_satellites = atoi(token_str);
1994timmeh 17:55ea4f38710b 269 // add code to read satellite specs if needed
1994timmeh 17:55ea4f38710b 270
1994timmeh 17:55ea4f38710b 271 _mutex.unlock();
1994timmeh 17:55ea4f38710b 272
1994timmeh 17:55ea4f38710b 273 return ret;
1994timmeh 17:55ea4f38710b 274 }
1994timmeh 17:55ea4f38710b 275
1994timmeh 17:55ea4f38710b 276 uint8_t GPSPARSER::parseRMC(char *nema_buf)
1994timmeh 17:55ea4f38710b 277 {
1994timmeh 17:55ea4f38710b 278 char* token_str;
1994timmeh 17:55ea4f38710b 279 char temp_str[6];
1994timmeh 17:55ea4f38710b 280 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 281
1994timmeh 17:55ea4f38710b 282 _mutex.lock();
1994timmeh 17:55ea4f38710b 283
1994timmeh 17:55ea4f38710b 284 token_str = strtok(nema_buf, ",");
1994timmeh 17:55ea4f38710b 285 // read timestamp
1994timmeh 17:55ea4f38710b 286 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 287 strncpy(temp_str,token_str,2);
1994timmeh 17:55ea4f38710b 288 _timestamp.tm_hour = atoi(temp_str);
1994timmeh 17:55ea4f38710b 289 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 290 strncpy(temp_str,token_str+2,2);
1994timmeh 17:55ea4f38710b 291 _timestamp.tm_min = atoi(temp_str);
1994timmeh 17:55ea4f38710b 292 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 293 strncpy(temp_str,token_str+4,2);
1994timmeh 17:55ea4f38710b 294 _timestamp.tm_sec = atoi(temp_str);
1994timmeh 17:55ea4f38710b 295 // set gps_status true = active
1994timmeh 17:55ea4f38710b 296 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 297 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 298 strncpy(temp_str,token_str,1);
1994timmeh 17:55ea4f38710b 299 if (temp_str[0] == 'A')
1994timmeh 17:55ea4f38710b 300 _gps_status = true;
1994timmeh 17:55ea4f38710b 301 else
1994timmeh 17:55ea4f38710b 302 _gps_status = false;
1994timmeh 17:55ea4f38710b 303 // read latitude degrees minutes
1994timmeh 17:55ea4f38710b 304 token_str = strtok(NULL, ".");
1994timmeh 17:55ea4f38710b 305 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 306 strncpy(temp_str,token_str,2);
1994timmeh 17:55ea4f38710b 307 _gps_latitude.degrees = atoi(temp_str);
1994timmeh 17:55ea4f38710b 308 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 309 strncpy(temp_str,token_str+2,2);
1994timmeh 17:55ea4f38710b 310 _gps_latitude.minutes = atoi(temp_str);
1994timmeh 17:55ea4f38710b 311 // read fractional minutes
1994timmeh 17:55ea4f38710b 312 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 313 _gps_latitude.seconds = atoi(token_str);
1994timmeh 17:55ea4f38710b 314 // read latitude hemisphere change sign if 'S'
1994timmeh 17:55ea4f38710b 315 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 316 if (token_str[0] == 'S')
1994timmeh 17:55ea4f38710b 317 _gps_latitude.degrees *= -1;
1994timmeh 17:55ea4f38710b 318 // read longitude degree minutes
1994timmeh 17:55ea4f38710b 319 token_str = strtok(NULL, ".");
1994timmeh 17:55ea4f38710b 320 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 321 strncpy(temp_str,token_str,3);
1994timmeh 17:55ea4f38710b 322 _gps_longitude.degrees = atoi(temp_str);
1994timmeh 17:55ea4f38710b 323 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 324 strncpy(temp_str,token_str+3,2);
1994timmeh 17:55ea4f38710b 325 _gps_longitude.minutes = atoi(temp_str);
1994timmeh 17:55ea4f38710b 326 // read fractional minutes
1994timmeh 17:55ea4f38710b 327 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 328 _gps_longitude.seconds = atoi(token_str);
1994timmeh 17:55ea4f38710b 329 // read longitude hemisphere change sign if 'W'
1994timmeh 17:55ea4f38710b 330 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 331 if (token_str[0] == 'W')
1994timmeh 17:55ea4f38710b 332 _gps_longitude.degrees *= -1;
1994timmeh 17:55ea4f38710b 333 // skip speed and track angle
1994timmeh 17:55ea4f38710b 334 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 335 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 336 // read date
1994timmeh 17:55ea4f38710b 337 token_str = strtok(NULL, ",");
1994timmeh 17:55ea4f38710b 338 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 339 strncpy(temp_str,token_str,2);
1994timmeh 17:55ea4f38710b 340 _timestamp.tm_mday = atoi(temp_str);
1994timmeh 17:55ea4f38710b 341 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 342 strncpy(temp_str,token_str+2,2);
1994timmeh 17:55ea4f38710b 343 _timestamp.tm_mon = atoi(temp_str) - 1;
1994timmeh 17:55ea4f38710b 344 memset(temp_str,0x00,6);
1994timmeh 17:55ea4f38710b 345 strncpy(temp_str,token_str+4,2);
1994timmeh 17:55ea4f38710b 346 _timestamp.tm_year = atoi(temp_str) + 100;
1994timmeh 17:55ea4f38710b 347
1994timmeh 17:55ea4f38710b 348 _mutex.unlock();
1994timmeh 17:55ea4f38710b 349
1994timmeh 17:55ea4f38710b 350 return ret;
1994timmeh 17:55ea4f38710b 351 }
1994timmeh 17:55ea4f38710b 352
1994timmeh 17:55ea4f38710b 353 uint8_t GPSPARSER::parseVTG(char *nema_buf)
1994timmeh 17:55ea4f38710b 354 {
1994timmeh 17:55ea4f38710b 355 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 356 //logInfo("ParseVTG****\r\n");
1994timmeh 17:55ea4f38710b 357 //logInfo(nema_buf);
1994timmeh 17:55ea4f38710b 358 //logInfo("\r\n");
1994timmeh 17:55ea4f38710b 359 return ret;
1994timmeh 17:55ea4f38710b 360 }
1994timmeh 17:55ea4f38710b 361
1994timmeh 17:55ea4f38710b 362 uint8_t GPSPARSER::parseGLL(char *nema_buf)
1994timmeh 17:55ea4f38710b 363 {
1994timmeh 17:55ea4f38710b 364 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 365 //logInfo("ParseGLL*****\r\n");
1994timmeh 17:55ea4f38710b 366 //logInfo(nema_buf);
1994timmeh 17:55ea4f38710b 367 //logInfo("\r\n");
1994timmeh 17:55ea4f38710b 368 return ret;
1994timmeh 17:55ea4f38710b 369 }
1994timmeh 17:55ea4f38710b 370
1994timmeh 17:55ea4f38710b 371 uint8_t GPSPARSER::parseZDA(char *nema_buf)
1994timmeh 17:55ea4f38710b 372 {
1994timmeh 17:55ea4f38710b 373 uint8_t ret = 0;
1994timmeh 17:55ea4f38710b 374 //logInfo("ParseZDA******\r\n");
1994timmeh 17:55ea4f38710b 375 //logInfo(nema_buf);
1994timmeh 17:55ea4f38710b 376 //logInfo("\r\n");
1994timmeh 17:55ea4f38710b 377 return ret;
1994timmeh 17:55ea4f38710b 378 }
1994timmeh 17:55ea4f38710b 379
1994timmeh 17:55ea4f38710b 380 bool GPSPARSER::gpsDetected(void)
1994timmeh 17:55ea4f38710b 381 {
1994timmeh 17:55ea4f38710b 382 bool detected;
1994timmeh 17:55ea4f38710b 383
1994timmeh 17:55ea4f38710b 384 _mutex.lock();
1994timmeh 17:55ea4f38710b 385 detected = _gps_detected;
1994timmeh 17:55ea4f38710b 386 _mutex.unlock();
1994timmeh 17:55ea4f38710b 387
1994timmeh 17:55ea4f38710b 388 return detected;
1994timmeh 17:55ea4f38710b 389 }
1994timmeh 17:55ea4f38710b 390
1994timmeh 17:55ea4f38710b 391 GPSPARSER::longitude GPSPARSER::getLongitude(void)
1994timmeh 17:55ea4f38710b 392 {
1994timmeh 17:55ea4f38710b 393 longitude lon;
1994timmeh 17:55ea4f38710b 394
1994timmeh 17:55ea4f38710b 395 _mutex.lock();
1994timmeh 17:55ea4f38710b 396 lon = _gps_longitude;
1994timmeh 17:55ea4f38710b 397 _mutex.unlock();
1994timmeh 17:55ea4f38710b 398
1994timmeh 17:55ea4f38710b 399 return lon;
1994timmeh 17:55ea4f38710b 400 }
1994timmeh 17:55ea4f38710b 401
1994timmeh 17:55ea4f38710b 402 GPSPARSER::latitude GPSPARSER::getLatitude(void)
1994timmeh 17:55ea4f38710b 403 {
1994timmeh 17:55ea4f38710b 404 latitude lat;
1994timmeh 17:55ea4f38710b 405
1994timmeh 17:55ea4f38710b 406 _mutex.lock();
1994timmeh 17:55ea4f38710b 407 lat = _gps_latitude;
1994timmeh 17:55ea4f38710b 408 _mutex.unlock();
1994timmeh 17:55ea4f38710b 409
1994timmeh 17:55ea4f38710b 410 return lat;
1994timmeh 17:55ea4f38710b 411 }
1994timmeh 17:55ea4f38710b 412
1994timmeh 17:55ea4f38710b 413 struct tm GPSPARSER::getTimestamp(void) {
1994timmeh 17:55ea4f38710b 414 struct tm time;
1994timmeh 17:55ea4f38710b 415
1994timmeh 17:55ea4f38710b 416 _mutex.lock();
1994timmeh 17:55ea4f38710b 417 time = _timestamp;
1994timmeh 17:55ea4f38710b 418 _mutex.unlock();
1994timmeh 17:55ea4f38710b 419
1994timmeh 17:55ea4f38710b 420 return time;
1994timmeh 17:55ea4f38710b 421 }
1994timmeh 17:55ea4f38710b 422
1994timmeh 17:55ea4f38710b 423 bool GPSPARSER::getLockStatus(void)
1994timmeh 17:55ea4f38710b 424 {
1994timmeh 17:55ea4f38710b 425 bool status;
1994timmeh 17:55ea4f38710b 426
1994timmeh 17:55ea4f38710b 427 _mutex.lock();
1994timmeh 17:55ea4f38710b 428 status = _gps_status;
1994timmeh 17:55ea4f38710b 429 _mutex.unlock();
1994timmeh 17:55ea4f38710b 430
1994timmeh 17:55ea4f38710b 431 return status;
1994timmeh 17:55ea4f38710b 432 }
1994timmeh 17:55ea4f38710b 433
1994timmeh 17:55ea4f38710b 434 uint8_t GPSPARSER::getFixStatus(void)
1994timmeh 17:55ea4f38710b 435 {
1994timmeh 17:55ea4f38710b 436 uint8_t fix;
1994timmeh 17:55ea4f38710b 437
1994timmeh 17:55ea4f38710b 438 _mutex.lock();
1994timmeh 17:55ea4f38710b 439 fix = _fix_status;
1994timmeh 17:55ea4f38710b 440 _mutex.unlock();
1994timmeh 17:55ea4f38710b 441
1994timmeh 17:55ea4f38710b 442 return fix;
1994timmeh 17:55ea4f38710b 443 }
1994timmeh 17:55ea4f38710b 444
1994timmeh 17:55ea4f38710b 445 uint8_t GPSPARSER::getFixQuality(void)
1994timmeh 17:55ea4f38710b 446 {
1994timmeh 17:55ea4f38710b 447 uint8_t fix;
1994timmeh 17:55ea4f38710b 448
1994timmeh 17:55ea4f38710b 449 _mutex.lock();
1994timmeh 17:55ea4f38710b 450 fix = _fix_quality;
1994timmeh 17:55ea4f38710b 451 _mutex.unlock();
1994timmeh 17:55ea4f38710b 452
1994timmeh 17:55ea4f38710b 453 return fix;
1994timmeh 17:55ea4f38710b 454 }
1994timmeh 17:55ea4f38710b 455
1994timmeh 17:55ea4f38710b 456 uint8_t GPSPARSER::getNumSatellites(void)
1994timmeh 17:55ea4f38710b 457 {
1994timmeh 17:55ea4f38710b 458 uint8_t sats;
1994timmeh 17:55ea4f38710b 459
1994timmeh 17:55ea4f38710b 460 _mutex.lock();
1994timmeh 17:55ea4f38710b 461 sats = _num_satellites;
1994timmeh 17:55ea4f38710b 462 _mutex.unlock();
1994timmeh 17:55ea4f38710b 463
1994timmeh 17:55ea4f38710b 464 return sats;
1994timmeh 17:55ea4f38710b 465 }
1994timmeh 17:55ea4f38710b 466
1994timmeh 17:55ea4f38710b 467 int16_t GPSPARSER::getAltitude(void)
1994timmeh 17:55ea4f38710b 468 {
1994timmeh 17:55ea4f38710b 469 int16_t alt;
1994timmeh 17:55ea4f38710b 470
1994timmeh 17:55ea4f38710b 471 _mutex.lock();
1994timmeh 17:55ea4f38710b 472 alt = _msl_altitude;
1994timmeh 17:55ea4f38710b 473 _mutex.unlock();
1994timmeh 17:55ea4f38710b 474
1994timmeh 17:55ea4f38710b 475 return alt;
1994timmeh 17:55ea4f38710b 476 }
1994timmeh 17:55ea4f38710b 477
1994timmeh 17:55ea4f38710b 478 void GPSPARSER::blinker()
1994timmeh 17:55ea4f38710b 479 {
1994timmeh 17:55ea4f38710b 480 _led_state = (_led_state == 0) ? 8 : 0;
1994timmeh 17:55ea4f38710b 481 // _led->setPWM(NCP5623B::LED_3, _led_state);
1994timmeh 17:55ea4f38710b 482 }
1994timmeh 17:55ea4f38710b 483