From: Mart Lubbers Date: Wed, 15 Mar 2017 17:49:47 +0000 (+0100) Subject: started with device handshake X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=32ff545d18253da21f25c69c6d99b96f90668773;p=mTask.git started with device handshake --- diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index c489d01..17acd10 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -10,7 +10,7 @@ import mTaskInterpret 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 @@ -20,13 +20,14 @@ derive consName MTaskResource, TCPSettings = 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 @@ -43,3 +44,4 @@ sendMessages :: [MTaskMSGSend] -> (MTaskDevice -> Task Channels) deviceTaskDelete :: MTaskDevice MTaskTask -> Task () deviceTaskAcked :: MTaskDevice Int -> Task () deviceTaskDeleteAcked :: MTaskDevice Int -> Task () +deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task () diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index 0304e7e..eb32f49 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -18,7 +18,7 @@ import iTasks.UI.Definition, iTasks.UI.Editor, iTasks.UI.Editor.Builtin, iTasks. 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 @@ -36,7 +36,8 @@ makeDevice name res = get randomInt @ \rand->{MTaskDevice ,deviceTasks=[] ,deviceTask=Nothing ,deviceError=Nothing - ,deviceData=res} + ,deviceData=res + ,deviceSpec=Nothing} 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]} + +deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task () +deviceAddSpec d s = withDevices d $ \r->{r&deviceSpec=Just s} diff --git a/Shares/mTaskShare.dcl b/Shares/mTaskShare.dcl index aab56db..9110254 100644 --- a/Shares/mTaskShare.dcl +++ b/Shares/mTaskShare.dcl @@ -19,4 +19,4 @@ manageShares :: [MTaskShare] -> Task () ///makeShare :: String Int Dynamic -> Task MTaskShare makeShare :: String Int BCValue -> Task MTaskShare -updateShare :: Int String -> Task () +updateShare :: Int BCValue -> Task () diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index fe65501..27c9544 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -60,9 +60,9 @@ makeShare withTask identifier value = treturn ,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" - Just mts = set (fromByteCode val) (getSDSShare mts)) + Just mts = set val (getSDSShare mts)) >>| traceValue "Updated" @! () diff --git a/client/Makefile.linux b/client/Makefile.linux index a08c84d..55e2e44 100644 --- a/client/Makefile.linux +++ b/client/Makefile.linux @@ -1,6 +1,6 @@ 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) diff --git a/client/main.c b/client/main.c index a7d6098..9de18bc 100644 --- a/client/main.c +++ b/client/main.c @@ -11,6 +11,7 @@ #include "interpret.h" #include "mTaskSymbols.h" #include "sds.h" +#include "spec.h" #include "task.h" #include "interface.h" @@ -104,7 +105,8 @@ int main(int argc, char *argv[]){ setup(); sds_init(); task_init(); - debug("booting up"); + debug("sending device spec"); + spec_send(); while(true){ //Check for newetasks loop(); diff --git a/client/spec.c b/client/spec.c new file mode 100644 index 0000000..7bf8576 --- /dev/null +++ b/client/spec.c @@ -0,0 +1,4 @@ +//TODO +void spec_send(void){ + +} diff --git a/client/spec.h b/client/spec.h new file mode 100644 index 0000000..0007dc3 --- /dev/null +++ b/client/spec.h @@ -0,0 +1,17 @@ +#ifndef SPEC_H +#define SPEC_H + +#include +#include + +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 diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl index 92f6683..f64cf62 100644 --- a/mTaskInterpret.dcl +++ b/mTaskInterpret.dcl @@ -15,8 +15,9 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi | MTTaskDelAck Int | MTSDSAck Int | MTSDSDelAck Int - | MTPub Int String + | MTPub Int BCValue | MTMessage String + | MTDevSpec MTaskDeviceSpec | MTEmpty :: MTaskMSGSend @@ -30,6 +31,14 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi | 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 @@ -84,7 +93,7 @@ decode :: String -> MTaskMSGRecv | BCDigitalWrite Pin | BCTest AnalogPin -derive gPrint BCValue +derive gPrint BCValue, MTaskDeviceSpec 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 fromByteCode MTaskInterval +instance fromByteCode MTaskInterval, MTaskDeviceSpec instance arith ByteCode instance boolExpr ByteCode diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index e603f82..b6ab929 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -55,12 +55,13 @@ decode :: String -> MTaskMSGRecv 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 - '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") @@ -152,8 +153,17 @@ instance fromByteCode MTaskInterval 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 diff --git a/miTask.icl b/miTask.icl index e14f9e3..45ee7dd 100644 --- a/miTask.icl +++ b/miTask.icl @@ -66,5 +66,6 @@ mTaskManager = startupDevices >>| anyTask MTPub i val = updateShare i val MTTaskAck i = deviceTaskAcked device i MTTaskDelAck i = deviceTaskDeleteAcked device i @! () + MTDevSpec s = deviceAddSpec device s @! () _ = treturn () ) >>| proc ms