gov.nasa.gsfc.drl.rtstps.core.ccsds
Class Packet

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.core.Unit
      extended by gov.nasa.gsfc.drl.rtstps.core.ccsds.Packet
All Implemented Interfaces:
PacketI

public final class Packet
extends Unit
implements PacketI

This class contains a single CCSDS packet. The software usually reuses all Packet objects, so you should not save a reference to a Packet in the expectations that the contents will not change.


Nested Class Summary
 class Packet.Annotation
          Packet annotation.
 
Field Summary
private  Packet.Annotation annotation
          This is packet annotation associated with this packet.
static int IDLE_PACKET
           
static int LENGTH_OFFSET
           
static int PRIMARY_HEADER_LENGTH
           
 
Fields inherited from class gov.nasa.gsfc.drl.rtstps.core.Unit
data, deleted, frameAnnotation, length, startOffset
 
Constructor Summary
Packet(int length)
          Constructor to creating a "copy" packet.
Packet(int offset, byte[] data)
          Alternate constructor for creating a "no copy" packet.
 
Method Summary
private  long calcTimeStamp(int offset, int timeStampSize)
           
 int getApplicationId()
          Get this packet's application ID.
static int getApplicationId(int offset, byte[] data)
          Static version to get a packet's application ID from a data buffer
 Packet.Annotation getPacketAnnotation()
          Get this packet's annotation.
 int getPacketLength()
          Get the packet length field from the header
static int getPacketLength(int offset, byte[] data)
          Static version of getPacketLength(), requires data and index into to be passed in.
 int getPacketSize()
          Get the total packet size, including header and body
static int getPacketSize(int offset, byte[] data)
          Static version of getPacketSize(), requires data and index into to be passed in.
 int getSequenceCounter()
          Get this packet's sequence counter.
static int getSequenceCounter(int offset, byte[] data)
          Get this packet's sequence counter from a data buffer
 int getSequenceFlags()
          Get sequence flags...
static int getSequenceFlags(int offset, byte[] data)
          Get sequence flags from a data buffer
 long getTimeStamp(int timeStampSize)
          Supports 8 bytes or less in the secondary header
static long getTimeStamp(int offset, byte[] data, int timeStampSize)
          Supports 8 bytes or less in the secondary header from a data buffer
 long getTimeStamp(int offset, int timeStampSize)
           
 int getType()
          Get the type field...
 int getType(int offset, byte[] data)
          Get the type field from a data buffer
 int getVersion()
          Get the version field...
 int getVersion(int offset, byte[] data)
          Get the version field from a data buffer
 boolean hasSecondaryHeader()
          Check secondary header flags
static boolean hasSecondaryHeader(int offset, byte[] data)
          Check secondary header flags from a data buffer
 java.lang.String hdrToString()
           
 boolean isFirstPacketInSequence()
          Check that this packet is the first in a series
static boolean isFirstPacketInSequence(int offset, byte[] data)
          Check that this packet is the first in a series from a data buffer
 boolean isLastPacketInSequence()
          Check that this packet is the last in a series
 boolean isLastPacketInSequence(int offset, byte[] data)
          Check that this packet is the last in a series from a data buffer
 boolean isMiddlePacketInSequence()
          Check that this packet is the middle in a series
static boolean isMiddlePacketInSequence(int offset, byte[] data)
          Check that this packet is the middle in a series from a data buffer
 boolean isStandalonePacket()
          Check that this packet is the last in a series
 boolean isStandalonePacket(int offset, byte[] data)
          Check that this packet is the last in a series from a data buffer
 void reset(int length)
          Reset this packet so that it may be used to contain a different packet.
 void setLength(int length)
           
 void setStartOffset(int offset)
           
 java.lang.String toString()
          Get debug information.
 
Methods inherited from class gov.nasa.gsfc.drl.rtstps.core.Unit
getData, getFrameAnnotation, getSize, getStartOffset, isDeleted, setDeleted, setFrameAnnotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRIMARY_HEADER_LENGTH

public static final int PRIMARY_HEADER_LENGTH
See Also:
Constant Field Values

LENGTH_OFFSET

public static final int LENGTH_OFFSET
See Also:
Constant Field Values

IDLE_PACKET

public static final int IDLE_PACKET
See Also:
Constant Field Values

annotation

private Packet.Annotation annotation
This is packet annotation associated with this packet.

Constructor Detail

Packet

public Packet(int length)
Constructor to creating a "copy" packet. A user of this constructor intends to copy the data to this objects data byte array. The reset method may be used if this class is used in this manner. Throughout RT-STPS this is the main if not only way it is being used.

Parameters:
length - the packet length in bytes

Packet

public Packet(int offset,
              byte[] data)
Alternate constructor for creating a "no copy" packet. This is a special case of this class and it should not be mixed with the other main case or things will break. The intent of this class is for it to be used in situations where a full copy is not needed and the user simply needs to momentarily wrap a data buffer with this class to get at the details of the packet. The reset method should not be used if the class is being used in this manner.

Parameters:
offset - offset into the data buffer the packet data starts
data - the data byte array
Method Detail

setStartOffset

public void setStartOffset(int offset)

setLength

public void setLength(int length)

reset

public void reset(int length)
Reset this packet so that it may be used to contain a different packet.

Parameters:
length - The length of the new packet

getApplicationId

public final int getApplicationId()
Get this packet's application ID.

Specified by:
getApplicationId in interface PacketI

getApplicationId

public static final int getApplicationId(int offset,
                                         byte[] data)
Static version to get a packet's application ID from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
application ID field

getSequenceCounter

public final int getSequenceCounter()
Get this packet's sequence counter.

Specified by:
getSequenceCounter in interface PacketI

getSequenceCounter

public static final int getSequenceCounter(int offset,
                                           byte[] data)
Get this packet's sequence counter from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
sequence counter field

hasSecondaryHeader

public final boolean hasSecondaryHeader()
Check secondary header flags

Specified by:
hasSecondaryHeader in interface PacketI
Returns:
true or false

hasSecondaryHeader

public static final boolean hasSecondaryHeader(int offset,
                                               byte[] data)
Check secondary header flags from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
true or false

isFirstPacketInSequence

public final boolean isFirstPacketInSequence()
Check that this packet is the first in a series

Specified by:
isFirstPacketInSequence in interface PacketI
Returns:
true or false

isFirstPacketInSequence

public static final boolean isFirstPacketInSequence(int offset,
                                                    byte[] data)
Check that this packet is the first in a series from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
true or false

isMiddlePacketInSequence

public final boolean isMiddlePacketInSequence()
Check that this packet is the middle in a series

Specified by:
isMiddlePacketInSequence in interface PacketI
Returns:
true or false

isMiddlePacketInSequence

public static final boolean isMiddlePacketInSequence(int offset,
                                                     byte[] data)
Check that this packet is the middle in a series from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
true or false

isLastPacketInSequence

public final boolean isLastPacketInSequence()
Check that this packet is the last in a series

Specified by:
isLastPacketInSequence in interface PacketI
Returns:
true or false

isLastPacketInSequence

public final boolean isLastPacketInSequence(int offset,
                                            byte[] data)
Check that this packet is the last in a series from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
true or false

isStandalonePacket

public final boolean isStandalonePacket()
Check that this packet is the last in a series

Specified by:
isStandalonePacket in interface PacketI
Returns:
true or false

isStandalonePacket

public final boolean isStandalonePacket(int offset,
                                        byte[] data)
Check that this packet is the last in a series from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
true or false

getPacketLength

public final int getPacketLength()
Get the packet length field from the header

Specified by:
getPacketLength in interface PacketI
Returns:
length field bytes

getPacketLength

public static final int getPacketLength(int offset,
                                        byte[] data)
Static version of getPacketLength(), requires data and index into to be passed in. Intended to be used to "peek" into a data buffer that contains a packet but that has not been processed further.

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
length field

getPacketSize

public final int getPacketSize()
Get the total packet size, including header and body

Specified by:
getPacketSize in interface PacketI
Returns:
total bytes

getPacketSize

public static final int getPacketSize(int offset,
                                      byte[] data)
Static version of getPacketSize(), requires data and index into to be passed in. Intended to be used to "peek" into a data buffer that contains a packet but that has not been processed further.

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
total size in bytes

getSequenceFlags

public final int getSequenceFlags()
Get sequence flags...

Specified by:
getSequenceFlags in interface PacketI
Returns:
0,1,2 or 3

getSequenceFlags

public static final int getSequenceFlags(int offset,
                                         byte[] data)
Get sequence flags from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
0, 1, 2 or 3

getType

public final int getType()
Get the type field...

Specified by:
getType in interface PacketI
Returns:
0 or 1

getType

public final int getType(int offset,
                         byte[] data)
Get the type field from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
0 or 1

getVersion

public final int getVersion()
Get the version field...

Specified by:
getVersion in interface PacketI
Returns:
0,1,2 or 3...

getVersion

public final int getVersion(int offset,
                            byte[] data)
Get the version field from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
Returns:
0, 1, 2 or 3...

getTimeStamp

public long getTimeStamp(int timeStampSize)
Supports 8 bytes or less in the secondary header

Parameters:
timeStampSize -
Returns:
timestamp copied into a long, right justified

getTimeStamp

public long getTimeStamp(int offset,
                         int timeStampSize)

calcTimeStamp

private long calcTimeStamp(int offset,
                           int timeStampSize)

getTimeStamp

public static long getTimeStamp(int offset,
                                byte[] data,
                                int timeStampSize)
Supports 8 bytes or less in the secondary header from a data buffer

Parameters:
offset - index into byte[] where packet starts
data - the byte[] array of the packet values
timeStampSize -
Returns:
timestamp copied into a long, right justified

toString

public java.lang.String toString()
Get debug information.

Overrides:
toString in class java.lang.Object

hdrToString

public java.lang.String hdrToString()

getPacketAnnotation

public final Packet.Annotation getPacketAnnotation()
Get this packet's annotation.