jAER project on SourceForge

net.sf.jaer.eventio
Class AEUnicastOutput

java.lang.Object
  extended by net.sf.jaer.eventio.AEUnicastOutput
All Implemented Interfaces:
AEUnicastSettings

public class AEUnicastOutput
extends java.lang.Object
implements AEUnicastSettings

Streams AE packets to network using UDP DatagramPacket's that are unicast. AEViewers can receive these packets to render them.

The implementation using a BlockingQueue to buffer the AEPacketRaw's that are offered. The packets are sent by a separate Consumer thread. The consumer has a queue length that determines how many packets can be buffered before the writePacket method blocks.

The datagram socket is not connect'ed to the receiver.

Author:
tobi

Field Summary
protected  java.nio.channels.DatagramChannel channel
           
protected  java.net.DatagramSocket socket
           
 
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
AEUnicastOutput()
          Creates a new instance, binding any available local port (since we will be just sending from here).
AEUnicastOutput(java.lang.String host, int port)
          Creates a new instance, binding any available local port (since we will be just sending from here) and using the last host and port.
 
Method Summary
 void close()
           
 java.lang.String getHost()
           
 int getPort()
           
 float getTimestampMultiplier()
           
 boolean is4ByteAddrTimestampEnabled()
           
 boolean isAddressFirstEnabled()
           
 boolean isSequenceNumberEnabled()
           
 boolean isSwapBytesEnabled()
           
 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)
          You need to setHost before this will send events.
 void setPort(int port)
          You set the port to say which port the packet will be sent to.
 void setSequenceNumberEnabled(boolean sequenceNumberEnabled)
          If set true (default), then an int32 sequence number is the first word of the packet.
 void setSwapBytesEnabled(boolean yes)
          Java is little endian (in linear memory, LSB comes first, at lower address) and intel procesors are big endian.
 void setTimestampMultiplier(float timestampMultiplier)
          Sets the mutliplier of jAER timestamps/remote host timestamps.
 java.lang.String toString()
           
 void writePacket(AEPacketRaw ae)
          Writes the packet out as sequence of address/timestamp's, just as they came as input from the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

channel

protected java.nio.channels.DatagramChannel channel

socket

protected java.net.DatagramSocket socket
Constructor Detail

AEUnicastOutput

public AEUnicastOutput(java.lang.String host,
                       int port)
Creates a new instance, binding any available local port (since we will be just sending from here) and using the last host and port.

Parameters:
host - the hostname to send to
port - the port to send to
See Also:
setHost(java.lang.String), setPort(int)

AEUnicastOutput

public AEUnicastOutput()
Creates a new instance, binding any available local port (since we will be just sending from here). The port and host need to be sent before any packets will be sent.

See Also:
setHost(java.lang.String), setPort(int)
Method Detail

writePacket

public void writePacket(AEPacketRaw ae)
                 throws java.io.IOException
Writes the packet out as sequence of address/timestamp's, just as they came as input from the device.

The notion of a packet is discarded to simplify later reading an input stream from the output stream result. The AEPacketRaw is written in chunks of AESocketStream.SOCKET_BUFFER_SIZE bytes (which must be a multiple of AESocketStream.EVENT_SIZE_BYTES). Each DatagramPacket has a sequence number as the first Integer value which is used on the reciever to detect dropped packets.

If an empty packet is supplied as ae, then a packet is still written but it contains only a sequence number.

This method actually offers new Datagram packets to the consumer thread for later tranmission. The datagram address and port are taken from the current settings for the AEUnicastOutput.

Parameters:
ae - a raw addresse-event packet
Throws:
java.io.IOException

toString

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

close

public void close()

getHost

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

setHost

public void setHost(java.lang.String host)
You need to setHost before this will send 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)
You set the port to say which port the packet will be sent to.

Specified by:
setPort in interface AEUnicastSettings
Parameters:
port - the UDP port number.

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)
Java is little endian (in linear memory, LSB comes first, at lower address) and intel procesors are big endian. If we send to a big endian host or native code, we can use this to swap the output ints to big endian.

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)
Sets the mutliplier of jAER timestamps/remote host timestamps. The outgoing timestamps are divided by timestampMultiplier to generate outgoing timestamps. The default jAER timestamp tick is 1 us. If the remote host uses a 1 ms tick, then set the mutliplier to 1000 so that jAER timestamps are output with 1 ms tick.

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