Search in sources :

Example 6 with KlvIntegerEncodedFloatingPoint

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)));
}
Also used : KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) KlvUnsignedByte(org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte) Test(org.junit.Test)

Example 7 with KlvIntegerEncodedFloatingPoint

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);
}
Also used : KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt)

Example 8 with KlvIntegerEncodedFloatingPoint

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)));
}
Also used : KlvUnsignedShort(org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort) KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) Test(org.junit.Test)

Aggregations

KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)8 Test (org.junit.Test)6 KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)3 KlvContext (org.codice.ddf.libs.klv.KlvContext)1 KlvLong (org.codice.ddf.libs.klv.data.numerical.KlvLong)1 KlvShort (org.codice.ddf.libs.klv.data.numerical.KlvShort)1 KlvUnsignedByte (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1