use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsUnsignedByte.
@Test
public // Example value taken from ST0601.8 Tag 36.
void testFloatingPointEncodedAsUnsignedByte() throws KlvDecodingException {
final byte[] klvBytes = { -8, 1, (byte) 0xB2 };
final KlvUnsignedByte klvUnsignedByte = new KlvUnsignedByte(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint windSpeed = new KlvIntegerEncodedFloatingPoint(klvUnsignedByte, 0, (1 << 8) - 1, 0, 100);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, windSpeed, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(69.80392, 1e-5)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method isErrorIndicatedIntegerIndicatedFloatingPoint.
private boolean isErrorIndicatedIntegerIndicatedFloatingPoint(int value, Optional<Integer> errorValue) throws KlvDecodingException {
KlvIntegerEncodedFloatingPoint klvIntegerEncodedFloatingPoint = new KlvIntegerEncodedFloatingPoint(new KlvInt(new byte[] { 0 }, "test", errorValue), Integer.MIN_VALUE + 1, Integer.MAX_VALUE, -90, 90);
byte[] dataBytes = new byte[6];
dataBytes[0] = 0;
dataBytes[1] = 4;
arraycopy(intToBytes(value), 0, dataBytes, 2, 4);
return isErrorIndicatedDecode(klvIntegerEncodedFloatingPoint, dataBytes);
}
use of org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsUnsignedShort.
@Test
public // Example value taken from ST0601.8 Tag 5.
void testFloatingPointEncodedAsUnsignedShort() throws KlvDecodingException {
final byte[] klvBytes = { -8, 2, 0x71, (byte) 0xC2 };
final KlvUnsignedShort klvUnsignedShort = new KlvUnsignedShort(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint platformHeadingAngle = new KlvIntegerEncodedFloatingPoint(klvUnsignedShort, 0, (1 << 16) - 1, 0, 360);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, platformHeadingAngle, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(159.9744, 1e-4)));
}
Aggregations