tuwien.auto.calimero
Class DataUnitBuilder

java.lang.Object
  extended by tuwien.auto.calimero.DataUnitBuilder

public final class DataUnitBuilder
extends java.lang.Object

Creates, extracts and decodes information of protocol data units.

The methods focus on transport layer and application layer data units.


Field Summary
static java.lang.String LOG_SERVICE
          Name of the log service used by data-unit builder methods.
 
Method Summary
static byte[] createAPDU(int service, byte[] asdu)
          Creates an application layer protocol data unit out of a service code and a service data unit.
static byte[] createCompactAPDU(int service, byte[] asdu)
          Creates a compact application layer protocol data unit out of a service code and a service data unit.
static java.lang.String decode(byte[] tpdu, KNXAddress dst)
          Decodes a protocol data unit into a textual representation.
static java.lang.String decodeAPCI(int apci)
          Decodes an application layer protocol control information into a textual representation.
static java.lang.String decodeTPCI(int tpci, KNXAddress dst)
          Decodes a transport layer protocol control information into a textual representation.
static byte[] extractASDU(byte[] apdu)
          Returns a copy of the ASDU contained in the supplied APDU.
static int getAPDUService(byte[] apdu)
          Returns the application layer service of a given protocol data unit.
static int getTPDUService(byte[] tpdu)
          Returns the transport layer service of a given protocol data unit.
static java.lang.String toHex(byte[] data, java.lang.String sep)
          Returns the content of data as unsigned bytes in hexadecimal string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_SERVICE

public static final java.lang.String LOG_SERVICE
Name of the log service used by data-unit builder methods.

See Also:
Constant Field Values
Method Detail

createAPDU

public static byte[] createAPDU(int service,
                                byte[] asdu)
Creates an application layer protocol data unit out of a service code and a service data unit.

The transport layer bits in the first byte (TL / AL control field) are set 0. For creating a compact APDU, refer to createCompactAPDU(int, byte[]).

Parameters:
service - application layer service code
asdu - application layer service data unit, asdu.length < 255
Returns:
APDU as byte array

createCompactAPDU

public static byte[] createCompactAPDU(int service,
                                       byte[] asdu)
Creates a compact application layer protocol data unit out of a service code and a service data unit.

The transport layer bits in the first byte (TL / AL control field) are set 0. If the compact APDU shall not contain any ASDU information, asdu can be left null.

Parameters:
service - application layer service code
asdu - application layer service data unit, asdu.length < 255; or null for no ASDU
Returns:
APDU as byte array

decode

public static java.lang.String decode(byte[] tpdu,
                                      KNXAddress dst)
Decodes a protocol data unit into a textual representation.

Currently, the transport layer protocol control information (TPCI) and the application layer protocol control information (APCI) is decoded. Decoding might be extended in the future.
The optional KNX destination address helps to determine the exact transport layer service.

Parameters:
tpdu - transport layer protocol data unit to decode
dst - KNX destination address belonging to the TPDU, might be null
Returns:
textual representation of control information in the TPDU

decodeAPCI

public static java.lang.String decodeAPCI(int apci)
Decodes an application layer protocol control information into a textual representation.

Parameters:
apci - application layer protocol control information
Returns:
textual representation of APCI

decodeTPCI

public static java.lang.String decodeTPCI(int tpci,
                                          KNXAddress dst)
Decodes a transport layer protocol control information into a textual representation.

Parameters:
tpci - transport layer protocol control information
dst - KNX destination address belonging to the tpci, might be null
Returns:
textual representation of TPCI

extractASDU

public static byte[] extractASDU(byte[] apdu)
Returns a copy of the ASDU contained in the supplied APDU.

The application layer service data unit (ASDU) is the APDU with the application layer service code removed.

Parameters:
apdu - application layer protocol data unit for which to get the ASDU
Returns:
the ASDU as byte array

getAPDUService

public static int getAPDUService(byte[] apdu)
Returns the application layer service of a given protocol data unit.

Parameters:
apdu - application layer protocol data unit
Returns:
APDU service code

getTPDUService

public static int getTPDUService(byte[] tpdu)
Returns the transport layer service of a given protocol data unit.

Parameters:
tpdu - transport layer protocol data unit
Returns:
TPDU service code

toHex

public static java.lang.String toHex(byte[] data,
                                     java.lang.String sep)
Returns the content of data as unsigned bytes in hexadecimal string representation.

This method does not add hexadecimal prefixes (like 0x).

Parameters:
data - data array to format
sep - separator to insert between 2 formatted data bytes, null or "" for no gap between byte tokens
Returns:
an unsigned hexadecimal string of data