Changeset 12421 in josm
- Timestamp:
- 2017-06-22T00:29:46+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/GpxImporter.java
r10615 r12421 166 166 } 167 167 168 /** 169 * Replies the new GPX and marker layers corresponding to the specified GPX file. 170 * @param is input stream to GPX data 171 * @param associatedFile GPX file 172 * @param gpxLayerName The GPX layer name 173 * @param markerLayerName The marker layer name 174 * @param progressMonitor The progress monitor 175 * @return the new GPX and marker layers corresponding to the specified GPX file 176 * @throws IOException if an I/O error occurs 177 */ 168 178 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 169 179 final String gpxLayerName, String markerLayerName, ProgressMonitor progressMonitor) throws IOException { -
trunk/src/org/openstreetmap/josm/io/NMEAImporter.java
r10621 r12421 20 20 import org.openstreetmap.josm.gui.util.GuiHelper; 21 21 import org.openstreetmap.josm.io.GpxImporter.GpxImporterData; 22 import org.openstreetmap.josm.io.nmea.NmeaReader; 22 23 23 24 /** … … 88 89 } 89 90 91 /** 92 * Replies the new GPX and marker layers corresponding to the specified NMEA file. 93 * @param is input stream to NMEA 0183 data 94 * @param associatedFile NMEA file 95 * @param gpxLayerName The GPX layer name 96 * @param markerLayerName The marker layer name 97 * @return the new GPX and marker layers corresponding to the specified NMEA file 98 * @throws IOException if an I/O error occurs 99 */ 90 100 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 91 101 final String gpxLayerName, String markerLayerName) throws IOException { -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java
r12418 r12421 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io ;2 package org.openstreetmap.josm.io.nmea; 3 3 4 4 import java.io.BufferedReader; … … 21 21 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 22 22 import org.openstreetmap.josm.data.gpx.WayPoint; 23 import org.openstreetmap.josm.io.IllegalDataException; 23 24 import org.openstreetmap.josm.tools.JosmRuntimeException; 24 25 import org.openstreetmap.josm.tools.date.DateUtils; 25 26 26 27 /** 27 * Reads a NMEA file. Based on information from 28 * <a href="http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm">http://www.kowoma.de</a> 28 * Reads a NMEA 0183 file. Based on information from 29 * <a href="http://www.catb.org/gpsd/NMEA.html">http://www.catb.org/gpsd</a>. 30 * 31 * NMEA files are in printable ASCII form and may include information such as position, 32 * speed, depth, frequency allocation, etc. 33 * Typical messages might be 11 to a maximum of 79 characters in length. 34 * 35 * NMEA standard aims to support one-way serial data transmission from a single "talker" 36 * to one or more "listeners". The type of talker is identified by a 2-character mnemonic. 37 * 38 * NMEA information is encoded through a list of "sentences". 29 39 * 30 40 * @author cbrill … … 32 42 public class NmeaReader { 33 43 34 // GPVTG 35 public enum GPVTG { 44 public enum VTG { 36 45 COURSE(1), COURSE_REF(2), // true course 37 46 COURSE_M(3), COURSE_M_REF(4), // magnetic course … … 42 51 public final int position; 43 52 44 GPVTG(int position) {53 VTG(int position) { 45 54 this.position = position; 46 55 } 47 56 } 48 57 49 // The following only applies to GPRMC 50 public enum GPRMC { 58 public enum RMC { 51 59 TIME(1), 52 60 /** Warning from the receiver (A = data ok, V = warning) */ … … 57 65 MAGNETIC_DECLINATION(10), UNKNOWN(11), // magnetic declination 58 66 /** 59 * Mode (A = autonom; D = differential; E = estimated; N = not valid; S 60 * = simulated) 67 * Mode (A = autonom; D = differential; E = estimated; N = not valid; S = simulated) 61 68 * 62 69 * @since NMEA 2.3 … … 66 73 public final int position; 67 74 68 GPRMC(int position) {75 RMC(int position) { 69 76 this.position = position; 70 77 } 71 78 } 72 79 73 // The following only applies to GPGGA 74 public enum GPGGA { 80 public enum GGA { 75 81 TIME(1), LATITUDE(2), LATITUDE_NAME(3), LONGITUDE(4), LONGITUDE_NAME(5), 76 82 /** 77 * Quality (0 = invalid, 1 = GPS, 2 = DGPS, 6 = estimanted (@since NMEA 78 * 2.3)) 83 * Quality (0 = invalid, 1 = GPS, 2 = DGPS, 6 = estimanted (@since NMEA 2.3)) 79 84 */ 80 85 QUALITY(6), SATELLITE_COUNT(7), … … 86 91 87 92 public final int position; 88 G PGGA(int position) {93 GGA(int position) { 89 94 this.position = position; 90 95 } 91 96 } 92 97 93 public enum G PGSA {98 public enum GSA { 94 99 AUTOMATIC(1), 95 100 FIX_TYPE(2), // 1 = not fixed, 2 = 2D fixed, 3 = 3D fixed) … … 102 107 103 108 public final int position; 104 G PGSA(int position) {109 GSA(int position) { 105 110 this.position = position; 106 111 } … … 200 205 } 201 206 207 /** 208 * Determines if the given address denotes the given NMEA sentence formatter of a known talker. 209 * @param address first tag of an NMEA sentence 210 * @param formatter sentence formatter mnemonic code 211 * @return {@code true} if the {@code address} denotes the given NMEA sentence formatter of a known talker 212 */ 213 static boolean isSentence(String address, Sentence formatter) { 214 for (TalkerId talker : TalkerId.values()) { 215 if (address.equals('$' + talker.name() + formatter.name())) { 216 return true; 217 } 218 } 219 return false; 220 } 221 202 222 // Parses split up sentences into WayPoints which are stored 203 223 // in the collection in the NMEAParserState object. 204 // Returns true if the input made sen ce, false otherwise.224 // Returns true if the input made sense, false otherwise. 205 225 private boolean parseNMEASentence(String s, NMEAParserState ps) throws IllegalDataException { 206 226 try { … … 236 256 237 257 // handle the packet content 238 if ( "$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {258 if (isSentence(e[0], Sentence.GGA)) { 239 259 // Position 240 260 LatLon latLon = parseLatLon( 241 e[G PGGA.LATITUDE_NAME.position],242 e[G PGGA.LONGITUDE_NAME.position],243 e[G PGGA.LATITUDE.position],244 e[G PGGA.LONGITUDE.position]261 e[GGA.LATITUDE_NAME.position], 262 e[GGA.LONGITUDE_NAME.position], 263 e[GGA.LATITUDE.position], 264 e[GGA.LONGITUDE.position] 245 265 ); 246 266 if (latLon == null) { … … 254 274 255 275 // time 256 accu = e[G PGGA.TIME.position];276 accu = e[GGA.TIME.position]; 257 277 Date d = readTime(currentDate+accu); 258 278 … … 269 289 } 270 290 // elevation 271 accu = e[G PGGA.HEIGHT_UNTIS.position];291 accu = e[GGA.HEIGHT_UNTIS.position]; 272 292 if ("M".equals(accu)) { 273 293 // Ignore heights that are not in meters for now 274 accu = e[G PGGA.HEIGHT.position];294 accu = e[GGA.HEIGHT.position]; 275 295 if (!accu.isEmpty()) { 276 296 Double.parseDouble(accu); … … 282 302 } 283 303 } 284 // number of sat telites285 accu = e[G PGGA.SATELLITE_COUNT.position];304 // number of satellites 305 accu = e[GGA.SATELLITE_COUNT.position]; 286 306 int sat = 0; 287 307 if (!accu.isEmpty()) { … … 290 310 } 291 311 // h-dilution 292 accu = e[G PGGA.HDOP.position];312 accu = e[GGA.HDOP.position]; 293 313 if (!accu.isEmpty()) { 294 314 currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu)); 295 315 } 296 316 // fix 297 accu = e[G PGGA.QUALITY.position];317 accu = e[GGA.QUALITY.position]; 298 318 if (!accu.isEmpty()) { 299 319 int fixtype = Integer.parseInt(accu); … … 316 336 } 317 337 } 318 } else if ( "$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {338 } else if (isSentence(e[0], Sentence.VTG)) { 319 339 // COURSE 320 accu = e[ GPVTG.COURSE_REF.position];340 accu = e[VTG.COURSE_REF.position]; 321 341 if ("T".equals(accu)) { 322 342 // other values than (T)rue are ignored 323 accu = e[ GPVTG.COURSE.position];343 accu = e[VTG.COURSE.position]; 324 344 if (!accu.isEmpty()) { 325 345 Double.parseDouble(accu); … … 328 348 } 329 349 // SPEED 330 accu = e[ GPVTG.SPEED_KMH_UNIT.position];350 accu = e[VTG.SPEED_KMH_UNIT.position]; 331 351 if (accu.startsWith("K")) { 332 accu = e[ GPVTG.SPEED_KMH.position];352 accu = e[VTG.SPEED_KMH.position]; 333 353 if (!accu.isEmpty()) { 334 354 double speed = Double.parseDouble(accu); … … 337 357 } 338 358 } 339 } else if ( "$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {359 } else if (isSentence(e[0], Sentence.GSA)) { 340 360 // vdop 341 accu = e[G PGSA.VDOP.position];361 accu = e[GSA.VDOP.position]; 342 362 if (!accu.isEmpty() && currentwp != null) { 343 363 currentwp.put(GpxConstants.PT_VDOP, Float.valueOf(accu)); 344 364 } 345 365 // hdop 346 accu = e[G PGSA.HDOP.position];366 accu = e[GSA.HDOP.position]; 347 367 if (!accu.isEmpty() && currentwp != null) { 348 368 currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu)); 349 369 } 350 370 // pdop 351 accu = e[G PGSA.PDOP.position];371 accu = e[GSA.PDOP.position]; 352 372 if (!accu.isEmpty() && currentwp != null) { 353 373 currentwp.put(GpxConstants.PT_PDOP, Float.valueOf(accu)); 354 374 } 355 } else if ( "$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {375 } else if (isSentence(e[0], Sentence.RMC)) { 356 376 // coordinates 357 377 LatLon latLon = parseLatLon( 358 e[ GPRMC.WIDTH_NORTH_NAME.position],359 e[ GPRMC.LENGTH_EAST_NAME.position],360 e[ GPRMC.WIDTH_NORTH.position],361 e[ GPRMC.LENGTH_EAST.position]378 e[RMC.WIDTH_NORTH_NAME.position], 379 e[RMC.LENGTH_EAST_NAME.position], 380 e[RMC.WIDTH_NORTH.position], 381 e[RMC.LENGTH_EAST.position] 362 382 ); 363 383 if (LatLon.ZERO.equals(latLon)) { … … 366 386 } 367 387 // time 368 currentDate = e[ GPRMC.DATE.position];369 String time = e[ GPRMC.TIME.position];388 currentDate = e[RMC.DATE.position]; 389 String time = e[RMC.TIME.position]; 370 390 371 391 Date d = readTime(currentDate+time); … … 379 399 currentwp.setTime(d); 380 400 // speed 381 accu = e[ GPRMC.SPEED.position];401 accu = e[RMC.SPEED.position]; 382 402 if (!accu.isEmpty() && !currentwp.attr.containsKey("speed")) { 383 403 double speed = Double.parseDouble(accu); … … 386 406 } 387 407 // course 388 accu = e[ GPRMC.COURSE.position];408 accu = e[RMC.COURSE.position]; 389 409 if (!accu.isEmpty() && !currentwp.attr.containsKey("course")) { 390 410 Double.parseDouble(accu); -
trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java
r12418 r12421 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io ;2 package org.openstreetmap.josm.io.nmea; 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 5 7 6 8 import java.io.FileInputStream; … … 20 22 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 21 23 import org.openstreetmap.josm.data.gpx.WayPoint; 24 import org.openstreetmap.josm.io.GpxReaderTest; 22 25 import org.openstreetmap.josm.testutils.JOSMTestRules; 23 26 import org.openstreetmap.josm.tools.date.DateUtils; … … 92 95 93 96 /** 97 * Unit test of {@link NmeaReader#isSentence}. 98 */ 99 @Test 100 public void testIsSentence() { 101 assertTrue(NmeaReader.isSentence("$GPVTG", Sentence.VTG)); 102 assertTrue(NmeaReader.isSentence("$GAVTG", Sentence.VTG)); 103 assertTrue(NmeaReader.isSentence("$GNVTG", Sentence.VTG)); 104 assertFalse(NmeaReader.isSentence("XGAVTG", Sentence.VTG)); 105 assertFalse(NmeaReader.isSentence("$GPXXX", Sentence.VTG)); 106 assertFalse(NmeaReader.isSentence("$XXVTG", Sentence.VTG)); 107 } 108 109 /** 94 110 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/1433">Bug #1433</a>. 95 111 * @throws Exception if an error occurs
Note:
See TracChangeset
for help on using the changeset viewer.