I have a function that reads in the NMEA strings from a GPS module. In order to just focus on the data that I am interested in I read in the first 5 characters and then perform a strcmp to determine if it is the appropriate sentence. If not it ignores the rest of the sentence. Here is the function:
//this just reads data in one character at a time until we have a complete sentence
boolean checkforSentence()
{
char c;
while(mySerial.available())
{
last_data_received = millis() + 2000;
c = mySerial.read();
//Serial.print(c);
if(sentenceBegins && c == '\r') //we have a full sentence
{
sentenceBegins = false;
Serial.println(buffer);
return true;
}
if(sentenceBegins) //store characters to buffer
{
buffer[index] = c;
index++;
buffer[index] = '\0';
/*
we need something to segregate out the RMC and GGA sentences and ignore
everything else. Originally I was sending a command to the GPS to
only send the string that I was interested in, but for some reason the GPS
is not accepting my commands anymore. It happened pretty suddenly so f'
it. I will just ignore everything that I don't want to see.
*/
if(index==5)
{
if(!(strcmp(buffer, "GPGGA") == 0 && data_index==true))
{
sentenceBegins = false;
Serial.println(buffer);
}
if(!(strcmp(buffer, "GPRMC") == 0 && data_index == false))
{
sentenceBegins = false;
Serial.println(buffer);
}
}
}
if(c == '
I have a feeling strcmp may be looking for a new line and carriage return character at the end of buffer but doing this:
if(!(strcmp(buffer, 'GPRMC') == 0 && data_index == false))
results in:
invalid conversion from 'int' to 'const char*'
The result of the Serial.println is:
GPGGA
GPGGA
GPGSA
GPGSA
GPGSV
GPGSV
GPRMC
GPGGA
GPGGA
GPGSA
GPGSA
GPGSV
GPGSV
GPRMC
which suggests that it is checking the appropriate number of characters. Any suggestions?) //beginning of sentence...start saving to buffer
{
sentenceBegins = true;
index = 0;
}
}
return false;
}
I have a feeling strcmp may be looking for a new line and carriage return character at the end of buffer but doing this:
§DISCOURSE_HOISTED_CODE_1§
results in:
§DISCOURSE_HOISTED_CODE_2§
The result of the Serial.println is:
§DISCOURSE_HOISTED_CODE_3§
which suggests that it is checking the appropriate number of characters. Any suggestions?