KnxEncoder { public static byte[] encode(boolean repeatBit, byte[] sourceByte, String targetAddress, byte[] dataByte, KnxCommand commandType, boolean multicast) { KnxTelegram telegram = new KnxTelegram(); telegram.createDefaultControlByte(); if (repeatBit) telegram.setRepeatBit(); telegram.setSourceByte(sourceByte); if (targetAddress.contains("/")) { telegram.setDestByte(KnxEncoder.convertToByteArray(KnxEncoder.convertGroupAddressToHex(targetAddress))); } else if (targetAddress.contains(".")) { telegram.setDestByte(KnxEncoder.convertToByteArray(KnxEncoder.convertDeviceAddressToHex(targetAddress))); } telegram.setDataBytes(dataByte); headerDataLength = Integer.toHexString(dataByte.length); telegram.setKnxCommandType(commandType); byte B_header[]; if (multicast) B_header = KnxEncoder.convertToByteArray(udpMcHeaderFront + headerDataLength + udpMcHeaderRear); else B_header = KnxEncoder.convertToByteArray(udpHeader); byte B_telegram[] = telegram.getByteArray(); byte message[] = new byte[B_header.length + B_telegram.length]; System.arraycopy(B_header, 0, message, 0, B_header.length); System.arraycopy(B_telegram, 0, message, B_header.length, B_telegram.length); return message; }  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 encodeTest() { String hexString = "0610053000112900bcd000000901010081"; assertTrue( "KnxEncoder.encode(false, '1/1/1', true, KnxCommand.VALUE_WRITE) returns " + KnxEncoder.convertToReadableHex(KnxEncoder.encode(false, new byte[] { 0, 0 }, "1/1/1", new byte[] { 0x1 }, KnxCommand.VALUE_WRITE, true)) + "; but should return " + hexString, Arrays.equals(KnxEncoder.encode(false, new byte[] { 0, 0 }, "1/1/1", new byte[] { 0x1 }, KnxCommand.VALUE_WRITE, true), KnxEncoder.convertToByteArray(hexString))); }