started with device handshake
authorMart Lubbers <mart@martlubbers.net>
Wed, 15 Mar 2017 17:49:47 +0000 (18:49 +0100)
committerMart Lubbers <mart@martlubbers.net>
Wed, 15 Mar 2017 17:52:12 +0000 (18:52 +0100)
Devices/mTaskDevice.dcl
Devices/mTaskDevice.icl
Shares/mTaskShare.dcl
Shares/mTaskShare.icl
client/Makefile.linux
client/main.c
client/spec.c [new file with mode: 0644]
client/spec.h [new file with mode: 0644]
mTaskInterpret.dcl
mTaskInterpret.icl
miTask.icl

index c489d01..17acd10 100644 (file)
@@ -10,7 +10,7 @@ import mTaskInterpret
 import Generics.gCons
 import iTasksTTY
 
 import Generics.gCons
 import iTasksTTY
 
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
+derive class iTask MTaskDevice, MTaskDeviceSpec, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
 derive conses MTaskResource, TCPSettings
 derive consName MTaskResource, TCPSettings
 
 derive conses MTaskResource, TCPSettings
 derive consName MTaskResource, TCPSettings
 
@@ -20,13 +20,14 @@ derive consName MTaskResource, TCPSettings
        = TCPDevice TCPSettings
        | SerialDevice TTYSettings
 
        = TCPDevice TCPSettings
        | SerialDevice TTYSettings
 
-:: MTaskDevice = {
-                deviceTask :: Maybe TaskId
-               ,deviceError :: Maybe String
-               ,deviceChannels :: String
-               ,deviceName :: String
-               ,deviceTasks :: [MTaskTask]
-               ,deviceData :: MTaskResource
+:: MTaskDevice =
+               { deviceTask :: Maybe TaskId
+               , deviceError :: Maybe String
+               , deviceChannels :: String
+               , deviceName :: String
+               , deviceTasks :: [MTaskTask]
+               , deviceData :: MTaskResource
+               , deviceSpec :: Maybe MTaskDeviceSpec
        }
 
 instance == MTaskDevice
        }
 
 instance == MTaskDevice
@@ -43,3 +44,4 @@ sendMessages :: [MTaskMSGSend] -> (MTaskDevice -> Task Channels)
 deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
 deviceTaskAcked :: MTaskDevice Int -> Task ()
 deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
 deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
 deviceTaskAcked :: MTaskDevice Int -> Task ()
 deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
+deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task ()
index 0304e7e..eb32f49 100644 (file)
@@ -18,7 +18,7 @@ import iTasks.UI.Definition, iTasks.UI.Editor, iTasks.UI.Editor.Builtin, iTasks.
 
 from Data.Func import $
 
 
 from Data.Func import $
 
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
+derive class iTask MTaskDevice, MTaskResource, MTaskDeviceSpec, MTaskMSGRecv, MTaskMSGSend, BCShare
 derive conses MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
 derive consName MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
 
 derive conses MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
 derive consName MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
 
@@ -36,7 +36,8 @@ makeDevice name res = get randomInt @ \rand->{MTaskDevice
                ,deviceTasks=[]
                ,deviceTask=Nothing
                ,deviceError=Nothing
                ,deviceTasks=[]
                ,deviceTask=Nothing
                ,deviceError=Nothing
-               ,deviceData=res}
+               ,deviceData=res
+               ,deviceSpec=Nothing}
 
 getSynFun :: MTaskResource -> ((Shared Channels) -> Task ())
 getSynFun (TCPDevice t) = synFun t
 
 getSynFun :: MTaskResource -> ((Shared Channels) -> Task ())
 getSynFun (TCPDevice t) = synFun t
@@ -140,3 +141,6 @@ deviceTaskDelete dev task = sendMessages [MTTaskDel task.ident] dev @! ()
 deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
 deviceTaskDeleteAcked d i = withDevices d $ deleteTask
        where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> s.ident]}
 deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
 deviceTaskDeleteAcked d i = withDevices d $ deleteTask
        where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> s.ident]}
+
+deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task ()
+deviceAddSpec d s = withDevices d $ \r->{r&deviceSpec=Just s}
index aab56db..9110254 100644 (file)
@@ -19,4 +19,4 @@ manageShares :: [MTaskShare] -> Task ()
 ///makeShare :: String Int Dynamic -> Task MTaskShare
 makeShare :: String Int BCValue -> Task MTaskShare
 
 ///makeShare :: String Int Dynamic -> Task MTaskShare
 makeShare :: String Int BCValue -> Task MTaskShare
 
-updateShare :: Int String -> Task ()
+updateShare :: Int BCValue -> Task ()
index fe65501..27c9544 100644 (file)
@@ -60,9 +60,9 @@ makeShare withTask identifier value = treturn
                ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
                } >>= \sh->set value (getSDSShare sh) >>| treturn sh
 
                ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
                } >>= \sh->set value (getSDSShare sh) >>| treturn sh
 
-updateShare :: Int String -> Task ()
+updateShare :: Int BCValue -> Task ()
 updateShare ident val = get sdsStore
        >>= \sh->(case find (\s->s.identifier==ident) sh of
                Nothing = abort "Help, no share found with this ident"
 updateShare ident val = get sdsStore
        >>= \sh->(case find (\s->s.identifier==ident) sh of
                Nothing = abort "Help, no share found with this ident"
-               Just mts = set (fromByteCode val) (getSDSShare mts))
+               Just mts = set val (getSDSShare mts))
        >>| traceValue "Updated" @! ()
        >>| traceValue "Updated" @! ()
index a08c84d..55e2e44 100644 (file)
@@ -1,6 +1,6 @@
 CFLAGS:=-g -Wall -Wextra  -DDEBUG
 PROG:=main
 CFLAGS:=-g -Wall -Wextra  -DDEBUG
 PROG:=main
-OBJS:=interpret.o sds.o task.o main.o interface.o
+OBJS:=interpret.o sds.o task.o main.o interface.o spec.o
 
 all: mTaskSymbols.h $(PROG)
 
 
 all: mTaskSymbols.h $(PROG)
 
index a7d6098..9de18bc 100644 (file)
@@ -11,6 +11,7 @@
 #include "interpret.h"
 #include "mTaskSymbols.h"
 #include "sds.h"
 #include "interpret.h"
 #include "mTaskSymbols.h"
 #include "sds.h"
+#include "spec.h"
 #include "task.h"
 #include "interface.h"
 
 #include "task.h"
 #include "interface.h"
 
@@ -104,7 +105,8 @@ int main(int argc, char *argv[]){
        setup();
        sds_init();
        task_init();
        setup();
        sds_init();
        task_init();
-       debug("booting up");
+       debug("sending device spec");
+       spec_send();
        while(true){
                //Check for newetasks
                loop();
        while(true){
                //Check for newetasks
                loop();
diff --git a/client/spec.c b/client/spec.c
new file mode 100644 (file)
index 0000000..7bf8576
--- /dev/null
@@ -0,0 +1,4 @@
+//TODO
+void spec_send(void){
+
+}
diff --git a/client/spec.h b/client/spec.h
new file mode 100644 (file)
index 0000000..0007dc3
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef SPEC_H
+#define SPEC_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+struct device_spec {
+       bool have_led;
+       bool have_aio;
+       bool have_dio;
+       uint8_t max_tasks;
+       uint8_t max_sds;
+};
+
+void spec_send(void);
+
+#endif
index 92f6683..f64cf62 100644 (file)
@@ -15,8 +15,9 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi
        | MTTaskDelAck Int
        | MTSDSAck Int
        | MTSDSDelAck Int
        | MTTaskDelAck Int
        | MTSDSAck Int
        | MTSDSDelAck Int
-       | MTPub Int String
+       | MTPub Int BCValue
        | MTMessage String
        | MTMessage String
+       | MTDevSpec MTaskDeviceSpec
        | MTEmpty
 
 :: MTaskMSGSend
        | MTEmpty
 
 :: MTaskMSGSend
@@ -30,6 +31,14 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi
        | OnInterval Int
        | OnInterrupt Int
 
        | OnInterval Int
        | OnInterrupt Int
 
+:: MTaskDeviceSpec =
+               {haveLed :: Bool
+               ,haveAio :: Bool
+               ,haveDio :: Bool
+               ,maxTask :: Int //Should be number of bytes reserved in total for shares, tasks and functions
+               ,maxSDS  :: Int
+       }
+
 :: BCValue = E.e: BCValue e & mTaskType e
 
 instance toString MTaskInterval
 :: BCValue = E.e: BCValue e & mTaskType e
 
 instance toString MTaskInterval
@@ -84,7 +93,7 @@ decode :: String -> MTaskMSGRecv
        | BCDigitalWrite Pin
        | BCTest AnalogPin
 
        | BCDigitalWrite Pin
        | BCTest AnalogPin
 
-derive gPrint BCValue
+derive gPrint BCValue, MTaskDeviceSpec
 derive consIndex BCValue
 derive consName BCValue
 derive conses BCValue
 derive consIndex BCValue
 derive consName BCValue
 derive conses BCValue
@@ -121,7 +130,7 @@ class mTaskType a | toByteCode, fromByteCode, iTask, TC a
 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
 instance toByteCode MTaskInterval
 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
 instance toByteCode MTaskInterval
-instance fromByteCode MTaskInterval
+instance fromByteCode MTaskInterval, MTaskDeviceSpec
 
 instance arith ByteCode
 instance boolExpr ByteCode
 
 instance arith ByteCode
 instance boolExpr ByteCode
index e603f82..b6ab929 100644 (file)
@@ -55,12 +55,13 @@ decode :: String -> MTaskMSGRecv
 decode x
 | size x == 0 = MTEmpty
 = case x.[0] of
 decode x
 | size x == 0 = MTEmpty
 = case x.[0] of
-       't' = MTTaskAck (from16bit (x % (1,3)))
-       'd' = MTTaskDelAck (from16bit (x % (1,3)))
+       't' = MTTaskAck $ fromByteCode x
+       'd' = MTTaskDelAck $ fromByteCode x
        'm' = MTMessage x
        'm' = MTMessage x
-       's' = MTSDSAck (from16bit (x % (1,3)))
-       'a' = MTSDSDelAck (from16bit (x % (1,3)))
-       'p' = MTPub (from16bit (x % (1,3))) (x % (3,size x))
+       's' = MTSDSAck $ fromByteCode x
+       'a' = MTSDSDelAck $ fromByteCode x
+       'p' = MTPub (fromByteCode x) $ fromByteCode $ x % (3,size x)
+       'c'     = MTDevSpec $ fromByteCode (x % (1, size x))
        '\0' = MTEmpty
        '\n' = MTEmpty
        _ = MTMessage x//abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n")
        '\0' = MTEmpty
        '\n' = MTEmpty
        _ = MTMessage x//abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n")
@@ -152,8 +153,17 @@ instance fromByteCode MTaskInterval
                        0 = OneShot
                        i = OnInterval i
                = OnInterrupt $ fromByteCode s bitand 127
                        0 = OneShot
                        i = OnInterval i
                = OnInterrupt $ fromByteCode s bitand 127
-
-derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC
+instance fromByteCode MTaskDeviceSpec where
+       fromByteCode s = let c = toInt s.[0] in
+               {MTaskDeviceSpec
+               |haveLed=c bitand 1 > 0
+               ,haveAio=c bitand 2 > 0
+               ,haveDio=c bitand 4 > 0
+               ,maxTask=toInt s.[1]
+               ,maxSDS =toInt s.[2]
+               }
+
+derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC, MTaskDeviceSpec
 derive class gCons BC
 
 consIndex{|BCValue|} _ = 0
 derive class gCons BC
 
 consIndex{|BCValue|} _ = 0
index e14f9e3..45ee7dd 100644 (file)
@@ -66,5 +66,6 @@ mTaskManager = startupDevices >>| anyTask
                                        MTPub i val = updateShare i val
                                        MTTaskAck i = deviceTaskAcked device i
                                        MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
                                        MTPub i val = updateShare i val
                                        MTTaskAck i = deviceTaskAcked device i
                                        MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
+                                       MTDevSpec s = deviceAddSpec device s @! ()
                                        _ = treturn ()
                                        ) >>| proc ms
                                        _ = treturn ()
                                        ) >>| proc ms