edu.nps.moves.dis
Class Pdu

java.lang.Object
  extended by edu.nps.moves.dis.Pdu
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DistributedEmissionsFamilyPdu, EntityInformationFamilyPdu, EntityManagementFamilyPdu, LogisticsFamilyPdu, MinefieldFamilyPdu, RadioCommunicationsFamilyPdu, SimulationManagementFamilyPdu, SimulationManagementWithReliabilityFamilyPdu, SyntheticEnvironmentFamilyPdu, WarfareFamilyPdu

@Entity
public class Pdu
extends java.lang.Object
implements java.io.Serializable

The superclass for all PDUs. This incorporates the PduHeader record, section 5.2.29. Copyright (c) 2008-2010, MOVES Institute, Naval Postgraduate School. All rights reserved. This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html

Author:
DMcG
See Also:
Serialized Form

Field Summary
protected  short exerciseID
          Exercise ID
protected  short padding
          zero-filled array of padding
protected  int pduLength
          Length, in bytes, of the PDU.
protected  short pduType
          Type of pdu, unique for each PDU class
protected  short protocolFamily
          value that refers to the protocol family, eg SimulationManagement, et
protected  short protocolVersion
          The version of the protocol.
protected  long timestamp
          Timestamp value
 
Constructor Summary
Pdu()
          Constructor
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 boolean equalsImpl(java.lang.Object obj)
          Compare all fields that contribute to the state, ignoring transient and static fields, for this and the supplied object
 short getExerciseID()
           
 int getLength()
           
 int getMarshalledSize()
           
 short getPadding()
           
 int getPduLength()
           
 short getPduType()
           
 edu.nps.moves.disenum.PduType getPduTypeEnum()
          Returns the PduType, an enumeration from the disenum jar file.
 long getPk_Pdu()
          Primary key for hibernate, not part of the DIS standard
 short getProtocolFamily()
           
 short getProtocolVersion()
           
 long getTimestamp()
           
 byte[] marshal()
          A convenience method for marshalling to a byte array.
 void marshal(java.nio.ByteBuffer buff)
          Packs a Pdu into the ByteBuffer.
 void marshal(java.io.DataOutputStream dos)
           
 byte[] marshalWithDisAbsoluteTimestamp()
          A convieneince method to marshal to a byte array with the timestamp set to the DIS standard for absolute timestamps (which works only if the host is slaved to NTP).
 void marshalWithDisAbsoluteTimestamp(java.nio.ByteBuffer buff)
           
 byte[] marshalWithDisRelativeTimestamp()
          A convieneince method to marshal to a byte array with the timestamp set to the DIS standard for relative timestamps.
 void marshalWithDisRelativeTimestamp(java.nio.ByteBuffer buff)
           
 byte[] marshalWithNpsTimestamp()
          A convienience method to marshal a PDU using the NPS-specific format for timestamps, which is hundredths of a second since the start of the year.
 void marshalWithNpsTimestamp(java.nio.ByteBuffer buff)
           
 byte[] marshalWithUnixTimestamp()
          Another option for marshalling with the timestamp field set automatically.
 void marshalWithUnixTimestamp(java.nio.ByteBuffer buff)
           
 long readUnsignedInt(java.nio.ByteBuffer buff)
           
 long readUnsignedInt(java.io.DataInputStream dis)
           
 void setExerciseID(short pExerciseID)
           
 void setPadding(short pPadding)
           
 void setPduLength(int pPduLength)
           
 void setPduType(short pPduType)
           
 void setPk_Pdu(long pKeyName)
          Hibernate primary key, not part of the DIS standard
 void setProtocolFamily(short pProtocolFamily)
           
 void setProtocolVersion(short pProtocolVersion)
           
 void setTimestamp(long pTimestamp)
           
 void unmarshal(java.nio.ByteBuffer buff)
          Unpacks a Pdu from the underlying data.
 void unmarshal(java.io.DataInputStream dis)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

protocolVersion

protected short protocolVersion
The version of the protocol. 5=DIS-1995, 6=DIS-1998.


exerciseID

protected short exerciseID
Exercise ID


pduType

protected short pduType
Type of pdu, unique for each PDU class


protocolFamily

protected short protocolFamily
value that refers to the protocol family, eg SimulationManagement, et


timestamp

protected long timestamp
Timestamp value


pduLength

protected int pduLength
Length, in bytes, of the PDU. Changed name from length to avoid use of Hibernate QL reserved word


padding

protected short padding
zero-filled array of padding

Constructor Detail

Pdu

public Pdu()
Constructor

Method Detail

getLength

public int getLength()

getMarshalledSize

public int getMarshalledSize()

getPk_Pdu

public long getPk_Pdu()
Primary key for hibernate, not part of the DIS standard


setPk_Pdu

public void setPk_Pdu(long pKeyName)
Hibernate primary key, not part of the DIS standard


setProtocolVersion

public void setProtocolVersion(short pProtocolVersion)

getProtocolVersion

public short getProtocolVersion()

setExerciseID

public void setExerciseID(short pExerciseID)

getExerciseID

public short getExerciseID()

setPduType

public void setPduType(short pPduType)

getPduType

public short getPduType()

getPduTypeEnum

public edu.nps.moves.disenum.PduType getPduTypeEnum()
Returns the PduType, an enumeration from the disenum jar file. This is an enumerated java type, rather than a simple short integer. This should NOT be marshalled to DIS or XML.

Returns:
this Pdu's type enumeration

setProtocolFamily

public void setProtocolFamily(short pProtocolFamily)

getProtocolFamily

public short getProtocolFamily()

setTimestamp

public void setTimestamp(long pTimestamp)

getTimestamp

public long getTimestamp()

setPduLength

public void setPduLength(int pPduLength)

getPduLength

public int getPduLength()

setPadding

public void setPadding(short pPadding)

getPadding

public short getPadding()

readUnsignedInt

public long readUnsignedInt(java.io.DataInputStream dis)

readUnsignedInt

public long readUnsignedInt(java.nio.ByteBuffer buff)

marshal

public void marshal(java.io.DataOutputStream dos)

unmarshal

public void unmarshal(java.io.DataInputStream dis)

marshal

public void marshal(java.nio.ByteBuffer buff)
Packs a Pdu into the ByteBuffer.

Parameters:
buff - The ByteBuffer at the position to begin writing
Throws:
java.nio.BufferOverflowException - if buff is too small
java.nio.ReadOnlyBufferException - if buff is read only
Since:
??
See Also:
ByteBuffer

unmarshal

public void unmarshal(java.nio.ByteBuffer buff)
Unpacks a Pdu from the underlying data.

Parameters:
buff - The ByteBuffer at the position to begin reading
Throws:
java.nio.BufferUnderflowException - if buff is too small
Since:
??
See Also:
ByteBuffer

marshal

public byte[] marshal()
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
Since:
??

marshalWithDisAbsoluteTimestamp

public byte[] marshalWithDisAbsoluteTimestamp()
A convieneince method to marshal to a byte array with the timestamp set to the DIS standard for absolute timestamps (which works only if the host is slaved to NTP). This means the timestamp will roll over every hour.

Returns:
IEEE format byte array, with the timestamp set to the current DIS time

marshalWithDisAbsoluteTimestamp

public void marshalWithDisAbsoluteTimestamp(java.nio.ByteBuffer buff)

marshalWithDisRelativeTimestamp

public byte[] marshalWithDisRelativeTimestamp()
A convieneince method to marshal to a byte array with the timestamp set to the DIS standard for relative timestamps. The timestamp will roll over every hour

Returns:
IEEE format byte array, with the timestamp set to relative DIS time

marshalWithDisRelativeTimestamp

public void marshalWithDisRelativeTimestamp(java.nio.ByteBuffer buff)

marshalWithNpsTimestamp

public byte[] marshalWithNpsTimestamp()
A convienience method to marshal a PDU using the NPS-specific format for timestamps, which is hundredths of a second since the start of the year. This effectively eliminates the rollover issues from a practical standpoint.

Returns:
IEEE format byte array, with the timestamp set to hundredths of a second since the start of the year

marshalWithNpsTimestamp

public void marshalWithNpsTimestamp(java.nio.ByteBuffer buff)

marshalWithUnixTimestamp

public byte[] marshalWithUnixTimestamp()
Another option for marshalling with the timestamp field set automatically. The UNIX time is conventionally seconds since January 1, 1970. UTC time is used, and leap seconds are excluded. This approach is popular in the wild, but the time resolution is not very good for high frequency updates, such as aircraft. An entity updating at 30 PDUs/second would see 30 PDUs sent out with the same timestamp, and have 29 of them discarded as duplicate packets. Note that there are other "Unix times", such milliseconds since 1/1/1970, saved in a long. This cannot be used, since the value is saved in a long. Java's System.getCurrentTimeMillis() uses this value.

Returns:
IEEE format byte array, with the timetamp set to seconds since 1970

marshalWithUnixTimestamp

public void marshalWithUnixTimestamp(java.nio.ByteBuffer buff)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

equalsImpl

public boolean equalsImpl(java.lang.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.