MeasurementProtocol extends DistoXProtocol { public static Leg parseDataPacket(byte[] packet) { int d0 = packet[ADMIN] & DISTANCE_BIT_MASK; int d1 = readByte(packet, DISTANCE_LOW_BYTE); int d2 = readByte(packet, DISTANCE_HIGH_BYTE); double distance = (d0 * 1024 + d2 * 256 + d1) / 1000.0; double azimuth_reading = readDoubleByte(packet, AZIMUTH_LOW_BYTE, AZIMUTH_HIGH_BYTE); double azimuth = azimuth_reading * 180.0 / 32768.0; double inclinationReading = readDoubleByte(packet, INCLINATION_LOW_BYTE, INCLINATION_HIGH_BYTE); double inclination = inclinationReading * 90.0 / 16384.0; if (inclinationReading >= 32768) { inclination = (65536 - inclinationReading) * -90.0 / 16384.0; } return new Leg(distance, azimuth, inclination); } MeasurementProtocol(
            SexyTopoActivity activity, BluetoothDevice bluetoothDevice, SurveyManager dataManager); static Leg parseDataPacket(byte[] packet); void go(DataInputStream inStream, DataOutputStream outStream); static final int DISTANCE_BIT_MASK; }
@Test public void testFlatMeasurementGetsParsedCorrectly() { byte[] packet = new byte[]{1, -31, 7, -94, 50, 58, 3, -5}; Assert.assertTrue(MeasurementProtocol.isDataPacket(packet)); Leg actual = MeasurementProtocol.parseDataPacket(packet); Leg expected = new Leg(2.017, 71.2, 4.5); assertLegEquality(expected, actual); }
@Test public void testDownMeasurementGetsParsedCorrectly() { byte[] packet = new byte[]{1, 84, 3, 113, -87, -83, -54, -13}; Assert.assertTrue(MeasurementProtocol.isDataPacket(packet)); Leg actual = MeasurementProtocol.parseDataPacket(packet); Leg expected = new Leg(0.852, 238.3, -75.0); assertLegEquality(expected, actual); }