use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsUnsignedInt.
@Test
public // 160.719211474396, which is wrong.
void testFloatingPointEncodedAsUnsignedInt() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, 0x72, 0x4A, 0x0A, 0x20 };
final KlvLong klvUnsignedInt = new KlvLong(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint sensorRelativeAzimuth = new KlvIntegerEncodedFloatingPoint(klvUnsignedInt, 0, (1L << 32) - 1, 0, 360);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, sensorRelativeAzimuth, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(160.719211436975, 1e-12)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsInt.
@Test
public // Example value taken from ST0601.8 Tag 19.
void testFloatingPointEncodedAsInt() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, (byte) 0x87, (byte) 0xF8, 0x4B, (byte) 0x86 };
final KlvInt klvInt = new KlvInt(new byte[] { -8 }, "test");
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, -180, 180);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, sensorRelativeElevationAngle, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(-168.792324833941, 1e-12)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsShort.
@Test
public // which is wrong.
void testFloatingPointEncodedAsShort() throws KlvDecodingException {
final byte[] klvBytes = { -8, 2, (byte) 0x08, (byte) 0xB8 };
final KlvShort klvShort = new KlvShort(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint platformRollAngle = // Short.MIN_VALUE is an "out of range" indicator, so it is not included in the range.
new KlvIntegerEncodedFloatingPoint(klvShort, Short.MIN_VALUE + 1, Short.MAX_VALUE, -50, 50);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, platformRollAngle, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(3.405865, 1e-6)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint 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.data.numerical.KlvIntegerEncodedFloatingPoint in project alliance by codice.
the class Stanag4609ProcessorImplTest method testDefaultHandlerForCallDataElementHandlers.
@Test
public void testDefaultHandlerForCallDataElementHandlers() throws KlvDecodingException {
KlvIntegerEncodedFloatingPoint otherKlvIntegerEncodedFloatingPoint = KlvUtilities.createTestFloat("someOtherField", 100);
stanag4609Processor.callDataElementHandlers(Collections.singletonMap(FIELD_NAME, klvHandler), defaultKlvHandler, otherKlvIntegerEncodedFloatingPoint, dataElements);
verify(defaultKlvHandler, atLeastOnce()).accept(otherKlvIntegerEncodedFloatingPoint);
}
Aggregations