Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lib_gps by
Diff: gps.cpp
- Revision:
- 7:44cb21f05dcc
- Parent:
- 6:9dfe135334c9
- Child:
- 8:7787d0060685
--- a/gps.cpp Mon Mar 07 15:20:16 2016 -0500 +++ b/gps.cpp Thu Apr 21 11:02:59 2016 -0400 @@ -174,19 +174,11 @@ // could we calculate a verification checksum ? if( checksumIndex < 0 ) - { - if (verbose) - printf("gps:checksumIndex:%d\r\n", checksumIndex); return false; - } // check if there are enough char in the serial buffer to read checksum if( checksumIndex >= ( rx_buf_lens[idx] - 2 ) ) - { - if (verbose) - printf("gps:checksumIndex:%d\r\n", checksumIndex); return false; - } // check the checksum if( ( NmeaString[checksumIndex] == checksum[0] ) && ( NmeaString[checksumIndex + 1] == checksum[1] ) ) @@ -194,11 +186,7 @@ return true; } else - { - if (verbose) - printf("gps:checksum fail idx:%d %c%c %c%c\r\n", checksumIndex, checksum[0], checksum[1], NmeaString[checksumIndex], NmeaString[checksumIndex+1]); return false; - } } void GPS::ConvertPositionFromStringToNumerical( ) @@ -276,11 +264,14 @@ LongitudeBinary = temp / 180; } - //printf("binary: %x %x\r\n", LatitudeBinary, LongitudeBinary); if (LatitudeBinary == LAT_UNFIXED && LongitudeBinary == LONG_UNFIXED) have_fix = false; else + { have_fix = true; + if(verbose == true) + printf("GPS: latitude=%f, longitude=%f\r\n", Latitude, Longitude); + } } int GPS::ParseGPSData(int idx) @@ -289,8 +280,6 @@ char *NmeaString; if (NmeaValidateChecksum(idx) == false) { - if (verbose) - printf("gps:bad nmea checksum:%s\r\n", rx_bufs[rx_bufs_out_idx]); return FAIL; } @@ -319,6 +308,9 @@ // Parse the GPGGA data if( strncmp( ( const char* )NmeaGpsData.NmeaDataType, ( const char* )NmeaDataTypeGPGGA, 5 ) == 0 ) { + if(verbose == true) + printf("GPGAA: %s\r\n",NmeaString); + // NmeaUtcTime fieldSize = 0; while( NmeaString[i + fieldSize++] != ',' ) @@ -341,7 +333,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) @@ -358,7 +350,7 @@ } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -373,7 +365,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) @@ -390,7 +382,7 @@ } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -491,11 +483,13 @@ //FormatGpsData( ); ConvertPositionFromStringToNumerical( ); ConvertPositionIntoBinary( ); - // printf("GPGAA: %s\r\n",NmeaString); return SUCCESS; } else if ( strncmp( ( const char* )NmeaGpsData.NmeaDataType, ( const char* )NmeaDataTypeGPRMC, 5 ) == 0 ) { + if(verbose == true) + printf("GPMRC: %s\r\n", NmeaString); + // NmeaUtcTime fieldSize = 0; while( NmeaString[i + fieldSize++] != ',' ) @@ -518,7 +512,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -538,7 +532,7 @@ } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) @@ -554,7 +548,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -569,7 +563,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -584,7 +578,7 @@ return FAIL; } } - if(fieldSize == 0) + if(fieldSize <= 1) return FAIL; for( j = 0; j < fieldSize; j++, i++ ) { @@ -633,8 +627,6 @@ //FormatGpsData( ); ConvertPositionFromStringToNumerical( ); ConvertPositionIntoBinary( ); - // printf("GPMRC: %s\r\n", NmeaString); - // printf("ParseGPSData: string=%s, lat=%f, long=%f\r\n",NmeaString, Latitude, Longitude); return SUCCESS; } else