use of org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort in project ddf by codice.
the class KlvDecoderTest method testUnsignedShortValue.
@Test
public void testUnsignedShortValue() throws KlvDecodingException {
final byte[] klvBytes = { -8, 2, (byte) 0xB6, 0x1f };
final KlvUnsignedShort klvUnsignedShort = new KlvUnsignedShort(new byte[] { -8 }, "test");
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvUnsignedShort, klvBytes);
final int value = ((KlvUnsignedShort) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(46623));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort in project alliance by codice.
the class AbstractMetadataPacket method validateChecksum.
private boolean validateChecksum(final KlvContext klvContext, final byte[] klvBytes) throws KlvDecodingException {
if (!klvContext.hasDataElement(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET)) {
throw new KlvDecodingException("KLV did not contain the UAS Datalink Local Set");
}
final KlvContext localSetContext = ((KlvLocalSet) klvContext.getDataElementByName(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET)).getValue();
if (localSetContext.hasDataElement(Stanag4609TransportStreamParser.CHECKSUM)) {
final int packetChecksum = ((KlvUnsignedShort) localSetContext.getDataElementByName(Stanag4609TransportStreamParser.CHECKSUM)).getValue();
short calculatedChecksum = 0;
// checksum length (the checksum value is 2 bytes, which is why we subtract 2).
for (int i = 0; i < klvBytes.length - 2; ++i) {
calculatedChecksum += (klvBytes[i] & 0xFF) << (8 * ((i + 1) % 2));
}
return (calculatedChecksum & 0xFFFF) == packetChecksum;
}
throw new KlvDecodingException("Decoded KLV packet didn't contain checksum (which is required).");
}
use of org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort 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));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort 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