Search in sources :

Example 1 with SatelliteInfo

use of net.sf.marineapi.nmea.util.SatelliteInfo in project marine-api by ktuukkan.

the class GSVTest method testGetSatelliteInfoWithShortSentence.

/**
	 * Test method for
	 * {@link net.sf.marineapi.nmea.parser.GSVParser#getSatelliteInfo()}.
	 */
@Test
public void testGetSatelliteInfoWithShortSentence() {
    GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47");
    List<SatelliteInfo> sat = g.getSatelliteInfo();
    assertEquals(2, sat.size());
    testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
    testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
}
Also used : GSVSentence(net.sf.marineapi.nmea.sentence.GSVSentence) SatelliteInfo(net.sf.marineapi.nmea.util.SatelliteInfo) Test(org.junit.Test)

Example 2 with SatelliteInfo

use of net.sf.marineapi.nmea.util.SatelliteInfo in project marine-api by ktuukkan.

the class GSVTest method testGetSatelliteInfoWithEmptyFields.

/**
	 * Test method for
	 * {@link net.sf.marineapi.nmea.parser.GSVParser#getSatelliteInfo()}.
	 */
@Test
public void testGetSatelliteInfoWithEmptyFields() {
    GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47,18,,,,21,53,329,47");
    List<SatelliteInfo> sat = g.getSatelliteInfo();
    assertEquals(3, sat.size());
    testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
    testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
    testSatelliteInfo(sat.get(2), "21", 53, 329, 47);
}
Also used : GSVSentence(net.sf.marineapi.nmea.sentence.GSVSentence) SatelliteInfo(net.sf.marineapi.nmea.util.SatelliteInfo) Test(org.junit.Test)

Example 3 with SatelliteInfo

use of net.sf.marineapi.nmea.util.SatelliteInfo in project marine-api by ktuukkan.

the class SatelliteInfoProvider method createProviderEvent.

/*
	 * (non-Javadoc)
	 * @see net.sf.marineapi.provider.AbstractProvider#createProviderEvent()
	 */
@Override
protected SatelliteInfoEvent createProviderEvent() {
    GSASentence gsa = null;
    List<SatelliteInfo> info = new ArrayList<SatelliteInfo>();
    for (Sentence sentence : getSentences()) {
        if ("GSA".equals(sentence.getSentenceId())) {
            gsa = (GSASentence) sentence;
        } else if ("GSV".equals(sentence.getSentenceId())) {
            GSVSentence gsv = (GSVSentence) sentence;
            info.addAll(gsv.getSatelliteInfo());
        }
    }
    return new SatelliteInfoEvent(this, gsa, info);
}
Also used : SatelliteInfoEvent(net.sf.marineapi.provider.event.SatelliteInfoEvent) GSASentence(net.sf.marineapi.nmea.sentence.GSASentence) GSVSentence(net.sf.marineapi.nmea.sentence.GSVSentence) ArrayList(java.util.ArrayList) SatelliteInfo(net.sf.marineapi.nmea.util.SatelliteInfo) GSASentence(net.sf.marineapi.nmea.sentence.GSASentence) GSVSentence(net.sf.marineapi.nmea.sentence.GSVSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence)

Example 4 with SatelliteInfo

use of net.sf.marineapi.nmea.util.SatelliteInfo in project marine-api by ktuukkan.

the class GSVParser method getSatelliteInfo.

/*
	 * (non-Javadoc)
	 * @see net.sf.marineapi.nmea.sentence.GSVSentence#getSatelliteInfo()
	 */
public List<SatelliteInfo> getSatelliteInfo() {
    List<SatelliteInfo> satellites = new ArrayList<SatelliteInfo>(4);
    for (int idf : ID_FIELDS) {
        try {
            String id = getStringValue(idf);
            int elev = getIntValue(idf + ELEVATION);
            int azm = getIntValue(idf + AZIMUTH);
            int snr = getIntValue(idf + NOISE);
            satellites.add(new SatelliteInfo(id, elev, azm, snr));
        } catch (DataNotAvailableException e) {
        // nevermind missing satellite info
        } catch (IndexOutOfBoundsException e) {
            // less than four satellites, give up
            break;
        }
    }
    return satellites;
}
Also used : ArrayList(java.util.ArrayList) SatelliteInfo(net.sf.marineapi.nmea.util.SatelliteInfo)

Example 5 with SatelliteInfo

use of net.sf.marineapi.nmea.util.SatelliteInfo in project marine-api by ktuukkan.

the class GSVParser method setSatelliteInfo.

/*
	 * (non-Javadoc)
	 * @see
	 * net.sf.marineapi.nmea.sentence.GSVSentence#setSatelliteInfo(java.util
	 * .List)
	 */
public void setSatelliteInfo(List<SatelliteInfo> info) {
    if (info.size() > 4) {
        throw new IllegalArgumentException("Maximum list size is 4");
    }
    int i = 0;
    for (int id : ID_FIELDS) {
        if (i < info.size()) {
            SatelliteInfo si = info.get(i++);
            setStringValue(id, si.getId());
            setIntValue(id + ELEVATION, si.getElevation());
            setIntValue(id + AZIMUTH, si.getAzimuth(), 3);
            setIntValue(id + NOISE, si.getNoise());
        } else {
            setStringValue(id, "");
            setStringValue(id + ELEVATION, "");
            setStringValue(id + AZIMUTH, "");
            setStringValue(id + NOISE, "");
        }
    }
}
Also used : SatelliteInfo(net.sf.marineapi.nmea.util.SatelliteInfo)

Aggregations

SatelliteInfo (net.sf.marineapi.nmea.util.SatelliteInfo)7 ArrayList (java.util.ArrayList)3 GSVSentence (net.sf.marineapi.nmea.sentence.GSVSentence)3 Test (org.junit.Test)3 GSASentence (net.sf.marineapi.nmea.sentence.GSASentence)1 Sentence (net.sf.marineapi.nmea.sentence.Sentence)1 SatelliteInfoEvent (net.sf.marineapi.provider.event.SatelliteInfoEvent)1