\hypertarget{TDATA_8c}{
\section{TDATA.c File Reference}
\label{TDATA_8c}\index{TDATA.c@{TDATA.c}}
}
Module to create and check a self-describing test data packet. 

{\tt \#include \char`\"{}LCBT/TDATA.h\char`\"{}}\par
{\tt \#include \char`\"{}LCBT/LCBT\_\-init\-Board.h\char`\"{}}\par
{\tt \#include \char`\"{}LCBT\_\-printf.h\char`\"{}}\par
{\tt \#include \char`\"{}PBS/WCT.h\char`\"{}}\par
{\tt \#include \char`\"{}CCSDS/CCSDS\_\-pkt.h\char`\"{}}\par


Include dependency graph for TDATA.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=214pt]{TDATA_8c__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{TDATA_8c_a0}{TDATA\_\-create} (unsigned short $\ast$ptr, int len\-In16b, int ccsds, \hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} test\-Type, unsigned int test\-Parm)
\begin{CompactList}\small\item\em Create a self describing test data buffer. \item\end{CompactList}\item 
void \hyperlink{TDATA_8c_a1}{TDATA\_\-set\-Ccsds\-Parms} (unsigned int app\-Id)
\begin{CompactList}\small\item\em set prameters for all CCSDS packets \item\end{CompactList}\item 
int \hyperlink{TDATA_8c_a2}{TDATA\_\-compare} (unsigned short $\ast$ptr, int len\-In16b, int ccsds, int print\-Errs)
\begin{CompactList}\small\item\em Analyse a self describing test data buffer for errors. \item\end{CompactList}\item 
int \hyperlink{TDATA_8c_a3}{TDATA\_\-compare\-Seq} (unsigned short $\ast$ptr, int len\-In16b, int seq, int ccsds, int print\-Errs)
\begin{CompactList}\small\item\em Analyse a buffer segment of a self describing test data buffer for errors. \item\end{CompactList}\item 
unsigned int \hyperlink{TDATA_8c_a4}{TDATA\_\-get\-Rand\-Ctx\-For\-Seq\-Val} (unsigned int seed)
\begin{CompactList}\small\item\em Create contex to use with \hyperlink{TDATA_8h_a13}{TDATA\_\-get\-Next\-Seq\-Val()}. \item\end{CompactList}\item 
unsigned int \hyperlink{TDATA_8c_a5}{TDATA\_\-get\-Next\-Seq\-Val} (\hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} test\-Type, unsigned int test\-Parm, int idx, unsigned int $\ast$rand\-Ctx)
\begin{CompactList}\small\item\em Create a data sequence one word at a time. \item\end{CompactList}\item 
char $\ast$ \hyperlink{TDATA_8c_a6}{TDATA\_\-test\-Str} (\hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} test\-Type)
\begin{CompactList}\small\item\em convert test type enum to a string \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Module to create and check a self-describing test data packet. 

\begin{Desc}
\item[Author:]Ed Bacho -- \href{mailto:ebacho@slac.stanford.edu}{\tt ebacho@slac.stanford.edu}\end{Desc}
Self describing test data packet format is :

14 bytes - optional CCSDS header, default App\-Id=0x3bf 8 bytes header defined as follows unsigned short len\-In16b - length of this heeader plus data buffer to follow (does not include legth of optional CCSDS packet or 32b synch workd before CCSDS) unsigned short where top unsigned byte checksum - checksum of header bottom unsigned byte test\-Type - type of test data packet (see below) unsigned short test\-Parm - parameter related to test data packet type unsigned short task\-Id - id of producing task (to differentiate between different senders) 2$\ast$len\-In16b bytes of data buffer

The test\-Type and use of test\-Parm is as follows:

test\-Type = TDATA\_\-DTEST\_\-CONSTANT = 1 test\-Parm = 16b constant value to be repeated as data

test\-Type = TDATA\_\-DTEST\_\-INCREMENT = 0 test\-Parm = 16b start value that is incremented on each 16b word

test\-Type = TDATA\_\-DTEST\_\-RANDOM = 2 test\-Parm = seed value for ranom generator, values are 16b but appear random in all d\-Types

test\-Type = TDATA\_\-DTEST\_\-WALK1 = 3 test\-Parm = 8=walk on bytes, 16=walk on 16b words, 32=walk on 32b words

test\-Type = TDATA\_\-DTEST\_\-TRANS01 = 4 test\-Parm = number of bits of 0's before all 1's in each packet

test\-Type = TDATA\_\-DTEST\_\-TRANS10 = 5 test\-Parm = number of bits of 1's before all 0's in each packet

test\-Type = DTEST\_\-TASKID = 6 test\-Parm = (not used)

The data buffer is assumed to be an array of short (16 bit) data words

\subsection{Function Documentation}
\hypertarget{TDATA_8c_a2}{
\index{TDATA.c@{TDATA.c}!TDATA_compare@{TDATA\_\-compare}}
\index{TDATA_compare@{TDATA\_\-compare}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-compare]{\setlength{\rightskip}{0pt plus 5cm}int TDATA\_\-compare (unsigned short $\ast$ {\em ptr}, int {\em len\-In16b}, int {\em ccsds}, int {\em print\-Errs})}}
\label{TDATA_8c_a2}


Analyse a self describing test data buffer for errors. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]\item[{\em len\-In16b}]\item[{\em ccsds}]1=expect CCSDS header on data \item[{\em print\-Errs}]1=print errors as found \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]number of errors detected\end{Desc}
This checks a data buffer created with \hyperlink{TDATA_8h_a8}{TDATA\_\-create()}. The buffer is assumd to be complete. Buffers broken into sequences should use TDATA\_\-compare\-Seq.

WARNING: Because of the sequence handling, this routine is no longer thread safe. It assumes a single thread is calling it and that sequences of buffer segments are received in order.\hypertarget{TDATA_8c_a3}{
\index{TDATA.c@{TDATA.c}!TDATA_compareSeq@{TDATA\_\-compareSeq}}
\index{TDATA_compareSeq@{TDATA\_\-compareSeq}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-compareSeq]{\setlength{\rightskip}{0pt plus 5cm}int TDATA\_\-compare\-Seq (unsigned short $\ast$ {\em ptr}, int {\em len\-In16b}, int {\em seq}, int {\em ccsds}, int {\em print\-Errs})}}
\label{TDATA_8c_a3}


Analyse a buffer segment of a self describing test data buffer for errors. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]The buffer segment to be compared \item[{\em len\-In16b}]length of this seqment \item[{\em seq}]sequence number of this buffer segment where seq=0 is the first \item[{\em ccsds}]1=expect CCSDS header on data \item[{\em print\-Errs}]1=print errors as found \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]number of errors detected\end{Desc}
This checks a data buffer created with \hyperlink{TDATA_8h_a8}{TDATA\_\-create()}. However this routine will alloc one to check the buffer when it is broken into a number segments (as done by the EBM, Event Builder Module). The sequence number of the segment must be specified and seq=0 MUST be first. Info about the buffer is stored staticly on seq=0 and used when seq!=0.

WARNING: Because of the sequence handling, this routine is no longer thread safe. It assumes a single thread is calling it and that sequences of buffer segments are received in order.\hypertarget{TDATA_8c_a0}{
\index{TDATA.c@{TDATA.c}!TDATA_create@{TDATA\_\-create}}
\index{TDATA_create@{TDATA\_\-create}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-create]{\setlength{\rightskip}{0pt plus 5cm}void TDATA\_\-create (unsigned short $\ast$ {\em ptr}, int {\em len\-In16b}, int {\em ccsds}, \hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} {\em test\-Type}, unsigned int {\em test\-Parm})}}
\label{TDATA_8c_a0}


Create a self describing test data buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]\item[{\em len\-In16b}]- total length of buffer including 8 byte header, data, and optional 14 byte CCSDS \item[{\em ccsds}]1=put CCSDS header on data sent out as event \item[{\em test\-Type}]Specifies the data sequence for test \item[{\em test\-Parm}]Parm to use with test\-Type \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
This creates a data buffer with an 8 byte header that describes the data so that \hyperlink{TDATA_8h_a9}{TDATA\_\-compare()} can compare and determine if the data has been corrupted.

The test\-Type and use of test\-Parm is as follows:

test\-Type = TDATA\_\-DTEST\_\-CONSTANT test\-Parm = 16b constant value to be repeated as data

test\-Type = TDATA\_\-DTEST\_\-INCREMENT test\-Parm = 16b start value that is incremented on each 16b word

test\-Type = TDATA\_\-DTEST\_\-RANDOM test\-Parm = seed value for ranom generator, values are 16b but appear random in all d\-Types

test\-Type = TDATA\_\-DTEST\_\-WALK1 test\-Parm = 8=walk on bytes, 16=walk on 16b words, 32=walk on 32b words

test\-Type = TDATA\_\-DTEST\_\-TRANS01 test\-Parm = number of bits of 0's before all 1's in each packet

test\-Type = TDATA\_\-DTEST\_\-TRANS10 test\-Parm = number of bits of 1's before all 0's in each packet\hypertarget{TDATA_8c_a5}{
\index{TDATA.c@{TDATA.c}!TDATA_getNextSeqVal@{TDATA\_\-getNextSeqVal}}
\index{TDATA_getNextSeqVal@{TDATA\_\-getNextSeqVal}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-getNextSeqVal]{\setlength{\rightskip}{0pt plus 5cm}unsigned int TDATA\_\-get\-Next\-Seq\-Val (\hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} {\em test\-Type}, unsigned int {\em test\-Parm}, int {\em idx}, unsigned int $\ast$ {\em rand\-Ctx})}}
\label{TDATA_8c_a5}


Create a data sequence one word at a time. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em test\-Type}]type of data sequence \item[{\em test\-Parm}]parm for data sequence \item[{\em idx}]index into sequence \item[{\em rand\-Ctx}]if test\-Type==TDATA\_\-DTEST\_\-RANDOM, supply pointer to int returned from \hyperlink{TDATA_8h_a12}{TDATA\_\-get\-Rand\-Ctx\-For\-Seq\-Val()} \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]data value in sequence\end{Desc}
Create a data sequence one word at a time. TDATA\_\-init\-Seq() needs to be called first.\hypertarget{TDATA_8c_a4}{
\index{TDATA.c@{TDATA.c}!TDATA_getRandCtxForSeqVal@{TDATA\_\-getRandCtxForSeqVal}}
\index{TDATA_getRandCtxForSeqVal@{TDATA\_\-getRandCtxForSeqVal}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-getRandCtxForSeqVal]{\setlength{\rightskip}{0pt plus 5cm}unsigned int TDATA\_\-get\-Rand\-Ctx\-For\-Seq\-Val (unsigned int {\em seed})}}
\label{TDATA_8c_a4}


Create contex to use with \hyperlink{TDATA_8h_a13}{TDATA\_\-get\-Next\-Seq\-Val()}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em seed}]seed value for random number generator \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]contex to be used for random number generator\end{Desc}
\hypertarget{TDATA_8c_a1}{
\index{TDATA.c@{TDATA.c}!TDATA_setCcsdsParms@{TDATA\_\-setCcsdsParms}}
\index{TDATA_setCcsdsParms@{TDATA\_\-setCcsdsParms}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-setCcsdsParms]{\setlength{\rightskip}{0pt plus 5cm}void TDATA\_\-set\-Ccsds\-Parms (unsigned int {\em app\-Id})}}
\label{TDATA_8c_a1}


set prameters for all CCSDS packets 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em app\-Id}]set the App\-Id fiels within CCSDS header \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
\hypertarget{TDATA_8c_a6}{
\index{TDATA.c@{TDATA.c}!TDATA_testStr@{TDATA\_\-testStr}}
\index{TDATA_testStr@{TDATA\_\-testStr}!TDATA.c@{TDATA.c}}
\subsubsection[TDATA\_\-testStr]{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ TDATA\_\-test\-Str (\hyperlink{TDATA_8h_a0}{TDATA\_\-DTEST} {\em test\-Type})}}
\label{TDATA_8c_a6}


convert test type enum to a string 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em test\-Type}]enum to turn to string \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]string of given enum\end{Desc}
