Class Pdu

java.lang.Object
edu.nps.moves.dis7.pdus.Pdu
All Implemented Interfaces:
Marshaller, Serializable
Direct Known Subclasses:
LiveEntityFamilyPdu, PduBase

public abstract class Pdu extends Object implements Serializable, Marshaller
Base class of PduBase and LiveEntityPdu
See Also:
  • Field Details

    • protocolVersion

      protected DISProtocolVersion protocolVersion
      The version of the protocol. 5=DIS-1995, 6=DIS-1998, 7=DIS-2012 uid 3
    • exerciseID

      protected byte exerciseID
      Exercise ID provides a unique identifier
    • pduType

      protected DisPduType pduType
      Type of pdu, unique for each PDU class uid 4
    • protocolFamily

      protected DISProtocolFamily protocolFamily
      value that refers to the protocol family, eg SimulationManagement, et uid 5
    • timestamp

      protected int timestamp
      Timestamp value, int representing number of 1.675 microseconds as interval past hour
    • length

      protected short length
      Length, in bytes, of the PDU
  • Constructor Details

    • Pdu

      public Pdu()
      Constructor creates and configures a new instance object
  • Method Details

    • copyByPduFactory

      public Pdu copyByPduFactory()
      Create deep copy of current object using PduFactory.
      Returns:
      deep copy of PDU
    • getMarshalledSize

      public int getMarshalledSize()
      Returns size of this serialized (marshalled) object in bytes
      Specified by:
      getMarshalledSize in interface Marshaller
      Returns:
      serialized size in bytes
      See Also:
    • setProtocolVersion

      public Pdu setProtocolVersion(DISProtocolVersion pProtocolVersion)
      Setter for protocolVersion
      Parameters:
      pProtocolVersion - new value of interest
      Returns:
      same object to permit progressive setters
    • getProtocolVersion

      public DISProtocolVersion getProtocolVersion()
      Getter for protocolVersion
      Returns:
      value of interest
    • setExerciseID

      public Pdu setExerciseID(byte pExerciseID)
      Setter for exerciseID
      Parameters:
      pExerciseID - new value of interest
      Returns:
      same object to permit progressive setters
    • setExerciseID

      public Pdu setExerciseID(int pExerciseID)
      Utility setter for exerciseID
      Parameters:
      pExerciseID - new value of interest
      Returns:
      same object to permit progressive setters
    • getExerciseID

      public byte getExerciseID()
      Getter for exerciseID
      Returns:
      value of interest
    • setPduType

      public Pdu setPduType(DisPduType pPduType)
      Setter for pduType
      Parameters:
      pPduType - new value of interest
      Returns:
      same object to permit progressive setters
    • getPduType

      public DisPduType getPduType()
      Getter for pduType
      Returns:
      value of interest
    • setProtocolFamily

      public Pdu setProtocolFamily(DISProtocolFamily pProtocolFamily)
      Setter for protocolFamily
      Parameters:
      pProtocolFamily - new value of interest
      Returns:
      same object to permit progressive setters
    • getProtocolFamily

      public DISProtocolFamily getProtocolFamily()
      Getter for protocolFamily
      Returns:
      value of interest
    • setTimestamp

      public Pdu setTimestamp(int pTimestamp)
      Setter for timestamp Warning: this method sets a DIS bit pattern
      Parameters:
      pTimestamp - new value of interest
      Returns:
      same object to permit progressive setters
      See Also:
    • getTimestamp

      public int getTimestamp()
      Getter for timestamp Warning: this method gets a DIS bit pattern
      Returns:
      value of interest
      See Also:
    • setLength

      public Pdu setLength(short pLength)
      Setter for length
      Parameters:
      pLength - new value of interest
      Returns:
      same object to permit progressive setters
    • setLength

      public Pdu setLength(int pLength)
      Utility setter for length
      Parameters:
      pLength - new value of interest
      Returns:
      same object to permit progressive setters
    • getLength

      public short getLength()
      Getter for length
      Returns:
      value of interest
    • marshal

      public void marshal(DataOutputStream dos) throws Exception
      Serializes an object to a DataOutputStream.
      Specified by:
      marshal in interface Marshaller
      Parameters:
      dos - the OutputStream
      Throws:
      Exception - if something goes wrong
      See Also:
    • unmarshal

      public int unmarshal(DataInputStream dis) throws Exception
      Deserializes an object from a DataInputStream.
      Specified by:
      unmarshal in interface Marshaller
      Parameters:
      dis - the InputStream
      Returns:
      marshalled serialized size in bytes
      Throws:
      Exception - if something goes wrong
      See Also:
    • marshal

      public void marshal(ByteBuffer byteBuffer) throws Exception
      Packs an object into the ByteBuffer.
      Specified by:
      marshal in interface Marshaller
      Parameters:
      byteBuffer - The ByteBuffer at the position to begin writing
      Throws:
      BufferOverflowException - if byteBuffer is too small
      ReadOnlyBufferException - if byteBuffer is read only
      Exception - ByteBuffer-generated exception
      See Also:
    • unmarshal

      public int unmarshal(ByteBuffer byteBuffer) throws Exception
      Unpacks a Pdu from the underlying data.
      Specified by:
      unmarshal in interface Marshaller
      Parameters:
      byteBuffer - The ByteBuffer at the position to begin reading
      Returns:
      marshalled serialized size in bytes
      Throws:
      BufferUnderflowException - if byteBuffer is too small
      Exception - ByteBuffer-generated exception
      See Also:
    • marshal

      public byte[] marshal() throws Exception
      A convenience method for marshalling to a byte array. This is not as efficient as reusing a ByteBuffer, but it is easy.
      Returns:
      a byte array with the marshalled Pdu
      Throws:
      Exception - ByteBuffer-generated exception
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equalsImpl

      public boolean equalsImpl(Object obj)
      Compare all fields that contribute to the state, ignoring transient and static fields, for this and the supplied object
      Parameters:
      obj - the object to compare to
      Returns:
      true if the objects are equal, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setTimestampSeconds

      public Pdu setTimestampSeconds(double newTimestamp)
      Utility setter for timestamp converting double (or float) to Timestamp in seconds at 2^31 - 1 units past top of hour
      Parameters:
      newTimestamp - new timestamp in seconds
      Returns:
      same object to permit progressive setters
      See Also:
    • getTimestampSeconds

      public double getTimestampSeconds()
      Utility getter for timestamp converting integer timestamp at 2^31 - 1 units past top of hour to double (or float)
      Returns:
      fractional timestamp past hour
      See Also:
    • occursAfter

      public boolean occursAfter(Pdu pdu2)
      Whether or not timestamp for this Pdu occurs after timestamp as another Pdu.
      Parameters:
      pdu2 - second Pdu for comparison
      Returns:
      whether timestamp for this Pdu occurs later
    • occursBefore

      public boolean occursBefore(Pdu pdu2)
      Whether or not timestamp for this Pdu occurs before timestamp as another Pdu.
      Parameters:
      pdu2 - second Pdu for comparison
      Returns:
      whether timestamp for this Pdu occurs earlier
    • occursSameTime

      public boolean occursSameTime(Pdu pdu2)
      Whether or not this Pdu occurs at same timestamp as another Pdu.
      Parameters:
      pdu2 - second Pdu for comparison
      Returns:
      whether timestamps are identical for both Pdus