>>= \ty->case ty of
TCP = (enterInformation "Host" [] -&&- enterInformation "Port" [])
>>= \(port,host)->syncNetworkChannel host port ch
-// Serial = accWorld getDevices
-// >>= \dl->(enterChoice "Device" [] dl -&&- enterInformation "Settings" [])
-// >>= \(dev,set)->syncSerialChannel dev set decode encode ch
+ Serial = accWorld getDevices
+ >>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero)
+ >>= \(dev,set)->syncSerialChannel dev set ch
where
getDevices :: !*World -> *(![String], !*World)
getDevices w = case readDirectory "/dev" w of
isTTY s = not (isEmpty (filter (flip startsWith s) prefixes))
prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"]
-
mTaskTask :: Task ()
-mTaskTask = let (msgs, sdsShares) = makeMsgs 500 bc in
+mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in
withShared ([], msgs, False) (\ch->
deviceSelector ch
-// ||- sendTasks msgs ch//sendMsg msgs ch
-// ||- (whileUnchanged ch (process sdsShares messageShare ch))
+ ||- processMessages ch messageShare sdsShares
||- viewSharedInformation "channels" [ViewWith lens] ch
||- viewSharedInformation "messages" [] messageShare
||- viewSh sdsShares ch
messageShare :: Shared [String]
messageShare = sharedStore "mTaskMessagesRecv" []
+ processMessages ch msgs sdss = forever (watch ch
+ >>* [OnValue (ifValue (not o isEmpty o fst3) (process ch))])
+ where
+ process :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> Task ()
+ process ch (r,_,_) = upd (appFst3 (const [])) ch >>| process` r
+ where
+ process` = foldr (\r t->updateSDSs sdss msgs r >>| t) (return ())
+
makeMsgs :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)])
makeMsgs timeout bc
# (msgs, st) = toMessages timeout (toRealByteCode (unMain bc))
sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task ()
sendMsg m ch = upd (\(r,s,ss)->(r,s ++ m,True)) ch @! ()
-syncSerialChannel :: String TTYSettings (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
-syncSerialChannel dev opts decodeFun encodeFun rw = Task eval
+syncSerialChannel :: String TTYSettings (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task ()
+syncSerialChannel dev opts rw = Task eval
where
eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world}
= case TTYopen dev opts world of
= (ExceptionResult (exception err), {iworld & world=world})
(True, tty, world)
# iworld = {iworld & world=world, resources=Just (TTYd tty)}
- = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw decodeFun encodeFun)) iworld of
+ = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw)) iworld of
(Error e, iworld) = (ExceptionResult (exception "h"), iworld)
(Ok _, iworld) = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=True} NoRep (TCBasic taskId ts JSONNull False), iworld)
(Error e, iworld) = (ExceptionResult (exception "h"), iworld)
(Ok _, iworld) = (DestroyedResult, iworld)
-serialDeviceBackgroundTask :: (Shared ([m],Bool,[n],Bool)) (String -> m) (n -> String) !*IWorld -> *IWorld
-serialDeviceBackgroundTask rw de en iworld
+serialDeviceBackgroundTask :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) !*IWorld -> *IWorld
+serialDeviceBackgroundTask rw iworld
= case read rw iworld of
(Error e, iworld) = abort "share couldn't be read"
- (Ok (r,rs,s,ss), iworld)
+ (Ok (r,s,ss), iworld)
# (Just (TTYd tty)) = iworld.resources
- # tty = writet (map en s) tty
+ # tty = writet (map encode s) tty
# (ml, tty) = case TTYavailable tty of
(False, tty) = ([], tty)
(_, tty)
# (l, tty) = TTYreadline tty
- = ([de l], tty)
+ | not (trace_tn ("recv: '" +++ l +++ "'")) = undef
+ = ([decode l], tty)
# iworld = {iworld & resources=Just (TTYd tty)}
- = case write (r++ml,rs,[],ss) rw iworld of
+ = case write (r++ml,[],False) rw iworld of
(Error e, iworld) = abort "share couldn't be written"
(Ok _, iworld) = case notify rw iworld of
(Error e, iworld) = abort "share couldn't be notified"
(Ok _, iworld) = iworld
where
- writet :: [String] !*TTY -> *TTY
- writet [] t = t
- writet [x:xs] t = writet xs (TTYwrite x t)
+ writet :: [String] -> (*TTY -> *TTY)
+ writet [] = id
+ writet [x:xs] = writet xs o TTYwrite x
syncNetworkChannel :: String Int (Shared ([MTaskMSGRecv], [MTaskMSGSend], Bool)) -> Task ()
= (Ok "", Just (msgs,[],sendStopped), map encode send, False)
whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
- whileConnected maybeNewData acc (msgs,send,sendStopped)
- # l = map decode (maybeToList maybeNewData)
- # send = if (not sendStopped) [] (map encode send)
- = (Ok acc, Just (msgs ++ l,[],sendStopped), send, False)
+ whileConnected Nothing acc (msgs,send,sendStopped)
+ = (Ok acc, Nothing, [], False)
+// = (Ok acc, Just (msgs,[],sendStopped), map encode send, False)
+
+ whileConnected (Just newData) acc (msgs,send,sendStopped)
+ | sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
+ = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False)
onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)