jAER project on SourceForge

net.sf.jaer.eventio
Class AEUnicastInput

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.jaer.eventio.AEUnicastInput
All Implemented Interfaces:
java.lang.Runnable, AEUnicastSettings

public class AEUnicastInput
extends java.lang.Thread
implements AEUnicastSettings

Receives input via datagram (connectionless, UDP) packets from a server.

The socket binds to the port which comes initially from the Preferences for AEUnicastInput. The port can be later changed.

Each packet consists of (by default) 1. a packet sequence integer (32 bits) which can be used to count missed packets 2. AEs. Each AE is a pair int32 address, int32 timestamp. Timestamps are assumed to have 1us tick.

Options allow different choices for use of sequence number, size of address/timestamp, order of address/timestamp, and swapping byte order to account for big/little endian peers.

The datagram socket is not connected to the receiver, i.e., connect() is not called on the socket.

See Also:
setAddressFirstEnabled(boolean), setSequenceNumberEnabled(boolean)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int MAX_EVENT_BUFFER_SIZE
          max size of event packet served to consumer by readPacket
static long MIN_INTERVAL_MS
          Maximum time inteval in ms to exchange EventPacketRaw with consumer
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface net.sf.jaer.eventio.AEUnicastSettings
ARC_TDS_4_BYTE_ADDR_AND_TIMESTAMPS, ARC_TDS_ADDRESS_BYTES_FIRST_ENABLED, ARC_TDS_SEQUENCE_NUMBERS_ENABLED, ARC_TDS_STREAM_PORT, ARC_TDS_SWAPBYTES_ENABLED, ARC_TDS_TIMESTAMP_MULTIPLIER, DEFAULT_ADDRESS_FIRST, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_SWAPBYTES_ENABLED, DEFAULT_TIMESTAMP_MULTIPLIER, DEFAULT_USE_4_BYTE_ADDR_AND_TIMESTAMP, DEFAULT_USE_SEQUENCE_NUMBER
 
Constructor Summary
AEUnicastInput()
          Constructs an instance of AEUnicastInput and binds it to the default port.
AEUnicastInput(int port)
           
 
Method Summary
 void close()
          Interrupts the thread which is acquiring data and closes the underlying DatagramSocket.
 java.lang.String getHost()
           
 int getPort()
           
 float getTimestampMultiplier()
           
 boolean is4ByteAddrTimestampEnabled()
           
 boolean isAddressFirstEnabled()
           
 boolean isSequenceNumberEnabled()
           
 boolean isSwapBytesEnabled()
           
 void open()
          Opens the input.
 AEPacketRaw readPacket()
          Returns the latest buffer of events.
 void run()
          This run method loops forever, filling the current filling buffer so that readPacket can return data that may be processed while the other buffer is being filled.
 void set4ByteAddrTimestampEnabled(boolean yes)
          Sets whether to use 4 byte address and 4 byte timestamp or 2 byte address and 2 byte timestamp.
 void setAddressFirstEnabled(boolean addressFirstEnabled)
          If set true, the first int32 of each AE is the address, and the second is the timestamp.
 void setHost(java.lang.String host)
          Deprecated. doesn't do anything here because we only set local port
 void setPort(int port)
          Set the local port for receiving events.
 void setSequenceNumberEnabled(boolean sequenceNumberEnabled)
          If set true (default), then an int32 sequence number is the first word of the packet.
 void setSwapBytesEnabled(boolean yes)
          To handle big endian event sources/sinks (e.g.
 void setTimestampMultiplier(float timestampMultiplier)
          Timestamps from the remote host are multiplied by this value to become jAER timestamps.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_EVENT_BUFFER_SIZE

public static int MAX_EVENT_BUFFER_SIZE
max size of event packet served to consumer by readPacket


MIN_INTERVAL_MS

public static final long MIN_INTERVAL_MS
Maximum time inteval in ms to exchange EventPacketRaw with consumer

See Also:
Constant Field Values
Constructor Detail

AEUnicastInput

public AEUnicastInput()
Constructs an instance of AEUnicastInput and binds it to the default port. The port preference value may have been modified from the Preferences default by a previous setPort() call which stored the preference value.

This Thread subclass must be started in order to receive event packets.


AEUnicastInput

public AEUnicastInput(int port)
Method Detail

run

public void run()
This run method loops forever, filling the current filling buffer so that readPacket can return data that may be processed while the other buffer is being filled.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

readPacket

public AEPacketRaw readPacket()
Returns the latest buffer of events. If a timeout occurs occurs a null packet is returned.

Returns:
the events collected since the last call to readPacket(), or null on a timeout or interrupt.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread

close

public void close()
Interrupts the thread which is acquiring data and closes the underlying DatagramSocket.


getHost

public java.lang.String getHost()
Specified by:
getHost in interface AEUnicastSettings
Returns:
"localhost".

open

public void open()
          throws java.io.IOException
Opens the input. Binds the port and starts the background receiver thread.

Throws:
java.io.IOException

setHost

public void setHost(java.lang.String host)
Deprecated. doesn't do anything here because we only set local port

Description copied from interface: AEUnicastSettings
You need to setHost to send unicast packets to a host. Ignored for receiving events.

Specified by:
setHost in interface AEUnicastSettings
Parameters:
host - the hostname

getPort

public int getPort()
Specified by:
getPort in interface AEUnicastSettings

setPort

public void setPort(int port)
Set the local port for receiving events.

Specified by:
setPort in interface AEUnicastSettings
Parameters:
port -

isSequenceNumberEnabled

public boolean isSequenceNumberEnabled()
Specified by:
isSequenceNumberEnabled in interface AEUnicastSettings

setSequenceNumberEnabled

public void setSequenceNumberEnabled(boolean sequenceNumberEnabled)
If set true (default), then an int32 sequence number is the first word of the packet. Otherwise the first int32 is part of the first AE.

Specified by:
setSequenceNumberEnabled in interface AEUnicastSettings
Parameters:
sequenceNumberEnabled - default true

isAddressFirstEnabled

public boolean isAddressFirstEnabled()
Specified by:
isAddressFirstEnabled in interface AEUnicastSettings
See Also:
setAddressFirstEnabled(boolean)

setAddressFirstEnabled

public void setAddressFirstEnabled(boolean addressFirstEnabled)
If set true, the first int32 of each AE is the address, and the second is the timestamp. If false, the first int32 is the timestamp, and the second is the address. This parameter is stored as a preference.

Specified by:
setAddressFirstEnabled in interface AEUnicastSettings
Parameters:
addressFirstEnabled - default true.

setSwapBytesEnabled

public void setSwapBytesEnabled(boolean yes)
Description copied from interface: AEUnicastSettings
To handle big endian event sources/sinks (e.g. intel code) the address and timestamp bytes can be swapped from big to little endian format

Specified by:
setSwapBytesEnabled in interface AEUnicastSettings

isSwapBytesEnabled

public boolean isSwapBytesEnabled()
Specified by:
isSwapBytesEnabled in interface AEUnicastSettings

getTimestampMultiplier

public float getTimestampMultiplier()
Specified by:
getTimestampMultiplier in interface AEUnicastSettings
See Also:
AEUnicastSettings.setTimestampMultiplier(float)

setTimestampMultiplier

public void setTimestampMultiplier(float timestampMultiplier)
Timestamps from the remote host are multiplied by this value to become jAER timestamps. If the remote host uses 1 ms timestamps, set timestamp multiplier to 1000.

Specified by:
setTimestampMultiplier in interface AEUnicastSettings
Parameters:
timestampMultiplier -

set4ByteAddrTimestampEnabled

public void set4ByteAddrTimestampEnabled(boolean yes)
Description copied from interface: AEUnicastSettings
Sets whether to use 4 byte address and 4 byte timestamp or 2 byte address and 2 byte timestamp. Set true to use 4 bytes for each.

Specified by:
set4ByteAddrTimestampEnabled in interface AEUnicastSettings

is4ByteAddrTimestampEnabled

public boolean is4ByteAddrTimestampEnabled()
Specified by:
is4ByteAddrTimestampEnabled in interface AEUnicastSettings

jAER project on SourceForge