Changeset 2626 in josm for trunk/src/org/openstreetmap/josm/io/NmeaReader.java
- Timestamp:
- 2009-12-13T11:48:12+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r1724 r2626 132 132 public GpxData data; 133 133 134 // private final static SimpleDateFormat GGATIMEFMT =135 // new SimpleDateFormat("HHmmss.SSS");134 // private final static SimpleDateFormat GGATIMEFMT = 135 // new SimpleDateFormat("HHmmss.SSS"); 136 136 private final static SimpleDateFormat RMCTIMEFMT = 137 137 new SimpleDateFormat("ddMMyyHHmmss.SSS"); … … 142 142 { 143 143 Date d = RMCTIMEFMT.parse(p, new ParsePosition(0)); 144 if (d == null) { 145 d = RMCTIMEFMTSTD.parse(p, new ParsePosition(0)); 146 } 144 147 if (d == null) 145 d = RMCTIMEFMTSTD.parse(p, new ParsePosition(0)); 146 if (d == null) throw(null); // malformed 148 throw new RuntimeException("Date is malformed"); // malformed 147 149 return d; 148 150 } … … 181 183 int loopstart_char = rd.read(); 182 184 ps = new NMEAParserState(); 183 if(loopstart_char == -1) {// zero size file185 if(loopstart_char == -1) 184 186 //TODO tell user about the problem? 185 187 return; 186 }187 188 sb.append((char)loopstart_char); 188 189 ps.p_Date="010100"; // TODO date problem 189 190 while(true) { 190 191 // don't load unparsable files completely to memory 191 if(sb.length()>=1020) sb.delete(0, sb.length()-1); 192 if(sb.length()>=1020) { 193 sb.delete(0, sb.length()-1); 194 } 192 195 int c = rd.read(); 193 196 if(c=='$') { … … 199 202 ParseNMEASentence(sb.toString(),ps); 200 203 break; 201 } else sb.append((char)c); 204 } else { 205 sb.append((char)c); 206 } 202 207 } 203 208 rd.close(); … … 209 214 } 210 215 } 211 private class NMEAParserState {216 private static class NMEAParserState { 212 217 protected Collection<WayPoint> waypoints = new ArrayList<WayPoint>(); 213 218 protected String p_Time; … … 239 244 byte[] chb = chkstrings[0].getBytes(); 240 245 int chk=0; 241 for(int i = 1; i < chb.length; i++) chk ^= chb[i]; 246 for(int i = 1; i < chb.length; i++) { 247 chk ^= chb[i]; 248 } 242 249 if(Integer.parseInt(chkstrings[1].substring(0,2),16) != chk) { 243 250 //System.out.println("Checksum error"); … … 246 253 return false; 247 254 } 255 } else { 256 ps.no_checksum++; 248 257 } 249 else250 ps.no_checksum++;251 258 // now for the content 252 259 String[] e = chkstrings[0].split(","); … … 264 271 e[GPGGA.LATITUDE.position], 265 272 e[GPGGA.LONGITUDE.position] 266 273 ); 267 274 if(latLon==null) throw(null); // malformed 268 275 … … 291 298 accu=e[GPGGA.HEIGHT_UNTIS.position]; 292 299 if(accu.equals("M")) { 293 294 295 300 // Ignore heights that are not in meters for now 301 accu=e[GPGGA.HEIGHT.position]; 302 if(!accu.equals("")) { 296 303 Double.parseDouble(accu); 297 304 // if it throws it's malformed; this should only happen if the 298 305 // device sends nonstandard data. 299 if(!accu.equals("")) currentwp.attr.put("ele", accu); 306 if(!accu.equals("")) { 307 currentwp.attr.put("ele", accu); 308 } 300 309 } 301 310 } … … 309 318 // h-dilution 310 319 accu=e[GPGGA.HDOP.position]; 311 if(!accu.equals("")) 320 if(!accu.equals("")) { 312 321 currentwp.attr.put("hdop", Float.parseFloat(accu)); 322 } 313 323 // fix 314 324 accu=e[GPGGA.QUALITY.position]; … … 320 330 break; 321 331 case 1: 322 if(sat < 4) currentwp.attr.put("fix", "2d"); 323 else currentwp.attr.put("fix", "3d"); 332 if(sat < 4) { 333 currentwp.attr.put("fix", "2d"); 334 } else { 335 currentwp.attr.put("fix", "3d"); 336 } 324 337 break; 325 338 case 2: … … 354 367 // vdop 355 368 accu=e[GPGSA.VDOP.position]; 356 if(!accu.equals("")) 369 if(!accu.equals("")) { 357 370 currentwp.attr.put("vdop", Float.parseFloat(accu)); 371 } 358 372 // hdop 359 373 accu=e[GPGSA.HDOP.position]; 360 if(!accu.equals("")) 374 if(!accu.equals("")) { 361 375 currentwp.attr.put("hdop", Float.parseFloat(accu)); 376 } 362 377 // pdop 363 378 accu=e[GPGSA.PDOP.position]; 364 if(!accu.equals("")) 379 if(!accu.equals("")) { 365 380 currentwp.attr.put("pdop", Float.parseFloat(accu)); 381 } 366 382 } 367 383 else if(e[0].equals("$GPRMC")) { … … 372 388 e[GPRMC.WIDTH_NORTH.position], 373 389 e[GPRMC.LENGTH_EAST.position] 374 ); 375 if(latLon==null) throw(null); 390 ); 376 391 if((latLon.lat()==0.0) && (latLon.lon()==0.0)) { 377 392 ps.zero_coord++; … … 439 454 440 455 private LatLon parseLatLon(String ns, String ew, String dlat, String dlon) 441 456 throws NumberFormatException { 442 457 String widthNorth = dlat.trim(); 443 458 String lengthEast = dlon.trim(); … … 456 471 int latdeg = Integer.parseInt(widthNorth.substring(0, latdegsep)); 457 472 double latmin = Double.parseDouble(widthNorth.substring(latdegsep)); 458 if(latdeg < 0) // strange data with '-' sign473 if(latdeg < 0) { 459 474 latmin *= -1.0; 475 } 460 476 double lat = latdeg + latmin / 60; 461 477 if ("S".equals(ns)) { … … 468 484 int londeg = Integer.parseInt(lengthEast.substring(0, londegsep)); 469 485 double lonmin = Double.parseDouble(lengthEast.substring(londegsep)); 470 if(londeg < 0) // strange data with '-' sign486 if(londeg < 0) { 471 487 lonmin *= -1.0; 488 } 472 489 double lon = londeg + lonmin / 60; 473 490 if ("W".equals(ew)) {
Note:
See TracChangeset
for help on using the changeset viewer.