Hardware Reference
In-Depth Information
Continued from previous page.
// last two digits of the date are year. Add the century too:
currentYear = date % 100 + 2000;
// second two digits of the date are month:
currentMonth = (date % 10000)/100;
// first two digits of the date are day:
currentDay = date/10000;
}
}
The getGGA() method parses out
the parts of the $GPGGA sentence.
Some of it is redundant with the
$GPRMC sentence, but the number of
satellites to fix a position is new.
8
void getGGA(String[] data) {
// move the items from the string into the variables:
int time = int(data[1]);
// first two digits of the time are hours:
hrs = time/10000;
// second two digits of the time are minutes:
mins = (time % 10000)/100;
// last two digits of the time are seconds:
secs = (time % 100);
// if you have a valid reading, parse the rest of it:
if (data[6].equals("1")) {
latitude = minutesToDegrees(float(data[2]));
northSouth = data[3];
longitude = minutesToDegrees(float(data[4]));
eastWest = data[5];
satellitesToFix = int(data[7]);
}
}
The getGSV() method parses out
the parts of the $GPGSV sentence. It
returns a single integer—the number of
satellites in view.
8
int getGSV(String[] data) {
int satellites = int(data[3]);
return satellites;
}
8
Finally, the minutesToDegrees()
method is used by both the getRMC()
and getGGA() methods. The NMEA
protocol sends latitude and longitude
like this:
float minutesToDegrees(float thisValue) {
// get the integer portion of the degree measurement:
int wholeNumber = (int)(thisValue / 100);
// get the fraction portion, and convert minutes to a decimal fraction:
float fraction = (thisValue - ( wholeNumber ) * 100) / 60;
// combine the two and return it:
float result = wholeNumber + fraction;
return result;
}
ddmm.mmmm
where dd is degrees, and mm.mmm
is minutes. This method converts the
minutes to a decimal fraction of the
degrees.
 
Search WWH ::




Custom Search