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);
}
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);
}
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();
}
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());
}
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);
}
Aggregations