fda80c843d7a1ed72aa83fe83f9d794255a98854
[mTask.git] / miTask.icl
1 module miTask
2
3 import StdDebug, StdMisc
4 from StdFunc import flip
5
6 import iTasks
7 import mTask
8 import Devices.mTaskDevice
9 import Shares.mTaskShare
10 import Tasks.Examples
11 import Utils.SDS
12
13 from Text import class Text(startsWith,concat,split,join), instance Text String
14
15 import qualified Data.Map as DM
16
17 from Data.Func import $
18 import Data.Tuple
19 import Data.List
20 import System.Directory
21
22 import iTasks._Framework.Store
23 import iTasks._Framework.Serialization
24
25 import TTY, iTasksTTY
26
27 //derive class iTask ByteSize, Parity, BaudRate, TTYSettings, TCPSettings
28 //derive class iTask MTaskDeviceSpec, MTaskResource, MTaskTask, MTaskDevice
29
30 Start :: *World -> *World
31 Start world = startEngine (viewInformation "" [] md) world
32 where
33 md =
34 { deviceTask = Just $ TaskId 0 0
35 , deviceError = Just ""
36 , deviceChannels = "abc"
37 , deviceName = "hoi"
38 , deviceTasks = []
39 , deviceData = TCPDevice {TCPSettings
40 |host="localhost",
41 port=8888
42 }
43 , deviceSpec = Just {MTaskDeviceSpec
44 |haveLed = True
45 ,haveAio = True
46 ,haveDio = True
47 ,maxTask = 42
48 ,maxSDS = 5
49 }
50 }
51
52
53
54 //Start world = startEngine (mTaskManager
55 // >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world
56
57 mTaskManager :: Task ()
58 mTaskManager = startupDevices >>| anyTask
59 [ viewmTasks @! ()
60 , whileUnchanged sdsStore manageShares
61 , whileUnchanged deviceStore $ manageDevices process
62 ] <<@ ApplyLayout (sequenceLayouts
63 [ arrangeWithSideBar 0 LeftSide 260 True
64 , arrangeSplit Vertical True
65 ])
66 where
67 viewmTasks :: Task String
68 viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
69 >&^ \sh->whileUnchanged sh $ \mi->forever (case mi of
70 Nothing = viewInformation "No task selected" [] ()
71 Just mTaskTask = get deviceStore
72 >>= \devices->case devices of
73 [] = viewInformation "No devices yet" [] ()
74 ds = fromJust ('DM'.get mTaskTask allmTasks)
75 >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds
76 -&&- enterInformation "Timeout" []
77 ) >>* [OnAction (Action "Send") (withValue $ Just o sendToDevice mTaskTask bc)]
78 @! ()
79 )
80
81 process :: MTaskDevice (Shared Channels) -> Task ()
82 process device ch = forever (watch ch >>* [OnValue (
83 ifValue (not o isEmpty o fst3)
84 (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))])
85 where
86 proc :: [MTaskMSGRecv] -> Task ()
87 proc [] = treturn ()
88 proc [MTEmpty:ms] = proc ms
89 proc [m:ms] = traceValue (toString m) >>| (case m of
90 // MTSDSAck i = traceValue (toString m) @! ()
91 // MTSDSDelAck i = traceValue (toString m) @! ()
92 MTPub i val = updateShare i val
93 MTTaskAck i = deviceTaskAcked device i
94 MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
95 MTDevSpec s = deviceAddSpec device s @! ()
96 _ = treturn ()
97 ) >>| proc ms