Beispiel #1
0
  public static Interrogation fromEncodedMessage(EncodedAISMessage encodedMessage) {
    if (!encodedMessage.isValid()) throw new InvalidEncodedMessage(encodedMessage);
    if (!encodedMessage.getMessageType().equals(AISMessageType.Interrogation))
      throw new UnsupportedMessageType(encodedMessage.getMessageType().getCode());

    int messageLength = encodedMessage.getNumberOfBits();
    Integer repeatIndicator = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(6, 8));
    MMSI sourceMmsi =
        MMSI.valueOf(DecoderImpl.convertToUnsignedLong(encodedMessage.getBits(8, 38)));

    MMSI mmsi1 = MMSI.valueOf(DecoderImpl.convertToUnsignedLong(encodedMessage.getBits(40, 70)));
    Integer type1_1 = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(70, 76));
    Integer offset1_1 = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(76, 88));
    Integer type1_2 =
        messageLength > 88
            ? DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(90, 96))
            : null;
    Integer offset1_2 =
        messageLength > 88
            ? DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(96, 108))
            : null;

    MMSI mmsi2 =
        messageLength > 160
            ? MMSI.valueOf(DecoderImpl.convertToUnsignedLong(encodedMessage.getBits(110, 140)))
            : null;
    Integer type2_1 =
        messageLength > 160
            ? DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(140, 146))
            : null;
    Integer offset2_1 =
        messageLength > 160
            ? DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(146, 158))
            : null;

    return new Interrogation(
        repeatIndicator,
        sourceMmsi,
        mmsi1,
        type1_1,
        offset1_1,
        type1_2,
        offset1_2,
        mmsi2,
        type2_1,
        offset2_1);
  }
  public static PositionReportClassAAssignedSchedule fromEncodedMessage(
      EncodedAISMessage encodedMessage) {
    if (!encodedMessage.isValid()) throw new InvalidEncodedMessage(encodedMessage);
    if (!encodedMessage
        .getMessageType()
        .equals(AISMessageType.PositionReportClassAAssignedSchedule))
      throw new UnsupportedMessageType(encodedMessage.getMessageType().getCode());

    Integer repeatIndicator = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(6, 8));
    MMSI sourceMmsi =
        MMSI.valueOf(DecoderImpl.convertToUnsignedLong(encodedMessage.getBits(8, 38)));

    NavigationStatus navigationStatus =
        NavigationStatus.fromInteger(
            DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(38, 42)));
    Integer rateOfTurn = DecoderImpl.convertToSignedInteger(encodedMessage.getBits(42, 50));
    Float speedOverGround =
        DecoderImpl.convertToUnsignedFloat(encodedMessage.getBits(50, 60)) / 10f;
    Boolean positionAccurate = DecoderImpl.convertToBoolean(encodedMessage.getBits(60, 61));
    Float longitude = DecoderImpl.convertToFloat(encodedMessage.getBits(61, 89)) / 600000f;
    Float latitude = DecoderImpl.convertToFloat(encodedMessage.getBits(89, 116)) / 600000f;
    Float courseOverGround =
        DecoderImpl.convertToUnsignedFloat(encodedMessage.getBits(116, 128)) / 10f;
    Integer trueHeading = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(128, 137));
    Integer second = DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(137, 143));
    ManeuverIndicator maneuverIndicator =
        ManeuverIndicator.fromInteger(
            DecoderImpl.convertToUnsignedInteger(encodedMessage.getBits(143, 145)));
    Boolean raimFlag = DecoderImpl.convertToBoolean(encodedMessage.getBits(148, 149));

    return new PositionReportClassAAssignedSchedule(
        AISMessageType.PositionReportClassAAssignedSchedule,
        repeatIndicator,
        sourceMmsi,
        navigationStatus,
        rateOfTurn,
        speedOverGround,
        positionAccurate,
        latitude,
        longitude,
        courseOverGround,
        trueHeading,
        second,
        maneuverIndicator,
        raimFlag);
  }