Search in sources :

Example 1 with GLLSentence

use of net.sf.marineapi.nmea.sentence.GLLSentence in project marine-api by ktuukkan.

the class PositionProvider method isValid.

/*
	 * (non-Javadoc)
	 * @see net.sf.marineapi.provider.AbstractProvider#isValid()
	 */
@Override
protected boolean isValid() {
    for (Sentence s : getSentences()) {
        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;
            }
        }
    }
    return true;
}
Also used : GLLSentence(net.sf.marineapi.nmea.sentence.GLLSentence) RMCSentence(net.sf.marineapi.nmea.sentence.RMCSentence) DataStatus(net.sf.marineapi.nmea.util.DataStatus) GpsFixQuality(net.sf.marineapi.nmea.util.GpsFixQuality) VTGSentence(net.sf.marineapi.nmea.sentence.VTGSentence) GLLSentence(net.sf.marineapi.nmea.sentence.GLLSentence) GGASentence(net.sf.marineapi.nmea.sentence.GGASentence) RMCSentence(net.sf.marineapi.nmea.sentence.RMCSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGASentence(net.sf.marineapi.nmea.sentence.GGASentence)

Example 2 with GLLSentence

use of net.sf.marineapi.nmea.sentence.GLLSentence in project marine-api by ktuukkan.

the class PositionProvider method createProviderEvent.

/*
	 * (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;
    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();
            // 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();
        }
    }
    // Ag-Star reciever does not provide RMC sentence. So we have to guess what date it is
    if (d == null) {
        d = new Date();
    }
    return new PositionEvent(this, p, sog, cog, d, t, mode, fix);
}
Also used : GLLSentence(net.sf.marineapi.nmea.sentence.GLLSentence) Position(net.sf.marineapi.nmea.util.Position) Time(net.sf.marineapi.nmea.util.Time) VTGSentence(net.sf.marineapi.nmea.sentence.VTGSentence) Date(net.sf.marineapi.nmea.util.Date) GGASentence(net.sf.marineapi.nmea.sentence.GGASentence) PositionEvent(net.sf.marineapi.provider.event.PositionEvent) RMCSentence(net.sf.marineapi.nmea.sentence.RMCSentence) DataNotAvailableException(net.sf.marineapi.nmea.parser.DataNotAvailableException) FaaMode(net.sf.marineapi.nmea.util.FaaMode) GpsFixQuality(net.sf.marineapi.nmea.util.GpsFixQuality) VTGSentence(net.sf.marineapi.nmea.sentence.VTGSentence) GLLSentence(net.sf.marineapi.nmea.sentence.GLLSentence) GGASentence(net.sf.marineapi.nmea.sentence.GGASentence) RMCSentence(net.sf.marineapi.nmea.sentence.RMCSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence)

Aggregations

GGASentence (net.sf.marineapi.nmea.sentence.GGASentence)2 GLLSentence (net.sf.marineapi.nmea.sentence.GLLSentence)2 RMCSentence (net.sf.marineapi.nmea.sentence.RMCSentence)2 Sentence (net.sf.marineapi.nmea.sentence.Sentence)2 VTGSentence (net.sf.marineapi.nmea.sentence.VTGSentence)2 GpsFixQuality (net.sf.marineapi.nmea.util.GpsFixQuality)2 DataNotAvailableException (net.sf.marineapi.nmea.parser.DataNotAvailableException)1 DataStatus (net.sf.marineapi.nmea.util.DataStatus)1 Date (net.sf.marineapi.nmea.util.Date)1 FaaMode (net.sf.marineapi.nmea.util.FaaMode)1 Position (net.sf.marineapi.nmea.util.Position)1 Time (net.sf.marineapi.nmea.util.Time)1 PositionEvent (net.sf.marineapi.provider.event.PositionEvent)1