From 184c730e7c9ab350be853218f5e1f9b8866531ce Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 9 Feb 2017 15:32:29 +0100 Subject: [PATCH] start with management tasks --- Makefile | 2 +- miTask.icl | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0beb478..04e4d8c 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ CLMLIBS:=\ BINARIES:= miTask mTaskExamples mTaskInterpret all: CleanSerial/Clean\ System\ Files/TTY.o $(BINARIES) client/mTaskSymbols.h - find $(CLEAN_HOME)/lib -path '*/WebPublic/*' -execdir cp -nR {} "$$PWD"/miTask-www/ \; + #find $(CLEAN_HOME)/lib -path '*/WebPublic/*' -execdir cp -nR {} "$$PWD"/miTask-www/ \; CleanSerial/Clean\ System\ Files/TTY.o: make -C CleanSerial diff --git a/miTask.icl b/miTask.icl index 767cd98..e81f47d 100644 --- a/miTask.icl +++ b/miTask.icl @@ -24,11 +24,15 @@ import TTY derive class iTask Queue, TTYSettings, Parity, BaudRate, ByteSize derive class iTask MTaskMSGRecv, MTaskMSGSend, SerTCP, UserLED +derive class iTask MTaskDevice + :: SerTCP = Serial | TCP :: *Resource | TTYd !*TTY +:: MTaskDevice = SerialDevice String TTYSettings | TCPDevice String Int Start :: *World -> *World -Start world = startEngine mTaskTask world +Start world = startEngine (mTaskManager + >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world //Start world = startEngine mTaskTask world bc :: Main (ByteCode () Stmt) @@ -55,7 +59,6 @@ bc2 d = {main = ledOn d} bc3 :: UserLED -> Main (ByteCode () Stmt) bc3 d = {main = ledOff d} - withDevice :: ((Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task a) -> Task a | iTask a withDevice t = withShared ([], [], False) \ch-> enterInformation "Type" [] @@ -74,6 +77,30 @@ withDevice t = withShared ([], [], False) \ch-> isTTY s = not (isEmpty (filter (flip startsWith s) prefixes)) prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"] +mTaskManager :: Task () +mTaskManager = viewSharedInformation "Devices" [] deviceStore + ||- forever (addDevice >>= \d->upd (\l->[d:l]) deviceStore) @! () + where + deviceStore :: Shared [MTaskDevice] + deviceStore = sdsFocus "mTaskDevices" $ memoryStore "" (Just []) + +addDevice :: Task MTaskDevice +addDevice = enterInformation "Enter device type" [] + >>= \ty->case ty of + TCP = (enterInformation "Host" [] -&&- enterInformation "Port" []) + >>= return o uncurry TCPDevice + Serial = accWorld getDevices + >>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero) + >>= return o uncurry SerialDevice + where + getDevices :: !*World -> *(![String], !*World) + getDevices w = case readDirectory "/dev" w of + (Error (errcode, errmsg), w) = abort errmsg + (Ok entries, w) = (map ((+++) "/dev/") (filter isTTY entries), w) + where + isTTY s = not (isEmpty (filter (flip startsWith s) prefixes)) + prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"] + mTaskTask :: Task () mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in withDevice \ch-> -- 2.20.1