use of au.gov.amsa.ais.AisMessage in project risky by amsa-code.
the class StreamsTest method stringRepresentationOfTimestampedAndLineContainsMessageInCaseOfSuccess.
@Test
public void stringRepresentationOfTimestampedAndLineContainsMessageInCaseOfSuccess() {
final Timestamped<AisMessage> aisMessage = new Timestamped<>(new AisMessageOther(4242, "source", 0), 0);
final TimestampedAndLine<AisMessage> message = new TimestampedAndLine<>(Optional.of(aisMessage), "test", null);
final String representation = message.toString();
assertNotNull(representation);
assertTrue("String representation should contain message ID, but got: " + representation, representation.contains("4242"));
}
use of au.gov.amsa.ais.AisMessage in project risky by amsa-code.
the class OperatorCraftProperty method call.
@Override
public Subscriber<? super Timestamped<? extends AisMessage>> call(final Subscriber<? super CraftProperty> child) {
return new Subscriber<Timestamped<? extends AisMessage>>(child) {
@Override
public void onCompleted() {
if (!isUnsubscribed())
child.onCompleted();
}
@Override
public void onError(Throwable e) {
if (!isUnsubscribed())
child.onError(e);
}
@SuppressWarnings("unchecked")
@Override
public void onNext(Timestamped<? extends AisMessage> m) {
if (m.message() instanceof AisShipStaticA) {
handleShipStatic((Timestamped<AisShipStaticA>) m, child);
} else if (m.message() instanceof AisPositionBExtended)
handleAisPositionBExtended((Timestamped<AisPositionBExtended>) m, child);
}
private void handleShipStatic(Timestamped<AisShipStaticA> m, Subscriber<? super CraftProperty> child) {
handleProperty(child, m, CraftPropertyName.CALLSIGN, m.message().getCallsign());
handleProperty(child, m, CraftPropertyName.DESTINATION, m.message().getDestination());
handleProperty(child, m, CraftPropertyName.DIMENSION_A, m.message().getDimensionA());
handleProperty(child, m, CraftPropertyName.DIMENSION_B, m.message().getDimensionB());
handleProperty(child, m, CraftPropertyName.DIMENSION_C, m.message().getDimensionC());
handleProperty(child, m, CraftPropertyName.DIMENSION_D, m.message().getDimensionD());
handleProperty(child, m, CraftPropertyName.IMO_NUMBER, m.message().getImo());
handleProperty(child, m, CraftPropertyName.LENGTH_METRES, m.message().getLengthMetres());
handleProperty(child, m, CraftPropertyName.DRAUGHT_METRES, m.message().getMaximumPresentStaticDraughtMetres());
handleProperty(child, m, CraftPropertyName.NAME, m.message().getName());
handleProperty(child, m, CraftPropertyName.SHIP_TYPE, m.message().getShipType());
handleProperty(child, m, CraftPropertyName.WIDTH_METRES, m.message().getWidthMetres());
}
private void handleAisPositionBExtended(Timestamped<AisPositionBExtended> m, Subscriber<? super CraftProperty> child) {
handleProperty(child, m, CraftPropertyName.DIMENSION_A, m.message().getDimensionA());
handleProperty(child, m, CraftPropertyName.DIMENSION_B, m.message().getDimensionB());
handleProperty(child, m, CraftPropertyName.DIMENSION_C, m.message().getDimensionC());
handleProperty(child, m, CraftPropertyName.DIMENSION_D, m.message().getDimensionD());
handleProperty(child, m, CraftPropertyName.LENGTH_METRES, m.message().getLengthMetres());
handleProperty(child, m, CraftPropertyName.NAME, m.message().getName());
handleProperty(child, m, CraftPropertyName.SHIP_TYPE, m.message().getShipType());
handleProperty(child, m, CraftPropertyName.WIDTH_METRES, m.message().getWidthMetres());
}
private <R extends AisMessage & HasMmsi> void handleProperty(Subscriber<? super CraftProperty> child, Timestamped<R> m, CraftPropertyName name, Object value) {
if (!isUnsubscribed() && value != null)
child.onNext(new CraftProperty(new Mmsi(m.message().getMmsi()), name, value.toString(), m.time()));
}
};
}
use of au.gov.amsa.ais.AisMessage in project risky by amsa-code.
the class StreamsTest method testExtractShipStaticA.
@Test
public void testExtractShipStaticA() {
String line = "\\c:1432212545,g:1-1-6*1F\\!BSVDM,1,1,6,B,58LOWB02BafgUKWO7V0LhuHU>0l4E=A8v2222216D8N<D1Kb0CQiAC3kQp8888888888880,0*6C";
TimestampedAndLine<AisMessage> x = Streams.extract(Observable.just(line)).toBlocking().single();
AisShipStaticA m = (AisShipStaticA) x.getMessage().get().message();
assertEquals(566749000, m.getMmsi());
assertEquals(9610987, (int) m.getImo().get());
assertEquals("9V9719", m.getCallsign());
assertEquals("GLOVIS MAESTRO", m.getName());
assertEquals(161, (int) m.getDimensionA().get());
assertEquals(70, m.getShipType());
System.out.println(x);
}
Aggregations