%! TEX root = ../thesis.tex
\chapter{Appendix - Firmware}
\section{Virtual Memory Mapping}
THe biggest Change done to the Firmware was the implementation of a new communication protocol.
This protocol uses the following table as reference

\begin{figure}
   \centering
   \input{./tabs/registerbuffer}
   \caption{}%
   \label{registerbuffer} 
\end{figure}

\section{How to calibrate a PowerIt Board}

The Calibration process is based on the PItSTOP Python scripts\footnote{
%  TODO: insert repo, and link to docs
    \href{https://acereca.ddns.net:11443/acereca/pitstop}{PItSTOP repository}
}.
These are split into \verb|server| and \verb|aggregator|. While the Server is handling the translation between raw I$^2$C data, and the JSON formatted result, the Aggregator takes this JSON and calculates a calibration.

Using the script any one of the following Values can be tested and calibrated:
\begin{itemize}
    \item Input Voltage (\verb|pitstop.Aggregator.test_v_48()|)
    \item Input Current (\verb|pitstop.Aggregator.test_i_48()|)
    \item 9.6V Output Voltage (\verb|pitstop.Aggregator.test_v_10()|)
    \item 1.8V Output Voltage (\verb|pitstop.Aggregator.test_v_18()|)
    \item 1.8V Output Current (\verb|pitstop.Aggregator.test_i_18()|)
\end{itemize}

\subsection{Setting up the Test Environment}
The simplest way to setup an environment consists of cloning the PItSTOP project on a client:
\begin{mintylst}{bash}

    > git clone https://url.to.pitstop

\end{mintylst}
then substituting the \verb|rsync| target:
\begin{mintylst}[label={makefile}]{makefile}
    all:
        rsync --progress ./*.py /remote.url/
\end{mintylst}

, to be your server (should be a RaspberryPi connected to the PowerIt) 

\subsection{Running a Test}
Running the test requires the following commands
\\
Serverside:
\begin{mintylst}{bash}
    > python server.py
\end{mintylst}
Clientside:
\begin{mintylst}{bash}
    > python aggregator.py
\end{mintylst}
Now just following the instructions given, the selected test can be run:
\begin{mintylst}{text}
    Setting up calibration test for {}
    Please be sure to:
     - connect the {} to the RaspberryPi running server.py.
     - connect the PowerIt to the RaspberryPi as described in the documentation
     - and be sure to connect the {} to the {} Terminal.

    Continue (y/N): y

    What is the Name given to the connected PowerIt? [Bxx]: B05
\end{mintylst}

The result will consist of two diagrams one without calibration and one with.
It will also write the newly obtained calibration data into \verb|pitdb.yaml|