Search in sources :

Example 1 with KlvShort

use of org.codice.ddf.libs.klv.data.numerical.KlvShort in project ddf by codice.

the class KlvDecoderTest method testShortValue.

@Test
public void testShortValue() throws KlvDecodingException {
    final byte[] klvBytes = { -8, 2, (byte) 0xB6, 0x1f };
    final KlvShort klvShort = new KlvShort(new byte[] { -8 }, "test");
    final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvShort, klvBytes);
    final short value = ((KlvShort) decodedKlvContext.getDataElementByName("test")).getValue();
    assertThat(value, is((short) -18913));
}
Also used : KlvShort(org.codice.ddf.libs.klv.data.numerical.KlvShort) Test(org.junit.Test)

Example 2 with KlvShort

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

Example 3 with KlvShort

use of org.codice.ddf.libs.klv.data.numerical.KlvShort in project ddf by codice.

the class KlvDecoderTest method isErrorIndicatedShort.

private boolean isErrorIndicatedShort(short value, Optional<Short> errorValue) throws KlvDecodingException {
    KlvShort klvShort = new KlvShort(new byte[] { 0 }, "test", errorValue);
    byte[] dataBytes = new byte[4];
    dataBytes[0] = 0;
    dataBytes[1] = 2;
    arraycopy(shortToBytes(value), 0, dataBytes, 2, 2);
    return isErrorIndicatedDecode(klvShort, dataBytes);
}
Also used : KlvShort(org.codice.ddf.libs.klv.data.numerical.KlvShort)

Example 4 with KlvShort

use of org.codice.ddf.libs.klv.data.numerical.KlvShort in project ddf by codice.

the class KlvDecoderTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    // The test KLV is a UAS Datalink Local Set (MISB ST 0601).
    EXPECTED_VALUES.put(TIMESTAMP, 1245257585099653L);
    EXPECTED_VALUES.put(UAS_LS_VERSION_NUMBER, (byte) 1);
    EXPECTED_VALUES.put(PLATFORM_HEADING_ANGLE, 15675);
    EXPECTED_VALUES.put(PLATFORM_PITCH_ANGLE, (short) 5504);
    EXPECTED_VALUES.put(PLATFORM_ROLL_ANGLE, (short) 338);
    EXPECTED_VALUES.put(IMAGE_SOURCE_SENSOR, "EON");
    EXPECTED_VALUES.put(IMAGE_COORDINATE_SYSTEM, "Geodetic WGS84");
    EXPECTED_VALUES.put(SENSOR_LATITUDE, 1304747195);
    EXPECTED_VALUES.put(SENSOR_LONGITUDE, -1314362114);
    EXPECTED_VALUES.put(SENSOR_TRUE_ALTITUDE, 8010);
    EXPECTED_VALUES.put(SENSOR_HORIZONTAL_FOV, 133);
    EXPECTED_VALUES.put(SENSOR_VERTICAL_FOV, 75);
    EXPECTED_VALUES.put(SENSOR_RELATIVE_AZIMUTH_ANGLE, 550031997L);
    EXPECTED_VALUES.put(SENSOR_RELATIVE_ELEVATION_ANGLE, -52624680);
    EXPECTED_VALUES.put(SENSOR_RELATIVE_ROLL_ANGLE, 4273523553L);
    EXPECTED_VALUES.put(SLANT_RANGE, 9387617L);
    EXPECTED_VALUES.put(TARGET_WIDTH, 457);
    EXPECTED_VALUES.put(FRAME_CENTER_LATITUDE, 1306364970);
    EXPECTED_VALUES.put(FRAME_CENTER_LONGITUDE, -1312907532);
    EXPECTED_VALUES.put(FRAME_CENTER_ELEVATION, 2949);
    EXPECTED_VALUES.put(TARGET_LOCATION_LATITUDE, 1306364970);
    EXPECTED_VALUES.put(TARGET_LOCATION_LONGITUDE, -1312907532);
    EXPECTED_VALUES.put(TARGET_LOCATION_ELEVATION, 2949);
    EXPECTED_VALUES.put(PLATFORM_GROUND_SPEED, (short) 46);
    EXPECTED_VALUES.put(GROUND_RANGE, 9294889L);
    EXPECTED_VALUES.put(CHECKSUM, 7263);
    DATA_ELEMENTS.add(new KlvLong(new byte[] { 0x02 }, TIMESTAMP));
    DATA_ELEMENTS.add(new KlvByte(new byte[] { 0x41 }, UAS_LS_VERSION_NUMBER));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x05 }, PLATFORM_HEADING_ANGLE));
    DATA_ELEMENTS.add(new KlvShort(new byte[] { 0x06 }, PLATFORM_PITCH_ANGLE));
    DATA_ELEMENTS.add(new KlvShort(new byte[] { 0x07 }, PLATFORM_ROLL_ANGLE));
    DATA_ELEMENTS.add(new KlvString(new byte[] { 0x0b }, IMAGE_SOURCE_SENSOR));
    DATA_ELEMENTS.add(new KlvString(new byte[] { 0x0c }, IMAGE_COORDINATE_SYSTEM));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x0d }, SENSOR_LATITUDE));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x0e }, SENSOR_LONGITUDE));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x0f }, SENSOR_TRUE_ALTITUDE));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x10 }, SENSOR_HORIZONTAL_FOV));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x11 }, SENSOR_VERTICAL_FOV));
    DATA_ELEMENTS.add(new KlvLong(new byte[] { 0x12 }, SENSOR_RELATIVE_AZIMUTH_ANGLE));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x13 }, SENSOR_RELATIVE_ELEVATION_ANGLE));
    DATA_ELEMENTS.add(new KlvLong(new byte[] { 0x14 }, SENSOR_RELATIVE_ROLL_ANGLE));
    DATA_ELEMENTS.add(new KlvLong(new byte[] { 0x15 }, SLANT_RANGE));
    // Target width isn't actually a 32-bit int in the UAS Datalink Local Set; it's an unsigned
    // 16-bit int. However, this KLV encodes the target width using 4 bytes (for some reason).
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x16 }, TARGET_WIDTH));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x17 }, FRAME_CENTER_LATITUDE));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x18 }, FRAME_CENTER_LONGITUDE));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x19 }, FRAME_CENTER_ELEVATION));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x28 }, TARGET_LOCATION_LATITUDE));
    DATA_ELEMENTS.add(new KlvInt(new byte[] { 0x29 }, TARGET_LOCATION_LONGITUDE));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x2a }, TARGET_LOCATION_ELEVATION));
    DATA_ELEMENTS.add(new KlvUnsignedByte(new byte[] { 0x38 }, PLATFORM_GROUND_SPEED));
    DATA_ELEMENTS.add(new KlvLong(new byte[] { 0x39 }, GROUND_RANGE));
    DATA_ELEMENTS.add(new KlvUnsignedShort(new byte[] { 0x01 }, CHECKSUM));
}
Also used : KlvLong(org.codice.ddf.libs.klv.data.numerical.KlvLong) KlvByte(org.codice.ddf.libs.klv.data.numerical.KlvByte) KlvShort(org.codice.ddf.libs.klv.data.numerical.KlvShort) KlvUnsignedShort(org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort) KlvString(org.codice.ddf.libs.klv.data.text.KlvString) KlvUnsignedByte(org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) BeforeClass(org.junit.BeforeClass)

Aggregations

KlvShort (org.codice.ddf.libs.klv.data.numerical.KlvShort)4 Test (org.junit.Test)2 KlvByte (org.codice.ddf.libs.klv.data.numerical.KlvByte)1 KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)1 KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)1 KlvLong (org.codice.ddf.libs.klv.data.numerical.KlvLong)1 KlvUnsignedByte (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1 KlvString (org.codice.ddf.libs.klv.data.text.KlvString)1 BeforeClass (org.junit.BeforeClass)1