\chapter{Control software}\label{ch:controlsw}
The preferred method to run the \gls{tlu} is by using the \href{https://github.com/eudaq/eudaq}{EUDAQ}\footnote{https://github.com/eudaq/eudaq} data acquisition framework.\\
A \gls{tlu} producer, based on C++, has been written to integrate the hardware in EUDAQ and is regularly pushed to the master repository. Checking out the latest EUDAQ software ensures to also have a stable version of the producer.\\
In addition to the EUDAQ producer, a set of Python scripts has been developed to enable users to configure and run the \gls{tlu} using a minimal environment without having to setup the whole data acquisition framework. The scripts are meant to reflect all the functionalities in the EUDAQ producers, i.e. using the scripts it should be possible to perform any operation available on the EUDAQ producer. However, they should only be used for local debugging and testing.\\
\begin{alertinfo}{Warning}
    When fixing bus or developing new software for the \gls{tlu}, priority will be given to ensure that the EUDAQ producer is patched first. As a consequence, there is a higher chance to find bugs in the Python scripts. 
\end{alertinfo}


\section{EUDAQ Producer}\label{ch:eudaqprod}
Current structure of a fmctlu producer event:
\lstset{language=XML}
\scriptsize
\begin{lstlisting}
<Event>
  <Type>2149999981</Type>
  <Extendword>171577627</Extendword>
  <Description>Ex0Tg</Description>
  <Flag>0x00000018</Flag>
  <RunN>0</RunN>
  <StreamN>0</StreamN>
  <EventN>0</EventN>
  <TriggerN>88</TriggerN>
  <Timestamp>0x0000000000000000  ->  0x0000000000000000</Timestamp>
  <Timestamp>0  ->  0</Timestamp>
  <Block_Size>0</Block_Size>
  <SubEvents>
    <Size>1</Size>
    <Event>
      <Type>2149999981</Type>
      <Extendword>3634980144</Extendword>
      <Description>TluRawDataEvent</Description>
      <Flag>0x00000010</Flag>
      <RunN>96</RunN>
      <StreamN>4008428646</StreamN>
      <EventN>88</EventN>
      <TriggerN>88</TriggerN>
      <Timestamp>0x0000000105b44f91  ->  0x0000000105b44faa</Timestamp>
      <Timestamp>4390670225  ->  4390670250</Timestamp>
      <Tags>
        <Tag>PARTICLES=89</Tag>
        <Tag>SCALER0=93</Tag>
        <Tag>SCALER1=93</Tag>
        <Tag>SCALER2=0</Tag>
        <Tag>SCALER3=0</Tag>
        <Tag>SCALER4=0</Tag>
        <Tag>SCALER5=0</Tag>
        <Tag>TEST=110011</Tag>
        <Tag>trigger=</Tag>
      </Tags>
      <Block_Size>0</Block_Size>
    </Event>
  </SubEvents>
</Event>
\end{lstlisting}
\normalsize
\begin{description}
  \item[Type] ??
  \item[ExtendWord] ??
  \item[Description]
  \item[Flag] Independent from producer. See the \href{https://github.com/eudaq/eudaq/blob/master/main/lib/core/include/eudaq/Event.hh#L87}{EUDAQ documentation} for details.
  \item[RunN]
  \item[StreamN]
  \item[EventN]
  \item[TriggerN] Both in the event and subevent this is written byt the producer with \verb|ev->SetTriggerN(trigger_n);|
  \item[Timestamp] The event timestamp is currently always 0. The subevent timestamps is written by the producer \verb|ev->SetTimestamp(ts_ns, ts_ns+25, false);|. The top line (0x0000000105b44f91, in the example) is coarse time stamp multiplied by 25, so it represents the time in nanoseconds. The bottom one (4390670225) is the same number but written in decimal format instead of hexadecimal.
  \item[PARTICLES] Number of pre-veto triggers recorded by the \gls{tlu}: the trigger logic can detect a valid trigger condition even when the unit is vetoed. In this case no trigger is issued to the \gls{dut}s but the number of such triggers is stored as number of particles. \verb|ev->SetTag("PARTICLES", std::to_string(pt));|
  \item[SCALER\#] Number of triggers edges seen by the specific discriminator. \verb|ev->SetTag("SCALER", std::to_string(sl));|
  \item[???] Event type from \gls{tlu} is missing?
  \item[???] Input trig, i.e. the actual firing inputs should be in TRIGGER but there seems to be nothing there
\end{description}

\section{Python scripts}
The scripts used to debug work locally with the \gls{tlu} are located in a dedicated folder in the \href{https://github.com/PaoloGB/firmware_AIDA/tree/master/TLU_v1e/scripts}{firmware repository}\footnote{https://github.com/PaoloGB/firmware\_AIDA/tree/master/TLU\_v1e/scripts} and rely on additional packages and software.
First of all, the user should download the \href{https://github.com/PaoloGB/firmware_AIDA/tree/master/packages}{packages} used to control the various components of the hardware\footnote{https://github.com/PaoloGB/firmware\_AIDA/tree/master/packages}. It is also necessary to have a local installation of \href{https://ipbus.web.cern.ch/ipbus/doc/user/html/index.html}{IPBUS and uHAL}\footnote{https://ipbus.web.cern.ch/ipbus/doc/user/html/index.html}.\\
Once all the necessary packages have been installed and the environment is set to point to the right folders, it is possible to run the \verb|startTLU_v1e.py| script to start an interface that allows to operate the \gls{tlu}.
 