tuwien.auto.eicl
Class CEMI_Connection
java.lang.Object
tuwien.auto.eicl.CEMI_Connection
- Runnable
public class CEMI_Connection
extends java.lang.Object
implements Runnable
This class represents an EIBnet/IP connection which is used to exchange cEMI
messages. This class is able to handle Tunnelling as well as Management
connections. The CEMIConnectionTypeInfoContainer classes passed to the
constructor are needed for selecting the desired connection type. Like
Discoverer, it runs as an independent thread. Again, this is hidden from the
user. Connection Heartbeating is also managed autonomously.
Two different send modes are provided.The first, "immediate send", sends out
the requested message and returns immediately after sending. It is up to the
programmer to check upon the progress of the transmission using the
getState() method. The second send mode, "wait for confirm", waits until both
the ACK and the cEMI CON message have been received successfully (with
acknowledge bit set). If this was not achieved within an interval of 5
seconds an exception is thrown.
The programmer has the possibility to register event handlers that are called
for each cEMI packet that reaches the socket and when the server closes the
connection.
Finally the disconnect method closes the connection, and stops the heartbeat
messaging. All registered event handlers are invoked with the disconnect
event.
static byte | AWAITING_ACK - Status byte: No Ack was received so far.
|
static byte | AWAITING_CEMI_CON - Status byte: Ack was received, but cEMI confirmation is missing
|
static boolean | IMMEDIATE_SEND - In this send mode the CEMI_Connection#sendFrame() method immediate
returns after processing the frame.
|
static byte | OK - Satus byte: Message was delivered successfully.
|
static boolean | WAIT_FOR_CONFIRM - In this send mode the sendFrame() method blocks until the Ack has been
received.
|
static byte | WRONG_MODE - Status byte: The connection is in wron mode.
|
void | addFrameListener(EICLEventListener eventListener) - Adds a frame listener that is called on each incoming cEMI packets
|
void | disconnect(String _Message) - Closes the connection and stops the heart beat thread.
|
byte | getState() - Returns the current state of delivery of the sent packet, if the tunnel
is in immediate send mode, otherwise constantly returns WRONG_MODE.
|
void | removeFrameListener(EICLEventListener eventListener) - Removes the frame listener
|
void | run() - The thread run method, waits for incoming messages.
|
void | sendFrame(CEMI _CEMI, boolean _Mode) - Sends out the requested cEMI packet.
|
AWAITING_ACK
public static final byte AWAITING_ACK
Status byte: No Ack was received so far.
AWAITING_CEMI_CON
public static final byte AWAITING_CEMI_CON
Status byte: Ack was received, but cEMI confirmation is missing
IMMEDIATE_SEND
public static final boolean IMMEDIATE_SEND
In this send mode the CEMI_Connection#sendFrame() method immediate
returns after processing the frame. Use the CEMI_Connection#getStatus()
method for following the packet state.
OK
public static final byte OK
Satus byte: Message was delivered successfully.
WAIT_FOR_CONFIRM
public static final boolean WAIT_FOR_CONFIRM
In this send mode the sendFrame() method blocks until the Ack has been
received.
WRONG_MODE
public static final byte WRONG_MODE
Status byte: The connection is in wron mode. No information can be given
about the packet state
CEMI_Connection
public CEMI_Connection(DatagramSocket _DatagramSocket,
InetSocketAddress _Server,
CEMIConnectionTypeInfoContainer _Connection)
throws EICLException
Sends out a connect request message and waits for response. If the
connection has been established successfully the constructor starts the
receiving threads and heart beating. Otherwise a exception is thrown.
_DatagramSocket
- An open socket_Server
- The server to which connect_Connection
- The Object which includes all relevant connection options
CEMI_Connection
public CEMI_Connection(InetSocketAddress _Server,
CEMIConnectionTypeInfoContainer _Connection)
throws EICLException
Sends out a connect request message and waits for response. If the
connection has been established successfully the constructor starts the
receiving threads and heart beating. Otherwise a exception is thrown.
_Server
- The server to which connect_Connection
- The Object which includes all relevant connection options
addFrameListener
public void addFrameListener(EICLEventListener eventListener)
Adds a frame listener that is called on each incoming cEMI packets
disconnect
public void disconnect(String _Message)
throws EICLException
Closes the connection and stops the heart beat thread. Then invokes all
registered event handlers with the given message.
_Message
- the message which is communicated to the event handlers
getState
public byte getState()
Returns the current state of delivery of the sent packet, if the tunnel
is in immediate send mode, otherwise constantly returns WRONG_MODE.
- the state (see constants)
removeFrameListener
public void removeFrameListener(EICLEventListener eventListener)
Removes the frame listener
run
public void run()
The thread run method, waits for incoming messages. Called on startup.
Don't use this.
sendFrame
public void sendFrame(CEMI _CEMI,
boolean _Mode)
throws EICLException
Sends out the requested cEMI packet. Depending on the send mode it
returns immediately or after successful sending. (Tunnelling Ack received
and cEMI CON received).
_CEMI
- the cEMI frame to send_Mode
- send mode