Search in sources :

Example 1 with VTGSentence

use of net.sf.marineapi.nmea.sentence.VTGSentence 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

DataNotAvailableException (net.sf.marineapi.nmea.parser.DataNotAvailableException)1 GGASentence (net.sf.marineapi.nmea.sentence.GGASentence)1 GLLSentence (net.sf.marineapi.nmea.sentence.GLLSentence)1 RMCSentence (net.sf.marineapi.nmea.sentence.RMCSentence)1 Sentence (net.sf.marineapi.nmea.sentence.Sentence)1 VTGSentence (net.sf.marineapi.nmea.sentence.VTGSentence)1 Date (net.sf.marineapi.nmea.util.Date)1 FaaMode (net.sf.marineapi.nmea.util.FaaMode)1 GpsFixQuality (net.sf.marineapi.nmea.util.GpsFixQuality)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