GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > LSE / V1-3-6

Constituent: lsew_stream     Tag: sun-gcc


Interface   Data Structures   File List   Data Fields   Globals  

CCSDS_ostream.c File Reference

Routine to post an CCSDS wrapped data to an output stream, formatting obeying the LCB buffering rules. More...

#include "LSE/CCSDS_ostream.h"
#include "CCSDS/CCSDS_pkt.h"
#include "EDS/io/EBF_swap.h"
#include "dprintf.h"
#include <stdlib.h>
#include <string.h>

Include dependency graph for CCSDS_ostream.c:


Data Structures

struct  _CCSDS_ostream
 The Post Control Block. More...

Defines

#define RND_TO(_x, _r)   ((((_x) + (_r) -1) / (_r)) * (_r))
 Rounds the specified number, _x up to the nearest multiple of _r.
#define MAX_WRITE   (4096 - 32)
 The maximum size, in bytes, of an LCB packet.

Typedefs

typedef _CCSDS_ostream CCSDS_ostream
 Typedef for struct _CCSDS_stream.

Functions

static __inline void setUnused (unsigned char *cur, int offset, unsigned short int unused_bytes)
 Sets the last short integer before the start of the data proper to the number of unused bytes written to the output packet.
static void post (void *buf, int nbytes, int nhdr, int nunused, CCSDS_ostreamPoster postRtn, void *postPrm)
 Posts the specified buffer using the specified posting routine and parameter. The CCSDS header and data are appropriately byte-swapped to big-endian style if necessary.
int CCSDS_ostreamDestroy (CCSDS_ostream *ostream)
 Frees any resources associated with the specified stream.
CCSDS_ostreamCCSDS_ostreamNew (void)
 Allocates enough memory for, but does not initialize an CCSDS_ostream structure.
int CCSDS_ostreamSizeof (void)
 Returns the size, in bytes, of the CCSDS output stream control structure CCSDS_ostream.
void CCSDS_ostreamConstruct (CCSDS_ostream *ostream, CCSDS_ostreamPoster postRtn, void *postPrm, unsigned short int sequence, unsigned short int max_write)
 Constructs/Initializes the Post Control Block.
void * CCSDS_ostreamPost (CCSDS_ostream *ostream, void *buf, int nbytes)
 Routine to write the data to post the data. The buffer is broken in multiple CCSDS packets, with the size limited to 4096-128 bytes.

Detailed Description

Routine to post an CCSDS wrapped data to an output stream, formatting obeying the LCB buffering rules.

Author:
JJRussell - russell@slac.stanford.edu
   CVS $Id: CCSDS_ostream.c,v 1.6 2006/01/06 00:21:44 russell Exp $

Overview
This set of routines is used mainly to simulate the results of posting a buffer to the SSR. As such it will likely not fly, not exist only as test code.
The facility chops a CCSDS input packet into LCB size pieces and then calls a user provided posting routine to perform the physical write. In most cases, this posting routine will do a simple write to a file.
Warning:
This is not an exact emulation of the scheme that does write to the SSR. While it does obey the physical constraint of quantizing the packet writes, the quantization is not exactly correct. This scheme uses a 16n whereas the right one is 12 + 16n. It also does not simulate the variation that comes with the initial buffer alignment. In the real hardware, the buffer alignment must be 512.

Define Documentation

#define RND_TO _x,
_r   )     ((((_x) + (_r) -1) / (_r)) * (_r))
 

Rounds the specified number, _x up to the nearest multiple of _r.

Returns:
The rounded number
Parameters:
_x The number to round
_r The number to round up to


Function Documentation

void CCSDS_ostreamConstruct CCSDS_ostream ostream,
CCSDS_ostreamPoster  postRtn,
void *  postPrm,
unsigned short int  sequence,
unsigned short int  max_write
 

Constructs/Initializes the Post Control Block.

Parameters:
ostream The output stream handle
postRtn The user provide physical posting routine
postPrm The user provide parameter to the post routine
sequence The starting CCSDS sequence number to use. This is almost always 0, but is provided as a parameter for testing purposes
max_write The maximum packet size to be written. This must be at least 32 (although why anyone would make it that small would be a mystery) and no bigger than 4096 - 32. If it is not a multiple of 16 bytes, it will be rounded up to the nearest 16 bytes boundary and then limited to the maximum of 4096 - 32.

int CCSDS_ostreamDestroy CCSDS_ostream ostream  ) 
 

Frees any resources associated with the specified stream.

Returns:
Status, currently always success (0)
Parameters:
ostream The output stream handle to destroy

CCSDS_ostream* CCSDS_ostreamNew void   ) 
 

Allocates enough memory for, but does not initialize an CCSDS_ostream structure.

Returns:
Pointer to the allocated CCSDS_ostream structure or NULL on failure.

void* CCSDS_ostreamPost CCSDS_ostream ostream,
void *  buf,
int  nbytes
 

Routine to write the data to post the data. The buffer is broken in multiple CCSDS packets, with the size limited to 4096-128 bytes.

Returns:
Pointer to the next buffer to be filled
Parameters:
ostream The output stream handle
buf The buffer to output
nbytes The size of the output buffer, in bytes.

int CCSDS_ostreamSizeof void   ) 
 

Returns the size, in bytes, of the CCSDS output stream control structure CCSDS_ostream.

Returns:
Size, in bytes, of the post control structure CCSDS_ostream

void post void *  buf,
int  nbytes,
int  nhdr,
int  nunused,
CCSDS_ostreamPoster  postRtn,
void *  postPrm
[static]
 

Posts the specified buffer using the specified posting routine and parameter. The CCSDS header and data are appropriately byte-swapped to big-endian style if necessary.

Parameters:
buf The buffer to post
nbytes The size, in bytes, of the buffer, including the header. This must be a multiple of 4-bytes.
nhdr The number of bytes in the header. This most be a multiple of 4 bytes less 2 bytes for the pad word.
nunused The number of unused (pad bytes) needed to round the actual payload to a multiple of 4 bytes
postRtn The posting routine
postPrm The posting parameter

static __inline void setUnused unsigned char *  cur,
int  offset,
unsigned short int  unused_bytes
[static]
 

Sets the last short integer before the start of the data proper to the number of unused bytes written to the output packet.

Parameters:
cur The base pointer
offset The byte offset from cur to the 16-bit address to store the number of unused bytes
unused_bytes The number of unused bytes that are padding the data packet


Generated on Wed Aug 27 01:34:54 2008 by  doxygen 1.4.4