tuwien.auto.calimero.knxnetip.util
Class CRD

java.lang.Object
  extended by tuwien.auto.calimero.knxnetip.util.CRD
Direct Known Subclasses:
TunnelCRD

public class CRD
extends java.lang.Object

Immutable container for connection response data (CRD).

The CRD structure is returned by a connection response, and contains information regarding the established communication.
It contains description data of a specific connection type. A CRD is built up of host protocol independent data and host protocol dependent data, both optional. Refer to the available subtypes for more specific type information.

For now, a plain CRD is returned for management connections, since this connection type doesn't require any additional host protocol data.

Factory methods are provided for creation of CRD objects.

See Also:
ConnectResponse

Constructor Summary
CRD(byte[] data, int offset)
          Creates a new CRD out of a byte array.
CRD(short connectionType, byte[] optionalData)
          Creates a new CRD for the given connection type.
 
Method Summary
static CRD createResponse(byte[] data, int offset)
          Creates a new CRD out of a byte array.
static CRD createResponse(short connectionType, byte[] optionalData)
          Creates a CRD for the given connection type.
 short getConnectionType()
          Returns the used connection type code.
 byte[] getOptionalData()
          Returns a copy of the optional data field.
 short getStructLength()
          Returns the structure length of this CR in bytes.
 byte[] toByteArray()
          Returns the byte representation of the whole CR structure.
 java.lang.String toString()
          Returns a textual representation of the connection type, length and optional data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CRD

public CRD(byte[] data,
           int offset)
    throws KNXFormatException
Creates a new CRD out of a byte array.

Parameters:
data - byte array containing a CRD structure
offset - start offset of CRD in data
Throws:
KNXFormatException - if no CRD found or invalid structure

CRD

public CRD(short connectionType,
           byte[] optionalData)
Creates a new CRD for the given connection type.

The array of optionalData is not copied for internal storage. No additional checks regarding content are done.

Parameters:
connectionType - connection type the description is intended for
optionalData - byte array containing optional host protocol independent and dependent data, this information is located starting at offset 2 in the CRD structure, optionalData.length < 254
Method Detail

createResponse

public static CRD createResponse(byte[] data,
                                 int offset)
                          throws KNXFormatException
Creates a new CRD out of a byte array.

If possible, a matching, more specific, CRD subtype is returned. Note, that CRD for specific communication types might expect certain characteristics on data (regarding contained data).

Parameters:
data - byte array containing the CRD structure
offset - start offset of CRD in data
Returns:
the new CRD object
Throws:
KNXFormatException - if no CRD found or invalid structure

createResponse

public static CRD createResponse(short connectionType,
                                 byte[] optionalData)
Creates a CRD for the given connection type.

If possible, a matching, more specific, CRD subtype is returned. Note, that CRD for specific communication types might expect certain characteristics on optionalData (regarding length and/or content).

Parameters:
connectionType - connection type this CRD is used for (e.g. tunnel connection)
optionalData - byte array containing optional host protocol independent and dependent data, this information is located starting at offset 2 in the CRD structure, optionalData.length < 254, may be null for no optional data
Returns:
the new CRD object

getConnectionType

public final short getConnectionType()
Returns the used connection type code.

Returns:
connection type as unsigned byte

getOptionalData

public final byte[] getOptionalData()
Returns a copy of the optional data field.

Optional data starts at offset 2 in the CR structure.

Returns:
byte array with optional data

getStructLength

public final short getStructLength()
Returns the structure length of this CR in bytes.

Returns:
structure length as unsigned byte

toByteArray

public byte[] toByteArray()
Returns the byte representation of the whole CR structure.

Returns:
byte array containing structure

toString

public java.lang.String toString()
Returns a textual representation of the connection type, length and optional data.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object