\chapter{Solution}
The solution consists of two separate applications: a website used for transmitting data and a smartphone application used for receiving data. Transmission between the two application happens using a simple protocol on top of signals made using magnetic induction. I call the system MagSend.

\section{Protocol}
\label{section:protocol}
The following section describes how the MagSend protocol works. I explain the entire protocol first by explaining how the data gets encoded on the sender site, then the transmission and finally how the data is received.

\subsection{Sending}
This section explains how a user-provided message gets encoded and finally transmitted using \gls{mi}.

Data over MagSend gets sent in a packet. For the structure of the packet I tried to follow other packet formats that already exist. Most of the structure is similiar to the structure of a LoRa packet. \cite{LoRaPacketFormat} I choose LoRa as example as I am familiar to it was a part of my studies and as LoRa is also a protocol designed with a low data-rate in mind. The packet contains three parts.

\subsubsection*{Header}
The first part of the packet is the header. The header is \SI{4}{\bit} long and contains the length of the payload in bytes. The length is mainly used, to be able to detect the end of the payload.

\subsubsection*{Payload}
Next is the actual payload. As the length of the payload is specified in the header, the payload is limited to a size of $2^4$ bytes. While the contents of the payload can be any bit stream, the sender and receiver should assume that the bit stream is interpreted as ASCII text.

\subsubsection*{Checksum}
For verifying the integrity of the payload, a checksum of the payload is calculated and placed at the end of the packet. The algorithm used is the 8-bit CRC-8-AUTOSAR algorithm (see \autoref{section:crc}). 

\subsubsection*{Encoding}
The contents of the packet is then encoded using a manchester code (see \autoref{section:manchester}) for transmission. 

\subsubsection*{Transmission}
The transmission works over magnetic induction. By putting a load on a CPU the resulting magnetic field can be changed. High signals should be interpreted as a 1 and low signals should be interpreted as a 0.

To indicate the start of a message in the signal, a preamble is used. The preamble used in this protocol is 3 high signals, followed by 3 low signals, followed by 3 high signals. The duration of one signal in the preamble is 1 second. That means the entire preamble takes 9 seconds.

After the preamble that contents of the manchester encoded packet is sent.

\begin{figure}[H]
    \begin{bytefield}[bitwidth=.05\linewidth, bitheight=11mm]{4}
        \bitbox[]{4}[]{9 Symbols} & \bitbox[]{2}[]{4 Bit} & \bitbox[]{10}[]{n Bytes} & \bitbox[]{4}[]{1 Byte} \\
        \bitbox{4}[bgcolor=gray!30]{Preamble} & \bitbox{2}[bgcolor=red!30]{Payload Length} & \bitbox{10}[bgcolor=blue!30]{Payload} & \bitbox{4}[bgcolor=green!30]{CRC-8-AUTOSAR}
    \end{bytefield}
    \caption{Packet Structure, with Preamble at the Start}
\end{figure}


The following pseudocode in \autoref{listing:sending_pseudo} explains step by
step how a message should get encoded and transmitted using MagSend.

\lstinputlisting[
    style=bfh-c,
    language=C,
    caption={Pseudocode for Sending},
    label={listing:sending_pseudo}
]{thesis/listings/sending_pseudo.py}

\subsection{Receiving}
The receiver utilizes a magnetometer to measure the magnetic field and
interprets the received sensor values as a signal.

The following pseudocode in \autoref{listing:receiving_pseudo} explains step by
step how the signal should get interpreted and decoded using MagSend.

\lstinputlisting[
    style=bfh-c,
    language=C,
    caption={Pseudocode for Receiving},
    label={listing:receiving_pseudo}
]{thesis/listings/receiving_pseudo.py}

\newpage
\section{Website}
The website provides the user with an interface to transmit text over the
MagSend protocol.

When the user opens the website they are greeted by a simple interface. It
contains an input field for entering text and two buttons. The first button
will send the entered text, and the second one will start the calibration
process.

\begin{figure}[H]
    \centering
    \fbox{\includegraphics[width=.65\textwidth]{test_cases/t1.png}}
    \caption{Website - Home}
\end{figure}

When the calibration process is started, a message is displayed so it's clear
that we are in the calibration process. What happens technically is the website
will just put a full load on the CPU for the duration of the calibration. The
actual calibration process happens in the smartphone application.

\begin{figure}[H]
    \centering
    \fbox{\includegraphics[width=.65\textwidth]{test_cases/t2.png}}
    \caption{Website - Calibration}
\end{figure}

\newpage
When the user presses the sending button, the text will be sent by website
using the protocol described in \autoref{section:protocol}, by putting stress
on the CPU to generate a signal. While sending there is a message which
indicates that there is currently a send in process.

\begin{figure}[H]
    \centering
    \fbox{\includegraphics[width=.65\textwidth]{test_cases/t9.png}}
    \caption{Website - Sending}
\end{figure}

\newpage
\section{App}
The app allows the user to receive messages over the protocol.

On the homescreen you have two buttons. One button is for receiving messages and one is to start the calibration process. By clicking one of the buttons the user will be switched to the corresponding screen.

\begin{figure}[H]
    \centering
    \fbox{\includegraphics[width=0.4\textwidth]{app_home.jpg}}
    \caption{App - Home}
\end{figure}

\newpage
The calibration mode is used to find the most optimal location where the user should put the smartphone on the sending device. The website will continously put a load on the CPU. The app will then show the current strength of the magnetic field. The location where the strength is the highest is the one, where you will get the best transmission results.

\begin{figure}[H]
    \centering
    \fbox{\includegraphics[width=0.4\textwidth]{test_cases/t5.jpg}}
    \caption{App - Calibration}
\end{figure}

\newpage
When receiving a message, the currently received text is displayed on the screen while a loading indicator indicates that the receiving is still in process. When the receiving is finished the complete text is displayed. While receiving the user has the possibility to restart the receiving process to receive a new message.

\begin{figure}[H]
    \begin{minipage}{.5\textwidth}
        \centering
        \fbox{\includegraphics[width=0.8\textwidth]{app_receive.jpg}}
        \caption{App - Receiving in Progress}
    \end{minipage}  
    \begin{minipage}{.5\textwidth}
        \centering
        \fbox{\includegraphics[width=0.8\textwidth]{test_cases/t11.jpg}}
        \caption{App - Receving Completed}
    \end{minipage}  
\end{figure}
