Search in sources :

Example 1 with KlvContext

use of org.codice.ddf.libs.klv.KlvContext in project alliance by codice.

the class KlvUtilities method createTestFloat.

/**
 * value should be between -180 and 180
 *
 * @param name name of the klv data element
 * @param value value of the klv data element
 * @return klv data element
 * @throws KlvDecodingException
 */
public static KlvIntegerEncodedFloatingPoint createTestFloat(String name, double value) throws KlvDecodingException {
    long encodedMin = -180;
    long encodedMax = 180;
    double actualRange = encodedMax - encodedMin;
    double scaledValue = (value - encodedMin) / actualRange;
    long encodedRangeMin = ((long) Integer.MIN_VALUE) + 1;
    long encodedRange = ((long) Integer.MAX_VALUE) - encodedRangeMin;
    long encodedValue = (long) (scaledValue * encodedRange + encodedRangeMin);
    byte byte1 = (byte) ((encodedValue & 0xFF000000) >> 24);
    byte byte2 = (byte) ((encodedValue & 0xFF0000) >> 16);
    byte byte3 = (byte) ((encodedValue & 0xFF00) >> 8);
    byte byte4 = (byte) (encodedValue & 0xFF);
    final byte[] klvBytes = { -8, 4, byte1, byte2, byte3, byte4 };
    final KlvInt klvInt = new KlvInt(new byte[] { -8 }, name);
    final KlvIntegerEncodedFloatingPoint sensorRelativeElevationAngle = new KlvIntegerEncodedFloatingPoint(klvInt, // Short.MIN_VALUE is an "out of range" indicator, so it is not included in the range.
    Integer.MIN_VALUE + 1, Integer.MAX_VALUE, encodedMin, encodedMax);
    final KlvContext decodedKlvContext = decodeKLV(Klv.KeyLength.OneByte, Klv.LengthEncoding.OneByte, sensorRelativeElevationAngle, klvBytes);
    return (KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName(name);
}
Also used : KlvContext(org.codice.ddf.libs.klv.KlvContext) KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt)

Example 2 with KlvContext

use of org.codice.ddf.libs.klv.KlvContext in project alliance by codice.

the class MetadataPacketTest method verifyDecodedKLV.

private void verifyDecodedKLV(final DecodedKLVMetadataPacket decodedPacket) {
    assertThat(decodedPacket, notNullValue());
    assertThat(decodedPacket.getDecodedKLV().hasDataElement(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET), is(true));
    final KlvContext localSetContext = ((KlvLocalSet) decodedPacket.getDecodedKLV().getDataElementByName(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET)).getValue();
    assertThat(((KlvUnsignedShort) localSetContext.getDataElementByName(Stanag4609TransportStreamParser.CHECKSUM)).getValue(), is(19537));
}
Also used : KlvLocalSet(org.codice.ddf.libs.klv.data.set.KlvLocalSet) KlvContext(org.codice.ddf.libs.klv.KlvContext)

Example 3 with KlvContext

use of org.codice.ddf.libs.klv.KlvContext in project alliance by codice.

the class Stanag4609ProcessorImplTest method testHandleWithStanagMetadata.

@Test
public void testHandleWithStanagMetadata() throws KlvDecodingException {
    DecodedKLVMetadataPacket p2 = mock(DecodedKLVMetadataPacket.class);
    when(p2.getDecodedKLV()).thenReturn(new KlvContext(Klv.KeyLength.OneByte, Klv.LengthEncoding.OneByte, Collections.singleton(klvIntegerEncodedFloatingPoint)));
    Map<String, KlvHandler> handlers = Collections.singletonMap(FIELD_NAME, klvHandler);
    Map<Integer, List<DecodedKLVMetadataPacket>> stanag = Collections.singletonMap(1, Collections.singletonList(p2));
    stanag4609Processor.handle(handlers, defaultKlvHandler, stanag);
    verify(klvHandler, atLeastOnce()).accept(klvIntegerEncodedFloatingPoint);
}
Also used : DecodedKLVMetadataPacket(org.codice.alliance.libs.stanag4609.DecodedKLVMetadataPacket) KlvContext(org.codice.ddf.libs.klv.KlvContext) List(java.util.List) Test(org.junit.Test)

Example 4 with KlvContext

use of org.codice.ddf.libs.klv.KlvContext in project alliance by codice.

the class Stanag4609ProcessorImplTest method testHandleWithKlvLocalSet.

@Test
public void testHandleWithKlvLocalSet() throws KlvDecodingException {
    KlvContext klvContext = new KlvContext(Klv.KeyLength.OneByte, Klv.LengthEncoding.OneByte, Collections.singleton(klvIntegerEncodedFloatingPoint));
    KlvDataElement klvLocalSet = mock(KlvLocalSet.class);
    when(klvLocalSet.getValue()).thenReturn(klvContext);
    stanag4609Processor.handle(Collections.singletonMap(FIELD_NAME, klvHandler), defaultKlvHandler, klvLocalSet, dataElements);
    verify(klvHandler, atLeastOnce()).accept(klvIntegerEncodedFloatingPoint);
}
Also used : KlvContext(org.codice.ddf.libs.klv.KlvContext) KlvDataElement(org.codice.ddf.libs.klv.KlvDataElement) Test(org.junit.Test)

Example 5 with KlvContext

use of org.codice.ddf.libs.klv.KlvContext in project alliance by codice.

the class KlvUtilities method decodeKLV.

private static KlvContext decodeKLV(final Klv.KeyLength keyLength, final Klv.LengthEncoding lengthEncoding, final KlvDataElement dataElement, final byte[] encodedBytes) throws KlvDecodingException {
    final KlvContext klvContext = new KlvContext(keyLength, lengthEncoding);
    klvContext.addDataElement(dataElement);
    return new KlvDecoder(klvContext).decode(encodedBytes);
}
Also used : KlvContext(org.codice.ddf.libs.klv.KlvContext) KlvDecoder(org.codice.ddf.libs.klv.KlvDecoder)

Aggregations

KlvContext (org.codice.ddf.libs.klv.KlvContext)8 KlvLocalSet (org.codice.ddf.libs.klv.data.set.KlvLocalSet)3 Test (org.junit.Test)3 KlvDataElement (org.codice.ddf.libs.klv.KlvDataElement)2 List (java.util.List)1 DecodedKLVMetadataPacket (org.codice.alliance.libs.stanag4609.DecodedKLVMetadataPacket)1 KlvDecoder (org.codice.ddf.libs.klv.KlvDecoder)1 KlvDecodingException (org.codice.ddf.libs.klv.KlvDecodingException)1 KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)1 KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1