tuwien.auto.calimero.knxnetip.util
Class HPAI

java.lang.Object
  extended by tuwien.auto.calimero.knxnetip.util.HPAI

public class HPAI
extends java.lang.Object

KNXnet/IP Host Protocol Address Information (HPAI).

The address information is used to describe a communication channel. Its structure varies according to the used underlying protocol. This class is implemented for IPv4.
For IP networks with NAT, consider use of HPAI(short, InetSocketAddress).
UDP is the default communication mode with mandatory support used in KNXnet/IP.

Objects of this type are immutable.


Field Summary
static short IPV4_TCP
          Internet protocol version 4 address, TCP communication.
static short IPV4_UDP
          Internet protocol version 4 address, UDP communication.
 
Constructor Summary
HPAI(byte[] data, int offset)
          Creates a HPAI out of a byte array.
HPAI(java.net.InetAddress addr, int port)
          Creates a HPAI for UDP communication with the given address information.
HPAI(short hostProtocol, java.net.InetAddress addr, int port)
          Creates a HPAI with the given address information.
HPAI(short hostProtocol, java.net.InetSocketAddress addr)
          Creates a HPAI with the given address information.
 
Method Summary
 java.net.InetAddress getAddress()
          Returns the IP network address as InetAddress representation.
 short getHostProtocol()
          Returns the host protocol of this HPAI.
 int getPort()
          Returns the port number of this HPAI.
 byte[] getRawAddress()
          Returns the raw IP network address.
 short getStructLength()
          Returns the structure length of this HPAI in bytes.
 byte[] toByteArray()
          Returns the byte representation of the whole HPAI structure.
 java.lang.String toString()
          Returns this HPAI representation in textual format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IPV4_TCP

public static final short IPV4_TCP
Internet protocol version 4 address, TCP communication.

See Also:
Constant Field Values

IPV4_UDP

public static final short IPV4_UDP
Internet protocol version 4 address, UDP communication.

See Also:
Constant Field Values
Constructor Detail

HPAI

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

Parameters:
data - byte array containing the HPAI structure
offset - start offset of HPAI in data
Throws:
KNXFormatException - if no HPAI found, invalid structure or unknown host protocol

HPAI

public HPAI(java.net.InetAddress addr,
            int port)
Creates a HPAI for UDP communication with the given address information.

The constructor uses the fact, that UDP is the default communication mode used in KNXnet/IP.
The following first matching rule is used for the addr argument:
1) addr holds an InetAddress, use that address
2) addr is null, the local host is retrieved by InetAddress.getLocalHost()
3) if no local host could be found, fall back to safe state and initialize IP and port to 0 (NAT aware mode)

Parameters:
addr - local IP address, use null for setting local host
port - local port number to set, 0 <= port <= 0xFFFF

HPAI

public HPAI(short hostProtocol,
            java.net.InetAddress addr,
            int port)
Creates a HPAI with the given address information.

Parameters:
hostProtocol - host protocol code (UDP or TCP on IP)
addr - local IP address
port - local port number to set, 0 <= port <= 0xFFFF

HPAI

public HPAI(short hostProtocol,
            java.net.InetSocketAddress addr)
Creates a HPAI with the given address information.

To indicate the use of network address translation (NAT) to the receiver, leave addr null.

Parameters:
hostProtocol - host protocol code (UDP or TCP on IP)
addr - socket with IP address and port number, if addr = null address and port are initialized to 0
Method Detail

getAddress

public final java.net.InetAddress getAddress()
Returns the IP network address as InetAddress representation.

Returns:
IP address as InetAddress object

getHostProtocol

public final short getHostProtocol()
Returns the host protocol of this HPAI.

Returns:
host protocol code as unsigned byte

getPort

public final int getPort()
Returns the port number of this HPAI.

Returns:
port as unsigned short

getRawAddress

public final byte[] getRawAddress()
Returns the raw IP network address.

Returns:
byte array with IP address in network byte order

getStructLength

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

Returns:
structure length as unsigned byte

toByteArray

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

Returns:
byte array containing structure

toString

public java.lang.String toString()
Returns this HPAI representation in textual format.

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