tuwien.auto.calimero.knxnetip.util
Class CRI

java.lang.Object
  extended by tuwien.auto.calimero.knxnetip.util.CRI
Direct Known Subclasses:
TunnelCRI

public class CRI
extends java.lang.Object

Immutable container for a connection request information (CRI).

The CRI structure is used for the additional information in a connection request.
It 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 CRI is returned for management connections, since this connection type doesn't require any additional host protocol data.

Factory methods are provided for creation of CRI objects.

See Also:
ConnectRequest

Constructor Summary
protected CRI(byte[] data, int offset)
          Creates a new CRI out of a byte array.
protected CRI(short connectionType, byte[] optionalData)
          Creates a new CRI for the given connection type.
 
Method Summary
static CRI createRequest(byte[] data, int offset)
          Creates a new CRI out of a byte array.
static CRI createRequest(short connectionType, byte[] optionalData)
          Creates a CRI 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

CRI

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

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

CRI

protected CRI(short connectionType,
              byte[] optionalData)
Creates a new CRI 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 CRI 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 CRI structure, optionalData.length < 254
Method Detail

createRequest

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

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

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

createRequest

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

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

Parameters:
connectionType - connection type this CRI 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 CRI structure, optionalData.length < 254, may be null for no optional data
Returns:
the new CRI 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