From c45698c752780ef2bf45ae9f8085585e9eee1d18 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 15 Nov 2022 18:58:23 +0100 Subject: [PATCH] updates --- dsl/first-class_datatypes.tex | 2 +- glossaries.tex | 11 ++- intro/intro.tex | 124 ++++++++++++++++++++-------------- intro/tosd.tex | 8 +-- intro/traditional.tex | 8 +-- preamble.tex | 4 +- top/top.tex | 39 +++++++++-- tvt/tvt.tex | 10 +-- 8 files changed, 126 insertions(+), 80 deletions(-) diff --git a/dsl/first-class_datatypes.tex b/dsl/first-class_datatypes.tex index 5c82b39..4c7f06f 100644 --- a/dsl/first-class_datatypes.tex +++ b/dsl/first-class_datatypes.tex @@ -22,7 +22,7 @@ By expressing the language constructs in the host language, the parser, the type checker, and the run time can be inherited from the host language. Unfortunately, data types defined in the host language are not automatically available in the \gls{EDSL}. -The two main strategies for embedding \glspl{DSL} in a \gls{FP} language are deep embedding (also called initial) and shallow embedding (also called final). +The two main strategies for embedding \glspl{DSL} in \pgls{FP} language are deep embedding (also called initial) and shallow embedding (also called final). Deep embedding represents the constructs in the language as data types and the semantics as functions over these data types. This makes extending the language with new semantics effortless: just add another function. In contrast, adding language constructs requires changing the data type and updating all existing semantics to support this new construct. diff --git a/glossaries.tex b/glossaries.tex index a1fdb87..392abab 100644 --- a/glossaries.tex +++ b/glossaries.tex @@ -8,7 +8,6 @@ \myacronym{ADT}{ADT}{algebraic data type} \myacronym{API}{API}{application programming interface} \myacronym{ARDSL}{ARDSL}{\gls{ARDUINO} \glsxtrshort{DSL}} -\myacronym{BLE}{BLE}{Bluetooth low energy} \myacronym{CEFP}{CEFP}{central European summer school of \glsxtrlong{FP}} \myacronym{CRS}{CRS}{\gls{CLEAN} Raspberry Pi system} \myacronym{CRTS}{CRTS}{\gls{CLEAN} Raspberry Pi temperature sensor} @@ -18,8 +17,8 @@ \myacronym{DSL}{DSL}{domain-specific language} \myacronym{ECO2}{eCO\textsubscript{2}}{equivalent carbon dioxide} \myacronym{EDSL}{eDSL}{embedded \glsxtrlong{DSL}} -\myacronym{FP}{FP}{functional programming} -\myacronym{FRP}{FRP}{functional reactive programming} +\myacronym[prefixfirst={a\ },prefix={an\ }]{FP}{FP}{functional programming} +\myacronym[prefixfirst={a\ },prefix={an\ }]{FRP}{FRP}{functional reactive programming} \myacronym{GADT}{GADT}{generalised \glsxtrshort{ADT}} \myacronym{GHC}{GHC}{Glasgow \gls{HASKELL} Compiler} \myacronym{GPIO}{GPIO}{general-purpose \glsxtrlong{IO}} @@ -32,7 +31,7 @@ \myacronym{IO}{IO}{input/output} \myacronym{IR}{IL}{intermediate representation} \myacronym{LEAN}{LEAN}{language of East-Anglia and Nijmegen} -\myacronym{LED}{LED}{light-emitting diode} +\myacronym[prefixfirst={a\ },prefix={an\ }]{LED}{LED}{light-emitting diode} \myacronym{OLED}{OLED}{organic \glsxtrlong{LED}} \myacronym{OS}{OS}{operating system} \myacronym{OTA}{OTA}{over-the-air} @@ -46,8 +45,8 @@ \myacronym{RFID}{RFID}{radio-frequency identification} \myacronym{RTOS}{RTOS}{real-time \glsxtrshort{OS}} \myacronym{RTS}{RTS}{run-time system} -\myacronym{SDS}{SDS}{shared data source} -\myacronym{SN}{SN}{sensor network} +\myacronym[prefixfirst={a\ },prefix={an\ }]{SDS}{SDS}{shared data source} +\myacronym[prefixfirst={a\ },prefix={an\ }]{SN}{SN}{sensor network} \myacronym{SLOC}{SLOC}{source lines of code} \myacronym{TH}{TH}{Template \gls{HASKELL}} \myacronym{TCP}{TCP}{transmission control protocol} diff --git a/intro/intro.tex b/intro/intro.tex index fbce504..c0cbb9e 100644 --- a/intro/intro.tex +++ b/intro/intro.tex @@ -6,38 +6,56 @@ \chapter{Prelude}% \label{chp:introduction} \begin{chapterabstract} - This chapter introduces the contents of the thesis and a reading guide. - Furthermore, it provides background material on \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, and \glsxtrlong{TOP}; and a detailed overview of the contributions. - It also gives a brief introduction to two \gls{TOP} languages: \gls{ITASK} and \gls{MTASK}. + This chapter: + \begin{itemize} + \item introduces the topic and research ventures of this dissertation; + \item shows a reading guide; + \item provides background material on \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, \glsxtrlong{TOP}, and the \gls{TOP} languages \gls{ITASK} and \gls{MTASK} in particular; + \item and concludes with a detailed overview of the contributions. + \end{itemize} \end{chapterabstract} There are at least 13.4 billion devices connected to the internet at the time of writing\footnote{\url{https://transformainsights.com/research/tam/market}, accessed on: \formatdate{13}{10}{2022}}. -These devices sense, act, or otherwise interact with people, other computers, and the world surrounding us. -Notwithstanding the substantial variety among these devices, they have one thing in common: they are all require software to operate. +Each and every one of those devices senses, acts, or otherwise interacts with people, other computers, and the environment surrounding us. +Even though there is a substantial variety among these devices, they have one thing in common: they all computers to some degree and for this reason require software to operate. An increasing amount of these connected devices are so-called \emph{edge devices} that operate in the \gls{IOT}. -Typically these edge devices are small microcontrollers containing sensors and actuators to interact with the physical world. -Microcontrollers are integrated circuits containing a microprocessor designed for use in embedded applications. -The edge devices come in many different types and they differ substantially from the other devices in the system. -Consequently, programming \gls{IOT} systems is very complex and error prone. -Hence, an \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction. - -This thesis introduces research on the many aspects of orchestrating \gls{IOT} systems using \gls{TOP}. -\Gls{TOP} is a innovative tierless programming paradigm for programming multi-tier interactive systems using a single declarative specification of the work that needs to be done. -Using advanced compiler technologies, much of the internals and communication of multi-tier applications is automatically generated and the result of compilation is a ready-for-work application. -Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive to be suitable for the average edge device. - -This is where \glspl{DSL} come into play. -\Glspl{DSL} are languages created with a specific domain in mind. -Consequently, domain knowledge does not have to be expressed in the language itself but they can be built-in features, thus drastically reducing the hardware requirements even with high levels of abstraction. +Typically, these edge devices are powered by microcontrollers +Microcontrollers contain integrated circuits accommodating a microprocessor designed for use in embedded applications. +Typical microprocessors therefore are tiny in size; have little memory; contain a slow, but energy efficient processor; and allow for a lot of connectivity to connect peripherals such as sensors and actuators to interact with their surroundings. +% +%\begin{figure}[ht] +% \centering +% \includegraphics[width=.4\linewidth]{esp} +% \caption{A typical ESP32 microcontroller prototyping board.}% +% \label{fig:esp_prototype} +%\end{figure} + +Edge devices come in numerous types, differing substantially from the other devices in the system. +An \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction. +Programming and maintaining \gls{IOT} systems is therefore a very complex and an error-prone process. + +This thesis introduces research on taming these complex \gls{IOT} systems using \gls{TOP}. +\Gls{TOP} is an innovative tierless programming paradigm for programming multi-tier interactive systems using a single declarative specification of the work that needs to be done. +By utilising advanced compiler technologies, much of the internals, communication, and interoperation of the multi-tier applications is automatically generated. +The result of this compilation is a ready-for-work application. +Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive for a general purpose \gls{TOP} system to be suitable for the average edge device. + +This is where \glspl{DSL} are brought into play. +\Glspl{DSL} are programming languages created with a specific domain in mind. +Consequently, domain jargon does not have to be expressed in the language itself, but they can be built-in features. +As a result, the hardware requirements can be drastically lower even with high levels of abstraction. + +Using \gls{MTASK}, a novel domain-specific \gls{TOP} \gls{DSL} fully integrated with \gls{ITASK}, all layers of the \gls{IOT} can be orchestrated from a single source. \section{Reading guide} +The thesis is presented as a purely functional rhapsody. On Wikipedia, a musical rhapsody is defined as follows \citep{wikipedia_contributors_rhapsody_2022}: \begin{quote}\emph{% A \emph{rhapsody} in music is a one-movement work that is episodic yet integrated, free-flowing in structure, featuring a range of highly contrasted moods, colour, and tonality.} \end{quote} -This thesis is structured as a pure functional rhapsody containing three episodes barded by the introduction and conclusion (\cref{chp:introduction,chp:conclusion}). -\Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode providing insight in advanced \gls{DSL} embedding techniques. +The three episodes are barded by the introduction and conclusion (\cref{chp:introduction,chp:conclusion}). +\Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode providing insight in advanced \gls{DSL} embedding techniques for \glspl{FP}. The chapters are readable independently. \Cref{prt:top} is a monograph showing \gls{MTASK}, a \gls{TOP} \gls{DSL} for the \gls{IOT}. Hence, the chapters are best read in order. @@ -46,10 +64,10 @@ The chapter is readable independently. The following sections provide background material on the \gls{IOT}, \glspl{DSL}, and \gls{TOP} after which a detailed overview of the contributions is presented. Text typeset as \texttt{teletype} represents source code. -Standalone source code listings are used are marked with the programming language used. -For the \gls{FP} language \gls{CLEAN}, a guide tailored to \gls{HASKELL} programmers is available as in \cref{chp:clean_for_haskell_programmers}. +Standalone source code listings are used are marked by the programming language used. +Specifically for the \gls{FP} language \gls{CLEAN}, a guide tailored to \gls{HASKELL} programmers is available in \cref{chp:clean_for_haskell_programmers}. -\section{Internet of things}\label{sec:back_iot} +\section{\texorpdfstring{\Glsxtrlong{IOT}}{Internet of things}}\label{sec:back_iot} The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world. While the term \gls{IOT} briefly gained interest around 1999 to describe the communication of \gls{RFID} devices \citep{ashton_internet_1999,ashton_that_2009}, it probably already popped up halfway the eighties in a speech by \citet{peter_t_lewis_speech_1985}: @@ -80,12 +98,12 @@ A cloud server or local server provides this layer in a typical home automation The perception layer---also called edge layer---collects the data and interacts with the environment. It consists of edge devices such as microcontrollers equipped with various sensors and actuators. -In home automation this layer consists of all the devices hosting the sensors and actuators such as a smart lightbulb, an actuator to open a door or a temperature and humidity sensor. +In home automation this layer consists of all the devices hosting the sensors and actuators such as a smart light bulb, an actuator to open a door or a temperature and humidity sensor. All layers are connected using the network layer. In many applications this is implemented using conventional networking techniques such as WiFi or Ethernet. However, networks or layers on top of it---tailored to the needs of the specific interconnection between layers---have been increasingly popular. -Examples of this are \gls{BLE}, LoRa, ZigBee, LTE-M, or \gls{MQTT} for connecting the perception layer to the application layer and techniques such as HTTP, AJAX, and WebSocket for connecting the presentation layer to the application layer. +Examples of this are BLE, LoRa, ZigBee, LTE-M, or \gls{MQTT} for connecting the perception layer to the application layer and techniques such as HTTP, AJAX, and WebSocket for connecting the presentation layer to the application layer. Across the layers, the devices are a large heterogeneous collection of different platforms, protocols, paradigms, and programming languages often resulting in impedance problems or semantic friction between layers when programming \citep{ireland_classification_2009}. Even more so, perception layer itself often is a heterogeneous collections of microcontrollers in itself as well, each having their own peculiarities, language of choice, and hardware interfaces. @@ -122,8 +140,8 @@ Examples of standalone \glspl{DSL} are regular expressions, make, yacc, XML, SQL The dichotomous approach is embedding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL} \citep{hudak_modular_1998}. By defining the language as constructs in the host language, much of the machinery is inherited and the cost of creating embedded languages is very low. -There is more linguistic reuse~\cite{krishnamurthi_linguistic_2001}. -There are however two sides to the this coin. +There is more linguistic reuse \citep{krishnamurthi_linguistic_2001}. +However, there are two sides to this coin. If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy. Furthermore, errors shown to the programmer may be larded with host language errors, making it difficult for a non-expert of the host language to work with the \gls{DSL}. Pure \gls{FP} languages are especially suitable for hosting embedded \glspl{DSL} because they have strong and versatile type systems, minimal but flexible syntax and offer referential transparency. @@ -182,8 +200,8 @@ This approach to software development is called \gls{TOSD} \citep{wang_maintaini Furthermore, a task is observable which means it is possible to observe a---partial---result during execution and act upon it by for example starting new tasks. Examples of tasks are filling in a form, sending an email, reading a sensor or even doing a physical task. \item[\Glsxtrshortpl{SDS} (resource access):] - Tasks can communicate using task values but this imposes a problem in many collaboration patterns where tasks that are not necessarily related need to share data. - Tasks can also share data using \glspl{SDS}, an abstraction over any data. + Tasks can communicate using task values, some collaboration require tasks that are not necessarily related need to share data. + Hence, tasks can also share data using \glspl{SDS}, an abstraction over any data. An \gls{SDS} can represent typed data stored in a file, a chunk of memory, a database \etc. \Glspl{SDS} can also represent external impure data such as the time, random numbers or sensory data. Similar to tasks, transformation and combination of \glspl{SDS} is possible. @@ -208,9 +226,9 @@ Only when the user entered a complete value in the web editor, then the continue Special combinators (e.g.\ \cleaninline{@>>} at \cref{lst:task_ui}) are available to tweak the \gls{UI} afterwards. \begin{figure}[ht] - \includegraphics[width=.32\linewidth]{person0} - \includegraphics[width=.32\linewidth]{person1} - \includegraphics[width=.32\linewidth]{person2} + \includegraphics[width=.325\linewidth]{person0g} + \includegraphics[width=.325\linewidth]{person1g} + \includegraphics[width=.325\linewidth]{person2g} \caption{The \gls{UI} for entering a person in \gls{ITASK}.}% \label{fig:enter_person} \end{figure} @@ -228,34 +246,38 @@ enterPerson \end{lstClean} \subsection{\texorpdfstring{\Gls{MTASK}}{MTask}} -This thesis uses \gls{ITASK} in conjunction with an innovative \gls{TOP} language designed for defining interactive systems for \gls{IOT} edge devices called \gls{MTASK} \citep{koopman_task-based_2018}. +This thesis uses \gls{ITASK} in conjunction with \gls{MTASK}, an innovative \gls{TOP} language designed for defining interactive systems for \gls{IOT} edge devices \citep{koopman_task-based_2018}. It is written in \gls{CLEAN} as a multi-view \gls{EDSL} and hence there are multiple interpretations of the language of which the byte code compiler is the most relevant for this thesis. From the terms in the \gls{TOP} language, a very compact binary representation of the work that needs to be done is compiled. This specification is then sent to a device that runs the \gls{MTASK} \gls{RTS}, a domain-specific \gls{TOP} engine implemented as a feather-light domain-specific \gls{OS}. \Gls{MTASK} is seamlessly integrated with \gls{ITASK}, it allows the programmer to define all layers of an \gls{IOT} system from a single declarative specification. -\todo[inline]{Is this example useful? Add more detailed explanation with line numbers?} -\Cref{lst:intro_blink} shows an \gls{MTASK}\slash{}\gls{ITASK} application for an interactive application where the \gls{LED} on the microcontroller blinks every user-specified interval. -Using a \glspl{SDS} defined in \gls{ITASK}, the blinking frequency of an \gls{LED} connected to \gls{GPIO} pin 13 can be changed on the fly. +\todo[inline]{Is this example useful? I think it's too technical} +\Cref{lst:intro_blink} shows an interactive \gls{MTASK}\slash{}\gls{ITASK} application for blinking \pgls{LED} on the microcontroller every user-specified interval. +\Crefrange{lst:intro:itask_fro}{lst:intro:itask_to} show the \gls{ITASK} part. +First a \gls{SDS} is defined to communicate the blinking interval, then the \gls{MTASK} is connected using \cleaninline{withDevice}. +Once connected, the \cleaninline{intBlink} task is sent to the device (\cref{lst:intro_liftmtask}) and in parallel, the value of the interval \gls{SDS} can be updated using an editor (\cref{lst:intro_editor}). +The \cleaninline{intBlink} task (\crefrange{lst:intro:mtask_fro}{lst:intro:mtask_to}) is the \gls{MTASK} part of the application that has its own tasks, \glspl{SDS}, and \gls{UOD}. +This task first defines \gls{GPIO} pin 13 to be of the output type (\cref{lst:intro:declarePin}) followed by lifting the \gls{ITASK} \gls{SDS} to an \gls{MTASK} \gls{SDS} (\cref{lst:intro:liftsds}). +The main expression of the program calls the \cleaninline{blink} function with the initial state. +This function on \crefrange{lst:intro:blink_fro}{lst:intro:blink_to} first reads the interval \gls{SDS}, waits the specified delay, writes the state to the \gls{GPIO} pin and calls itself recursively using the inverse of the state. \begin{lstClean}[numbers=left,caption={\Gls{MTASK}\slash{}\gls{ITASK} interactive blinking.},label={lst:intro_blink}] -interactiveBlink :: Task Int +interactiveBlink :: Task Int[+\label{lst:intro:itask_fro}+] interactiveBlink = - withShared 500 \iInterval-> + withShared 500 \iInterval->[+\label{lst:intro_withshared}+] withDevice {TCPSettings | host = ..., port = ...} \dev-> - liftmTask (intBlink iInterval) dev - -|| Hint "Interval (ms)" @>> updateSharedInformation [] iInterval + liftmTask (intBlink iInterval) dev[+\label{lst:intro_liftmtask}+] + -|| Hint "Interval (ms)" @>> updateSharedInformation [] iInterval[+\label{lst:intro_editor}+][+\label{lst:intro:itask_to}+] -intBlink :: Shared sds Int -> MTask v Int | mtask, liftsds v & RWShared sds +intBlink :: Shared sds Int -> MTask v Int | mtask, liftsds v & RWShared sds[+\label{lst:intro:mtask_fro}+] intBlink iInterval = - declarePin D13 PMOutput \d13-> - liftsds \mInterval=iInterval - In fun \blink=(\st-> - writeD d13 st - >>|. getSds mInterval - >>=. \i->delay i - >>|. blink (Not st)) - In {main = blink true} + declarePin D13 PMOutput \d13->[+\label{lst:intro:declarePin}+] + liftsds \mInterval=iInterval[+\label{lst:intro:liftsds}+] + In fun \blink=(\st->[+\label{lst:intro:blink_fro}+] + getSds mInterval >>=. \i->delay i + >>|. writeD d13 st >>|. blink (Not st))[+\label{lst:intro:blink_to}+] + In {main = blink true}[+\label{lst:intro:mtask_to}+] \end{lstClean} \subsection{Other \texorpdfstring{\glsxtrshort{TOP}}{TOP} languages} @@ -296,7 +318,7 @@ It provides a gentle introduction to the \gls{MTASK} system elaborates on \gls{T This paper was an extension of my Master's thesis \citep{lubbers_task_2017}. It shows how a simple imperative variant of \gls{MTASK} was integrated with \gls{ITASK}. - While the language was a lot different than later versions, the integration mechanism is still used in \gls{MTASK} today. + While the language was a lot different from later versions, the integration mechanism is still used in \gls{MTASK} today. % \paragraph{Contribution} % The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer in which we discussed and refined the ideas. \item \emph{Multitasking on Microcontrollers using Task Oriented Programming} \citep{lubbers_multitasking_2019}\footnote{% diff --git a/intro/tosd.tex b/intro/tosd.tex index 0f45e93..3fbee44 100644 --- a/intro/tosd.tex +++ b/intro/tosd.tex @@ -3,18 +3,18 @@ \begin{document} \begin{tikzpicture} \pie[% - color={red,violet,teal,blue}, + color={black!20,black!40,black!60,black!80}, explode={0.1}, hide number, text=inside, rotate=45, radius=1.8, ]{% - 25/\textcolor{white}{UI}, - 25/\textcolor{white}{Tasks}, + 25/\textcolor{black}{UI}, + 25/\textcolor{black}{Tasks}, 25/\textcolor{white}{UoD}, 25/\textcolor{white}{SDS} } - \node [draw,fill=yellow,circle]{Types}; + \node [draw,fill=white,circle]{Types}; \end{tikzpicture} \end{document} diff --git a/intro/traditional.tex b/intro/traditional.tex index 81b0c46..39f678b 100644 --- a/intro/traditional.tex +++ b/intro/traditional.tex @@ -1,10 +1,10 @@ \documentclass[tikz]{standalone} \usetikzlibrary{positioning} \begin{document} -\begin{tikzpicture}[node distance=1em,nodes={rectangle,draw,text=white,minimum width=10em,minimum height=2.5em}] - \node (0) [fill=red] {Presentation layer}; - \node (1) [fill=violet,below=of 0] {Business layer}; - \node (2) [fill=blue,below=of 1] {Resource access layer}; +\begin{tikzpicture}[node distance=1em,nodes={rectangle,draw,minimum width=10em,minimum height=2.5em}] + \node (0) [fill=black!20,text=black] {Presentation layer}; + \node (1) [fill=black!40,text=black,below=of 0] {Business layer}; + \node (2) [fill=black!80,text=white,below=of 1] {Resource access layer}; \draw [<->] (0) -- (1); \draw [<->] (1) -- (2); diff --git a/preamble.tex b/preamble.tex index 6625618..2518545 100644 --- a/preamble.tex +++ b/preamble.tex @@ -107,7 +107,7 @@ \def\part@nostar@nopt#1{\NR@gettitle{#1}\titlesec@part{#1}} \def\part@nostar@opt[#1]#2{\NR@gettitle{#1}\titlesec@part[#1]{#2}} \makeatother -\newenvironment{chapterabstract}{\begin{quotation}\em}{\end{quotation}} %chktex 6 +\newenvironment{chapterabstract}{\begin{quotation}\em\noindent}{\end{quotation}} %chktex 6 % Increase the depth for the table of contents \setcounter{secnumdepth}{3} @@ -277,7 +277,7 @@ \newcommand{\Fullref}[1]{\Cref{#1}: \nameref{#1}} % Glossaries and acronyms -\usepackage[nolangwarn,abbreviations,nonumberlist]{glossaries-extra} +\usepackage[nolangwarn,abbreviations,nonumberlist,prefix]{glossaries-extra} \setabbreviationstyle[acronym]{long-short} \Addlcwords{of} % Titlecase glossary commands diff --git a/top/top.tex b/top/top.tex index 63151d3..2ca397e 100644 --- a/top/top.tex +++ b/top/top.tex @@ -9,15 +9,40 @@ \chapter{Edge device programming}% \label{chp:top4iot} -\todo{betere chapter naam} \begin{chapterabstract} - This chapter introduces \gls{MTASK} and puts it into perspective compared to traditional microcontroller programming. - It does so by showing how to program microcontrollers using \gls{ARDUINO}, a popular microcontroller framework, and the equivalent \gls{MTASK} programs. + This chapter: + \begin{itemize} + \item shows how to create the \emph{Hello World!} application for microcontrollers using \gls{ARDUINO}; + \item extends this idea with multithreading, demonstrating the difficulty programming multi-tasking applications; + \item describes a comparative variant in \gls{MTASK} and shows that upgrading to a multi-tasking variant is straightforward + \item demonstrates that the complexity of running multiple tasks; + \item and concludes with a short history of \gls{MTASK}'s development. + \end{itemize} \end{chapterabstract} -The edge layer of \gls{IOT} system mostly consists of microcontrollers that require a different method of programming. +The edge layer of \gls{IOT} system mostly consists of microcontrollers. +Microcontrollers are tiny computers designed specifically for embedded applications. +They therefore only have a soup\c{c}on of memory, have a slow processor, come with many energy efficient sleep modes and have a lot of peripheral support such as \gls{GPIO} pins. Usually, programming microcontrollers requires an elaborate multi-step toolchain of compilation, linkage, binary image creation, and burning this image onto the flash memory of the microcontroller in order to compile and run a program. The programs are usually cyclic executives instead of tasks running in an operating system, i.e.\ there is only a single task that continuously runs on the bare metal. +\Cref{tbl:mcu_laptop} compares the hardware properties of a typical laptop with two very popular microcontrollers. + +\begin{table} + \begin{tabular}{llll} + \toprule + & Laptop & Atmega328P & ESP8266\\ + \midrule + CPU speed & \qtyrange{2}{4}{\giga\hertz} & \qty{16}{\mega\hertz} & \qty{80}{\mega\hertz} or \qty{160}{\mega\hertz}\\ + \textnumero{} cores & \numrange{4}{8} & 1 & 1\\ + Storage & \qty{1}{\tebi\byte} & \qty{32}{\kibi\byte} & \qtyrange{0.5}{4}{\mebi\byte}\\ + \gls{RAM} & \qtyrange{4}{16}{\gibi\byte} & \qty{2}{\kibi\byte} & \qty{160}{\kibi\byte}\\ + Power & \qtyrange{50}{100}{\watt} & \qtyrange{0.13}{250}{\milli\watt} & \qtyrange{0.1}{350}{\milli\watt}\\ + \bottomrule + \end{tabular} + \caption{Hardware characteristics of typical microcontrollers and laptops.}% + \label{tbl:mcu_laptop} +\end{table} + Each type of microcontrollers comes with vendor-provided drivers, compilers and \glspl{RTS} but there are many platform that abstract away from this such as \gls{MBED} and \gls{ARDUINO} of which \gls{ARDUINO} is specifically designed for education and prototyping and hence used here. The popular \gls{ARDUINO} \gls{C}\slash\gls{CPP} dialect and accompanying libraries provide an abstraction layer for common microcontroller behaviour allowing the programmer to program multiple types of microcontrollers using a single language. Originally it was designed for the in-house developed open-source hardware with the same name but the setup allows porting to many architectures. @@ -27,7 +52,7 @@ It provides an \gls{IDE} and toolchain automation to perform all steps of the to Traditionally, the first program that one writes when trying a new language is the so called \emph{Hello World!} program. This program has the single task of printing the text \emph{Hello World!} to the screen and exiting again, useful to become familiarised with the syntax and verify that the toolchain and runtime environment is working. On microcontrollers, there usually is no screen for displaying text. -Nevertheless, almost always there is a built-in monochrome $1\times1$ pixel screen, namely an \gls{LED}. +Nevertheless, almost always there is a built-in monochrome $1\times1$ pixel screen, namely \pgls{LED}. The \emph{Hello World!} equivalent on microcontrollers blinks this \gls{LED}. \Cref{lst:arduinoBlink} shows how the logic of a blink program might look when using \gls{ARDUINO}'s \gls{C}\slash\gls{CPP} dialect. @@ -650,9 +675,9 @@ task = Similar to peripherals (see \cref{sssec:peripherals}), they are constructed at the top level and are accessed through interaction tasks. The \cleaninline{getSds} task yields the current value of the \gls{SDS} as an unstable value. This behaviour is similar to the \cleaninline{watch} task in \gls{ITASK}. -Writing a new value to an \gls{SDS} is done using \cleaninline{setSds}. +Writing a new value to \pgls{SDS} is done using \cleaninline{setSds}. This task yields the written value as a stable result after it is done writing. -Getting and immediately after setting an \gls{SDS} is not necessarily an \emph{atomic} operation in \gls{MTASK} because it is possible that another task accesses the \gls{SDS} in between. +Getting and immediately after setting \pgls{SDS} is not necessarily an \emph{atomic} operation in \gls{MTASK} because it is possible that another task accesses the \gls{SDS} in between. To circumvent this issue, \cleaninline{updSds} is created, this task atomically updates the value of the \gls{SDS}. The \cleaninline{updSds} task only guarantees atomicity within \gls{MTASK}. diff --git a/tvt/tvt.tex b/tvt/tvt.tex index 68bc991..222b09e 100644 --- a/tvt/tvt.tex +++ b/tvt/tvt.tex @@ -307,7 +307,7 @@ There are also standard combinators for common patterns. Tasks can exchange information via \glspl{SDS} \citep{ParametricLenses}. All tasks involved can atomically observe and change the value of a typed \gls{SDS}, allowing more flexible communication than with task combinators. \Glspl{SDS} offer a general abstraction of data shared by different tasks, analogous to variables, persistent values, files, databases and peripherals like sensors. Combinators compose \glspl{SDS} into a larger \gls{SDS}, and -parametric lenses define a specific view on an \gls{SDS}. +parametric lenses define a specific view on \pgls{SDS}. \subsection{The \texorpdfstring{\glsentrytext{ITASK}}{iTask} \texorpdfstring{\glsxtrlong{EDSL}}{eDSL}}% \label{sec_t4t:itasks} @@ -453,7 +453,7 @@ The \cleaninline{controlSDS} task illustrates communication from the web page us A typical \gls{IOT} system goes beyond a web application by incorporating a distributed set of sensor nodes each with a collection of sensors or actuators. That is, they add the perception and network layers in \cref{fig_t4t:iot_arch}. If the sensor nodes have the computational resources to support an \gls{ITASK} server, as a Raspberry Pi does, then \gls{ITASK} can also be used to implement these layers, and integrate them with the application and presentation layers tierlessly. As an example of tierless \gls{IOT} programming in \gls{CLEAN}\slash\gls{ITASK} \cref{lst_t4t:itaskTempFull} shows a complete temperature sensing system with a server and a single sensor node (\gls{CRTS}), omitting only the module name and imports. -It is similar to the SimpleTempSensor and TempHistory programs above, for example \cleaninline{devTask} repeatedly sleeps and records temperatures and times, and \cleaninline{mainTask} displays the temperatures on the web page in \cref{fig_t4t:cwtsweb}. There are some important differences, however. The \cleaninline{devTask} (\crefrange{lst_t4t:itaskTempFull:sensorfro}{lst_t4t:itaskTempFull:sensorto}) executes on the sensor node and records the temperatures in a standard timestamped (lens on) an \gls{SDS}: \cleaninline{dateTimeStampedShare} \cleaninline{latestTemp}. +It is similar to the SimpleTempSensor and TempHistory programs above, for example \cleaninline{devTask} repeatedly sleeps and records temperatures and times, and \cleaninline{mainTask} displays the temperatures on the web page in \cref{fig_t4t:cwtsweb}. There are some important differences, however. The \cleaninline{devTask} (\crefrange{lst_t4t:itaskTempFull:sensorfro}{lst_t4t:itaskTempFull:sensorto}) executes on the sensor node and records the temperatures in a standard timestamped (lens on) \pgls{SDS}: \cleaninline{dateTimeStampedShare} \cleaninline{latestTemp}. The \cleaninline{mainTask} (\cref{lst_t4t:itaskTempFull:main}) executes on the server: it starts \cleaninline{devTask} as an asynchronous task on the specified sensor node (\cref{lst_t4t:itaskTempFull:startdevtask}) and then generates a web page to display the latest temperature and time (\cref{lst_t4t:itaskTempFull:displaystart,lst_t4t:itaskTempFull:displayend}). The \cleaninline{tempSDS} is very similar to the \cleaninline{measurementsSDS} from the previous listings. @@ -535,7 +535,7 @@ We illustrate with \gls{CWTS}: a simple room temperature sensor with a web displ The program uses the same shares \cleaninline{tempSDS} and~\cleaninline{latestTemp} as \gls{CRTS}, and for completeness we repeat those definitions. The body of \cleaninline{devTask} is the \gls{MTASK} slice of the program (\crefrange{lst_t4t:mtasktemp:DHT}{lst_t4t:mtasktemp:setSds}). With \cleaninline{DHT} we again create a temperature sensor object \cleaninline{dht}. -The \gls{ITASK} \gls{SDS} \cleaninline{latestTemp} is first transformed to a \gls{SDS} that accepts only temperature values, +The \gls{ITASK} \gls{SDS} \cleaninline{latestTemp} is first transformed to \pgls{SDS} that accepts only temperature values, the \cleaninline{dateTimeStampedShare} adds the data via a lens. The \cleaninline{mapRead} adjusts the read type. This new \gls{SDS} of type \cleaninline{Real} is lifted to the \gls{MTASK} program with \cleaninline{liftsds}. @@ -746,7 +746,7 @@ The smart campus sensor node programs executing on the Raspberry Pis have far hi In \gls{PRS} the sensor node program is written in \gls{PYTHON}, a language far less focused on minimising memory usage than \gls{MICROPYTHON}. For example an object like a string is larger in \gls{PYTHON} than in \gls{MICROPYTHON} and consequently does not support all features such as \emph{f-strings}. Furthermore, not all advanced \gls{PYTHON} feature regarding classes are available in \gls{MICROPYTHON}, i.e.\ only a subset of the \gls{PYTHON} specification is supported \citep{diffmicro}. -In summary the sensor node code generated by both tierless languages, \gls{ITASK} and \gls{MTASK}, is sufficiently memory efficient for the target sensor node hardware. Indeed, the maximum residencies of the \gls{CLEAN} sensor node code is less than the corresponding hand-written (Micro)\gls{PYTHON} code. Of course in a tiered stack the hand-written code can be more easily optimised to minimise residency, and this could even entail using a memory efficienthat thet language like \gls{C}\slash\gls{CPP}. However, such optimisation requires additional developer effort, and a new language would introduce additional semantic friction. +In summary the sensor node code generated by both tierless languages, \gls{ITASK} and \gls{MTASK}, is sufficiently memory efficient for the target sensor node hardware. Indeed, the maximum residencies of the \gls{CLEAN} sensor node code is less than the corresponding hand-written (Micro)\gls{PYTHON} code. Of course in a tiered stack the hand-written code can be more easily optimised to minimise residency, and this could even entail using a memory efficient language like \gls{C}\slash\gls{CPP}. However, such optimisation requires additional developer effort, and a new language would introduce additional semantic friction. \paragraph{Power} Sensor nodes and sensors are designed to have low power demands, and this is particularly important if they are operating on batteries. The grey literature consensus is that with all sensors enabled a sensor node should typically have sub-\qty{1}{\watt} peak power draw. The \gls{WEMOS} sensor nodes used in \gls{CWS} and \gls{PWS} have the low power consumption of a typical embedded device: with all sensors enabled, they consume around \qty{0.2}{\watt}. @@ -808,7 +808,7 @@ The most striking information in \cref{table_t4t:multi} is that \emph{the tierle \end{table} \paragraph{Code proportions.} -Comparing the percentages of code required to implement the smart campus functionalities normalises the data and avoids some issues when comparing \gls{SLOC} for different programming languages, and especially for languages with different paradigms like object-oriented \gls{PYTHON} and functional \gls{CLEAN}. \Cref{fig_t4t:multipercentage} shows the percentage of the total \gls{SLOC} required to implement the smart campus functionalities in each of the four implementations, and is computed from the data in \cref{table_t4t:multi}. It shows that there are significant differences between the percentage of code for each functionality between the tiered and tierless implementations. For example 17\% of the tiered implementations specifies communication, whereas this requires only 3\% of the tierless implementations, i.e.\ 6$\times$ less. We explore the reasons for this in \cref{sec_t4t:Communication}. The other major difference is the massive percentage of Database Interface code in the tierless implementations: at least 47\%. The smart campus specification required a standard DBMS, and the \gls{CLEAN}\slash\gls{ITASK} SQL interface occupies some 78 \gls{SLOC}. While this is a little less than the 106 \gls{SLOC} used in \gls{PYTHON} (\cref{table_t4t:multi}), it is a far higher percentage of systems with total codebases of only around 160 \gls{SLOC}. Idiomatic \gls{CLEAN}/\gls{ITASK} would use high level abstractions to store persistent data in an \gls{SDS}, requiring just a few \gls{SLOC}. +Comparing the percentages of code required to implement the smart campus functionalities normalises the data and avoids some issues when comparing \gls{SLOC} for different programming languages, and especially for languages with different paradigms like object-oriented \gls{PYTHON} and functional \gls{CLEAN}. \Cref{fig_t4t:multipercentage} shows the percentage of the total \gls{SLOC} required to implement the smart campus functionalities in each of the four implementations, and is computed from the data in \cref{table_t4t:multi}. It shows that there are significant differences between the percentage of code for each functionality between the tiered and tierless implementations. For example 17\% of the tiered implementations specifies communication, whereas this requires only 3\% of the tierless implementations, i.e.\ 6$\times$ less. We explore the reasons for this in \cref{sec_t4t:Communication}. The other major difference is the massive percentage of Database Interface code in the tierless implementations: at least 47\%. The smart campus specification required a standard DBMS, and the \gls{CLEAN}\slash\gls{ITASK} SQL interface occupies some 78 \gls{SLOC}. While this is a little less than the 106 \gls{SLOC} used in \gls{PYTHON} (\cref{table_t4t:multi}), it is a far higher percentage of systems with total codebases of only around 160 \gls{SLOC}. Idiomatic \gls{CLEAN}/\gls{ITASK} would use high level abstractions to store persistent data in \pgls{SDS}, requiring just a few \gls{SLOC}. The total size of \gls{CWS} and \gls{CRS} would be reduced by a factor of two and the percentage of Database Interface code would be even less than in the tiered \gls{PYTHON} implementations. -- 2.20.1