Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/io/NmeaReader.java
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r8449 r8510 59 59 // GPVTG 60 60 public static enum GPVTG { 61 COURSE(1), COURSE_REF(2), // true course61 COURSE(1), COURSE_REF(2), // true course 62 62 COURSE_M(3), COURSE_M_REF(4), // magnetic course 63 63 SPEED_KN(5), SPEED_KN_UNIT(6), // speed in knots … … 107 107 HEIGHT(9), HEIGHT_UNTIS(10), // height above NN (above geoid) 108 108 HEIGHT_2(11), HEIGHT_2_UNTIS(12), // height geoid - height ellipsoid (WGS84) 109 GPS_AGE(13), // Age of differential GPS data109 GPS_AGE(13), // Age of differential GPS data 110 110 REF(14); // REF station 111 111 … … 153 153 return ps.unknown; 154 154 } 155 155 156 public int getParserZeroCoordinates() { 156 157 return ps.zeroCoord; 157 158 } 159 158 160 public int getParserChecksumErrors() { 159 161 return ps.checksumErrors+ps.noChecksum; 160 162 } 163 161 164 public int getParserMalformed() { 162 165 return ps.malformed; 163 166 } 167 164 168 public int getNumberOfCoordinates() { 165 169 return ps.success; … … 176 180 int loopstart_char = rd.read(); 177 181 ps = new NMEAParserState(); 178 if (loopstart_char == -1)182 if (loopstart_char == -1) 179 183 //TODO tell user about the problem? 180 184 return; 181 sb.append((char) loopstart_char);182 ps.pDate ="010100"; // TODO date problem183 while (true) {185 sb.append((char) loopstart_char); 186 ps.pDate = "010100"; // TODO date problem 187 while (true) { 184 188 // don't load unparsable files completely to memory 185 if (sb.length()>=1020) {189 if (sb.length() >= 1020) { 186 190 sb.delete(0, sb.length()-1); 187 191 } 188 192 int c = rd.read(); 189 if (c=='$') {193 if (c == '$') { 190 194 parseNMEASentence(sb.toString(), ps); 191 195 sb.delete(0, sb.length()); 192 196 sb.append('$'); 193 } else if (c == -1) {197 } else if (c == -1) { 194 198 // EOF: add last WayPoint if it works out 195 parseNMEASentence(sb.toString(), ps);199 parseNMEASentence(sb.toString(), ps); 196 200 break; 197 201 } else { 198 sb.append((char) c);202 sb.append((char) c); 199 203 } 200 204 } … … 237 241 if (chkstrings.length > 1) { 238 242 byte[] chb = chkstrings[0].getBytes(StandardCharsets.UTF_8); 239 int chk =0;243 int chk = 0; 240 244 for (int i = 1; i < chb.length; i++) { 241 245 chk ^= chb[i]; 242 246 } 243 if (Integer.parseInt(chkstrings[1].substring(0, 2),16) != chk) {247 if (Integer.parseInt(chkstrings[1].substring(0, 2), 16) != chk) { 244 248 ps.checksumErrors++; 245 ps.pWp =null;249 ps.pWp = null; 246 250 return false; 247 251 } … … 257 261 258 262 // handle the packet content 259 if ("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {263 if ("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) { 260 264 // Position 261 265 LatLon latLon = parseLatLon( … … 265 269 e[GPGGA.LONGITUDE.position] 266 270 ); 267 if (latLon ==null) {271 if (latLon == null) { 268 272 throw new IllegalDataException("Malformed lat/lon"); 269 273 } … … 278 282 Date d = readTime(currentDate+accu); 279 283 280 if ((ps.pTime==null) || (currentwp==null) || !ps.pTime.equals(accu)) {284 if ((ps.pTime == null) || (currentwp == null) || !ps.pTime.equals(accu)) { 281 285 // this node is newer than the previous, create a new waypoint. 282 // no matter if previous WayPoint was null, we got something 283 // better now. 284 ps.pTime=accu; 286 // no matter if previous WayPoint was null, we got something better now. 287 ps.pTime = accu; 285 288 currentwp = new WayPoint(latLon); 286 289 } 287 if (!currentwp.attr.containsKey("time")) {290 if (!currentwp.attr.containsKey("time")) { 288 291 // As this sentence has no complete time only use it 289 292 // if there is no time so far … … 291 294 } 292 295 // elevation 293 accu =e[GPGGA.HEIGHT_UNTIS.position];294 if ("M".equals(accu)) {296 accu = e[GPGGA.HEIGHT_UNTIS.position]; 297 if ("M".equals(accu)) { 295 298 // Ignore heights that are not in meters for now 296 accu =e[GPGGA.HEIGHT.position];297 if (!accu.isEmpty()) {299 accu = e[GPGGA.HEIGHT.position]; 300 if (!accu.isEmpty()) { 298 301 Double.parseDouble(accu); 299 302 // if it throws it's malformed; this should only happen if the 300 303 // device sends nonstandard data. 301 if (!accu.isEmpty()) { // FIX ? same check304 if (!accu.isEmpty()) { // FIX ? same check 302 305 currentwp.put(GpxConstants.PT_ELE, accu); 303 306 } … … 305 308 } 306 309 // number of sattelites 307 accu =e[GPGGA.SATELLITE_COUNT.position];310 accu = e[GPGGA.SATELLITE_COUNT.position]; 308 311 int sat = 0; 309 if (!accu.isEmpty()) {312 if (!accu.isEmpty()) { 310 313 sat = Integer.parseInt(accu); 311 314 currentwp.put(GpxConstants.PT_SAT, accu); 312 315 } 313 316 // h-dilution 314 accu =e[GPGGA.HDOP.position];315 if (!accu.isEmpty()) {317 accu = e[GPGGA.HDOP.position]; 318 if (!accu.isEmpty()) { 316 319 currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu)); 317 320 } 318 321 // fix 319 accu =e[GPGGA.QUALITY.position];320 if (!accu.isEmpty()) {322 accu = e[GPGGA.QUALITY.position]; 323 if (!accu.isEmpty()) { 321 324 int fixtype = Integer.parseInt(accu); 322 325 switch(fixtype) { … … 325 328 break; 326 329 case 1: 327 if (sat < 4) {330 if (sat < 4) { 328 331 currentwp.put(GpxConstants.PT_FIX, "2d"); 329 332 } else { … … 338 341 } 339 342 } 340 } else if ("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {343 } else if ("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) { 341 344 // COURSE 342 345 accu = e[GPVTG.COURSE_REF.position]; 343 if ("T".equals(accu)) {346 if ("T".equals(accu)) { 344 347 // other values than (T)rue are ignored 345 348 accu = e[GPVTG.COURSE.position]; 346 if (!accu.isEmpty()) {349 if (!accu.isEmpty()) { 347 350 Double.parseDouble(accu); 348 351 currentwp.put("course", accu); … … 351 354 // SPEED 352 355 accu = e[GPVTG.SPEED_KMH_UNIT.position]; 353 if (accu.startsWith("K")) {356 if (accu.startsWith("K")) { 354 357 accu = e[GPVTG.SPEED_KMH.position]; 355 if (!accu.isEmpty()) {358 if (!accu.isEmpty()) { 356 359 double speed = Double.parseDouble(accu); 357 360 speed /= 3.6; // speed in m/s … … 359 362 } 360 363 } 361 } else if ("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {364 } else if ("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) { 362 365 // vdop 363 accu =e[GPGSA.VDOP.position];364 if (!accu.isEmpty()) {366 accu = e[GPGSA.VDOP.position]; 367 if (!accu.isEmpty()) { 365 368 currentwp.put(GpxConstants.PT_VDOP, Float.valueOf(accu)); 366 369 } 367 370 // hdop 368 accu =e[GPGSA.HDOP.position];369 if (!accu.isEmpty()) {371 accu = e[GPGSA.HDOP.position]; 372 if (!accu.isEmpty()) { 370 373 currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu)); 371 374 } 372 375 // pdop 373 accu =e[GPGSA.PDOP.position];374 if (!accu.isEmpty()) {376 accu = e[GPGSA.PDOP.position]; 377 if (!accu.isEmpty()) { 375 378 currentwp.put(GpxConstants.PT_PDOP, Float.valueOf(accu)); 376 379 } 377 } else if ("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {380 } else if ("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) { 378 381 // coordinates 379 382 LatLon latLon = parseLatLon( … … 393 396 Date d = readTime(currentDate+time); 394 397 395 if (ps.pTime==null || currentwp==null || !ps.pTime.equals(time)) {398 if (ps.pTime == null || currentwp == null || !ps.pTime.equals(time)) { 396 399 // this node is newer than the previous, create a new waypoint. 397 ps.pTime =time;400 ps.pTime = time; 398 401 currentwp = new WayPoint(latLon); 399 402 } … … 402 405 // speed 403 406 accu = e[GPRMC.SPEED.position]; 404 if (!accu.isEmpty() && !currentwp.attr.containsKey("speed")) {407 if (!accu.isEmpty() && !currentwp.attr.containsKey("speed")) { 405 408 double speed = Double.parseDouble(accu); 406 409 speed *= 0.514444444; // to m/s … … 409 412 // course 410 413 accu = e[GPRMC.COURSE.position]; 411 if (!accu.isEmpty() && !currentwp.attr.containsKey("course")) {414 if (!accu.isEmpty() && !currentwp.attr.containsKey("course")) { 412 415 Double.parseDouble(accu); 413 416 currentwp.put("course", accu); … … 426 429 } 427 430 ps.pDate = currentDate; 428 if (ps.pWp != currentwp) {429 if (ps.pWp!=null) {431 if (ps.pWp != currentwp) { 432 if (ps.pWp != null) { 430 433 ps.pWp.setTime(); 431 434 } … … 440 443 // out of bounds and such 441 444 ps.malformed++; 442 ps.pWp =null;445 ps.pWp = null; 443 446 return false; 444 447 } … … 452 455 // return a zero latlon instead of null so it is logged as zero coordinate 453 456 // instead of malformed sentence 454 if (widthNorth.isEmpty() && lengthEast.isEmpty()) return new LatLon(0.0,0.0);457 if (widthNorth.isEmpty() && lengthEast.isEmpty()) return new LatLon(0.0, 0.0); 455 458 456 459 // The format is xxDDLL.LLLL … … 463 466 int latdeg = Integer.parseInt(widthNorth.substring(0, latdegsep)); 464 467 double latmin = Double.parseDouble(widthNorth.substring(latdegsep)); 465 if (latdeg < 0) {468 if (latdeg < 0) { 466 469 latmin *= -1.0; 467 470 } … … 476 479 int londeg = Integer.parseInt(lengthEast.substring(0, londegsep)); 477 480 double lonmin = Double.parseDouble(lengthEast.substring(londegsep)); 478 if (londeg < 0) {481 if (londeg < 0) { 479 482 lonmin *= -1.0; 480 483 }
Note:
See TracChangeset
for help on using the changeset viewer.