diff --git a/src/main/java/net/sf/marineapi/ais/util/MMSI.java b/src/main/java/net/sf/marineapi/ais/util/MMSI.java index bd930473..34268ed5 100644 --- a/src/main/java/net/sf/marineapi/ais/util/MMSI.java +++ b/src/main/java/net/sf/marineapi/ais/util/MMSI.java @@ -28,49 +28,43 @@ public class MMSI { private static final long MINVALUE = 0; - private static final long MAXVALUE = 999999999; + private static final long MAXVALUE = 999999999; - /** - * Checks whether the MMSI value is correct, i.e. within valid range. - * - * @param value MMSI value to check - * @return true if the value is semantically correct. - */ - public static boolean isCorrect(long value) { - return (MINVALUE <= value) && (value <= MAXVALUE); - } + private static final String[] REGION_DESCRIPTIONS = { + "Ship group, coast station, or group of coast stations", + "SAR aircraft", + "Europe", + "North and Central America and Caribbean", + "Asia", + "Oceana", + "Africa", + "South America", + "Assigned for regional Use", + "Nav aids or craft associated with a parent ship", + "Invalid MMSI number" + }; - /** - * Returns the origin associated with the MMSI number. - * - * @param value MMSI value to stringify - * @return A String describing the region of the transmitter - */ - public static String toString(long value) { - int firstDigit = (int)(value / 100000000L); - switch (firstDigit) { - case 0: - return "Ship group, coast station, or group of coast stations"; - case 1: - return "SAR aircraft"; - case 2: - return "Europe"; - case 3: - return "North and Central America and Caribbean"; - case 4: - return "Asia"; - case 5: - return "Oceana"; - case 6: - return "Africa"; - case 7: - return "South America"; - case 8: - return "Assigned for regional Use"; - case 9: - return "Nav aids or craft associated with a parent ship"; - default: - return "Invalid MMSI number"; - } - } + /** + * Checks whether the MMSI value is correct, i.e. within valid range. + * + * @param value MMSI value to check + * @return true if the value is semantically correct. + */ + public static boolean isCorrect(long value) { + return (MINVALUE <= value) && (value <= MAXVALUE); + } + + /** + * Returns the origin associated with the MMSI number. + * + * @param value MMSI value to stringify + * @return A String describing the region of the transmitter + */ + public static String toString(long value) { + int firstDigit = (int) (value / 100000000L); + if (0 <= firstDigit && firstDigit <= 9) { + return REGION_DESCRIPTIONS[firstDigit]; + } + return REGION_DESCRIPTIONS[10]; + } } \ No newline at end of file diff --git a/src/main/java/net/sf/marineapi/ais/util/NavAidType.java b/src/main/java/net/sf/marineapi/ais/util/NavAidType.java index d55cdc17..4ce06832 100644 --- a/src/main/java/net/sf/marineapi/ais/util/NavAidType.java +++ b/src/main/java/net/sf/marineapi/ais/util/NavAidType.java @@ -33,74 +33,52 @@ public class NavAidType { * @param deviceType Device type value to Stringify. * @return a text string describing the Nav Aid type */ - static public String toString (int deviceType) { - switch (deviceType) { - case 0: - return "Default, Type of Aid to Navigation not specified"; - case 1: - return "Reference point"; - case 2: - return "RACON (radar transponder marking a navigation hazard)"; - case 3: - return "Fixed structure off shore, such as oil platforms, wind farms, rigs"; - case 4: - return "Spare, Reserved for future use"; - case 5: - return "Light, without sectors"; - case 6: - return "Light, with sectors"; - case 7: - return "Leading Light Front"; - case 8: - return "Leading Light Rear"; - case 9: - return "Beacon, Cardinal N"; - case 10: - return "Beacon, Cardinal E"; - case 11: - return "Beacon, Cardinal S"; - case 12: - return "Beacon, Cardinal W"; - case 13: - return "Beacon, Port hand"; - case 14: - return "Beacon, Starboard hand"; - case 15: - return "Beacon, Preferred Channel port hand"; - case 16: - return "Beacon, Preferred Channel starboard hand"; - case 17: - return "Beacon, Isolated danger"; - case 18: - return "Beacon, Safe water"; - case 19: - return "Beacon, Special mark"; - case 20: - return "Cardinal Mark N"; - case 21: - return "Cardinal Mark E"; - case 22: - return "Cardinal Mark S"; - case 23: - return "Cardinal Mark W"; - case 24: - return "Port hand Mark"; - case 25: - return "Starboard hand Mark"; - case 26: - return "Preferred Channel Port hand"; - case 27: - return "Preferred Channel Starboard hand"; - case 28: - return "Isolated danger"; - case 29: - return "Safe Water"; - case 30: - return "Special Mark"; - case 31: - return "Light Vessel / LANBY / Rigs"; - default: - return "not used"; - } - } + static private String[] navAidTypes = { + "Default, Type of Aid to Navigation not specified", + "Reference point", + "RACON (radar transponder marking a navigation hazard)", + "Fixed structure off shore, such as oil platforms, wind farms, rigs", + "Spare, Reserved for future use", + "Light, without sectors", + "Light, with sectors", + "Leading Light Front", + "Leading Light Rear", + "Beacon, Cardinal N", + "Beacon, Cardinal E", + "Beacon, Cardinal S", + "Beacon, Cardinal W", + "Beacon, Port hand", + "Beacon, Starboard hand", + "Beacon, Preferred Channel port hand", + "Beacon, Preferred Channel starboard hand", + "Beacon, Isolated danger", + "Beacon, Safe water", + "Beacon, Special mark", + "Cardinal Mark N", + "Cardinal Mark E", + "Cardinal Mark S", + "Cardinal Mark W", + "Port hand Mark", + "Starboard hand Mark", + "Preferred Channel Port hand", + "Preferred Channel Starboard hand", + "Isolated danger", + "Safe Water", + "Special Mark", + "Light Vessel / LANBY / Rigs", + "not used" + }; + + /** + * Returns a text string for the NavAid. + * + * @param deviceType Device type value to Stringify. + * @return a text string describing the Nav Aid type + */ + static public String toString(int deviceType) { + if (deviceType >= 0 && deviceType < navAidTypes.length) { + return navAidTypes[deviceType]; + } + return "not used"; + } } diff --git a/src/main/java/net/sf/marineapi/ais/util/PositioningDevice.java b/src/main/java/net/sf/marineapi/ais/util/PositioningDevice.java index 61a060d3..a88f4259 100644 --- a/src/main/java/net/sf/marineapi/ais/util/PositioningDevice.java +++ b/src/main/java/net/sf/marineapi/ais/util/PositioningDevice.java @@ -21,42 +21,67 @@ package net.sf.marineapi.ais.util; /** - * Checks the positioning device type for validity. + * Provides functionality related to positioning devices. * * @author Lázár József */ public class PositioningDevice { - - /** - * Returns a text string for the EPFD. - * - * @param deviceType Device type value to Stringify. - * @return a text string describing the positioning device type - */ - static public String toString (int deviceType) { - switch (deviceType) { - case 0: - return "undefined device"; - case 1: - return "GPS"; - case 2: - return "GLONASS"; - case 3: - return "combined GPS/GLONASS"; - case 4: - return "Loran-C"; - case 5: - return "Chayka"; - case 6: - return "integrated navigation system"; - case 7: - return "surveyed"; - case 8: - return "Galileo"; - case 15: - return "internal GNSS"; - default: - return "not used"; - } - } + + private static final String[] DEVICE_TYPES = { + "undefined device", + "GPS", + "GLONASS", + "combined GPS/GLONASS", + "Loran-C", + "Chayka", + "integrated navigation system", + "surveyed", + "Galileo", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "internal GNSS", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used", + "not used" + }; + + /** + * Returns a text string for the EPFD. + * + * @param deviceType Device type value to stringify. + * @return a text string describing the positioning device type + */ + static public String toString(int deviceType) { + if (isValidDeviceType(deviceType)) { + return DEVICE_TYPES[deviceType]; + } + return "not used"; + } + + /** + * Checks whether the device type value is correct. + * + * @param deviceType Device type value to check. + * @return true if the value is semantically correct. + */ + static private boolean isValidDeviceType(int deviceType) { + return 0 <= deviceType && deviceType < DEVICE_TYPES.length; + } } diff --git a/src/main/java/net/sf/marineapi/ais/util/ShipType.java b/src/main/java/net/sf/marineapi/ais/util/ShipType.java index f7f04a2f..7ba66d46 100644 --- a/src/main/java/net/sf/marineapi/ais/util/ShipType.java +++ b/src/main/java/net/sf/marineapi/ais/util/ShipType.java @@ -1,182 +1,134 @@ -/* - * ShipType.java - * Copyright (C) 2015-2020 Lázár József, Joshua Sweaney - * - * This file is part of Java Marine API. - * - * - * Java Marine API is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Java Marine API is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java Marine API. If not, see . - */ -package net.sf.marineapi.ais.util; - -/** - * Checks the ship type for validity. - * - * @author Lázár József, Joshua Sweaney - */ public class ShipType { - final static private String[] SPECIAL = { - "Pilot vessel", - "Search and rescue vessel", - "Tug", - "Port tender", - "Vessel with anti-pollution capability", - "Law enforcement vessel", - "Spare - for local vessels", - "Spare - for local vessels", - "Medical transport", - "Ship not party to an armed conflict" - }; + private static final String[] SPECIAL = { + "Pilot vessel", + "Search and rescue vessel", + "Tug", + "Port tender", + "Vessel with anti-pollution capability", + "Law enforcement vessel", + "Spare - for local vessels", + "Spare - for local vessels", + "Medical transport", + "Ship not party to an armed conflict" + }; + + private static final String[] FIRST_DIGIT = { + "Not specified", + "Reserved for future use", + "WIG", + "Vessel", + "HSC", + "See above", + "Passenger ship", + "Cargo ship", + "Tanker", + "Other types of ship" + }; + + private static final String[] SECOND_DIGIT = { + "General", + "Category X", + "Category Y", + "Category Z", + "Category OS", + "Reserved for future use", + "Reserved for future use", + "Reserved for future use", + "Reserved for future use", + "No additional information" + }; + + private static final String[] VESSEL = { + "Fishing", + "Towing", + "Towing and exceeding", + "Engaged in dredging or underwater operations", + "Engaged in diving operations", + "Engaged in military operations", + "Sailing", + "Pleasure craft", + "Reserved for future use", + "Reserved for future use" + }; - final static private String[] FIRST_DIGIT = { - "Not specified", - "Reserved for future use", - "WIG", - "Vessel", - "HSC", - "See above", - "Passenger ship", - "Cargo ship", - "Tanker", - "Other types of ship" - }; - - final static private String[] SECOND_DIGIT = { - "General", - "Category X", - "Category Y", - "Category Z", - "Category OS", - "Reserved for future use", - "Reserved for future use", - "Reserved for future use", - "Reserved for future use", - "No additional information" - }; + /** + * Return string describing the ship and cargo type. + * + * @param type Ship and cargo type indicator + * @return a text string describing the ship and cargo type. + */ + public static String shipTypeToString(int type) { + if (isValidType(type)) { + int d1 = type / 10; + int d2 = type % 10; - final static private String[] VESSEL = { - "Fishing", - "Towing", - "Towing and exceeding", - "Engaged in dredging or underwater operations", - "Engaged in diving operations", - "Engaged in military operations", - "Sailing", - "Pleasure craft", - "Reserved for future use", - "Reserved for future use" - }; - - /** - * Return string describing the ship and cargo type. - * - * @param type Ship and cargo type indicator - * @return a text string describing the ship and cargo type. - */ - static public String shipTypeToString (int type) { - String typeStr ="N/A"; - if (0 <= type && type <= 255) { - if (type >= 200) - return "Reserved for future use"; - if (type >= 100) - return "Reserved for regional use"; - if (type == 0) - return "Not available / no ship"; + switch (d1) { + case 0: + return FIRST_DIGIT[0] + " " + Integer.toString(type); + case 3: + return FIRST_DIGIT[3] + ", " + VESSEL[d2]; + case 5: + return SPECIAL[d2]; + default: + return FIRST_DIGIT[d1] + ", " + SECOND_DIGIT[d2]; + } + } + return "N/A"; + } - int d1 = type / 10; - int d2 = type % 10; - if (0 <= d1 && d1 <= 9 && 0 <= d2 && d2 <= 9) { - switch(d1) { - case 0: - return FIRST_DIGIT[0] + " " + Integer.toString(type); - case 3: - return FIRST_DIGIT[3] + ", " + VESSEL[d2]; - case 5: - return SPECIAL[d2]; - default: - return FIRST_DIGIT[d1] + ", " + SECOND_DIGIT[d2]; - } - } - } - return typeStr; - } + /** + * Returns a string describing the first digit. Describes the type of vessel. + * + * @param type Ship and cargo type indicator + * @return String a text string describing the ship type digit + */ + public static String shipTypeToVesselString(int type) { + if (isValidType(type)) { + int d1 = type / 10; + int d2 = type % 10; - /** - * Returns a string describing the first digit. Describes the type of vessel. - * @param type Ship and cargo type indicator - * @return String a text string describing the ship type digit - */ - static public String shipTypeToVesselString(int type) { - String typeStr ="N/A"; - if (0 <= type && type <= 255) { - if (type >= 200) - return "Reserved for future use"; - if (type >= 100) - return "Reserved for regional use"; - if (type == 0) - return "Not available / no ship"; + switch (d1) { + case 0: + return FIRST_DIGIT[0] + " " + Integer.toString(type); + case 3: + return FIRST_DIGIT[3]; + case 5: + return SPECIAL[d2]; + default: + return FIRST_DIGIT[d1]; + } + } + return "N/A"; + } - int d1 = type / 10; - int d2 = type % 10; - if (0 <= d1 && d1 <= 9 && 0 <= d2 && d2 <= 9) { - switch(d1) { - case 0: - return FIRST_DIGIT[0] + " " + Integer.toString(type); // Ship type not specified, so just print whole type number - case 3: - return FIRST_DIGIT[3]; // Vessel - case 5: - return SPECIAL[d2]; // Describes special vessel types for vessels in U.S. waters - default: - return FIRST_DIGIT[d1]; // Ship type - } - } - } - return typeStr; - } + /** + * Returns a string describing the second digit. Usually describes the type of cargo being carried, + * but may also describe the activity the vessel is engaged in. + * + * @param type Ship and cargo type indicator + * @return String a text string describing the cargo type digit + */ + public static String shipTypeToCargoString(int type) { + if (isValidType(type)) { + int d1 = type / 10; + int d2 = type % 10; - /** - * Returns a string describing the second digit. Usually describes the type - * of cargo being carried, but may also describe the activity the vessel is engaged in. - * @param type Ship and cargo type indicator - * @return String a text string describing the cargo type digit - */ - static public String shipTypeToCargoString(int type) { - String typeStr ="N/A"; - if (0 <= type && type <= 255) { - if (type >= 200) - return "Reserved for future use"; - if (type >= 100) - return "Reserved for regional use"; - if (type == 0) - return "Not available / no ship"; + switch (d1) { + case 0: + return FIRST_DIGIT[0] + " " + Integer.toString(type); + case 3: + return VESSEL[d2]; + case 5: + return SPECIAL[d2]; + default: + return SECOND_DIGIT[d2]; + } + } + return "N/A"; + } - int d1 = type / 10; - int d2 = type % 10; - if (0 <= d1 && d1 <= 9 && 0 <= d2 && d2 <= 9) { - switch(d1) { - case 0: - return FIRST_DIGIT[0] + " " + Integer.toString(type); // Cargo not specified, so just print whole type number - case 3: - return VESSEL[d2]; // Describes an activity the vessel is engaged in - case 5: - return SPECIAL[d2]; // Describes special vessel types for vessels in U.S. waters - default: - return SECOND_DIGIT[d2]; // Describes the cargo being carried - } - } - } - return typeStr; - } -} \ No newline at end of file + private static boolean isValidType(int type) { + return 0 <= type && type <= 255 && type < 100 || (type >= 100 && type < 200) || type >= 200 && type < 256; + } +} diff --git a/src/main/java/net/sf/marineapi/provider/PositionProvider.java b/src/main/java/net/sf/marineapi/provider/PositionProvider.java index 9eeb616c..aae67811 100644 --- a/src/main/java/net/sf/marineapi/provider/PositionProvider.java +++ b/src/main/java/net/sf/marineapi/provider/PositionProvider.java @@ -1,172 +1,109 @@ -/* - * PositionProvider.java - * Copyright (C) 2011 Kimmo Tuukkanen - * - * This file is part of Java Marine API. - * - * - * Java Marine API is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Java Marine API is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Java Marine API. If not, see . - */ -package net.sf.marineapi.provider; +public class PositionProvider extends AbstractProvider { -import net.sf.marineapi.nmea.io.SentenceReader; -import net.sf.marineapi.nmea.parser.DataNotAvailableException; -import net.sf.marineapi.nmea.sentence.GGASentence; -import net.sf.marineapi.nmea.sentence.GLLSentence; -import net.sf.marineapi.nmea.sentence.RMCSentence; -import net.sf.marineapi.nmea.sentence.VTGSentence; -import net.sf.marineapi.nmea.sentence.Sentence; -import net.sf.marineapi.nmea.sentence.SentenceId; -import net.sf.marineapi.nmea.util.DataStatus; -import net.sf.marineapi.nmea.util.Date; -import net.sf.marineapi.nmea.util.FaaMode; -import net.sf.marineapi.nmea.util.GpsFixQuality; -import net.sf.marineapi.nmea.util.Position; -import net.sf.marineapi.nmea.util.Time; -import net.sf.marineapi.provider.event.PositionEvent; + public PositionProvider(SentenceReader reader) { + super(reader, SentenceId.RMC, SentenceId.GGA, SentenceId.GLL, SentenceId.VTG); + } -/** - *

- * Provides Time, Position and Velocity reports from GPS. Data is captured from - * RMC, GGA and GLL sentences. RMC is used for date/time, speed and course. GGA - * is used as primary source for position as it contains also the altitude. When - * GGA is not available, position may be taken from GLL or RMC. If this is the - * case, there is no altitude included in the - * {@link net.sf.marineapi.nmea.util.Position}. GPS data statuses are also - * captured and events are dispatched only when sentences report - * {@link net.sf.marineapi.nmea.util.DataStatus#ACTIVE}. FAA mode transmitted in - * RMC is also checked and captured when available, but may be {@code null} - * depending on used NMEA version. - * - * @author Kimmo Tuukkanen - * @see net.sf.marineapi.provider.event.PositionListener - * @see net.sf.marineapi.provider.event.PositionEvent - * @see net.sf.marineapi.nmea.io.SentenceReader - */ -public class PositionProvider extends AbstractProvider { + @Override + protected PositionEvent createProviderEvent() { + Position p = null; + Double sog = null; + Double cog = null; + Date d = null; + Time t = null; + FaaMode mode = null; + GpsFixQuality fix = null; + + for (Sentence s : getSentences()) { + if (s instanceof RMCSentence) { + handleRMCSentence((RMCSentence) s, p, sog, cog, d, t, mode); + } else if (s instanceof VTGSentence) { + handleVTGSentence((VTGSentence) s, sog, cog); + } else if (s instanceof GGASentence) { + handleGGASentence((GGASentence) s, p, d, t, fix); + } else if (s instanceof GLLSentence) { + handleGLLSentence((GLLSentence) s, p); + } + } + + if (d == null) { + d = new Date(); + } - /** - * Creates a new instance of PositionProvider. - * - * @param reader SentenceReader that provides the required sentences. - */ - public PositionProvider(SentenceReader reader) { - super(reader, SentenceId.RMC, SentenceId.GGA, SentenceId.GLL, SentenceId.VTG); - } + return new PositionEvent(this, p, sog, cog, d, t, mode, fix); + } - /* - * (non-Javadoc) - * @see net.sf.marineapi.provider.AbstractProvider#createProviderEvent() - */ - @Override - protected PositionEvent createProviderEvent() { - Position p = null; - Double sog = null; - Double cog = null; - Date d = null; - Time t = null; - FaaMode mode = null; - GpsFixQuality fix = null; + private void handleRMCSentence(RMCSentence rmc, Position p, Double sog, Double cog, Date d, Time t, FaaMode mode) { + sog = rmc.getSpeed(); + try { + cog = rmc.getCourse(); + } catch (DataNotAvailableException e) { + // If we are not moving, course can be undefined. Leave null in that case. + } + d = rmc.getDate(); + t = rmc.getTime(); + if (p == null) { + p = rmc.getPosition(); + if (rmc.getFieldCount() > 11) { + mode = rmc.getMode(); + } + } + } - for (Sentence s : getSentences()) { - if (s instanceof RMCSentence) { - RMCSentence rmc = (RMCSentence) s; - sog = rmc.getSpeed(); - try { - cog = rmc.getCourse(); - } catch (DataNotAvailableException e) { - // If we are not moving, cource can be undefined. Leave null in that case. - } - d = rmc.getDate(); - t = rmc.getTime(); - if (p == null) { - p = rmc.getPosition(); - if(rmc.getFieldCount() > 11) { - mode = rmc.getMode(); - } - } - } else if (s instanceof VTGSentence) { - VTGSentence vtg = (VTGSentence) s; - sog = vtg.getSpeedKnots(); - try { - cog = vtg.getTrueCourse(); - } catch (DataNotAvailableException e) { - // If we are not moving, cource can be undefined. Leave null in that case. - } - } else if (s instanceof GGASentence) { - // Using GGA as primary position source as it contains both - // position and altitude - GGASentence gga = (GGASentence) s; - p = gga.getPosition(); - fix = gga.getFixQuality(); + private void handleVTGSentence(VTGSentence vtg, Double sog, Double cog) { + sog = vtg.getSpeedKnots(); + try { + cog = vtg.getTrueCourse(); + } catch (DataNotAvailableException e) { + // If we are not moving, course can be undefined. Leave null in that case. + } + } - // Some receivers do not provide RMC message - if (t == null) { - t = gga.getTime(); - } - } else if (s instanceof GLLSentence && p == null) { - GLLSentence gll = (GLLSentence) s; - p = gll.getPosition(); - } - } + private void handleGGASentence(GGASentence gga, Position p, Date d, Time t, GpsFixQuality fix) { + p = gga.getPosition(); + fix = gga.getFixQuality(); - // Ag-Star reciever does not provide RMC sentence. So we have to guess what date it is - if (d == null) { - d = new Date(); - } + // Some receivers do not provide RMC message + if (t == null) { + t = gga.getTime(); + } + } - return new PositionEvent(this, p, sog, cog, d, t, mode, fix); - } + private void handleGLLSentence(GLLSentence gll, Position p) { + p = gll.getPosition(); + } - /* - * (non-Javadoc) - * @see net.sf.marineapi.provider.AbstractProvider#isReady() - */ - @Override - protected boolean isReady() { - return hasOne("RMC", "VTG") && hasOne("GGA", "GLL"); - } + @Override + protected boolean isReady() { + return hasOne("RMC", "VTG") && hasOne("GGA", "GLL"); + } - /* - * (non-Javadoc) - * @see net.sf.marineapi.provider.AbstractProvider#isValid() - */ - @Override - protected boolean isValid() { + @Override + protected boolean isValid() { + for (Sentence s : getSentences()) { + if (s instanceof RMCSentence && !isValidRMCSentence((RMCSentence) s)) { + return false; + } else if (s instanceof GGASentence && !isValidGGASentence((GGASentence) s)) { + return false; + } else if (s instanceof GLLSentence && !isValidGLLSentence((GLLSentence) s)) { + return false; + } + } + return true; + } - for (Sentence s : getSentences()) { + private boolean isValidRMCSentence(RMCSentence rmc) { + DataStatus ds = rmc.getStatus(); + return !DataStatus.VOID.equals(ds) && !(rmc.getFieldCount() > 11 && FaaMode.NONE.equals(rmc.getMode())); + } - if (s instanceof RMCSentence) { - RMCSentence rmc = (RMCSentence)s; - DataStatus ds = rmc.getStatus(); - if (DataStatus.VOID.equals(ds) || - (rmc.getFieldCount() > 11 && FaaMode.NONE.equals(rmc.getMode()))) { - return false; - } - } else if (s instanceof GGASentence) { - GpsFixQuality fq = ((GGASentence) s).getFixQuality(); - if (GpsFixQuality.INVALID.equals(fq)) { - return false; - } - } else if (s instanceof GLLSentence) { - DataStatus ds = ((GLLSentence) s).getStatus(); - if (DataStatus.VOID.equals(ds)) { - return false; - } - } - } + private boolean isValidGGASentence(GGASentence gga) { + GpsFixQuality fq = gga.getFixQuality(); + return !GpsFixQuality.INVALID.equals(fq); + } - return true; - } + private boolean isValidGLLSentence(GLLSentence gll) { + DataStatus ds = gll.getStatus(); + return !DataStatus.VOID.equals(ds); + } } diff --git a/src/test/java/net/sf/marineapi/nmea/parser/GGATest.java b/src/test/java/net/sf/marineapi/nmea/parser/GGATest.java index dfd8034a..ad15c9e7 100644 --- a/src/test/java/net/sf/marineapi/nmea/parser/GGATest.java +++ b/src/test/java/net/sf/marineapi/nmea/parser/GGATest.java @@ -146,10 +146,14 @@ public void testSetAltitude() { } @Test - public void testSetAltitudeUnits() { - assertEquals(Units.METER, gga.getAltitudeUnits()); - gga.setAltitudeUnits(Units.FEET); - assertEquals(Units.FEET, gga.getAltitudeUnits()); + public void testDefaultAltitudeUnits() { + assertEquals(Units.METER, gga.getAltitudeUnits()); + } + + @Test + public void testSetAltitudeUnitsToFeet() { + gga.setAltitudeUnits(Units.FEET); + assertEquals(Units.FEET, gga.getAltitudeUnits()); } @Test @@ -166,10 +170,14 @@ public void testSetDgpsStationId() { } @Test - public void testSetFixQuality() { - assertEquals(GpsFixQuality.NORMAL, gga.getFixQuality()); - gga.setFixQuality(GpsFixQuality.INVALID); - assertEquals(GpsFixQuality.INVALID, gga.getFixQuality()); + public void testDefaultFixQuality() { + assertEquals(GpsFixQuality.NORMAL, gga.getFixQuality()); + } + + @Test + public void testSetFixQualityToInvalid() { + gga.setFixQuality(GpsFixQuality.INVALID); + assertEquals(GpsFixQuality.INVALID, gga.getFixQuality()); } @Test @@ -180,10 +188,14 @@ public void testSetGeoidalHeight() { } @Test - public void testSetGeoidalHeightUnits() { - assertEquals(Units.METER, gga.getGeoidalHeightUnits()); - gga.setGeoidalHeightUnits(Units.FEET); - assertEquals(Units.FEET, gga.getGeoidalHeightUnits()); + public void testDefaultGeoidalHeightUnits() { + assertEquals(Units.METER, gga.getGeoidalHeightUnits()); + } + + @Test + public void testSetGeoidalHeightUnitsToFeet() { + gga.setGeoidalHeightUnits(Units.FEET); + assertEquals(Units.FEET, gga.getGeoidalHeightUnits()); } @Test diff --git a/src/test/java/net/sf/marineapi/nmea/parser/TXTTest.java b/src/test/java/net/sf/marineapi/nmea/parser/TXTTest.java index e353e570..969b2dc1 100644 --- a/src/test/java/net/sf/marineapi/nmea/parser/TXTTest.java +++ b/src/test/java/net/sf/marineapi/nmea/parser/TXTTest.java @@ -32,9 +32,17 @@ public void testStringConstructor() { } @Test - public void testTalkerIdConstructor() { + public void testTalkerId() { assertEquals(TalkerId.II, empty.getTalkerId()); + } + + @Test + public void testSentenceId() { assertEquals("TXT", empty.getSentenceId()); + } + + @Test + public void testFieldCount() { assertEquals(4, empty.getFieldCount()); } diff --git a/src/test/java/net/sf/marineapi/nmea/parser/XTETest.java b/src/test/java/net/sf/marineapi/nmea/parser/XTETest.java index 062b5a77..e12a4be6 100644 --- a/src/test/java/net/sf/marineapi/nmea/parser/XTETest.java +++ b/src/test/java/net/sf/marineapi/nmea/parser/XTETest.java @@ -26,19 +26,43 @@ public void setUp() throws Exception { } @Test - public void testXTEParserString() { - assertEquals(TalkerId.II, instance.getTalkerId()); - assertEquals(SentenceId.XTE.name(), instance.getSentenceId()); - assertEquals(6, instance.getFieldCount()); - assertTrue(instance.isValid()); + public void testTalkerId() { + assertEquals(TalkerId.II, instance.getTalkerId()); } @Test - public void testXTEParserTalkerId() { - assertEquals(TalkerId.GP, empty.getTalkerId()); - assertEquals(SentenceId.XTE.name(), empty.getSentenceId()); - assertEquals(6, empty.getFieldCount()); - assertTrue(empty.isValid()); + public void testSentenceId() { + assertEquals(SentenceId.XTE.name(), instance.getSentenceId()); + } + + @Test + public void testFieldCount() { + assertEquals(6, instance.getFieldCount()); + } + + @Test + public void testIsValid() { + assertTrue(instance.isValid()); + } + + @Test + public void testTalkerId() { + assertEquals(TalkerId.GP, empty.getTalkerId()); + } + + @Test + public void testSentenceId() { + assertEquals(SentenceId.XTE.name(), empty.getSentenceId()); + } + + @Test + public void testFieldCount() { + assertEquals(6, empty.getFieldCount()); + } + + @Test + public void testIsValid() { + assertTrue(empty.isValid()); } @Test