1f33b15061cfb5c6fd93638a3d27c008a5d70364
[msc-thesis1617.git] / results.arch.tex
1 \section{Architecture}
2 \subsection{Devices}
3 The client code for the devices is compiled from one codebase. For a device to
4 be eligible for \glspl{mTask} it must be able to compile the shared codebase
5 and implement (part of) the device specific interface. The shared codebase only
6 uses standard \gls{C} and no special libraries or tricks are used. Therefore
7 the code is compilable for almost any device or system. Note that it is not
8 needed to implement a full interface. The full interface excluding the device
9 specific settings is listed in Appendix~\ref{app:device-interface}. The
10 interface works in a similar fashion as the \gls{EDSL}. Devices do not have to
11 implement all functionality, this is analogous to the fact that views do not
12 have to implement all type classes in the \gls{EDSL}. When the device connects
13 for the first time with a server the specifications of what is implemented is
14 communicated.
15
16 At the time of writing the following device families are supported and can run
17 the device software.
18 \begin{itemize}
19 \item \texttt{POSIX} compatible systems
20
21 This includes systems running \emph{Linux} and \emph{MacOS}.
22 \item \texttt{STM32} family microcontrollers supported by \texttt{ChibiOS}.
23
24 This is tested in particular on the \texttt{STM32f7x} series \gls{ARM}
25 development board.
26 \item Microcontrollers programmable by the \emph{Arduino} \gls{IDE}.\\
27
28 This does not only include \emph{Arduino} compatible boards but also
29 other boards capable of running \emph{Arduino} code. The code
30 has been found working on the \texttt{ESP8266} powered \emph{NodeMCU}.
31 It is tested on devices as small as the regular \emph{Arduino UNO}
32 board that only boasts a meager \emph{2K} of \emph{RAM}.
33 \end{itemize}
34
35 \subsection{Specification}
36 Devices are stored in a record type and all devices in the system are stored in
37 a \gls{SDS} containing all devices. From the macro settings in the interface
38 file a profile is created for the device that describes the specification. When
39 a connection between the server and a client is established the server will
40 send a request for specification. The client will serialize his specification
41 and send it to the server so that the server knows what the client is capable
42 of. The exact specification is listed in Listing~\ref{lst:devicespec}
43
44 \begin{lstlisting}[language=Clean,label={lst:devicespec},
45 caption={Device specification for \glspl{mTask}}]
46 :: MTaskDeviceSpec =
47 {haveLed :: Bool
48 ,haveAio :: Bool
49 ,haveDio :: Bool
50 ,bytesMemory :: Int
51 }
52 \end{lstlisting}
53
54 \subsection{Communication}
55 The communication to and fro a device runs via a single \gls{SDS}. Every
56 device has a specific resource that is used to connect to the device. The
57 current system supports connecting devices via a serial connection and via a
58 \gls{TCP} connection. Every device has the type \CI{MTaskDevice} and which
59 is listed in Listing~\ref{lst:mtaskdevice}. When a device is added a background
60 task is started that runs the \CI{synFun}. The \CI{synFun} is the task that
61 synchronizes the channel \gls{SDS} with the actual device. For the \gls{TCP}
62 device this is a simple \CI{tcpconnect}. The \CI{TaskId} of the background task
63 is saved to be able to stop the task in the future. When the task is unable to
64 connect it will set the \CI{deviceError} field to notify the user.
65 \todo{netter maken}
66
67 \begin{lstlisting}[language=Clean,caption={Device type},label={lst:mtaskdevice}]
68 :: Channels :== ([MTaskMSGRecv], [MTaskMSGSend], Bool)
69 :: MTaskResource
70 = TCPDevice TCPSettings
71 | SerialDevice TTYSettings
72 :: MTaskDevice =
73 { deviceTask :: Maybe TaskId
74 , deviceError :: Maybe String
75 , deviceChannels :: String
76 , deviceName :: String
77 , deviceTasks :: [MTaskTask]
78 , deviceData :: MTaskResource
79 , deviceSpec :: Maybe MTaskDeviceSpec
80 }
81
82 class MTaskDuplex a where
83 synFun :: a (Shared Channels) -> Task ()
84 \end{lstlisting}