Terrenus HRPT v2.2

terrenus.telemetry
Class AbstractTelemetryStream

java.lang.Object
  extended by terrenus.telemetry.AbstractTelemetryStream
All Implemented Interfaces:
TelemetryStream
Direct Known Subclasses:
CHRPTStream, HRPTStream

public abstract class AbstractTelemetryStream
extends java.lang.Object
implements TelemetryStream

The AbstractTelemetryStream class is a stream that obtains data from a buffer. The buffer may have extra data at the start and before each frame, and may be in little or big endian byte order for multibyte data streams.


Field Summary
protected  java.nio.ByteBuffer input
          The buffer used for data input.
 
Constructor Summary
AbstractTelemetryStream()
           
 
Method Summary
protected abstract  boolean checkFrame(int frame)
          Checks a frame for errors.
protected  boolean checkStream()
          Checks the telemetry stream for errors.
 java.nio.ByteBuffer getBlock(int frame, int block)
          Gets the data for the specified block.
protected abstract  int getBlockLength(int block)
          Gets the length of a block.
protected abstract  int getBlockPosition(int block)
          Gets the position of a block within a frame.
 int getDayCount()
          Gets the starting day count, or -1 if not available.
 int getFrameCount()
          Gets the total number of telemetry frames.
protected  int getFramePosition(int frame)
          Gets the position of a frame within the input.
static java.nio.ByteBuffer getInputBuffer(java.lang.String fileName)
          Gets a mapped byte input buffer for the specified data file.
 int getYear()
          Gets the starting year, or -1 if not available.
protected  void initStream(java.nio.ByteBuffer input, int headerLength, int frameLength, int frameHeaderLength, boolean isLittleEndian)
          Initializes a new stream using the specified buffer as input.
static void main(java.lang.String[] argv)
          Tests this class.
 void setDayCount(int dayCount)
          Sets the starting day count.
 void setYear(int year)
          Sets the starting year.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface terrenus.telemetry.TelemetryStream
getBlockCount, getDecoder, getFormat
 

Field Detail

input

protected java.nio.ByteBuffer input
The buffer used for data input.

Constructor Detail

AbstractTelemetryStream

public AbstractTelemetryStream()
Method Detail

getInputBuffer

public static java.nio.ByteBuffer getInputBuffer(java.lang.String fileName)
                                          throws java.io.IOException
Gets a mapped byte input buffer for the specified data file.

Parameters:
fileName - the name of the file.
Returns:
a buffer for accessing the data.
Throws:
java.io.IOException - if an error occurred accessing the file.

initStream

protected void initStream(java.nio.ByteBuffer input,
                          int headerLength,
                          int frameLength,
                          int frameHeaderLength,
                          boolean isLittleEndian)
Initializes a new stream using the specified buffer as input.

Parameters:
input - the input buffer to read.
headerLength - the input header length in bytes.
frameLength - the frame length in bytes (including header).
frameHeaderLength - the frame header length.
isLittleEndian - the little endian flag, true for LSB first or false for MSB first.

getFramePosition

protected int getFramePosition(int frame)
Gets the position of a frame within the input.

Parameters:
frame - the frame in question.
Returns:
the position in bytes, relative to the end of any input header data.

getBlockPosition

protected abstract int getBlockPosition(int block)
Gets the position of a block within a frame.

Parameters:
block - the block in question.
Returns:
the position in bytes, relative to the end of any frame header data.

getBlockLength

protected abstract int getBlockLength(int block)
Gets the length of a block.

Parameters:
block - the block in question.
Returns:
the length of the block in bytes.

getBlock

public java.nio.ByteBuffer getBlock(int frame,
                                    int block)
Description copied from interface: TelemetryStream
Gets the data for the specified block.

Specified by:
getBlock in interface TelemetryStream
Parameters:
frame - the frame to get data.
block - the block number to get data.
Returns:
the block data buffer.

getYear

public int getYear()
            throws java.io.IOException
Description copied from interface: TelemetryStream
Gets the starting year, or -1 if not available.

Specified by:
getYear in interface TelemetryStream
Throws:
java.io.IOException

setYear

public void setYear(int year)
Description copied from interface: TelemetryStream
Sets the starting year. This may be needed if the year cannot be detected from the stream.

Specified by:
setYear in interface TelemetryStream
Parameters:
year - the starting year. The year is returned by the next call to TelemetryStream.getYear().

getDayCount

public int getDayCount()
                throws java.io.IOException
Description copied from interface: TelemetryStream
Gets the starting day count, or -1 if not available.

Specified by:
getDayCount in interface TelemetryStream
Throws:
java.io.IOException

setDayCount

public void setDayCount(int dayCount)
Description copied from interface: TelemetryStream
Sets the starting day count. This may be needed if the day count cannot be detected from the stream.

Specified by:
setDayCount in interface TelemetryStream
Parameters:
dayCount - the starting day count. The day count is returned by the next call to TelemetryStream.getDayCount().

checkFrame

protected abstract boolean checkFrame(int frame)
Checks a frame for errors. The check procedure may involve looking for expected patterns such as synchronization bytes.

Parameters:
frame - the frame number to check.
Returns:
true if the frame check was successful, or false if it failed.
See Also:
checkStream()

checkStream

protected boolean checkStream()
Checks the telemetry stream for errors. This method calls checkFrame(int) for a contiguous sequence of frames at the start of the stream to determine if the stream has valid frame data. Child classes may want to override this method to perform more elaborate stream checking.

Returns:
true if the frame check was successful, or false if it failed.

getFrameCount

public int getFrameCount()
Description copied from interface: TelemetryStream
Gets the total number of telemetry frames.

Specified by:
getFrameCount in interface TelemetryStream

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Tests this class.

Throws:
java.lang.Exception

Terrenus HRPT v2.2