Search in sources :

Example 1 with SentenceFactory

use of net.sf.marineapi.nmea.parser.SentenceFactory 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 SentenceFactory

use of net.sf.marineapi.nmea.parser.SentenceFactory 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 SentenceFactory

use of net.sf.marineapi.nmea.parser.SentenceFactory in project marine-api by ktuukkan.

the class AbstractDataReader method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    ActivityMonitor monitor = new ActivityMonitor(parent);
    SentenceFactory factory = SentenceFactory.getInstance();
    while (isRunning) {
        try {
            String data = read();
            if (data == null) {
                Thread.sleep(SLEEP_TIME);
            } else if (SentenceValidator.isValid(data)) {
                monitor.refresh();
                Sentence s = factory.createParser(data);
                parent.fireSentenceEvent(s);
            } else if (!SentenceValidator.isSentence(data)) {
                parent.fireDataEvent(data);
            }
        } catch (Exception e) {
            parent.handleException("Data read failed", e);
            try {
                Thread.sleep(SLEEP_TIME);
            } catch (InterruptedException interruptException) {
            }
        } finally {
            monitor.tick();
        }
    }
    monitor.reset();
    parent.fireReadingStopped();
}
Also used : SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory) Sentence(net.sf.marineapi.nmea.sentence.Sentence)

Example 4 with SentenceFactory

use of net.sf.marineapi.nmea.parser.SentenceFactory in project marine-api by ktuukkan.

the class OutputExample method main.

public static void main(String[] args) {
    // Create a fresh MWV parser
    SentenceFactory sf = SentenceFactory.getInstance();
    MWVSentence mwv = (MWVSentence) sf.createParser(TalkerId.II, "MWV");
    // should output "$IIMWV,,,,,V*36" 
    System.out.println(mwv.toSentence());
    // Be sure to set all needed values correctly. For instance, in this
    // example setAngle() and setTrue() have mutual dependency. Likewise,
    // pay attention to set units correctly.
    mwv.setAngle(43.7);
    mwv.setTrue(true);
    mwv.setSpeed(4.54);
    mwv.setSpeedUnit(Units.METER);
    mwv.setStatus(DataStatus.ACTIVE);
    // should output "$IIMWV,043.7,T,4.5,M,A*39"
    System.out.println(mwv.toSentence());
}
Also used : MWVSentence(net.sf.marineapi.nmea.sentence.MWVSentence) SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory)

Example 5 with SentenceFactory

use of net.sf.marineapi.nmea.parser.SentenceFactory in project marine-api by ktuukkan.

the class SentenceReaderTest method testFireSentenceEventWithExpectedType.

@Test
public void testFireSentenceEventWithExpectedType() {
    assertNull(sentence);
    SentenceFactory sf = SentenceFactory.getInstance();
    Sentence s = sf.createParser(GGATest.EXAMPLE);
    reader.fireSentenceEvent(s);
    assertEquals(s, sentence);
}
Also used : SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGATest(net.sf.marineapi.nmea.parser.GGATest) Test(org.junit.Test) BODTest(net.sf.marineapi.nmea.parser.BODTest)

Aggregations

SentenceFactory (net.sf.marineapi.nmea.parser.SentenceFactory)7 Sentence (net.sf.marineapi.nmea.sentence.Sentence)6 GGATest (net.sf.marineapi.nmea.parser.GGATest)5 Test (org.junit.Test)5 SentenceEvent (net.sf.marineapi.nmea.event.SentenceEvent)3 GLLTest (net.sf.marineapi.nmea.parser.GLLTest)3 RMCTest (net.sf.marineapi.nmea.parser.RMCTest)3 BODTest (net.sf.marineapi.nmea.parser.BODTest)2 MWVSentence (net.sf.marineapi.nmea.sentence.MWVSentence)1