From 2498dced580be1e7af31a662dadee26c4fd159ed Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 9 Jul 2017 11:56:13 +0200 Subject: [PATCH] update presentation, the body is there --- arch.communication.tex | 2 +- arch.example.tex | 5 +- arch.itasks.tex | 2 +- pres.conclusion.tex | 2 - pres.system.tex | 322 ++++++++++++++++++++++++++++++++++++----- presentation.pre | 1 - 6 files changed, 291 insertions(+), 43 deletions(-) diff --git a/arch.communication.tex b/arch.communication.tex index 916b780..0bb3746 100644 --- a/arch.communication.tex +++ b/arch.communication.tex @@ -124,7 +124,7 @@ where MTDevSpec s = deviceAddSpec device s @! () ) >>| proc ms -connectDevice :: MTaskDevice -> Task Channels +connectDevice :: MTaskDevice -> Task MTaskDevice connectDevice device = set ([], [], False) ch >>| appendTopLevelTask 'DM'.newMap True ( process device ch -||- catchAll (getSynFun device.deviceData ch) errHdl) diff --git a/arch.example.tex b/arch.example.tex index 2d28698..b8ef049 100644 --- a/arch.example.tex +++ b/arch.example.tex @@ -51,7 +51,10 @@ where IF cool (ledOn LED1) (ledOff LED1) :. digitalWrite D5 cool } - nodeMCU = TCP + nodeMCU = makeDevice "NodeMCU" + (TCPDevice {host="192.168.0.12", port=8888}) + stm32 = makeDevice "Stm32" + (SerialDevice {devicePath="/dev/ttyUSB0", baudrate=B9600, ...} \end{lstlisting} \subsection[Lifting mTasks to iTasks-Tasks]% diff --git a/arch.itasks.tex b/arch.itasks.tex index 5168510..a699fd8 100644 --- a/arch.itasks.tex +++ b/arch.itasks.tex @@ -72,7 +72,7 @@ the specification of the device that is received when connecting. All of this is given in Listing~\ref{lst:mtaskdevice}. The definitions of the message format are explained in the following section. -\subsection{Shares} +\subsection{\glspl{SDS}} \Glspl{SDS} on the device can be accessed by both the device and the server. While it would be possible to only store the \glspl{SDS} on the device, this would require a lot of communication because every read operation will then diff --git a/pres.conclusion.tex b/pres.conclusion.tex index bf626bc..28c5b49 100644 --- a/pres.conclusion.tex +++ b/pres.conclusion.tex @@ -9,7 +9,6 @@ \end{itemize} \end{frame} -\subsection{Further Research} \begin{frame} \frametitle{Future Research} \begin{itemize}[<+->] @@ -25,7 +24,6 @@ \end{itemize} \end{frame} -\subsection{Demo} \begin{frame} \frametitle{And ofcourse\ldots\pause{} a demo} \pause{} diff --git a/pres.system.tex b/pres.system.tex index 84b9b1e..c3642bf 100644 --- a/pres.system.tex +++ b/pres.system.tex @@ -63,7 +63,7 @@ instance arith ByteCode where \frametitle{Control flow} \begin{itemize} \item Use labels - \item Label resolving + \item Label are resolved \pause{} \item Thus no reuse \end{itemize} @@ -129,16 +129,10 @@ instance sdspub ByteCode where \end{block} \pause{} \begin{block}{New} - \begin{itemize} + \begin{itemize}[<+->] \item Old system, taskserver, tasks start tasks \item New system, task+strategy - \pause{} - \begin{itemize} - \item \CI{OnShot} - \item \CI{OnInterval} - \item \CI{OnInterrupt} - \end{itemize} - \pause{} + \item \CI{OnShot}, \CI{OnInterval}, \CI{OnInterrupt} \item How to handle termination \end{itemize} \pause{} @@ -149,24 +143,132 @@ class retrn v where \end{block} \end{frame} -\subsection{Interpretation} +\subsection{Devices} \begin{frame}[fragile] - \frametitle{mTask implementation} - %TODO + \frametitle{Devices} + \begin{itemize}[<+->] + \item Standard C client software + \item Modular implementation + \item Specification generated from the macros + \end{itemize} + + \begin{lstlisting}[language=C,caption={interface.h}] +... +#elif defined TARGET_STM32F767ZI +#define APINS 128 +#define DPINS 128 +#define STACKSIZE 1024 +#define MEMSIZE 1024 +#define HAVELED 1 +#define HAVEHB 1 + +#elif defined ARDUINO_ESP8266_NODEMCU +... +bool input_available(void); +uint8_t read_byte(void); +void write_byte(uint8_t b); + +#if DPINS > 0 +void write_dpin(uint8_t i, bool b); +... + \end{lstlisting} \end{frame} -\subsection{Devices} -\begin{frame} - \frametitle{Devices} - \begin{itemize} - \item Standard C - \item Implement some classes in interface - \pause{} - \item How to handle termination +\begin{frame}[fragile] + \frametitle{Storage} + \begin{itemize}[<+->] + \item Heap is there, but inefficient + \item Allocate space in global data + \item Selfmanage it + \item Tasks grow up + \item SDSs grow down + \item Compacting on removal \end{itemize} + \pause{} + \begin{lstlisting}[language=C] +struct task { + uint16_t tasklength; + uint16_t interval; + unsigned long lastrun; + uint8_t taskid; + uint8_t *bc; +}; + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Interpreter} + Stack machine, modular + \pause{} + \begin{lstlisting}[language=C] +#define f16(p) program[pc]*265+program[pc+1] + +void run_task(struct task *t){ + uint8_t *program = t->bc; + int plen = t->tasklength, pc = 0, sp = 0; + while(pc < plen){ + switch(program[pc++]){ + case BCPUSH: + stack[sp++] = pc++ //Simplified + break; + case BCADD: + stack[sp-2] = stack[sp-2] + stack[sp-1]; + sp -= 1; + break; + case BCJMPT: + pc = stack[--sp] ? program[pc]-1 : pc+1; + break; +#if APINS > 0 + case BCANALOGREAD: + ... + \end{lstlisting} \end{frame} \subsection{Server} +\begin{frame}[fragile] + \frametitle{Device storage} + \begin{lstlisting}[language=Clean] +:: Channels :== ([MTaskMSGRecv], [MTaskMSGSend], Bool) +:: MTaskResource + = TCPDevice TCPSettings + | SerialDevice TTYSettings + | ... +:: MTaskDevice = + { deviceTask :: Maybe TaskId , deviceError :: Maybe String + , deviceChannels :: String , deviceName :: String + , deviceState :: BCState , deviceTasks :: [MTaskTask] + , deviceResource :: MTaskResource + , deviceSpec :: Maybe MTaskDeviceSpec + , deviceShares :: [MTaskShare] + } + +channels :: MTaskDevice -> Shared Channels + +class MTaskDuplex a where + synFun :: a (Shared Channels) -> Task () + \end{lstlisting} +\end{frame} + +\begin{frame} + \frametitle{SDS storage} + \begin{block}{Approaches} + \begin{itemize}[<+->] + \item One SDS per SDS + \item One SDS per Device and map + \item One SDS in the entire system and map + \end{itemize} + \end{block} + + \pause{} + + \begin{block}{Notifications} + \begin{itemize}[<+->] + \item Tasks monitoring the SDSs + \item Parametric lenses! + \end{itemize} + \end{block} +\end{frame} + \begin{frame}[fragile] \frametitle{SDS (2)} \framesubtitle{Parametric Lenses} @@ -178,20 +280,166 @@ class retrn v where \item On write the SDS returns \CI{p -> Bool} \end{itemize} \end{block} -% -% \begin{lstlisting} -%sdsFocus :: p1 (RWShared p1 r w) -> RWShared p2 r w | iTask p -% -%:: SDSNotifyPred p :== p -> Bool -%:: SDSLensRead p r rs = SDSRead (p -> rs -> MaybeError TaskException r) -% | SDSReadConst (p -> r) -%:: SDSLensWrite p w rs ws = SDSWrite (p -> rs -> w -> MaybeError TaskException (Maybe ws)) -% | SDSWriteConst (p -> w -> MaybeError TaskException (Maybe ws)) -%:: SDSLensNotify p w rs = SDSNotify (p -> rs -> w -> SDSNotifyPred p) -% | SDSNotifyConst (p -> w -> SDSNotifyPred p) -% -%sdsLens :: String (p -> ps) (SDSLensRead p r rs) (SDSLensWrite p w rs ws) -% (SDSLensNotify p w rs) (RWShared ps rs ws) -> RWShared p r w | iTask ps -% \end{lstlisting} -\end{frame} -\subsection{Examples} + \begin{lstlisting}[language=Clean] +sdsFocus :: p1 (RWShared p1 r w) -> RWShared p2 r w | iTask p + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Solve the notification problem and how to relay information?} + \begin{itemize} + \item Tailor made share + \item The read and write functions have the World + \end{itemize} + + \pause{} + + \begin{onlyenv}<2> + \begin{lstlisting}[language=Clean] +:: P :== Maybe (MTaskDevice, Int) +deviceStore :: RWShared P [MTaskDevice] [MTaskDevice] +deviceStore = SDSSource {SDSSource + | name="deviceStore", read=realRead, write=realWrite} +where + realDeviceStore :: Shared [MTaskDevice] + realDeviceStore = sharedStore "mTaskDevices" [] + + realRead :: P *IWorld + -> (MaybeError TaskException [MTaskDevice], *IWorld) + realRead p iw = read realDeviceStore iw + \end{lstlisting} + \end{onlyenv} + + \begin{onlyenv}<3> + \begin{lstlisting}[language=Clean] +realWrite :: P [MTaskDevice] *IWorld + -> (MaybeError TaskException (SDSNotifyPred P), *IWorld) +realWrite mi w iw +# (merr, iw) = write w realDeviceStore iw +| isNothing mi = (Ok $ gEq{|*|} mi, iw) +# (Just (dev, ident)) = mi +| ident == -1 = (Ok $ gEq{|*|} mi, iw) += case find ((==)dev) w of + Nothing = (Error $ exception "Device lost", iw) + Just {deviceShares} = case find (\d->d.identifier == ident) deviceShares of + Nothing = (Error $ exception "Share lost", iw) + Just s = case sendMessagesIW [MTUpd ident s.MTaskShare.value] dev iw of + (Error e, iw) = (Error e, iw) + (Ok _, iw) = (Ok $ gEq{|*|} mi, iw) + \end{lstlisting} + \end{onlyenv} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Specific SDS functions} + \begin{lstlisting} +deviceStoreNP :: Shared [MTaskDevice] +deviceStoreNP = sdsFocus Nothing deviceStore + +deviceShare :: MTaskDevice -> Shared MTaskDevice +deviceShare d = mapReadWriteError + ( \ds->case find ((==)d) ds of + Nothing = exception "Device lost" + Just d = Ok d) + , \w ds->case splitWith ((==)d) ds of + ([], _) = Error $ exception "Device lost" + ([_:_], ds) = Ok $ Just [w:ds]) + $ sdsFocus (Just (d, -1)) deviceStore + +shareShare :: MTaskDevice MTaskShare -> Shared BCValue +... +\end{lstlisting} +\end{frame} + +\subsection{Communication} +\begin{frame} + \frametitle{The glue of the system} + \begin{itemize} + \item Compile, send and interact with Tasks + \item Interact with SDSs + \item All communication via channels + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Messages} + \begin{lstlisting}[language=Clean] +:: MTaskId :== Int +:: MSDSId :== Int +:: MTaskFreeBytes :== Int +:: MTaskMSGRecv + = MTTaskAck MTaskId MTaskFreeBytes | MTTaskDelAck MTaskId + | MTSDSAck MSDSId | MTSDSDelAck MSDSId + | MTPub MSDSId BCValue | MTMessage String + | MTDevSpec MTaskDeviceSpec | MTEmpty + +:: MTaskMSGSend + = MTTask MTaskInterval String | MTTaskDel MTaskId + | MTShutdown | MTSds MSDSId BCValue + | MTUpd MSDSId BCValue | MTSpec + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Connecting with a device} + \begin{lstlisting}[language=Clean] +process :: MTaskDevice (Shared Channels) -> Task () +process ... + +makeDevice :: String MTaskResource -> MTaskDevice + +connectDevice :: MTaskDevice -> Task MTaskDevice +connectDevice device = set ([], [], False) ch + >>| appendTopLevelTask newMap True + ( process device ch -||- catchAll (getSynFun device.deviceData ch) errHdl) + >>= \tid->upd (\d->{d&deviceTask=Just tid,deviceError=Nothing}) (deviceShare device) + >>| set (r,[MTSpec],ss) ch + >>| treturn device +where + errHdl e = upd (\d->{d & deviceTask=Nothing, deviceError=Just e}) (deviceShare device) @! () + ch = channels device + \end{lstlisting} +\end{frame} + +\begin{frame} + \frametitle{Compilation} + \begin{itemize}[<+->] + \item Get device's compiler state + \item Run the RWS + \item Resolve labels + \item Instantiate shares + \item Convert to messages + \item Update state + \item Send the messages + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Interaction with devices} + \begin{block}{Send task} + \begin{lstlisting}[language=Clean] +sendTaskToDevice :: String (Main (ByteCode a Stmt)) (MTaskDevice, MTaskInterval) + -> Task (MTaskTask, [MTaskShare]) + \end{lstlisting} + \end{block} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Example, blink} + \begin{lstlisting}[language=Clean] +blink :: Task () +blink = makeDevice "stm32" stm32 >>= connectDevice + >>= \stm-> sendTaskToDevice "blink" blinkTask (stm32, OnInterval 1000) + >>= \(st, [t:_])->forever ( + updateSharedInformation "Which led to blink" [] (shareShare stm t) + ) >>* [OnAction (Action "Shutdown") $ always + $ deleteDevice stm >>| shutDown 0 + ] +where + stm32 = makeDevice "Stm32" + (SerialDevice {devicePath="/dev/ttyUSB0", baudrate=B9600, ...} + blinkTask = sds \led=LED0 In sds \x=True In + {main = IF x (ledOff led) (ledOn led) :. x =. Not x } + + \end{lstlisting} +\end{frame} diff --git a/presentation.pre b/presentation.pre index 35ade65..98a4af6 100644 --- a/presentation.pre +++ b/presentation.pre @@ -41,7 +41,6 @@ literate=% % Basic Clean constructs {\\}{{$\lambda\:$}}1 - {->}{{$\rightarrow\:$}}1 {A.}{{$\forall\;\,$}}1 {E.}{{$\exists\;\,$}}1 {*}{{$^*$}}1 -- 2.20.1