Adafruit GPS library

Dependents:   GPSLibrary

Committer:
ptcrews
Date:
Sat Dec 05 07:30:18 2015 +0000
Revision:
0:ba9ed1caafc3
Adafruit GPS library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptcrews 0:ba9ed1caafc3 1 /***********************************
ptcrews 0:ba9ed1caafc3 2 This is our GPS library
ptcrews 0:ba9ed1caafc3 3
ptcrews 0:ba9ed1caafc3 4 Adafruit invests time and resources providing this open source code,
ptcrews 0:ba9ed1caafc3 5 please support Adafruit and open-source hardware by purchasing
ptcrews 0:ba9ed1caafc3 6 products from Adafruit!
ptcrews 0:ba9ed1caafc3 7
ptcrews 0:ba9ed1caafc3 8 Written by Limor Fried/Ladyada for Adafruit Industries.
ptcrews 0:ba9ed1caafc3 9 BSD license, check license.txt for more information
ptcrews 0:ba9ed1caafc3 10 All text above must be included in any redistribution
ptcrews 0:ba9ed1caafc3 11 ****************************************/
ptcrews 0:ba9ed1caafc3 12
ptcrews 0:ba9ed1caafc3 13 #include "MBed_Adafruit_GPS.h"
ptcrews 0:ba9ed1caafc3 14
ptcrews 0:ba9ed1caafc3 15 // how long are max NMEA lines to parse?
ptcrews 0:ba9ed1caafc3 16 #define MAXLINELENGTH 120
ptcrews 0:ba9ed1caafc3 17
ptcrews 0:ba9ed1caafc3 18 // we double buffer: read one line in and leave one for the main program
ptcrews 0:ba9ed1caafc3 19 volatile char line1[MAXLINELENGTH];
ptcrews 0:ba9ed1caafc3 20 volatile char line2[MAXLINELENGTH];
ptcrews 0:ba9ed1caafc3 21 // our index into filling the current line
ptcrews 0:ba9ed1caafc3 22 volatile uint16_t lineidx=0;
ptcrews 0:ba9ed1caafc3 23 // pointers to the double buffers
ptcrews 0:ba9ed1caafc3 24 volatile char *currentline;
ptcrews 0:ba9ed1caafc3 25 volatile char *lastline;
ptcrews 0:ba9ed1caafc3 26 volatile bool recvdflag;
ptcrews 0:ba9ed1caafc3 27 volatile bool inStandbyMode;
ptcrews 0:ba9ed1caafc3 28
ptcrews 0:ba9ed1caafc3 29
ptcrews 0:ba9ed1caafc3 30 bool Adafruit_GPS::parse(char *nmea) {
ptcrews 0:ba9ed1caafc3 31 // do checksum check
ptcrews 0:ba9ed1caafc3 32
ptcrews 0:ba9ed1caafc3 33 // first look if we even have one
ptcrews 0:ba9ed1caafc3 34 if (nmea[strlen(nmea)-4] == '*') {
ptcrews 0:ba9ed1caafc3 35 uint16_t sum = parseHex(nmea[strlen(nmea)-3]) * 16;
ptcrews 0:ba9ed1caafc3 36 sum += parseHex(nmea[strlen(nmea)-2]);
ptcrews 0:ba9ed1caafc3 37
ptcrews 0:ba9ed1caafc3 38 // check checksum
ptcrews 0:ba9ed1caafc3 39 for (uint8_t i=1; i < (strlen(nmea)-4); i++) {
ptcrews 0:ba9ed1caafc3 40 sum ^= nmea[i];
ptcrews 0:ba9ed1caafc3 41 }
ptcrews 0:ba9ed1caafc3 42 if (sum != 0) {
ptcrews 0:ba9ed1caafc3 43 // bad checksum :(
ptcrews 0:ba9ed1caafc3 44 //return false;
ptcrews 0:ba9ed1caafc3 45 }
ptcrews 0:ba9ed1caafc3 46 }
ptcrews 0:ba9ed1caafc3 47
ptcrews 0:ba9ed1caafc3 48 // look for a few common sentences
ptcrews 0:ba9ed1caafc3 49 if (strstr(nmea, "$GPGGA")) {
ptcrews 0:ba9ed1caafc3 50 // found GGA
ptcrews 0:ba9ed1caafc3 51 char *p = nmea;
ptcrews 0:ba9ed1caafc3 52 // get time
ptcrews 0:ba9ed1caafc3 53 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 54 float timef = atof(p);
ptcrews 0:ba9ed1caafc3 55 uint32_t time = timef;
ptcrews 0:ba9ed1caafc3 56 hour = time / 10000;
ptcrews 0:ba9ed1caafc3 57 minute = (time % 10000) / 100;
ptcrews 0:ba9ed1caafc3 58 seconds = (time % 100);
ptcrews 0:ba9ed1caafc3 59
ptcrews 0:ba9ed1caafc3 60 milliseconds = fmod((double) timef, 1.0) * 1000;
ptcrews 0:ba9ed1caafc3 61
ptcrews 0:ba9ed1caafc3 62 // parse out latitude
ptcrews 0:ba9ed1caafc3 63 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 64 latitude = atof(p);
ptcrews 0:ba9ed1caafc3 65
ptcrews 0:ba9ed1caafc3 66 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 67 if (p[0] == 'N') lat = 'N';
ptcrews 0:ba9ed1caafc3 68 else if (p[0] == 'S') lat = 'S';
ptcrews 0:ba9ed1caafc3 69 else if (p[0] == ',') lat = 0;
ptcrews 0:ba9ed1caafc3 70 else return false;
ptcrews 0:ba9ed1caafc3 71
ptcrews 0:ba9ed1caafc3 72 // parse out longitude
ptcrews 0:ba9ed1caafc3 73 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 74 longitude = atof(p);
ptcrews 0:ba9ed1caafc3 75
ptcrews 0:ba9ed1caafc3 76 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 77 if (p[0] == 'W') lon = 'W';
ptcrews 0:ba9ed1caafc3 78 else if (p[0] == 'E') lon = 'E';
ptcrews 0:ba9ed1caafc3 79 else if (p[0] == ',') lon = 0;
ptcrews 0:ba9ed1caafc3 80 else return false;
ptcrews 0:ba9ed1caafc3 81
ptcrews 0:ba9ed1caafc3 82 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 83 fixquality = atoi(p);
ptcrews 0:ba9ed1caafc3 84
ptcrews 0:ba9ed1caafc3 85 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 86 satellites = atoi(p);
ptcrews 0:ba9ed1caafc3 87
ptcrews 0:ba9ed1caafc3 88 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 89 HDOP = atof(p);
ptcrews 0:ba9ed1caafc3 90
ptcrews 0:ba9ed1caafc3 91 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 92 altitude = atof(p);
ptcrews 0:ba9ed1caafc3 93 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 94 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 95 geoidheight = atof(p);
ptcrews 0:ba9ed1caafc3 96 return true;
ptcrews 0:ba9ed1caafc3 97 }
ptcrews 0:ba9ed1caafc3 98 if (strstr(nmea, "$GPRMC")) {
ptcrews 0:ba9ed1caafc3 99 // found RMC
ptcrews 0:ba9ed1caafc3 100 char *p = nmea;
ptcrews 0:ba9ed1caafc3 101
ptcrews 0:ba9ed1caafc3 102 // get time
ptcrews 0:ba9ed1caafc3 103 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 104 float timef = atof(p);
ptcrews 0:ba9ed1caafc3 105 uint32_t time = timef;
ptcrews 0:ba9ed1caafc3 106 hour = time / 10000;
ptcrews 0:ba9ed1caafc3 107 minute = (time % 10000) / 100;
ptcrews 0:ba9ed1caafc3 108 seconds = (time % 100);
ptcrews 0:ba9ed1caafc3 109
ptcrews 0:ba9ed1caafc3 110 milliseconds = fmod((double) timef, 1.0) * 1000;
ptcrews 0:ba9ed1caafc3 111
ptcrews 0:ba9ed1caafc3 112 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 113 // Serial.println(p);
ptcrews 0:ba9ed1caafc3 114 if (p[0] == 'A')
ptcrews 0:ba9ed1caafc3 115 fix = true;
ptcrews 0:ba9ed1caafc3 116 else if (p[0] == 'V')
ptcrews 0:ba9ed1caafc3 117 fix = false;
ptcrews 0:ba9ed1caafc3 118 else
ptcrews 0:ba9ed1caafc3 119 return false;
ptcrews 0:ba9ed1caafc3 120
ptcrews 0:ba9ed1caafc3 121 // parse out latitude
ptcrews 0:ba9ed1caafc3 122 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 123 latitude = atof(p);
ptcrews 0:ba9ed1caafc3 124
ptcrews 0:ba9ed1caafc3 125 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 126 if (p[0] == 'N') lat = 'N';
ptcrews 0:ba9ed1caafc3 127 else if (p[0] == 'S') lat = 'S';
ptcrews 0:ba9ed1caafc3 128 else if (p[0] == ',') lat = 0;
ptcrews 0:ba9ed1caafc3 129 else return false;
ptcrews 0:ba9ed1caafc3 130
ptcrews 0:ba9ed1caafc3 131 // parse out longitude
ptcrews 0:ba9ed1caafc3 132 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 133 longitude = atof(p);
ptcrews 0:ba9ed1caafc3 134
ptcrews 0:ba9ed1caafc3 135 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 136 if (p[0] == 'W') lon = 'W';
ptcrews 0:ba9ed1caafc3 137 else if (p[0] == 'E') lon = 'E';
ptcrews 0:ba9ed1caafc3 138 else if (p[0] == ',') lon = 0;
ptcrews 0:ba9ed1caafc3 139 else return false;
ptcrews 0:ba9ed1caafc3 140
ptcrews 0:ba9ed1caafc3 141 // speed
ptcrews 0:ba9ed1caafc3 142 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 143 speed = atof(p);
ptcrews 0:ba9ed1caafc3 144
ptcrews 0:ba9ed1caafc3 145 // angle
ptcrews 0:ba9ed1caafc3 146 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 147 angle = atof(p);
ptcrews 0:ba9ed1caafc3 148
ptcrews 0:ba9ed1caafc3 149 p = strchr(p, ',')+1;
ptcrews 0:ba9ed1caafc3 150 uint32_t fulldate = atof(p);
ptcrews 0:ba9ed1caafc3 151 day = fulldate / 10000;
ptcrews 0:ba9ed1caafc3 152 month = (fulldate % 10000) / 100;
ptcrews 0:ba9ed1caafc3 153 year = (fulldate % 100);
ptcrews 0:ba9ed1caafc3 154
ptcrews 0:ba9ed1caafc3 155 // we dont parse the remaining, yet!
ptcrews 0:ba9ed1caafc3 156 return true;
ptcrews 0:ba9ed1caafc3 157 }
ptcrews 0:ba9ed1caafc3 158
ptcrews 0:ba9ed1caafc3 159 return false;
ptcrews 0:ba9ed1caafc3 160 }
ptcrews 0:ba9ed1caafc3 161
ptcrews 0:ba9ed1caafc3 162 char Adafruit_GPS::read(void) {
ptcrews 0:ba9ed1caafc3 163 char c = 0;
ptcrews 0:ba9ed1caafc3 164
ptcrews 0:ba9ed1caafc3 165 if (paused) return c;
ptcrews 0:ba9ed1caafc3 166
ptcrews 0:ba9ed1caafc3 167 if(!gpsSerial->readable()) return c;
ptcrews 0:ba9ed1caafc3 168 c = gpsSerial->getc();
ptcrews 0:ba9ed1caafc3 169
ptcrews 0:ba9ed1caafc3 170 //Serial.print(c);
ptcrews 0:ba9ed1caafc3 171
ptcrews 0:ba9ed1caafc3 172 if (c == '$') {
ptcrews 0:ba9ed1caafc3 173 currentline[lineidx] = 0;
ptcrews 0:ba9ed1caafc3 174 lineidx = 0;
ptcrews 0:ba9ed1caafc3 175 }
ptcrews 0:ba9ed1caafc3 176 if (c == '\n') {
ptcrews 0:ba9ed1caafc3 177 currentline[lineidx] = 0;
ptcrews 0:ba9ed1caafc3 178
ptcrews 0:ba9ed1caafc3 179 if (currentline == line1) {
ptcrews 0:ba9ed1caafc3 180 currentline = line2;
ptcrews 0:ba9ed1caafc3 181 lastline = line1;
ptcrews 0:ba9ed1caafc3 182 } else {
ptcrews 0:ba9ed1caafc3 183 currentline = line1;
ptcrews 0:ba9ed1caafc3 184 lastline = line2;
ptcrews 0:ba9ed1caafc3 185 }
ptcrews 0:ba9ed1caafc3 186
ptcrews 0:ba9ed1caafc3 187 lineidx = 0;
ptcrews 0:ba9ed1caafc3 188 recvdflag = true;
ptcrews 0:ba9ed1caafc3 189 }
ptcrews 0:ba9ed1caafc3 190
ptcrews 0:ba9ed1caafc3 191 currentline[lineidx++] = c;
ptcrews 0:ba9ed1caafc3 192 if (lineidx >= MAXLINELENGTH)
ptcrews 0:ba9ed1caafc3 193 lineidx = MAXLINELENGTH-1;
ptcrews 0:ba9ed1caafc3 194
ptcrews 0:ba9ed1caafc3 195 return c;
ptcrews 0:ba9ed1caafc3 196 }
ptcrews 0:ba9ed1caafc3 197
ptcrews 0:ba9ed1caafc3 198 Adafruit_GPS::Adafruit_GPS (Serial *ser)
ptcrews 0:ba9ed1caafc3 199 {
ptcrews 0:ba9ed1caafc3 200 common_init(); // Set everything to common state, then...
ptcrews 0:ba9ed1caafc3 201 gpsSerial = ser; // ...override gpsSwSerial with value passed.
ptcrews 0:ba9ed1caafc3 202 }
ptcrews 0:ba9ed1caafc3 203
ptcrews 0:ba9ed1caafc3 204 // Initialization code used by all constructor types
ptcrews 0:ba9ed1caafc3 205 void Adafruit_GPS::common_init(void) {
ptcrews 0:ba9ed1caafc3 206 gpsSerial = NULL;
ptcrews 0:ba9ed1caafc3 207 recvdflag = false;
ptcrews 0:ba9ed1caafc3 208 paused = false;
ptcrews 0:ba9ed1caafc3 209 lineidx = 0;
ptcrews 0:ba9ed1caafc3 210 currentline = line1;
ptcrews 0:ba9ed1caafc3 211 lastline = line2;
ptcrews 0:ba9ed1caafc3 212
ptcrews 0:ba9ed1caafc3 213 hour = minute = seconds = year = month = day =
ptcrews 0:ba9ed1caafc3 214 fixquality = satellites = 0; // uint8_t
ptcrews 0:ba9ed1caafc3 215 lat = lon = mag = 0; // char
ptcrews 0:ba9ed1caafc3 216 fix = false; // bool
ptcrews 0:ba9ed1caafc3 217 milliseconds = 0; // uint16_t
ptcrews 0:ba9ed1caafc3 218 latitude = longitude = geoidheight = altitude =
ptcrews 0:ba9ed1caafc3 219 speed = angle = magvariation = HDOP = 0.0; // float
ptcrews 0:ba9ed1caafc3 220 }
ptcrews 0:ba9ed1caafc3 221
ptcrews 0:ba9ed1caafc3 222 void Adafruit_GPS::begin(int baud)
ptcrews 0:ba9ed1caafc3 223 {
ptcrews 0:ba9ed1caafc3 224 gpsSerial->baud(baud);
ptcrews 0:ba9ed1caafc3 225 wait_ms(10);
ptcrews 0:ba9ed1caafc3 226 }
ptcrews 0:ba9ed1caafc3 227
ptcrews 0:ba9ed1caafc3 228 void Adafruit_GPS::sendCommand(char *str) {
ptcrews 0:ba9ed1caafc3 229 gpsSerial->printf("%s",str);
ptcrews 0:ba9ed1caafc3 230 }
ptcrews 0:ba9ed1caafc3 231
ptcrews 0:ba9ed1caafc3 232 bool Adafruit_GPS::newNMEAreceived(void) {
ptcrews 0:ba9ed1caafc3 233 return recvdflag;
ptcrews 0:ba9ed1caafc3 234 }
ptcrews 0:ba9ed1caafc3 235
ptcrews 0:ba9ed1caafc3 236 void Adafruit_GPS::pause(bool p) {
ptcrews 0:ba9ed1caafc3 237 paused = p;
ptcrews 0:ba9ed1caafc3 238 }
ptcrews 0:ba9ed1caafc3 239
ptcrews 0:ba9ed1caafc3 240 char *Adafruit_GPS::lastNMEA(void) {
ptcrews 0:ba9ed1caafc3 241 recvdflag = false;
ptcrews 0:ba9ed1caafc3 242 return (char *)lastline;
ptcrews 0:ba9ed1caafc3 243 }
ptcrews 0:ba9ed1caafc3 244
ptcrews 0:ba9ed1caafc3 245 // read a Hex value and return the decimal equivalent
ptcrews 0:ba9ed1caafc3 246 uint8_t Adafruit_GPS::parseHex(char c) {
ptcrews 0:ba9ed1caafc3 247 if (c < '0')
ptcrews 0:ba9ed1caafc3 248 return 0;
ptcrews 0:ba9ed1caafc3 249 if (c <= '9')
ptcrews 0:ba9ed1caafc3 250 return c - '0';
ptcrews 0:ba9ed1caafc3 251 if (c < 'A')
ptcrews 0:ba9ed1caafc3 252 return 0;
ptcrews 0:ba9ed1caafc3 253 if (c <= 'F')
ptcrews 0:ba9ed1caafc3 254 return (c - 'A')+10;
ptcrews 0:ba9ed1caafc3 255 }
ptcrews 0:ba9ed1caafc3 256
ptcrews 0:ba9ed1caafc3 257 bool Adafruit_GPS::waitForSentence(char *wait4me, uint8_t max) {
ptcrews 0:ba9ed1caafc3 258 char str[20];
ptcrews 0:ba9ed1caafc3 259
ptcrews 0:ba9ed1caafc3 260 uint8_t i=0;
ptcrews 0:ba9ed1caafc3 261 while (i < max) {
ptcrews 0:ba9ed1caafc3 262 if (newNMEAreceived()) {
ptcrews 0:ba9ed1caafc3 263 char *nmea = lastNMEA();
ptcrews 0:ba9ed1caafc3 264 strncpy(str, nmea, 20);
ptcrews 0:ba9ed1caafc3 265 str[19] = 0;
ptcrews 0:ba9ed1caafc3 266 i++;
ptcrews 0:ba9ed1caafc3 267
ptcrews 0:ba9ed1caafc3 268 if (strstr(str, wait4me))
ptcrews 0:ba9ed1caafc3 269 return true;
ptcrews 0:ba9ed1caafc3 270 }
ptcrews 0:ba9ed1caafc3 271 }
ptcrews 0:ba9ed1caafc3 272
ptcrews 0:ba9ed1caafc3 273 return false;
ptcrews 0:ba9ed1caafc3 274 }
ptcrews 0:ba9ed1caafc3 275
ptcrews 0:ba9ed1caafc3 276 bool Adafruit_GPS::LOCUS_StartLogger(void) {
ptcrews 0:ba9ed1caafc3 277 sendCommand(PMTK_LOCUS_STARTLOG);
ptcrews 0:ba9ed1caafc3 278 recvdflag = false;
ptcrews 0:ba9ed1caafc3 279 return waitForSentence(PMTK_LOCUS_LOGSTARTED);
ptcrews 0:ba9ed1caafc3 280 }
ptcrews 0:ba9ed1caafc3 281
ptcrews 0:ba9ed1caafc3 282 bool Adafruit_GPS::LOCUS_ReadStatus(void) {
ptcrews 0:ba9ed1caafc3 283 sendCommand(PMTK_LOCUS_QUERY_STATUS);
ptcrews 0:ba9ed1caafc3 284
ptcrews 0:ba9ed1caafc3 285 if (! waitForSentence("$PMTKLOG"))
ptcrews 0:ba9ed1caafc3 286 return false;
ptcrews 0:ba9ed1caafc3 287
ptcrews 0:ba9ed1caafc3 288 char *response = lastNMEA();
ptcrews 0:ba9ed1caafc3 289 uint16_t parsed[10];
ptcrews 0:ba9ed1caafc3 290 uint8_t i;
ptcrews 0:ba9ed1caafc3 291
ptcrews 0:ba9ed1caafc3 292 for (i=0; i<10; i++) parsed[i] = -1;
ptcrews 0:ba9ed1caafc3 293
ptcrews 0:ba9ed1caafc3 294 response = strchr(response, ',');
ptcrews 0:ba9ed1caafc3 295 for (i=0; i<10; i++) {
ptcrews 0:ba9ed1caafc3 296 if (!response || (response[0] == 0) || (response[0] == '*'))
ptcrews 0:ba9ed1caafc3 297 break;
ptcrews 0:ba9ed1caafc3 298 response++;
ptcrews 0:ba9ed1caafc3 299 parsed[i]=0;
ptcrews 0:ba9ed1caafc3 300 while ((response[0] != ',') &&
ptcrews 0:ba9ed1caafc3 301 (response[0] != '*') && (response[0] != 0)) {
ptcrews 0:ba9ed1caafc3 302 parsed[i] *= 10;
ptcrews 0:ba9ed1caafc3 303 char c = response[0];
ptcrews 0:ba9ed1caafc3 304 if (isdigit(c))
ptcrews 0:ba9ed1caafc3 305 parsed[i] += c - '0';
ptcrews 0:ba9ed1caafc3 306 else
ptcrews 0:ba9ed1caafc3 307 parsed[i] = c;
ptcrews 0:ba9ed1caafc3 308 response++;
ptcrews 0:ba9ed1caafc3 309 }
ptcrews 0:ba9ed1caafc3 310 }
ptcrews 0:ba9ed1caafc3 311 LOCUS_serial = parsed[0];
ptcrews 0:ba9ed1caafc3 312 LOCUS_type = parsed[1];
ptcrews 0:ba9ed1caafc3 313 if (isalpha(parsed[2])) {
ptcrews 0:ba9ed1caafc3 314 parsed[2] = parsed[2] - 'a' + 10;
ptcrews 0:ba9ed1caafc3 315 }
ptcrews 0:ba9ed1caafc3 316 LOCUS_mode = parsed[2];
ptcrews 0:ba9ed1caafc3 317 LOCUS_config = parsed[3];
ptcrews 0:ba9ed1caafc3 318 LOCUS_interval = parsed[4];
ptcrews 0:ba9ed1caafc3 319 LOCUS_distance = parsed[5];
ptcrews 0:ba9ed1caafc3 320 LOCUS_speed = parsed[6];
ptcrews 0:ba9ed1caafc3 321 LOCUS_status = !parsed[7];
ptcrews 0:ba9ed1caafc3 322 LOCUS_records = parsed[8];
ptcrews 0:ba9ed1caafc3 323 LOCUS_percent = parsed[9];
ptcrews 0:ba9ed1caafc3 324
ptcrews 0:ba9ed1caafc3 325 return true;
ptcrews 0:ba9ed1caafc3 326 }
ptcrews 0:ba9ed1caafc3 327
ptcrews 0:ba9ed1caafc3 328 // Standby Mode Switches
ptcrews 0:ba9ed1caafc3 329 bool Adafruit_GPS::standby(void) {
ptcrews 0:ba9ed1caafc3 330 if (inStandbyMode) {
ptcrews 0:ba9ed1caafc3 331 return false; // Returns false if already in standby mode, so that you do not wake it up by sending commands to GPS
ptcrews 0:ba9ed1caafc3 332 }
ptcrews 0:ba9ed1caafc3 333 else {
ptcrews 0:ba9ed1caafc3 334 inStandbyMode = true;
ptcrews 0:ba9ed1caafc3 335 sendCommand(PMTK_STANDBY);
ptcrews 0:ba9ed1caafc3 336 //return waitForSentence(PMTK_STANDBY_SUCCESS); // don't seem to be fast enough to catch the message, or something else just is not working
ptcrews 0:ba9ed1caafc3 337 return true;
ptcrews 0:ba9ed1caafc3 338 }
ptcrews 0:ba9ed1caafc3 339 }
ptcrews 0:ba9ed1caafc3 340
ptcrews 0:ba9ed1caafc3 341 bool Adafruit_GPS::wakeup(void) {
ptcrews 0:ba9ed1caafc3 342 if (inStandbyMode) {
ptcrews 0:ba9ed1caafc3 343 inStandbyMode = false;
ptcrews 0:ba9ed1caafc3 344 sendCommand(""); // send byte to wake it up
ptcrews 0:ba9ed1caafc3 345 return waitForSentence(PMTK_AWAKE);
ptcrews 0:ba9ed1caafc3 346 }
ptcrews 0:ba9ed1caafc3 347 else {
ptcrews 0:ba9ed1caafc3 348 return false; // Returns false if not in standby mode, nothing to wakeup
ptcrews 0:ba9ed1caafc3 349 }
ptcrews 0:ba9ed1caafc3 350 }