KnxEncoder { public static KnxTelegram decode(byte knxMessage[]) { if (knxMessage.length < 9) return null; KnxTelegram telegram = new KnxTelegram(knxMessage); if (!telegram.telegramDatalengthIsCorrect) return null; return telegram; }  static byte[] encode(boolean repeatBit, byte[] sourceByte, String targetAddress, byte[] dataByte,
			KnxCommand commandType, boolean multicast); static KnxTelegram decode(byte knxMessage[]); static byte[] removeTrailingZeros(byte[] original); static String convertDeviceAddressToHex(String address); static String convertGroupAddressToHex(String address); static byte[] convertToByteArray(String hexString); static String convertToReadableHex(byte[] b); static String convertToHex(byte[] b); static String convertGroupAddressToReadable(byte buffer[]); static String clearHexValue(String hexValue);  }
@Test public void priorityTest() { byte[] message = new byte[] { (byte) 0xbc, 0x0d, 0, 0, 9, 1, 3, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }; assertTrue( "KnxEncoder.decode(new byte[] {(byte) 0xbc, 0x0d, 0, 0, 9, 1, 1, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }).getPriority() is " + KnxEncoder.decode(message).getPriority() + "; but should be AUTO(3)", KnxEncoder.decode(message).getPriority() == KnxPacketPriority.AUTO); }
@Test public void knxCommandTest() { byte[] message = new byte[] { (byte) 0xbc, 0x0d, 0, 0, 9, 1, 1, 0, (byte) 0x81 }; assertTrue( "KnxEncoder.decode(new byte[] {(byte) 0xbc, 0x0d, 0, 0, 9, 1, 1, 0, (byte) 0x81}).knxCommand is " + KnxEncoder.decode(message).knxCommand + "; but should be AUTO(3)", KnxEncoder.decode(message).knxCommand == KnxCommand.VALUE_WRITE); }
@Test public void dataLengthTest() { byte[] message = new byte[] { (byte) 0xbc, 0x0d, 0, 0, 9, 1, 3, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }; assertTrue( "KnxEncoder.decode(new byte[] {(byte) 0xbc, 0x0d, 0, 0, 9, 1, 3, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }).telegramDatalengthIsCorrect is " + KnxEncoder.decode(message).telegramDatalengthIsCorrect + "; but should be true", KnxEncoder.decode(message).telegramDatalengthIsCorrect == true); byte[] message2 = new byte[] { (byte) 0xbc, 0x0d, 0, 0, 9, 1, 4, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }; assertTrue( "KnxEncoder.decode(new byte[] {(byte) 0xbc, 0x0d, 0, 0, 9, 1, 4, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13 }) is " + KnxEncoder.decode(message2) + "; but should be NULL", KnxEncoder.decode(message2) == null); byte[] message3 = new byte[] { (byte) 0xbc, 0x0d, 0, 0, 9, 1, 3, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13, (byte) 0xAE }; assertTrue( "KnxEncoder.decode(new byte[] {(byte) 0xbc, 0x0d, 0, 0, 9, 1, 3, 0, (byte) 0x80, (byte) 0x12, (byte) 0x13, (byte) 0xAE }) is " + KnxEncoder.decode(message3) + "; but should be NULL", KnxEncoder.decode(message3) == null); }