faa.tg.dis
Class TgPduFactory

java.lang.Object
  extended by faa.tg.util.concurrency.RepeatingStrand
      extended by faa.tg.dis.PduFactory
          extended by faa.tg.dis.TgPduFactory
All Implemented Interfaces:
UpdateCompleteListener, PduListener, ComputeCompleteListener, EndOfEpochListener, ExecutiveEventListener<ExecutiveEvent>, FlightActivatedListener, FlightTerminatedListener, Strand, java.lang.Runnable, java.util.EventListener

public class TgPduFactory
extends PduFactory
implements UpdateCompleteListener, FlightTerminatedListener, FlightActivatedListener, ExecutiveEventListener<ExecutiveEvent>, ComputeCompleteListener, EndOfEpochListener, PduListener

 The TgPduFactory creates ProtocolDataUnits. TgPduFactory listens for
 aircraft and simulation events and generates the appropriate PDUs.
 These PDUs packaged in datagram packets and sent to the DIS_Transmitter.

 The TgPduFactory also reads PDU packets from the DIS_Receiver, constructs
 the appropriate PDUs and sends them to any registered PduListeners.
 
See the source: TgPduFactory.java

Version:
$Id: TgPduFactory.java,v 3.19 2008/12/31 16:38:52 lykensj Exp $
Author:
David D'Auria, SRC/FAA/ACT-510

Nested Class Summary
 
Nested classes/interfaces inherited from class faa.tg.util.concurrency.RepeatingStrand
RepeatingStrand.ThreadFactory
 
Field Summary
private static Port BASE
           
static java.lang.String CVS_VERSION_ID
          The CVS Version ID
private  short disApp
          DIS application id (host)
private  short disId
          DIS id (chassis)
private  short disSite
          DIS site id (subnet)
private  DIS_UdpTransmitter distx
          The DIS Transmitter for this scenario.
private  short entityId
          Next available entity id.
private  PduOutputStream espduOs
          The PDU output stream used to build and queue up Entity State PDUs.
private  boolean isRunning
          VERY BAD.
private  PduOutputStream pduOs
          The PDU output stream used to build misc.
private  int pduPerPacket
          Maximum number of Entity State PDUs in a disPacket
private  PduOutputStream pfpduOs
          The PDU output stream used to build and queue up Pre Flight PDUs.
private  Scenario scenario
           
private  double simTime
          The simulation time as a double.
 
Constructor Summary
TgPduFactory(DIS_UdpTransmitter distx, DIS_Receiver disrx, Scenario scenario)
          Constructor TgPduFactory
TgPduFactory(java.net.InetAddress sendAddress, Port disSendPort, Port disRecvPort, Scenario scenario)
          Constructor TgPduFactory if you what to transmitt and receive on different ports (as XPVDSupport needs to)
TgPduFactory(java.net.InetAddress sendAddress, Port disPort, Scenario scenario)
          construct the TgPduFactory.
 
Method Summary
 EntityStatePDU buildEntityStatePDU(Aircraft ac)
          Builds an EnityStatePDU for an aircraft.
 PreFlightPDU buildPreFlightPDU(Flight flt)
          Builds a PreFlightPDU for a Flight.
 StartPDU buildStartPDU()
          Construct and return a StartPDU.
 StopPDU buildStopPDU(byte reason)
          Construct and return a StopPDU with the specified reason code.
 DIS_UdpTransmitter getTransmitter()
          Method getTransmitter ...
 void handleComputeCompleteEvent(ComputeCompleteEvent cce)
          This method flushes any flights to the wire
 void handleEndOfEpochEvent(EndOfEpochEvent eoee)
          Method handleEndOfEpochEvent ...
 void handleExecutiveEvent(ExecutiveEvent ee)
          Transmits start/stop/pause pdus
 void handleFlightActivatedEvent(FlightActivatedEvent fae)
          Registers the DIS_Transmitter to receive UpdateCompleteEvents and builds a PreFlightPDU for the flight.
 void handleFlightTerminatedEvent(FlightTerminatedEvent ft)
          Builds an EntityStatePDU for the flight with the terminate bit set.
 void handlePdu(ProtocolDataUnit pdu)
          Decodes a portion of a byte array into a Protocol Data Unit.
 void handlePreFlightRequestPDU(PreFlightRequestPDU pfrpdu)
          Builds and sends PreFlightPDUs for the requested flights.
 void handleUpdateCompleteEvent(UpdateCompleteEvent uce)
          Builds an EntityStatePDU for an Aircraft and writes it to a PduOutputStream, triggered by the UpdateCompleteEvent.
private  void registerForActiveAircraft()
          xpvdSupport constructs a PduFactory after the start of the sim so collect active aircraft
 void sendRemainingPDUs(PduOutputStream pos)
          Sends any remaining PDUs to the DIS Transmitter.
 void write2Pos(ProtocolDataUnit pdu)
          Writes a PDU to the pduOs output stream.
private  void write2Pos(ProtocolDataUnit pdu, PduOutputStream pos)
          Writes a PDU to a PduOutputStream.
 
Methods inherited from class faa.tg.dis.PduFactory
addPduListener, isCommunicating, repeatedAction, stopCleanup
 
Methods inherited from class faa.tg.util.concurrency.RepeatingStrand
defaultName, incrementingName, isActive, isAlive, resume, run, runlimiter, runlimiter, sameName, start, startSetup, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_VERSION_ID

public static final java.lang.String CVS_VERSION_ID
The CVS Version ID

See Also:
Constant Field Values

BASE

private static final Port BASE

distx

private DIS_UdpTransmitter distx
The DIS Transmitter for this scenario.


disSite

private short disSite
DIS site id (subnet)


disApp

private short disApp
DIS application id (host)


disId

private short disId
DIS id (chassis)


pduPerPacket

private int pduPerPacket
Maximum number of Entity State PDUs in a disPacket


simTime

private double simTime
The simulation time as a double.


entityId

private short entityId
Next available entity id.


espduOs

private PduOutputStream espduOs
The PDU output stream used to build and queue up Entity State PDUs.


pfpduOs

private PduOutputStream pfpduOs
The PDU output stream used to build and queue up Pre Flight PDUs.


pduOs

private PduOutputStream pduOs
The PDU output stream used to build misc. PDUs.


isRunning

private boolean isRunning
VERY BAD. Revisit this flag.


scenario

private final Scenario scenario
Constructor Detail

TgPduFactory

public TgPduFactory(java.net.InetAddress sendAddress,
                    Port disPort,
                    Scenario scenario)
construct the TgPduFactory.

Parameters:
sendAddress - the address to send the PDU to ie. 172.26.64.255 or unicast
disPort - the port to send and receive PDU's on
scenario - the Scenario to attach to.

TgPduFactory

public TgPduFactory(DIS_UdpTransmitter distx,
                    DIS_Receiver disrx,
                    Scenario scenario)
Constructor TgPduFactory

Parameters:
distx -
disrx -
scenario - the Scenario to attach to.

TgPduFactory

public TgPduFactory(java.net.InetAddress sendAddress,
                    Port disSendPort,
                    Port disRecvPort,
                    Scenario scenario)
Constructor TgPduFactory if you what to transmitt and receive on different ports (as XPVDSupport needs to)

Parameters:
sendAddress - the address to send the PDU to ie. 172.26.64.255 or unicast
disSendPort - the port to send on
disRecvPort - the port to receive PDU's on
scenario - the Scenario to attach to.
Method Detail

registerForActiveAircraft

private void registerForActiveAircraft()
xpvdSupport constructs a PduFactory after the start of the sim so collect active aircraft


getTransmitter

public DIS_UdpTransmitter getTransmitter()
Method getTransmitter ...

Returns:
Returns the DIS Transmitter for this scenario.

handlePdu

public void handlePdu(ProtocolDataUnit pdu)
Decodes a portion of a byte array into a Protocol Data Unit.

Specified by:
handlePdu in interface PduListener
Parameters:
the - bytes of the PDU
Throws:
UnrecognizedPduTypeException

buildPreFlightPDU

public PreFlightPDU buildPreFlightPDU(Flight flt)
Builds a PreFlightPDU for a Flight.

Parameters:
flt - Flight to build PDU from.
Returns:
Returns the PreFlightPDU for this Flight.

buildEntityStatePDU

public EntityStatePDU buildEntityStatePDU(Aircraft ac)
Builds an EnityStatePDU for an aircraft.

Parameters:
ac - the aircraft to get the entity state of.
Returns:
an EntityStatePdu

buildStartPDU

public StartPDU buildStartPDU()
Construct and return a StartPDU.

Returns:
the StartPDU.

buildStopPDU

public StopPDU buildStopPDU(byte reason)
Construct and return a StopPDU with the specified reason code.

Parameters:
reason - code. Constant in StopPDU class.
Returns:
the StopPDU.

handleExecutiveEvent

public void handleExecutiveEvent(ExecutiveEvent ee)
Transmits start/stop/pause pdus

Specified by:
handleExecutiveEvent in interface ExecutiveEventListener<ExecutiveEvent>
Parameters:
ee - the Executive event start/stop/pause

handleComputeCompleteEvent

public void handleComputeCompleteEvent(ComputeCompleteEvent cce)
This method flushes any flights to the wire

Specified by:
handleComputeCompleteEvent in interface ComputeCompleteListener
Parameters:
cce -

handleEndOfEpochEvent

public void handleEndOfEpochEvent(EndOfEpochEvent eoee)
Method handleEndOfEpochEvent ...

Specified by:
handleEndOfEpochEvent in interface EndOfEpochListener
Parameters:
eoee -

handleFlightActivatedEvent

public void handleFlightActivatedEvent(FlightActivatedEvent fae)
Registers the DIS_Transmitter to receive UpdateCompleteEvents and builds a PreFlightPDU for the flight.

Specified by:
handleFlightActivatedEvent in interface FlightActivatedListener
Parameters:
fae - FlightActivatedEvent

handleFlightTerminatedEvent

public void handleFlightTerminatedEvent(FlightTerminatedEvent ft)
Builds an EntityStatePDU for the flight with the terminate bit set.

Specified by:
handleFlightTerminatedEvent in interface FlightTerminatedListener
Parameters:
ft -

handlePreFlightRequestPDU

public void handlePreFlightRequestPDU(PreFlightRequestPDU pfrpdu)
Builds and sends PreFlightPDUs for the requested flights.

Parameters:
pfrpdu -

handleUpdateCompleteEvent

public void handleUpdateCompleteEvent(UpdateCompleteEvent uce)
Builds an EntityStatePDU for an Aircraft and writes it to a PduOutputStream, triggered by the UpdateCompleteEvent.

Specified by:
handleUpdateCompleteEvent in interface UpdateCompleteListener
Parameters:
uce - An UpdateCompleteEvent
See Also:
UpdateCompleteEvent

write2Pos

public void write2Pos(ProtocolDataUnit pdu)
Writes a PDU to the pduOs output stream. If the PDU count has reached the max., a packet is created and sent to the DIS transmitter.

Parameters:
pdu -

write2Pos

private void write2Pos(ProtocolDataUnit pdu,
                       PduOutputStream pos)
Writes a PDU to a PduOutputStream. If the PDU count has reached the max., a packet is created and sent to the DIS transmitter.

Parameters:
pdu -
pos -

sendRemainingPDUs

public void sendRemainingPDUs(PduOutputStream pos)
Sends any remaining PDUs to the DIS Transmitter.

Parameters:
pos -