}
// now for the content
String[] e = chkstrings[0].split(",");
String accu;
WayPoint currentwp = ps.p_Wp;
String currentDate = ps.p_Date;
// handle the packet content
if("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {
// Position
LatLon latLon = parseLatLon(
e[GPGGA.LATITUDE_NAME.position],
e[GPGGA.LONGITUDE_NAME.position],
e[GPGGA.LATITUDE.position],
e[GPGGA.LONGITUDE.position]
);
if (latLon==null) {
throw new IllegalDataException("Malformed lat/lon");
}
if ((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
ps.zero_coord++;
return false;
}
// time
accu = e[GPGGA.TIME.position];
Date d = readTime(currentDate+accu);
if((ps.p_Time==null) || (currentwp==null) || !ps.p_Time.equals(accu)) {
// this node is newer than the previous, create a new waypoint.
// no matter if previous WayPoint was null, we got something
// better now.
ps.p_Time=accu;
currentwp = new WayPoint(latLon);
}
if(!currentwp.attr.containsKey("time")) {
// As this sentence has no complete time only use it
// if there is no time so far
currentwp.attr.put("time", DateUtils.fromDate(d));
}
// elevation
accu=e[GPGGA.HEIGHT_UNTIS.position];
if("M".equals(accu)) {
// Ignore heights that are not in meters for now
accu=e[GPGGA.HEIGHT.position];
if(!accu.isEmpty()) {
Double.parseDouble(accu);
// if it throws it's malformed; this should only happen if the
// device sends nonstandard data.
if(!accu.isEmpty()) { // FIX ? same check
currentwp.attr.put("ele", accu);
}
}
}
// number of sattelites
accu=e[GPGGA.SATELLITE_COUNT.position];
int sat = 0;
if(!accu.isEmpty()) {
sat = Integer.parseInt(accu);
currentwp.attr.put("sat", accu);
}
// h-dilution
accu=e[GPGGA.HDOP.position];
if(!accu.isEmpty()) {
currentwp.attr.put("hdop", Float.parseFloat(accu));
}
// fix
accu=e[GPGGA.QUALITY.position];
if(!accu.isEmpty()) {
int fixtype = Integer.parseInt(accu);
switch(fixtype) {
case 0:
currentwp.attr.put("fix", "none");
break;
case 1:
if(sat < 4) {
currentwp.attr.put("fix", "2d");
} else {
currentwp.attr.put("fix", "3d");
}
break;
case 2:
currentwp.attr.put("fix", "dgps");
break;
default:
break;
}
}
} else if("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {
// COURSE
accu = e[GPVTG.COURSE_REF.position];
if("T".equals(accu)) {
// other values than (T)rue are ignored
accu = e[GPVTG.COURSE.position];
if(!accu.isEmpty()) {
Double.parseDouble(accu);
currentwp.attr.put("course", accu);
}
}
// SPEED
accu = e[GPVTG.SPEED_KMH_UNIT.position];
if(accu.startsWith("K")) {
accu = e[GPVTG.SPEED_KMH.position];
if(!accu.isEmpty()) {
double speed = Double.parseDouble(accu);
speed /= 3.6; // speed in m/s
currentwp.attr.put("speed", Double.toString(speed));
}
}
} else if("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {
// vdop
accu=e[GPGSA.VDOP.position];
if(!accu.isEmpty()) {
currentwp.attr.put("vdop", Float.parseFloat(accu));
}
// hdop
accu=e[GPGSA.HDOP.position];
if(!accu.isEmpty()) {
currentwp.attr.put("hdop", Float.parseFloat(accu));
}
// pdop
accu=e[GPGSA.PDOP.position];
if(!accu.isEmpty()) {
currentwp.attr.put("pdop", Float.parseFloat(accu));
}
}
else if("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {
// coordinates
LatLon latLon = parseLatLon(
e[GPRMC.WIDTH_NORTH_NAME.position],
e[GPRMC.LENGTH_EAST_NAME.position],
e[GPRMC.WIDTH_NORTH.position],
e[GPRMC.LENGTH_EAST.position]
);
if((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
ps.zero_coord++;
return false;
}
// time
currentDate = e[GPRMC.DATE.position];
String time = e[GPRMC.TIME.position];
Date d = readTime(currentDate+time);
if((ps.p_Time==null) || (currentwp==null) || !ps.p_Time.equals(time)) {
// this node is newer than the previous, create a new waypoint.
ps.p_Time=time;
currentwp = new WayPoint(latLon);
}
// time: this sentence has complete time so always use it.
currentwp.attr.put("time", DateUtils.fromDate(d));
// speed
accu = e[GPRMC.SPEED.position];