bool GPS_parseGPRMCSentence(const char * pSentence, GPS_DATA * pData) { /* Refer to http://www.gpsinformation.org/dale/nmea.htm#RMS * Sample Data: $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A * Where: * RMC Recommended Minimum sentence C * 123519 Fix taken at 12:35:19 UTC * A Status A=active or V=Void. * 4807.038,N Latitude 48 deg 07.038' N * 01131.000,E Longitude 11 deg 31.000' E * 022.4 Speed over the ground in knots * 084.4 Track angle in degrees True * 230394 Date - 23rd of March 1994 * 003.1,W Magnetic Variation * 6A The checksum data, always begins with * */ if (!pSentence || !pData) { return false; } // NULL pointer check on arguments bool success = true; success &= strncmp(pSentence, "$GPRMC,", 7) == 0; success &= rmcSentenceIsValid(pSentence); if (success) { pSentence += 7; // Now pointing at first data, which is time pSentence += parseHHMMSSTime(pSentence, &pData->hour, &pData->min, &pData->sec); pSentence += skipToNextComma(pSentence); // Skip over any decimals in the time pSentence += skipToNextComma(pSentence); // Skip over valid char and comma pSentence += parseLatitude(pSentence, &pData->latitude) + 1; // +1 skips over comma pSentence += parseLongitude(pSentence, &pData->longitude) + 1; // +1 skips over comma pSentence += skipToNextComma(pSentence); // Skip over speed pSentence += skipToNextComma(pSentence); // Skip over trackAngle pSentence += parseHHMMSSTime(pSentence, &pData->dd, &pData->mm, &pData->yy); } return success; }
/***************************************************************************** ** Function name: GPSRetreiveData ** ** Descriptions: Reads and parses the next set of GPS data. ** ** parameters: None ** Returned value: The parsed information ** *****************************************************************************/ const gpsData* GPSRetreiveData(void) { uint8_t * pattern = (uint8_t*)"GPGGA"; while (1) { uint8_t buf[100]; uint8_t ch = 0; uint8_t *ptr = 0; int index = 0; // Retrieve the first byte if (!UARTGetChar(&ch)) continue; // look for "$GPGGA," header if (ch != '$') { continue; } // Retrieve the next six bytes for (index=0; index<6; index++) { buf[index] = UARTGetCharBlock(); } //Check if its Global Positioning System fixed Data if(hasPattern((uint8_t*)&buf, pattern) == 0) { continue; } //Retrieve the data from the GPS module for (index=0; index<100; index++) { buf[index] = UARTGetCharBlock(); if (buf[index] == '\r') { buf[index] = END_OF_MESSAGE; break; } } ptr = &buf[0]; //parse UTC time parseUTC(&ptr); //parse Latitude parseLatitude(&ptr); // parse N/S field parseNSIndicator(&ptr); // parse Longitude parseLongitude(&ptr); // parse E/W field parseEWIndicator(&ptr); // parse fix position parseFixIndicator(&ptr); // parse satellites parseSatellites(&ptr); // parse horizontal-dilution-of-precision field parseHDOP(&ptr); // parse altitude parseAltitudes(&ptr); break; } return &data; }