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