\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 $<$LCBT/TDATA.h$>$}\par
{\tt \#include $<$LCBT/LCBT\_\-initBoard.h$>$}\par
{\tt \#include $<$LCBT\_\-printf.h$>$}\par
{\tt \#include $<$PBS/WCT.h$>$}\par
{\tt \#include $<$CCSDS/CCSDS\_\-pkt.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{TDATA_8c_8204e7ffce7a5793dabd4dcc26628086}{TDATA\_\-create} (unsigned short $\ast$ptr, int lenIn16b, int ccsds, \hyperlink{TDATA_8h_fafb1ba1ffdfa0f77e907069435b6f43}{TDATA\_\-DTEST} testType, unsigned int testParm)
\begin{CompactList}\small\item\em Create a self describing test data buffer. \item\end{CompactList}\item 
void \hyperlink{TDATA_8c_bdfec9c6de2718bc02cba74ee22da2ca}{TDATA\_\-setCcsdsParms} (unsigned int appId)
\begin{CompactList}\small\item\em set prameters for all CCSDS packets \item\end{CompactList}\item 
int \hyperlink{TDATA_8c_2ae974be1ad65fba40d4e323970989eb}{TDATA\_\-compare} (unsigned short $\ast$ptr, int lenIn16b, int ccsds, int printErrs)
\begin{CompactList}\small\item\em Analyse a self describing test data buffer for errors. \item\end{CompactList}\item 
int \hyperlink{TDATA_8c_7f7494294b2d96510c82660974939391}{TDATA\_\-compareSeq} (unsigned short $\ast$ptr, int lenIn16b, int seq, int ccsds, int printErrs)
\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_fad11ec72d534452f2e038d7ebe0c7f0}{TDATA\_\-getRandCtxForSeqVal} (unsigned int seed)
\begin{CompactList}\small\item\em Create contex to use with \hyperlink{TDATA_8h_2e61fe73cdbd6b14e5bdbfa1f9867ec3}{TDATA\_\-getNextSeqVal()}. \item\end{CompactList}\item 
unsigned int \hyperlink{TDATA_8c_1a05f13ab567e3790419ee68cde920bc}{TDATA\_\-getNextSeqVal} (\hyperlink{TDATA_8h_fafb1ba1ffdfa0f77e907069435b6f43}{TDATA\_\-DTEST} testType, unsigned int testParm, int idx, unsigned int $\ast$randCtx)
\begin{CompactList}\small\item\em Create a data sequence one word at a time. \item\end{CompactList}\item 
char $\ast$ \hyperlink{TDATA_8c_2c9f14613b1d85a4e2f2a8df0d363058}{TDATA\_\-testStr} (\hyperlink{TDATA_8h_fafb1ba1ffdfa0f77e907069435b6f43}{TDATA\_\-DTEST} testType)
\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} Self describing test data packet format is :\end{Desc}
14 bytes - optional CCSDS header, default AppId=0x3bf 8 bytes header defined as follows unsigned short lenIn16b - length of this heeader plus data buffer to follow (does not include length of the optional CCSDS packet or 32b synch workd before CCSDS) unsigned short where top unsigned byte checksum - checksum of header bottom unsigned byte testType - type of test data packet (see below)

unsigned short testParm - parameter related to test data packet type unsigned short taskId - id of producing task (to differentiate between different senders) 2$\ast$lenIn16b bytes of data buffer

The testType and use of testParm is as follows:

testType = TDATA\_\-DTEST\_\-CONSTANT = 1 testParm = 16b constant value to be repeated as data

testType = TDATA\_\-DTEST\_\-INCREMENT = 0 testParm = 16b start value that is incremented on each 16b word

testType = TDATA\_\-DTEST\_\-RANDOM = 2 testParm = seed value for random generator, values are 16b but appear random in all dTypes

testType = TDATA\_\-DTEST\_\-WALK1 = 3 testParm = 8=walk on bytes, 16=walk on 16b words, 32=walk on 32b words

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

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

testType = DTEST\_\-TASKID = 6 testParm = (not used)

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

\subsection{Function Documentation}
\hypertarget{TDATA_8c_2ae974be1ad65fba40d4e323970989eb}{
\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 lenIn16b}, \/  int {\em ccsds}, \/  int {\em printErrs})}}
\label{TDATA_8c_2ae974be1ad65fba40d4e323970989eb}


Analyse a self describing test data buffer for errors. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]\item[{\em lenIn16b}]\item[{\em ccsds}]1=expect CCSDS header on data \item[{\em printErrs}]1=print errors as found \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]number of errors detected This checks a data buffer created with \hyperlink{TDATA_8h_8204e7ffce7a5793dabd4dcc26628086}{TDATA\_\-create()}. The buffer is assumd to be complete. Buffers broken into sequences should use TDATA\_\-compareSeq.\end{Desc}
WARNING: Because of the sequence handling, this routine is no longer thread safe. Itassumes a single thread is calling it and that sequences of buffer segments are received in order. 

References TDATA\_\-compareSeq().\hypertarget{TDATA_8c_7f7494294b2d96510c82660974939391}{
\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\_\-compareSeq (unsigned short $\ast$ {\em ptr}, \/  int {\em lenIn16b}, \/  int {\em seq}, \/  int {\em ccsds}, \/  int {\em printErrs})}}
\label{TDATA_8c_7f7494294b2d96510c82660974939391}


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 lenIn16b}]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 printErrs}]1=print errors as found \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]number of errors detected This checks a data buffer created with \hyperlink{TDATA_8h_8204e7ffce7a5793dabd4dcc26628086}{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.\end{Desc}
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. 

References EPRINTF, TDATA\_\-DTEST\_\-CONSTANT, TDATA\_\-DTEST\_\-INCREMENT, TDATA\_\-DTEST\_\-RANDOM, TDATA\_\-DTEST\_\-TASKID, TDATA\_\-DTEST\_\-TRANS01, TDATA\_\-DTEST\_\-TRANS10, and TDATA\_\-DTEST\_\-WALK1.

Referenced by LCBTB\_\-echo(), and TDATA\_\-compare().\hypertarget{TDATA_8c_8204e7ffce7a5793dabd4dcc26628086}{
\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 lenIn16b}, \/  int {\em ccsds}, \/  {\bf TDATA\_\-DTEST} {\em testType}, \/  unsigned int {\em testParm})}}
\label{TDATA_8c_8204e7ffce7a5793dabd4dcc26628086}


Create a self describing test data buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]\item[{\em lenIn16b}]- 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 testType}]Specifies the data sequence for test \item[{\em testParm}]Parm to use with testType \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none This creates a data buffer with an 8 byte header that describes the data so that \hyperlink{TDATA_8h_2ae974be1ad65fba40d4e323970989eb}{TDATA\_\-compare()} can compare and determine if the data has been corrupted.\end{Desc}
The testType and use of testParm is as follows:

testType = TDATA\_\-DTEST\_\-CONSTANT testParm = 16b constant value to be repeated as data

testType = TDATA\_\-DTEST\_\-INCREMENT testParm = 16b start value that is incremented on each 16b word

testType = TDATA\_\-DTEST\_\-RANDOM testParm = seed value for ranom generator, values are 16b but appear random in all dTypes

testType = TDATA\_\-DTEST\_\-WALK1 testParm = 8=walk on bytes, 16=walk on 16b words, 32=walk on 32b words

testType = TDATA\_\-DTEST\_\-TRANS01 testParm = number of bits of 0's before all 1's in each packet

testType = TDATA\_\-DTEST\_\-TRANS10 testParm = number of bits of 1's before all 0's in each packet 

References TDATA\_\-DTEST\_\-CONSTANT, TDATA\_\-DTEST\_\-INCREMENT, TDATA\_\-DTEST\_\-RANDOM, TDATA\_\-DTEST\_\-TASKID, TDATA\_\-DTEST\_\-TRANS01, TDATA\_\-DTEST\_\-TRANS10, and TDATA\_\-DTEST\_\-WALK1.\hypertarget{TDATA_8c_1a05f13ab567e3790419ee68cde920bc}{
\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\_\-getNextSeqVal ({\bf TDATA\_\-DTEST} {\em testType}, \/  unsigned int {\em testParm}, \/  int {\em idx}, \/  unsigned int $\ast$ {\em randCtx})}}
\label{TDATA_8c_1a05f13ab567e3790419ee68cde920bc}


Create a data sequence one word at a time. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em testType}]type of data sequence \item[{\em testParm}]parm for data sequence \item[{\em idx}]index into sequence \item[{\em randCtx}]if testType==TDATA\_\-DTEST\_\-RANDOM, supply pointer to int returned from \hyperlink{TDATA_8h_3d22ccbedcd99c01f4e435ce51208af2}{TDATA\_\-getRandCtxForSeqVal()} \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]data value in sequence Create a data sequence one word at a time. TDATA\_\-initSeq() needs to be called first. \end{Desc}


References TDATA\_\-DTEST\_\-CONSTANT, TDATA\_\-DTEST\_\-INCREMENT, TDATA\_\-DTEST\_\-RANDOM, TDATA\_\-DTEST\_\-TASKID, TDATA\_\-DTEST\_\-TRANS01, TDATA\_\-DTEST\_\-TRANS10, and TDATA\_\-DTEST\_\-WALK1.\hypertarget{TDATA_8c_fad11ec72d534452f2e038d7ebe0c7f0}{
\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\_\-getRandCtxForSeqVal (unsigned int {\em seed})}}
\label{TDATA_8c_fad11ec72d534452f2e038d7ebe0c7f0}


Create contex to use with \hyperlink{TDATA_8h_2e61fe73cdbd6b14e5bdbfa1f9867ec3}{TDATA\_\-getNextSeqVal()}. 

\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_bdfec9c6de2718bc02cba74ee22da2ca}{
\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\_\-setCcsdsParms (unsigned int {\em appId})}}
\label{TDATA_8c_bdfec9c6de2718bc02cba74ee22da2ca}


set prameters for all CCSDS packets 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em appId}]set the AppId fiels within CCSDS header \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none \end{Desc}
\hypertarget{TDATA_8c_2c9f14613b1d85a4e2f2a8df0d363058}{
\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\_\-testStr ({\bf TDATA\_\-DTEST} {\em testType})}}
\label{TDATA_8c_2c9f14613b1d85a4e2f2a8df0d363058}


convert test type enum to a string 

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


References TDATA\_\-DTEST\_\-CONSTANT, TDATA\_\-DTEST\_\-INCREMENT, TDATA\_\-DTEST\_\-RANDOM, TDATA\_\-DTEST\_\-TASKID, TDATA\_\-DTEST\_\-TRANS01, TDATA\_\-DTEST\_\-TRANS10, and TDATA\_\-DTEST\_\-WALK1.