updates
[phd-thesis.git] / top / int.tex
1 \documentclass[../thesis.tex]{subfiles}
2
3 \input{subfilepreamble}
4
5 \begin{document}
6 \input{subfileprefix}
7
8 \chapter{Integration with \texorpdfstring{\gls{ITASK}}{iTask}}%
9 \label{chp:integration_with_itask}
10 \begin{chapterabstract}
11 This chapter shows the integration of \gls{MTASK} with \gls{ITASK} by showing:
12 \begin{itemize}
13 \item an architectural overview of \gls{MTASK};
14 \item on the interface for connecting devices;
15 \item the interface for lifting \gls{MTASK} tasks to \gls{ITASK} tasks;
16 \item and interface for lifting \gls{ITASK} \glspl{SDS} to \gls{MTASK} \glspl{SDS}.
17 \end{itemize}
18 \end{chapterabstract}
19
20 The \gls{MTASK} language is a multi-view \gls{DSL}, i.e.\ there are multiple interpretations possible for a single \gls{MTASK} term.
21 Using the byte code compiler (\cleaninline{BCInterpret}) \gls{DSL} interpretation, \gls{MTASK} tasks can be fully integrated in \gls{ITASK}.
22 They are executed as if they are regular \gls{ITASK} tasks and they communicate may access \glspl{SDS} from \gls{ITASK} as well.
23 \Gls{MTASK} devices contain a domain-specific \gls{OS} (\gls{RTS}) and are little \gls{TOP} engines in their own respect, being able to execute tasks.
24 \Cref{fig:mtask_integration} shows the architectural layout of a typical \gls{IOT} system created with \gls{ITASK} and \gls{MTASK}.
25 The entire system is written as a single \gls{CLEAN} specification where multiple tasks are executed at the same time.
26 Tasks can access \glspl{SDS} according to many-to-many communication and multiple clients can work on the same task.
27 Devices are integrated into the system using the \cleaninline{withDevice} function (see \cref{sec:withdevice}).
28 Using \cleaninline{liftmTask}, \gls{MTASK} tasks are lifted to a device (see \cref{sec:liftmtask}).
29 \Gls{ITASK} \glspl{SDS} are lifted to the \gls{MTASK} device using \cleaninline{liftsds} (see \cref{sec:liftmtask}).
30
31 \begin{figure}[ht]
32 \centering
33 \includestandalone{mtask_integration}
34 \caption{\Gls{MTASK}'s integration with \gls{ITASK}.}%
35 \label{fig:mtask_integration}
36 \end{figure}
37
38 \section{Devices}\label{sec:withdevice}
39 When interpreted by the byte code compiler view, an \gls{MTASK} task produces a compiler.
40 This compiler is exceuted at run time so that the resulting byte code can be sent to an edge device.
41 All communication with this device happens through a so-called \emph{channels} \gls{SDS}.
42 The channels contain three fields, a queue of messages that are received, a queue of messages to send and a stop flag.
43 Every communication method that implements the \cleaninline{channelSync} class can provide the communication with an \gls{MTASK} device.
44 As of now, serial port communication, direct \gls{TCP} communication and \gls{MQTT} over \gls{TCP} are supported as communication providers.
45 The \cleaninline{withDevice} function transforms a communication provider and a task that does something with this device to an \gls{ITASK} task.
46 Internally, the task sets up the communication, exchanges specifications, executes the inner task while handling errors, and finally cleans up after closing.
47 \Cref{lst:mtask_device} shows the types and interface to connecting devices.
48
49 \begin{lstClean}[label={lst:mtask_device},caption={Device communication interface in \gls{MTASK}.}]
50 :: MTDevice //abstract
51 :: Channels :== ([MTMessageFro], [MTMessageTo], Bool)
52
53 class channelSync a :: a (Shared sds Channels) -> Task () | RWShared sds
54
55 withDevice :: a (MTDevice -> Task b) -> Task b | iTask b & channelSync, iTask a
56 \end{lstClean}
57
58 \section{Lifting tasks}\label{sec:liftmtask}
59 Once the connection with the device is established, \gls{MTASK} tasks can be lifted to \gls{MTASK} tasks using the \cleaninline{liftmTask} family of functions (see \cref{lst:liftmtask}).
60 Given an \gls{MTASK} task in the \cleaninline{BCInterpret} view and a device obtained from \cleaninline{withDevice}, an \gls{ITASK} task is returned.
61 This \gls{ITASK} task tethers the \gls{MTASK} task that is executed on the microcontroller.
62 Hence, when for example observing the task value, the actual task value from the microcontroller is observed.
63
64 \begin{lstClean}[label={lst:liftmtask},caption={The interface for lifting \gls{MTASK} tasks to \gls{ITASK} tasks.}]
65 liftmTask :: (Main (MTask BCInterpret u)) MTDevice -> Task u | iTask u
66 \end{lstClean}
67
68 Under the hood, \cleaninline{liftmTask} compiler the \gls{MTASK} task to byte code, gathers the initial values for the lifted \glspl{SDS} and sends the data to the device.
69 Once acknowledged, the \gls{MTASK} task value and the \glspl{SDS} are monitored.
70 If the \gls{ITASK} server updates the value of a lifted \gls{SDS}, the appropriate message is sent to the \gls{MTASK} to notify it of the change.
71 Furthermore, the \gls{MTASK} device may update the \gls{SDS}, and in that case the message is picked up by the \cleaninline{liftmTask} task and the \gls{SDS} on the \gls{ITASK} server updated accordingly.
72
73 \section{Lifting \texorpdfstring{\glsxtrlongpl{SDS}}{shared data sources}}\label{sec:liftsds}
74 \begin{lstClean}[label={lst:mtask_itasksds},caption={Lifted \gls{ITASK} \glspl{SDS} in \gls{MTASK}.}]
75 class liftsds v where
76 liftsds :: ((v (Sds t)) -> In (Shared sds t) (Main (MTask v u)))
77 -> Main (MTask v u) | RWShared sds
78 \end{lstClean}
79
80 \section{Conclusion}
81
82
83 \input{subfilepostamble}
84 \end{document}