Skip to content

Instantly share code, notes, and snippets.

@itpcc
Created May 11, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itpcc/fcb8315dc53498982d8b934f8466de3b to your computer and use it in GitHub Desktop.
Save itpcc/fcb8315dc53498982d8b934f8466de3b to your computer and use it in GitHub Desktop.
GPS Helper function for Mini-project: Cellular Tower logger
/***** GPS Helper function *****/
char* getGPGGA(){
unsigned long startTime = millis();
char ch = '\0';
char *newline;
size_t len;
memset(strBuffer, '\0', 121);
do{
while(
gpsSerial.available() &&
ch != '$' &&
millis() - startTime < MAX_WAIT_TIME
){
ch = gpsSerial.read();
}
if(ch == '$'){
*strBuffer = ch;
currBuffer = strBuffer+1;
len = 1;
while(
millis() - startTime < MAX_WAIT_TIME &&
len < 120 &&
ch != '\n'
){
if(gpsSerial.available()){
ch = gpsSerial.read();
*(currBuffer) = ch;
++currBuffer;
++len;
}
}
currBuffer = strstr(strBuffer ,"$GPGGA");
if(currBuffer != NULL){
if((newline = strchr(strBuffer, '\n'))!=NULL)
*newline = '\0';
if((newline = strchr(strBuffer, '\r'))!=NULL)
*newline = '\0';
return currBuffer;
}
}
}while(
millis() - startTime < MAX_WAIT_TIME
);
return NULL;
}
bool parseGPGGA(){
char *GPGGAStr, *pch;
GPGGAStr = getGPGGA();
Serial.print("GPGGA>"); Serial.println(GPGGAStr);
if(strlen(GPGGAStr) == 0 || strstr(GPGGAStr, ",,,,,0") != NULL)
return false;
strtok (GPGGAStr,",");
strcpy(UTCTime, strtok (NULL,","));
strcpy(Lat, strtok (NULL,","));
strcat(Lat, strtok (NULL,","));
strcpy(Lng, strtok (NULL,","));
strcat(Lng, strtok (NULL,","));
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment