// @! ()
// where
// errorHandle e = withDevices d (\d->{d&deviceTask=Nothing,deviceError=Just e}) @! ()
+import StdDebug
connectDevice :: (MTaskDevice (Shared Channels) -> Task ()) MTaskDevice -> Task Channels
connectDevice procFun device = let ch = channels device
in traceValue "connectDevice" >>| appendTopLevelTask 'DM'.newMap True
- ( procFun device ch
- -||- catchAll (getSynFun device.deviceData ch) errHdl)
+ ( procFun device ch -||- catchAll (getSynFun device.deviceData ch) errHdl)
>>= \tid->withDevices device (\d->{d&deviceTask=Just tid,deviceError=Nothing})
>>| upd (\(r,s,ss)->(r,s++[MTSpec],ss)) ch
where
- errHdl e = withDevices device (\d->{d & deviceTask=Nothing, deviceError=Just e}) @! ()
+ errHdl e
+ | not (trace_tn "error") = undef
+ = withDevices device (\d->{d & deviceTask=Nothing, deviceError=Just e}) @! ()
manageDevices :: (MTaskDevice (Shared Channels) -> Task ()) -> Task ()
manageDevices processFun = get deviceStoreNP >>= \ds->anyTask [
- addDevice processFun <<@ Title "Add new device" @! ():
- [viewDevice processFun d <<@ Title d.deviceName\\d<-ds]]
+ addDevice processFun <<@ Title "Add new device" @! ()]//:
+// [viewDevice processFun d <<@ Title d.deviceName\\d<-ds]]
<<@ ArrangeWithTabs
@! ()
viewDevice :: (MTaskDevice (Shared Channels) -> Task ()) MTaskDevice -> Task ()
viewDevice pf d = forever $ traceValue "viewDevice" >>| anyTask
[viewInformation "Device settings" [] d @! ()
- ,viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
+ /*,viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()*/
,forever $
enterChoice "Delete task on device" [ChooseFromGrid id] d.deviceTasks
>>* [OnAction (Action "Delete") $ ifValue (\t->t.ident <> -1) (deviceTaskDelete d)]
onConnect :: String ChD -> (MaybeErrorString String, Maybe ChD, [String], Bool)
onConnect acc (msgs,send,sendStopped)
| not (trace_tn "onConnect") = undef
- = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
+ | isEmpty send = (Ok "", Nothing, [], False)
+ = (Ok "", Just (msgs, [], sendStopped), map encode send, False)
onData :: String String ChD -> (MaybeErrorString String, Maybe ChD, [String], Bool)
onData newdata acc (msgs,send,True)
onData newdata acc (msgs,send,sendStopped)
| not (trace_tn "onData: notstop") = undef
# split = indexOf "\n" newdata
- | split == -1 = (Ok acc, Just (msgs, send, True), [], False)
+ | split == -1 = (Ok acc, Just (msgs, send, False), [], False)
# newMsg = decode (newdata % (0, split-1))
// Recurse with smaller data, empty accumulator and new message
= onData (newdata % (split+1, size newdata - split))
| not (trace_tn "onSC: stop") = undef
= (Ok acc, Nothing, [], True)
// Nothing to send
- onShareChange acc (msgs,[], _)
- | not (trace_tn "onSC: nothing") = undef
- = (Ok acc, Nothing, [], False)
+ onShareChange acc (msgs,[], _) = (Ok acc, Nothing, [], False)
// Something to send
onShareChange acc (msgs,send, ss)
| not (trace_tn "onSC: send") = undef
makeTask name ident = get currentDateTime
@ \dt->{MTaskTask | name=name,ident=ident,dateAdded=dt}
+import StdDebug
+import StdMisc
sendTaskToDevice :: String (Main (ByteCode a Stmt)) (MTaskDevice, MTaskInterval) -> Task [MTaskDevice]
sendTaskToDevice wta mTask (device, timeout)
+| not (trace_tn "compiling task") = undef
# (msgs, newState) = toMessages timeout mTask device.deviceState
+| not (trace_tn "Done compiling task") = undef
# shares = [makeShare wta sdsi sdsval\\{sdsi,sdsval}<-newState.sdss, (MTSds sdsi` _)<-msgs | sdsi == sdsi`]
= updateShares device ((++) shares)
>>| sendMessages msgs device
deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice]
deviceStore = SDSSource {SDSSource
| name = "deviceStore"
- , read = \_->read realDeviceStore
+ , read = realRead
, write= realWrite
}
where
}
:: BCState = {
- freshl :: [Int],
- freshs :: [Int],
+ freshl :: Int,
+ freshs :: Int,
sdss :: [BCShare]
}
instance zero BCState
t >>| tell [BCJmp endif, BCLab else] >>|
e >>| tell [BCLab endif]
-freshl = get >>= \st=:{freshl=[fr:frs]}->put {st & freshl=frs} >>| pure fr
-freshs = get >>= \st=:{freshs=[fr:frs]}->put {st & freshs=frs} >>| pure fr
+freshl = get >>= \st=:{freshl}->put ({st & freshl=freshl+1}) >>| pure freshl
+freshs = get >>= \st=:{freshs}->put ({st & freshs=freshs+1}) >>| pure freshs
instance noOp ByteCode where noOp = tell` [BCNop]
retrn = tell` [BCReturn]
instance zero BCState where
- zero = {freshl=[1..], freshs=[1..], sdss=[]}
+ zero = {freshl=1, freshs=1, sdss=[]}
toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)
toRealByteCode x s
mTaskManager :: Task ()
mTaskManager = (>>|) startupDevices $
- viewmTasks ||-
+ forever viewmTasks ||-
((manageShares ||- forever (manageDevices process)) <<@ ArrangeSplit Vertical True)
<<@ ArrangeWithSideBar 0 LeftSide 260 True
where
- viewmTasks :: Task String
+ viewmTasks :: Task [MTaskDevice]
viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
- >&^ \sh->whileUnchanged sh $ \mi->forever (case mi of
- Nothing = viewInformation "No task selected" [] ()
- Just mTaskTask = get deviceStoreNP
- >>= \devices->case devices of
- [] = viewInformation "No devices yet" [] ()
- ds = fromJust ('DM'.get mTaskTask allmTasks)
- >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds
- -&&- enterInformation "Timeout" []
- ) >>* [OnAction (Action "Send") (withValue $ Just o sendTaskToDevice mTaskTask bc)]
- @! ()
- )
+ >>= \task->get deviceStoreNP
+ >>* [OnValue $ (ifValue isEmpty) $ \_->
+ viewInformation "No devices yet" [] [] >>= treturn
+ ,OnValue $ (ifValue $ not o isEmpty) $ \d->
+ fromJust ('DM'.get task allmTasks)
+ >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] d
+ -&&- enterInformation "Timeout" []
+ ) >>* [OnAction (Action "Send") (withValue $ Just o sendTaskToDevice task bc)]
+ ]
process :: MTaskDevice (Shared Channels) -> Task ()
- process device ch = forever (watch ch >>* [OnValue (
- ifValue (not o isEmpty o fst3)
- (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))])
+ process device ch = forever
+ $ traceValue "Waiting for channel change"
+ >>| wait "process" (not o isEmpty o fst3) ch
+ >>= \(r,s,ss)->upd (appFst3 (const [])) ch
+ >>| proc r
where
proc :: [MTaskMSGRecv] -> Task ()
proc [] = treturn ()