Changeset 14083 in josm


Ignore:
Timestamp:
2018-08-04T19:25:42+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #16554 - read NMEA speeds in km/h

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java

    r14067 r14083  
    432432                    if (!accu.isEmpty() && currentwp != null) {
    433433                        double speed = Double.parseDouble(accu);
    434                         speed /= 3.6; // speed in m/s
    435                         currentwp.put("speed", Double.toString(speed));
     434                        currentwp.put("speed", Double.toString(speed)); // speed in km/h
    436435                    }
    437436                }
     
    481480                if (!accu.isEmpty() && !currentwp.attr.containsKey("speed")) {
    482481                    double speed = Double.parseDouble(accu);
    483                     speed *= 0.514444444; // to m/s
     482                    speed *= 0.514444444 * 3.6; // to km/h
    484483                    currentwp.put("speed", Double.toString(speed));
    485484                }
  • trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java

    r14079 r14083  
    160160    }
    161161
    162     private static Date readDate(String nmeaLine) throws IOException, SAXException {
     162    private static GpxData read(String nmeaLine) throws IOException, SAXException {
    163163        NmeaReader in = new NmeaReader(new ByteArrayInputStream(nmeaLine.getBytes(StandardCharsets.UTF_8)));
    164164        in.parse(true);
    165         return in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator().next().getTime();
     165        return in.data;
     166    }
     167
     168    private static WayPoint readWayPoint(String nmeaLine) throws IOException, SAXException {
     169        return read(nmeaLine).tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator().next();
     170    }
     171
     172    private static Date readDate(String nmeaLine) throws IOException, SAXException {
     173        return readWayPoint(nmeaLine).getTime();
     174    }
     175
     176    private static double readSpeed(String nmeaLine) throws IOException, SAXException {
     177        return Double.parseDouble(readWayPoint(nmeaLine).getString("speed"));
    166178    }
    167179
     
    179191                readDate("$GNRMC,162859.4,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
    180192    }
     193
     194    /**
     195     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/16554">Bug #16554</a>.
     196     * @throws Exception if an error occurs
     197     */
     198    @Test
     199    public void testTicket16554() throws Exception {
     200        assertEquals(63.2420959, readSpeed(
     201                  "$GNRMC,141448.80,A,4659.05514,N,00130.44695,W,34.148,289.80,300718,,,D,V*26"), 1e-7);
     202        assertEquals(63.2430000, readSpeed(
     203                  "$GNRMC,141448.80,A,4659.05514,N,00130.44695,W,34.148,289.80,300718,,,D,V*26"
     204                + "$GNVTG,289.80,T,,M,34.148,N,63.243,K,D*27"), 1e-7);
     205    }
    181206}
Note: See TracChangeset for help on using the changeset viewer.