From be3f747f775c05facb8a34cf0baba523401b88fb Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 19 Mar 2017 20:33:12 +0100 Subject: [PATCH] forgot to commit --- Devices/mTaskDevice.dcl | 2 +- Devices/mTaskDevice.icl | 4 ++-- Devices/mTaskTCP.icl | 8 +++++--- client/main.c | 1 + client/spec.c | 2 ++ mTaskInterpret.dcl | 2 +- mTaskInterpret.icl | 4 +++- miTask.icl | 30 ++++++++++++++++++++++++++++-- 8 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index 17acd10..ce6e608 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -10,7 +10,7 @@ import mTaskInterpret import Generics.gCons import iTasksTTY -derive class iTask MTaskDevice, MTaskDeviceSpec, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare +derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare derive conses MTaskResource, TCPSettings derive consName MTaskResource, TCPSettings diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index 537a3b9..9b26455 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, MTaskDeviceSpec, MTaskMSGRecv, MTaskMSGSend, BCShare +derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare derive conses MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings derive consName MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings @@ -143,4 +143,4 @@ 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} +deviceAddSpec d s = withDevices d $ \r->{MTaskDevice | r & deviceSpec=Just s} diff --git a/Devices/mTaskTCP.icl b/Devices/mTaskTCP.icl index 52832d6..4ebc1ac 100644 --- a/Devices/mTaskTCP.icl +++ b/Devices/mTaskTCP.icl @@ -23,7 +23,7 @@ instance MTaskDuplex TCPSettings where onDisconnect=onDisconnect} @! () where onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) - onConnect acc (msgs,send,sendStopped) = (Ok acc, Just (msgs,[],sendStopped), map encode send, False) + onConnect acc (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False) whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) //We stop @@ -37,9 +37,11 @@ instance MTaskDuplex TCPSettings where = (Ok acc, Just (msgs++map decode nd,[],sendStopped), map encode send, False) process :: String -> (String, [String]) - process s = case indexOf "\n" s of + process s + | not (trace_tn ("process: " +++ toString (toJSON s))) = undef + = case indexOf "\n" s of -1 = (s, []) - i = appSnd (\ss->[s % (0,i):ss]) (process (s % (i+1, size s))) + i = appSnd (\ss->[s % (0,i-1):ss]) (process (s % (i+1, size s))) onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool)) onDisconnect _ (msgs,send,sendStopped) = (Ok "", Nothing) diff --git a/client/main.c b/client/main.c index 9de18bc..012e062 100644 --- a/client/main.c +++ b/client/main.c @@ -50,6 +50,7 @@ void read_message(void) task_register(); break; case '\0': + die("Server closed connection"); break; case '\n': break; diff --git a/client/spec.c b/client/spec.c index 8098a77..825e894 100644 --- a/client/spec.c +++ b/client/spec.c @@ -4,9 +4,11 @@ void spec_send(void) { + debug("Writing spec"); write_byte('c'); write_byte(0 | (HAVELED << 0) | (HAVEAIO << 1) | (HAVEDIO << 2)); write16(MAXTASKS); write16(MAXSDSS); write_byte('\n'); + debug("Done writing spec"); } diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl index f64cf62..f0795e1 100644 --- a/mTaskInterpret.dcl +++ b/mTaskInterpret.dcl @@ -100,7 +100,7 @@ derive conses BCValue derive consNum BCValue derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin -derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode +derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode, MTaskDeviceSpec derive gEditor BCValue derive gText BCValue derive JSONEncode BCValue diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 716fc18..c986ec5 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -51,8 +51,10 @@ encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n" encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" +import StdDebug decode :: String -> MTaskMSGRecv decode x +| not (trace_tn ("decoding: " +++ toString (toJSON x))) = undef | size x == 0 = MTEmpty = case x.[0] of 't' = MTTaskAck $ fromByteCode x @@ -193,7 +195,7 @@ gDefault{|BCValue|} = BCValue 0 gEq{|BCValue|} (BCValue e) (BCValue f) = toByteCode e == toByteCode f derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin -derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode +derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode, MTaskDeviceSpec op2 :: (ByteCode a p1) (ByteCode a p2) BC -> ByteCode b Expr op2 (BC x) (BC y) bc = BC $ x >>| y >>| tell [bc] diff --git a/miTask.icl b/miTask.icl index 45ee7dd..fda80c8 100644 --- a/miTask.icl +++ b/miTask.icl @@ -24,9 +24,35 @@ import iTasks._Framework.Serialization import TTY, iTasksTTY +//derive class iTask ByteSize, Parity, BaudRate, TTYSettings, TCPSettings +//derive class iTask MTaskDeviceSpec, MTaskResource, MTaskTask, MTaskDevice + Start :: *World -> *World -Start world = startEngine (mTaskManager - >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world +Start world = startEngine (viewInformation "" [] md) world + where + md = + { deviceTask = Just $ TaskId 0 0 + , deviceError = Just "" + , deviceChannels = "abc" + , deviceName = "hoi" + , deviceTasks = [] + , deviceData = TCPDevice {TCPSettings + |host="localhost", + port=8888 + } + , deviceSpec = Just {MTaskDeviceSpec + |haveLed = True + ,haveAio = True + ,haveDio = True + ,maxTask = 42 + ,maxSDS = 5 + } + } + + + +//Start world = startEngine (mTaskManager +// >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world mTaskManager :: Task () mTaskManager = startupDevices >>| anyTask -- 2.20.1