tuwien.auto.eicl

Class CEMI_Connection

Implemented Interfaces:
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.

See Also:
Discoverer, tuwien.auto.eicl.Heartbeat, EICLEventListener, FrameEvent, DisconnectEvent, TunnellingConnectionType, CEMIConnectionTypeInfoContainer

Field Summary

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.

Constructor Summary

CEMI_Connection(DatagramSocket _DatagramSocket, InetSocketAddress _Server, CEMIConnectionTypeInfoContainer _Connection)
Sends out a connect request message and waits for response.
CEMI_Connection(InetSocketAddress _Server, CEMIConnectionTypeInfoContainer _Connection)
Sends out a connect request message and waits for response.

Method Summary

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.

Field Details

AWAITING_ACK

public static final byte AWAITING_ACK
Status byte: No Ack was received so far.
Field Value:
1

AWAITING_CEMI_CON

public static final byte AWAITING_CEMI_CON
Status byte: Ack was received, but cEMI confirmation is missing
Field Value:
2

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.
Field Value:
false

OK

public static final byte OK
Satus byte: Message was delivered successfully.
Field Value:
0

WAIT_FOR_CONFIRM

public static final boolean WAIT_FOR_CONFIRM
In this send mode the sendFrame() method blocks until the Ack has been received.
Field Value:
true

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
Field Value:
-1

Constructor Details

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.
Parameters:
_DatagramSocket - An open socket
_Server - The server to which connect
_Connection - The Object which includes all relevant connection options
Throws:
EICLException - Forwards the SocketException

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.
Parameters:
_Server - The server to which connect
_Connection - The Object which includes all relevant connection options
Throws:
EICLException -

Method Details

addFrameListener

public void addFrameListener(EICLEventListener eventListener)
Adds a frame listener that is called on each incoming cEMI packets
Parameters:
eventListener -

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.
Parameters:
_Message - the message which is communicated to the event handlers
Throws:
EICLException - If the wasn't sent successfully

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.
Returns:
the state (see constants)

removeFrameListener

public void removeFrameListener(EICLEventListener eventListener)
Removes the frame listener
Parameters:
eventListener -

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).
Parameters:
_CEMI - the cEMI frame to send
_Mode - send mode
Throws:
EICLException - if something goes wrong