Hello.
I read already a lot in the last days and found plenty of code for GPS parsing.
Like this:
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
I don't completly understand a few things in this code.
- Why are there no {} in "while" and "if" ? Is this kind of sloppy shortcut programming?
- Why is my "gps.encode(Serial1.read());" also exiting the "while" loop? Because it gets smaller than zero?
- Even if i use " if (gps.encode(Serial1.read()))" in the while loop my code doesn't work as it should.
while (Serial1.available() >0) // As long as data arrives Do the loop
{
if(gps.encode(Serial1.read())); // If TRUE exit the while loop
}
This makes me think.
What if the MEGA arrives in the while loop when an already started, incomplete sentence was sent?
Then it still does the loop because serial1.available is still > 0
Then it gets the encode() = TRUE and exits the loop
The result is a incomplete sentence of GPS data.
Am i right so far?