Search in sources :

Example 1 with AisPositionBExtended

use of au.gov.amsa.ais.message.AisPositionBExtended 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()));
        }
    };
}
Also used : HasMmsi(au.gov.amsa.ais.HasMmsi) Mmsi(au.gov.amsa.ais.rx.Mmsi) Subscriber(rx.Subscriber) Timestamped(au.gov.amsa.ais.Timestamped) CraftPropertyName(au.gov.amsa.ais.rx.CraftPropertyName) AisShipStaticA(au.gov.amsa.ais.message.AisShipStaticA) AisMessage(au.gov.amsa.ais.AisMessage) AisPositionBExtended(au.gov.amsa.ais.message.AisPositionBExtended) CraftProperty(au.gov.amsa.ais.rx.CraftProperty) HasMmsi(au.gov.amsa.ais.HasMmsi)

Example 2 with AisPositionBExtended

use of au.gov.amsa.ais.message.AisPositionBExtended in project risky by amsa-code.

the class AisMessageParser method parse.

/**
 * Returns an {@link AisMessage} from the string representation of the
 * message as per 1371-4 IMO specification (as per the appropriate column in
 * the NMEA message).
 *
 * @param message
 * @param source
 * @return
 */
public AisMessage parse(String message, String source, int padBits) {
    AisExtractor extractor = factory.create(message, 0, padBits);
    int id = extractor.getMessageId();
    if (Util.isClassAPositionReport(id)) {
        return new AisPositionA(message, source, padBits);
    } else if (id == 4)
        return new AisBaseStation(message, source, padBits);
    else if (id == 5)
        return new AisShipStaticA(message, source, padBits);
    else if (id == 18)
        return new AisPositionB(message, source, padBits);
    else if (id == 19)
        return new AisPositionBExtended(message, source, padBits);
    else if (id == 21)
        return new AisAidToNavigation(message, source, padBits);
    else if (id == AisMessageType.STATIC_DATA_REPORT.getId()) {
        int partNumber = AbstractAisBStaticDataReport.extractPartNumber(factory, message, padBits);
        return parseStaticDataReport(partNumber, id, message, source, padBits);
    } else if (id == 27)
        return new AisPositionGPS(message, source, padBits);
    else
        return new AisMessageOther(id, source, padBits);
}
Also used : AisPositionA(au.gov.amsa.ais.message.AisPositionA) AisAidToNavigation(au.gov.amsa.ais.message.AisAidToNavigation) AisPositionGPS(au.gov.amsa.ais.message.AisPositionGPS) AisBaseStation(au.gov.amsa.ais.message.AisBaseStation) AisPositionB(au.gov.amsa.ais.message.AisPositionB) AisShipStaticA(au.gov.amsa.ais.message.AisShipStaticA) AisPositionBExtended(au.gov.amsa.ais.message.AisPositionBExtended) AisMessageOther(au.gov.amsa.ais.message.AisMessageOther)

Example 3 with AisPositionBExtended

use of au.gov.amsa.ais.message.AisPositionBExtended in project risky by amsa-code.

the class ExtractStaticDataAsCsvFromNmeaGz method extractStaticData.

public static void extractStaticData(File input, File output) throws IOException {
    output.getParentFile().mkdirs();
    try (PrintStream out = new PrintStream(output)) {
        // 
        Streams.nmeaFromGzip(input).compose(// 
        o -> Streams.extractMessages(o)).filter(x -> // 
        (x.message() instanceof AisShipStatic) || // 
        (x.message() instanceof AisBStaticDataReportPartA) || // 
        (x.message() instanceof AisBStaticDataReportPartB)).groupBy(// 
        x -> ((HasMmsi) x.message()).getMmsi()).flatMap(o -> // 
        o.scan(// 
        new Timed<State>(new State(o.getKey(), null, null, null, null, null), 0L), (timed, x) -> {
            State state = timed.object;
            String name = state.name;
            String callsign = state.callsign;
            Integer imo = state.imo;
            Integer shipType = state.shipType;
            AisClass aisClass = state.aisClass;
            if (x.message() instanceof AisShipStaticA) {
                AisShipStaticA a = (AisShipStaticA) x.message();
                callsign = a.getCallsign();
                name = a.getName();
                imo = a.getImo().orElse(null);
                shipType = a.getShipType();
                aisClass = AisClass.A;
            } else if (x.message() instanceof AisPositionBExtended) {
                AisPositionBExtended a = (AisPositionBExtended) x.message();
                name = a.getName();
                shipType = a.getShipType();
                aisClass = AisClass.B;
            } else if (x.message() instanceof AisBStaticDataReportPartA) {
                AisBStaticDataReportPartA a = (AisBStaticDataReportPartA) x.message();
                if (a.getName().isPresent()) {
                    name = a.getName().get();
                }
                aisClass = AisClass.B;
            } else if (x.message() instanceof AisBStaticDataReportPartB) {
                aisClass = AisClass.B;
            }
            return new Timed<State>(new State(o.getKey(), aisClass, name, callsign, imo, shipType), x.time());
        }).skip(// 
        1).distinctUntilChanged(ts -> ts.object)).doOnNext(x -> {
            State y = x.object;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            String line = // 
            y.mmsi + "," + sdf.format(new Date(x.time)) + // 
            "," + y.aisClass + // 
            "," + integer(y.imo) + // 
            "," + integer(y.shipType) + // 
            "," + string(y.name) + ",";
            out.println(line);
        }).subscribe();
    }
}
Also used : PrintStream(java.io.PrintStream) AisBStaticDataReportPartA(au.gov.amsa.ais.message.AisBStaticDataReportPartA) Date(java.util.Date) TimeZone(java.util.TimeZone) AisClass(au.gov.amsa.risky.format.AisClass) AisShipStatic(au.gov.amsa.ais.message.AisShipStatic) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) AisPositionBExtended(au.gov.amsa.ais.message.AisPositionBExtended) File(java.io.File) AisBStaticDataReportPartB(au.gov.amsa.ais.message.AisBStaticDataReportPartB) HasMmsi(au.gov.amsa.ais.HasMmsi) Streams(au.gov.amsa.ais.rx.Streams) AisShipStaticA(au.gov.amsa.ais.message.AisShipStaticA) PrintStream(java.io.PrintStream) AisPositionBExtended(au.gov.amsa.ais.message.AisPositionBExtended) Date(java.util.Date) HasMmsi(au.gov.amsa.ais.HasMmsi) AisShipStatic(au.gov.amsa.ais.message.AisShipStatic) AisClass(au.gov.amsa.risky.format.AisClass) AisBStaticDataReportPartA(au.gov.amsa.ais.message.AisBStaticDataReportPartA) AisBStaticDataReportPartB(au.gov.amsa.ais.message.AisBStaticDataReportPartB) AisShipStaticA(au.gov.amsa.ais.message.AisShipStaticA) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AisPositionBExtended (au.gov.amsa.ais.message.AisPositionBExtended)3 AisShipStaticA (au.gov.amsa.ais.message.AisShipStaticA)3 HasMmsi (au.gov.amsa.ais.HasMmsi)2 AisMessage (au.gov.amsa.ais.AisMessage)1 Timestamped (au.gov.amsa.ais.Timestamped)1 AisAidToNavigation (au.gov.amsa.ais.message.AisAidToNavigation)1 AisBStaticDataReportPartA (au.gov.amsa.ais.message.AisBStaticDataReportPartA)1 AisBStaticDataReportPartB (au.gov.amsa.ais.message.AisBStaticDataReportPartB)1 AisBaseStation (au.gov.amsa.ais.message.AisBaseStation)1 AisMessageOther (au.gov.amsa.ais.message.AisMessageOther)1 AisPositionA (au.gov.amsa.ais.message.AisPositionA)1 AisPositionB (au.gov.amsa.ais.message.AisPositionB)1 AisPositionGPS (au.gov.amsa.ais.message.AisPositionGPS)1 AisShipStatic (au.gov.amsa.ais.message.AisShipStatic)1 CraftProperty (au.gov.amsa.ais.rx.CraftProperty)1 CraftPropertyName (au.gov.amsa.ais.rx.CraftPropertyName)1 Mmsi (au.gov.amsa.ais.rx.Mmsi)1 Streams (au.gov.amsa.ais.rx.Streams)1 AisClass (au.gov.amsa.risky.format.AisClass)1 File (java.io.File)1