GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > QLSM / dev

Constituent: qlsm     Tag: sun-gcc


Interface   Data Structures   File List   Data Fields   Globals  

QLSM_istream.c File Reference

Utility routines to read and write QLSM (magic 7) streams. More...

#include "QLSM/QLSM_istream.h"
#include "QSD/CCSDS_istream.h"
#include "QSD/CCSDS_apidDsc.h"
#include "QSD/CCSDS_telemetry.h"
#include "LSF/LSF.h"
#include "PBS/BSWP.ih"
#include "PBI/Endianness.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

Include dependency graph for QLSM_istream.c:


Data Structures

struct  _QLSM_istream
 Standard header for both input and output streams. More...

Typedefs

typedef enum _QLSM_ISTREAM_BOUNDS_K QLSM_ISTREAM_BOUNDS_K
 Typedef for enum _QLSM_ISTREAM_BOUNDS_K.
typedef _QLSM_istream QLSM_istream

Enumerations

enum  _QLSM_ISTREAM_BOUNDS_K {
  QLSM_ISTREAM_BOUNDS_K_MAXPKT = 1 << 16,
  QLSM_ISTREAM_BOUNDS_K_LOWER = QLSM_ISTREAM_BOUNDS_K_MAXPKT,
  QLSM_ISTREAM_BOUNDS_K_UPPER = 1 << 25,
  QLSM_ISTREAM_BOUNDS_K_OVERFLOW = QLSM_ISTREAM_BOUNDS_K_MAXPKT
}
 Upper and lower bounds on the segment size. More...

Functions

static void * mem_alloc (unsigned int nbytes)
 Wraps the 'real' allocator.
static void mem_free (void *ptr)
 Wraps the 'real' deallocator.
static int get_datagram (QLSM_istream *istream)
 Gets the next datagram into the buffer.
int QLSM_istreamSizeof (void)
 Returns the size, in bytes, of QLSM_istream handle.
QLSM_istreamQLSM_istreamNew (void)
 Allocates a QLSM_istream handle.
int QLSM_istreamClose (QLSM_istream *stream)
 Closes the stream.
int QLSM_istreamConstruct (QLSM_istream *istream, CCSDS_istream *ccsds)
 Opens a QLSM file or data for reading.
int QLSM_istreamFileOpen (QLSM_istream *istream, const char *filename, unsigned int options, unsigned char *buf, unsigned int buf_size)
 Convenience routine to construct a QLSM_istreamFileOpen to read from the specified name file filename.
int QLSM_istreamRead (QLSM_istream *istream, QLSM_istreamDsc *dsc, unsigned int filter)
 Reads the next object in the QLSM stream.
int QLSM_istreamDelete (QLSM_istream *istream)
 Deletes the QLSM_istream.

Detailed Description

Utility routines to read and write QLSM (magic 7) streams.

Author:
JJRussell - russell@slac.stanford.edu
   CVS $Id: QLSM_istream.c,v 1.1 2008/09/20 00:39:15 russell Exp $

Typedef Documentation

QLSM_ISTREAM_BOUNDS_K
 

Typedef for enum _QLSM_ISTREAM_BOUNDS_K.

The lower bound must be constrained to be at least the size of the largest contribution

The upper bound is really only a default used and can be easily overridden. The upper bound must be at least the size of a maximally sized contribution, but really is set by purely practical considerations. Since this is unit of a read, on very large files, there can be a considerable delay if this read is very large. This is annoying, particularly in the case where one working interactively and just processing the first few records. So this size is set to be something that is large enough to be accommodate most files, but small enough to keep the read latency to something tolerable on human timescales.


Enumeration Type Documentation

enum _QLSM_ISTREAM_BOUNDS_K
 

Upper and lower bounds on the segment size.

Enumerator:
QLSM_ISTREAM_BOUNDS_K_MAXPKT  Size of maximum event
QLSM_ISTREAM_BOUNDS_K_LOWER  Lower bound must be at least the size of a maximally sized event
QLSM_ISTREAM_BOUNDS_K_UPPER  Upper bound must be at least the lower bound, choose 32Mbytes
QLSM_ISTREAM_BOUNDS_K_OVERFLOW  Overflow area must at least the size of a maximally sized event


Function Documentation

static int get_datagram QLSM_istream istream  )  [static]
 

Gets the next datagram into the buffer.

DO we want recovery here

static void * mem_alloc unsigned int  nbytes  )  [static]
 

Wraps the 'real' allocator.

Returns:
Pointer to the allocated memory or NULL if not available
Parameters:
nbytes The number of bytes
On the embedded systems, the memory pool available to malloc is too small for the larger .ebf files. Typically in this environment one should use MBA_alloc/MBA_free, However, because the EDS package is supposed to be independent of other packages (including PBS) one can not link against in the traditional manner.
The solution is two fold
  • Do the usual thing and define wrapper functions that are different for the host and embedded systems.
  • Go one step further and define MBA_alloc/MBA_free as weak symbols.
This second point effectively transfers the burden of determining when the MBA_alloc/MBA_free symbols need to be satistied. Instead of at the static link or dynamic load stage, this is deferred till runtime.
Note:
There is likely an even trickier way to do this. Currently the code checks if MBA_alloc/MBA_free are non-NULL and if so uses them, else it reverts to malloc/free. Ideally the dynamic loader should do this, thus eliminating the need for any run-time code.

static void mem_free void *  ptr  )  [static]
 

Wraps the 'real' deallocator.

See also:
mem_alloc
Parameters:
ptr Pointer to the memory to free
Note:
See mem_alloc for a discussion on why mem_alloc and mem_free exist and for the implementation details

int QLSM_istreamClose QLSM_istream stream  ) 
 

Closes the stream.

This function only closes the file.To free the memory associated with the contents of the file, the user must call QLSM_istreamFree().

int QLSM_istreamConstruct QLSM_istream istream,
CCSDS_istream *  ccsds
 

Opens a QLSM file or data for reading.

Return values:
0,success 
!= 0, failure
Parameters:
istream The stream handle to construct
ccsds A previously construct CCSDS_istream

int QLSM_istreamDelete QLSM_istream istream  ) 
 

Deletes the QLSM_istream.

Parameters:
istream The event builder stream handle
After calling QLSM_istreamDelete, the contents and the QLSM stream handle are no longer valid.

int QLSM_istreamFileOpen QLSM_istream istream,
const char *  filename,
unsigned int  options,
unsigned char *  buf,
unsigned int  buf_size
 

Convenience routine to construct a QLSM_istreamFileOpen to read from the specified name file filename.

Return values:
0,If successful
-1,If could not allocate a new stream (i.e. out of memory)
-2,If the file does not exist
Parameters:
istream The target CCSDS_istream
filename The name of the file to open
options Bit list of options, currently unused, specify as 0
buf Optional parameter specifying the FILE's input read buffer
buf_size Optional parameter specifying the size of buf

int QLSM_istreamRead QLSM_istream istream,
QLSM_istreamDsc dsc,
unsigned int  filter
 

Reads the next object in the QLSM stream.

Return values:
0,if successful
-1,if not
Parameters:
istream A previously opened event builder stream handle
dsc If successful, filled in with a description of the read object. This includes its
  • type
  • length, in 32-bit words
  • address
filter A bit mask of the object(s) the user wishes to have returned.

int QLSM_istreamSizeof void   ) 
 

Returns the size, in bytes, of QLSM_istream handle.

Returns:
The size, in bytes, of QLSM_istream handle


Generated on Sat Sep 20 02:27:15 2008 by  doxygen 1.4.4