Commit abb4ab29 authored by Mart Lubbers's avatar Mart Lubbers

make work without tcdestroy, need to test

parent 0f351a7a
Pipeline #22723 passed with stage
in 3 minutes and 20 seconds
...@@ -21,6 +21,17 @@ derive class iTask TTYSettings, Parity, BaudRate, ByteSize ...@@ -21,6 +21,17 @@ derive class iTask TTYSettings, Parity, BaudRate, ByteSize
syncSerialChannel :: Timespec TTYSettings (b -> String) (String -> (Either String [a], String)) (Shared sds ([a],[b],Bool)) -> Task () | iTask a & iTask b & RWShared sds syncSerialChannel :: Timespec TTYSettings (b -> String) (String -> (Either String [a], String)) (Shared sds ([a],[b],Bool)) -> Task () | iTask a & iTask b & RWShared sds
syncSerialChannel poll opts enc dec rw = Task eval syncSerialChannel poll opts enc dec rw = Task eval
where where
eval DestroyEvent evalOpts tree iworld=:{IWorld|resources,world}
# (mtty, iworld) = getResource iworld
= case mtty of
[] = (exc "This tty was already closed", iworld)
[_,_:_] = (exc "Multiple matching resources", iworld)
[TTYd _ tty]
# (ok, world) = TTYclose tty iworld.world
# iworld & world = world
| not ok = (exc "Couldn't close device", iworld)
= (DestroyedResult, iworld)
eval event evalOpts tree=:(TCInit taskId ts) iworld eval event evalOpts tree=:(TCInit taskId ts) iworld
# (mtty, iworld=:{world,resources}) = getResource iworld # (mtty, iworld=:{world,resources}) = getResource iworld
= case mtty of = case mtty of
...@@ -39,6 +50,10 @@ where ...@@ -39,6 +50,10 @@ where
, iworld) , iworld)
_ = (exc "This tty was already open", iworld) _ = (exc "This tty was already open", iworld)
eval _ _ TCNop iworld
= (ValueResult (Value () True)
{TaskEvalInfo|lastEvent=0,removedTasks=[],attributes=newMap}
rep TCNop, iworld)
eval _ _ tree=:(TCBasic taskId ts (DeferredJSONNode (JSONString acc)) _) iworld eval _ _ tree=:(TCBasic taskId ts (DeferredJSONNode (JSONString acc)) _) iworld
# (mtty, iworld) = getResource iworld # (mtty, iworld) = getResource iworld
= case mtty of = case mtty of
...@@ -48,17 +63,19 @@ where ...@@ -48,17 +63,19 @@ where
# (merr, iworld) = readRegister taskId ticker iworld # (merr, iworld) = readRegister taskId ticker iworld
| isError merr = (ExceptionResult (fromError merr), iworld) | isError merr = (ExceptionResult (fromError merr), iworld)
//TODO Keep async in mind //TODO Keep async in mind
# (merr, iworld=:{resources}) = read rw EmptyContext iworld # (merr, iworld) = read rw EmptyContext iworld
| isError merr = (ExceptionResult (fromError merr), iworld) | isError merr = (ExceptionResult (fromError merr), iworld)
= case fromOk merr of = case fromOk merr of
//We need to stop //We need to stop
ReadingDone (_,_,True) = ReadingDone (_,_,True)
(ValueResult # (ok, world) = TTYclose tty iworld.world
(Value () True) # iworld & world = world
{TaskEvalInfo|lastEvent=ts,removedTasks=[],attributes=newMap} | not ok = (exc "Couldn't close device", iworld)
rep = (ValueResult
(TCDestroy tree) (Value () True)
, {iworld & resources=[TTYd dp tty:resources]}) {TaskEvalInfo|lastEvent=ts,removedTasks=[],attributes=newMap}
rep
TCNop, iworld)
ReadingDone (r,s,ss) ReadingDone (r,s,ss)
# tty = foldr TTYwrite tty $ reverse $ map enc s # tty = foldr TTYwrite tty $ reverse $ map enc s
# (merr, tty) = readWhileAvailable tty # (merr, tty) = readWhileAvailable tty
...@@ -79,17 +96,6 @@ where ...@@ -79,17 +96,6 @@ where
(TCBasic taskId ts (DeferredJSONNode $ JSONString newacc) False) (TCBasic taskId ts (DeferredJSONNode $ JSONString newacc) False)
, iworld) , iworld)
eval event evalOpts tree=:(TCDestroy _) iworld=:{IWorld|resources,world}
# (mtty, iworld) = getResource iworld
= case mtty of
[] = (exc "This tty was already closed", iworld)
[_,_:_] = (exc "Multiple matching resources", iworld)
[TTYd _ tty]
# (ok, world) = TTYclose tty iworld.world
# iworld & world = world
| not ok = (exc "Couldn't close device", iworld)
= (DestroyedResult, iworld)
rep = ReplaceUI $ stringDisplay $ "Serial client " <+++ opts.devicePath rep = ReplaceUI $ stringDisplay $ "Serial client " <+++ opts.devicePath
ticker = sdsFocus {start=zero,interval=poll} iworldTimespec ticker = sdsFocus {start=zero,interval=poll} iworldTimespec
getResource = iworldResource (\t=:(TTYd p _)->(p == opts.devicePath, t)) getResource = iworldResource (\t=:(TTYd p _)->(p == opts.devicePath, t))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment