Search in sources :

Example 1 with SentenceEvent

use of net.sf.marineapi.nmea.event.SentenceEvent in project marine-api by ktuukkan.

the class PositionProviderTest method testSentenceReadWithGLL.

/**
	 * Test method for
	 * {@link net.sf.marineapi.provider.AbstractProvider#sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent)}
	 * .
	 */
@Test
public void testSentenceReadWithGLL() {
    SentenceFactory sf = SentenceFactory.getInstance();
    Sentence gll = sf.createParser(GLLTest.EXAMPLE);
    assertNull(event);
    instance.sentenceRead(new SentenceEvent(this, gll));
    assertNull(event);
    Sentence rmc = sf.createParser(RMCTest.EXAMPLE);
    instance.sentenceRead(new SentenceEvent(this, rmc));
    assertNotNull(event);
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGATest(net.sf.marineapi.nmea.parser.GGATest) GLLTest(net.sf.marineapi.nmea.parser.GLLTest) Test(org.junit.Test) RMCTest(net.sf.marineapi.nmea.parser.RMCTest)

Example 2 with SentenceEvent

use of net.sf.marineapi.nmea.event.SentenceEvent in project marine-api by ktuukkan.

the class PositionProviderTest method testSentenceReadWithLegacyRMC.

@Test
public void testSentenceReadWithLegacyRMC() {
    SentenceFactory sf = SentenceFactory.getInstance();
    Sentence gll = sf.createParser(GLLTest.EXAMPLE);
    assertNull(event);
    instance.sentenceRead(new SentenceEvent(this, gll));
    assertNull(event);
    Sentence rmc = sf.createParser(RMCTest.EXAMPLE_LEGACY);
    instance.sentenceRead(new SentenceEvent(this, rmc));
    assertNotNull(event);
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGATest(net.sf.marineapi.nmea.parser.GGATest) GLLTest(net.sf.marineapi.nmea.parser.GLLTest) Test(org.junit.Test) RMCTest(net.sf.marineapi.nmea.parser.RMCTest)

Example 3 with SentenceEvent

use of net.sf.marineapi.nmea.event.SentenceEvent in project marine-api by ktuukkan.

the class SentenceReader method fireSentenceEvent.

/**
	 * Dispatch data to all listeners.
	 *
	 * @param sentence sentence string.
	 */
void fireSentenceEvent(Sentence sentence) {
    String type = sentence.getSentenceId();
    Set<SentenceListener> targets = new HashSet<SentenceListener>();
    if (listeners.containsKey(type)) {
        targets.addAll(listeners.get(type));
    }
    if (listeners.containsKey(DISPATCH_ALL)) {
        targets.addAll(listeners.get(DISPATCH_ALL));
    }
    for (SentenceListener listener : targets) {
        try {
            SentenceEvent se = new SentenceEvent(this, sentence);
            listener.sentenceRead(se);
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, LOG_MSG, e);
        }
    }
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) SentenceListener(net.sf.marineapi.nmea.event.SentenceListener) HashSet(java.util.HashSet)

Example 4 with SentenceEvent

use of net.sf.marineapi.nmea.event.SentenceEvent in project marine-api by ktuukkan.

the class HeadingProviderTest method testHDGSentenceRead.

/**
	 * Test method for
	 * {@link net.sf.marineapi.provider.AbstractProvider#sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent)}
	 * .
	 */
@Test
public void testHDGSentenceRead() {
    Sentence s = factory.createParser(HDGTest.EXAMPLE);
    assertNull(event);
    instance.sentenceRead(new SentenceEvent(this, s));
    assertNotNull(event);
    assertEquals(123.4, event.getHeading(), 0.1);
    assertFalse(event.isTrue());
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) Sentence(net.sf.marineapi.nmea.sentence.Sentence) HDMTest(net.sf.marineapi.nmea.parser.HDMTest) Test(org.junit.Test) HDTTest(net.sf.marineapi.nmea.parser.HDTTest) HDGTest(net.sf.marineapi.nmea.parser.HDGTest)

Example 5 with SentenceEvent

use of net.sf.marineapi.nmea.event.SentenceEvent in project marine-api by ktuukkan.

the class HeadingProviderTest method testHDMSentenceRead.

/**
	 * Test method for
	 * {@link net.sf.marineapi.provider.AbstractProvider#sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent)}
	 * .
	 */
@Test
public void testHDMSentenceRead() {
    Sentence s = factory.createParser(HDMTest.EXAMPLE);
    assertNull(event);
    instance.sentenceRead(new SentenceEvent(this, s));
    assertNotNull(event);
    assertEquals(90.0, event.getHeading(), 0.1);
    assertFalse(event.isTrue());
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) Sentence(net.sf.marineapi.nmea.sentence.Sentence) HDMTest(net.sf.marineapi.nmea.parser.HDMTest) Test(org.junit.Test) HDTTest(net.sf.marineapi.nmea.parser.HDTTest) HDGTest(net.sf.marineapi.nmea.parser.HDGTest)

Aggregations

SentenceEvent (net.sf.marineapi.nmea.event.SentenceEvent)7 Sentence (net.sf.marineapi.nmea.sentence.Sentence)6 Test (org.junit.Test)6 GGATest (net.sf.marineapi.nmea.parser.GGATest)3 GLLTest (net.sf.marineapi.nmea.parser.GLLTest)3 HDGTest (net.sf.marineapi.nmea.parser.HDGTest)3 HDMTest (net.sf.marineapi.nmea.parser.HDMTest)3 HDTTest (net.sf.marineapi.nmea.parser.HDTTest)3 RMCTest (net.sf.marineapi.nmea.parser.RMCTest)3 SentenceFactory (net.sf.marineapi.nmea.parser.SentenceFactory)3 HashSet (java.util.HashSet)1 SentenceListener (net.sf.marineapi.nmea.event.SentenceListener)1