• Antelope Release 5.10 Linux CentOS release 7.6.1810 (Core) 3.10.0 2020-05-12

 

NAME

pktchannel2buffer_create, pktchannel2buffer_free, pktchannel2buffer_put, pktchannel2buffer_flush, pktchannel2buffer_chan_copy, pktchannel2buffer_chan_free - trace data buffer

SYNOPSIS

#include "brttpkt.h"

PktChannel2Buffer *pktchannel2buffer_create (
      int (*flush_callback) (PktChannel2BufferChan *bchan, void *user_data),
      void *flush_callback_user_data)

void pktchannel2buffer_free (PktChannel2Buffer *pbuf)

int pktchannel2buffer_put (PktChannel2Buffer *buf, PktChannel *pktchan,
      long maxheap, double maxduration, int verbose)

int pktchannel2buffer_flush (PktChannel2Buffer *buf)

PktChannel2BufferChan *pktchannel2buffer_chan_copy (PktChannel2BufferChan *cbuf)

void pktchannel2buffer_chan_free (PktChannel2BufferChan *cbuf)

DESCRIPTION

These routines provide a utility for buffering waveform data into time contiguous segments. Data is accumulated for each channel into buffers until one of the following conditions causes the buffer to be flushed and a new buffer to be started.
  • srate
    The samplerate of a new packet is different from the samplerate of the buffered data.
  • time
    The time of the first sample of a new packet is different from the projected next sample time value of the buffered data.
  • calib
    The calib value of the new packet is different from the calib value of the buffered data.
  • calper
    The calper value of the new packet is different from the calper value of the buffered data.
  • isfloat
    The sample value formats of the new packet are different from the sample value formats of the buffered data.
  • segtype
    The segtype value of the new packet is different from the segtype value of the buffered data.
  • heap
    The total memory heap allocation for this channel exceeds the specified maximum.
  • duration
    The total time duration for this channel exceeds the specified maximum.

pktchannel2buffer_create creates a new PktChannel2Buffer object and returns a pointer to the object instance. This pointer is used as a handle for subsequent operations. flush_callback specifies a user callback function that is called whenever a buffer is full and needs to be flushed. The callback function is called with the following syntax:


int flush_callback (PktChannel2BufferChan *bchan, void *userdata)

The private pointer passed to pktchannel2buffer_create, flush_callback_user_data, is passed back to flush_callback along with the particular bchan channel that needs to be processed. flush_callback returns 0 for success, and a negative value if any error occurred. Note that the memory associated with the bchan object as automatically freed as soon as flush_callback returns, so the user should make copies of this object if the memory is required. The PktChannel2BufferChan structure given to the callback routine is defined as follows:


typedef struct pktchannel2buffer_chan_ {
	char snet[8];      /* Seed net code */
	char ssta[16];     /* Seed sta code */
	char schan[16];    /* Seed chan code */
	char sloc[8];      /* SEED loc code */
	char why[8];       /* reason why buffer is being flushed */
	double samprate;   /* sample rate */
	double calib;      /* data calib value */
	double calper;     /* data calper value */
	char segtype[4];   /* data segtype value */
	char datatype[4];  /* data datatype, one of i4, s4, f4, t4 */
	double time;       /* time of first sample */
	int nsamp;         /* number of samples */
	int isfloat;       /* is data in floating point? */
	size_t data_size;  /* heap size of data buffer */
	int *data;         /* sample data */
	size_t heap;       /* total heap size of this packet */
} PktChannel2BufferChan;

A PktChannel2Buffer object is freed with pktchannel2buffer_free.

pktchannel2buffer_put will put a single PktChannel packet of data into a PktChannel2Buffer object. A maximum heap memory allocation for this channel buffer can be specified with maxheap and a maximum time duration for this channel buffer can be specified with maxduration. If either of these is 0, then buffer flushing will happen immediately. If either of these is -1, then that threshold will not effect buffer flushing at all. Verbose logging is accomplished through verbose. The flush callback routine is called automatically whenever the various conditions are satisfied as described previously.

pktchannel2buffer_flush will force flushing of all currently active buffers.

pktchannel2buffer_chan_copy is a utility routine for making copies of PktChannel2BufferChan objects.

pktchannel2buffer_chan_free is a utility routine for freeing copies of PktChannel2BufferChan objects.

RETURN VALUES

pktchannel2buffer_create returns a PktChannel2Buffer process handle (pointer to a PktChannel2Buffer structure) or NULL if there is an error. pktchannel2buffer_chan_copy returns a PktChannel2BufferChan process handle (pointer to a PktChannel2BufferChan structure) or NULL if there is an error. If there is an error, then messages are left on the error register.

Everything else returns 0 if OK or -1 if there is an error. If there is an error, then messages are left on the error register.

LIBRARY

-lbrttpkt $(ORBLIBS)

AUTHOR

Danny Harvey
Printer icon