:: SerTCP = SerialDevice | TCPDevice
:: MTaskDevice = {
- deviceTask :: Maybe TaskId,
- deviceConnected :: Maybe String,
- deviceName :: String,
- deviceTasks :: [(String, Int)]
+ deviceTask :: Maybe TaskId
+ ,deviceChannels :: String
+ ,deviceName :: String
+ ,deviceTasks :: [(String, Int)]
+// ,deviceSyncfun :: (Shared Channels) -> Task ()
}
:: MTaskShare = {
initValue :: Int,
@! ()
where
createBytecode st = toMessages timeout $ toRealByteCode (unMain $ fromJust ('DM'.get mTask mTaskMap)) st
- sharename i = fromJust (device.deviceConnected) +++ "-" +++ toString i
+ sharename i = device.deviceChannels +++ "-" +++ toString i
toSDSRecords st = [{MTaskShare |
initValue=toInt d1*265 + toInt d2,
withTask=mTask,
getSDSRecord i = get sdsStore @ \l->hd [s\\s<-l | s.identifier == i]
channels :: MTaskDevice -> Shared Channels
- channels d = memoryShare (fromJust d.deviceConnected) ([], [], False)
+ channels d = memoryShare d.deviceChannels ([], [], False)
viewShares :: [MTaskShare] -> Task ()
viewShares st = anyTask $ map viewer st
viewDevice :: MTaskDevice -> Task ()
viewDevice d = (viewInformation "Device settings" [] d
- ||- (case d.deviceConnected of
- Just s = viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
- Nothing = viewInformation "No channels yet" [] "" @! ()
- )) <<@ ArrangeHorizontal
+ ||- viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
+ ) <<@ ArrangeHorizontal
where
dropEmpty (r,s,ss) = (filter ((=!=)MTEmpty) r,s,ss)
where
cont :: String ((Shared Channels) -> Task ()) -> Task ()
cont name synfun = get randomInt
- @ (\randint->{deviceConnected=Just (name +++ toString randint), deviceName=name, deviceTasks=[], deviceTask=Nothing})
+ @ (\randint->{MTaskDevice |
+ deviceChannels=name +++ toString randint,
+ deviceName=name,
+ deviceTasks=[],
+ deviceTask=Nothing})
>>= \dev->appendTopLevelTask 'DM'.newMap True (let ch = channels dev in process ch -||- synfun ch)
>>= \tid->upd (\l->[{dev & deviceTask=Just tid}:l]) devices
@! ()
+// addDevice :: (Shared [MTaskDevice]) -> Task SerTCP
+// addDevice devices = enterInformation "Device type" []
+// >&^ \sh->whileUnchanged sh $ \mty->case mty of
+// Nothing = viewInformation "No type selected yet" [] "" @! ()
+// Just ty = case ty of
+// TCPDevice = (enterInformation "Name" [] -&&- enterInformation "Hostname" [] -&&- enterInformation "Port" [])
+// >>= \(name, (host, port))->cont name (syncNetworkChannel host port)
+// SerialDevice = (enterInformation "Name" [] -&&- enterTTYSettings)
+// >>= \(name, set)->cont name (syncSerialChannel set encode decode)
+// where
+// cont :: String ((Shared Channels) -> Task ()) -> Task ()
+// cont name synfun = get randomInt
+// @ (\randint->{deviceChannels=name +++ toString randint, deviceName=name, deviceTasks=[], deviceTask=Nothing})
+// >>= \dev->appendTopLevelTask 'DM'.newMap True (let ch = channels dev in process ch -||- synfun ch)
+// >>= \tid->upd (\l->[{dev & deviceTask=Just tid}:l]) devices
+// @! ()
+
process :: (Shared Channels) -> Task ()
process ch = forever (watch ch >>* [OnValue (
ifValue (not o isEmpty o fst3)
deviceviewer :: [MTaskDevice] -> [MTaskDeviceStatus]
deviceviewer ds = [{MTaskDeviceStatus | name = d.deviceName,
- connected = if (isNothing d.deviceConnected) False True,
+ connected = if (isNothing d.deviceTask) False True,
tasks = [s +++ toString i\\(s, i)<-d.deviceTasks]}\\d<-ds]
mapPar :: (a -> Task a) [a] -> 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 Nothing acc (msgs,send,sendStopped)
- = (Ok acc, Nothing, [], False)
-
- whileConnected (Just newData) acc (msgs,send,sendStopped)
- = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
+
+ //whileConnected Nothing acc (msgs,send,sendStopped)
+ //= (Ok acc, Just (msgs,[],sendStopped), map encode send, False)
+ whileConnected mnewData acc (msgs,send,sendStopped)
+ = (Ok acc, Just (msgs ++ map decode (maybeToList mnewData),[],sendStopped), map encode send, False)
//| sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
// = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False)
--- /dev/null
+implementation module miTaskDevices
+
+import mTask
+import iTasks
+
+:: Channels :== ([MTaskMSGRecv], [MTaskMSGSend], Bool)
+:: TCPDevice = {hostname :: String, port :: Int}
+:: SerialDevice = {settings :: TTYSettings}
+
+:: DeviceType = SerialDevice | TCPDevice
+
+derive class iTask TCPDevice, SerialDevice, DeviceType
+
+getmTaskDevice :: Task a | mTaskDevice a
+getmTaskDevice = enterInformation "Device type" []
+ >&^ \st->whileUnchanged st $ \dt->case dt of
+ Nothing = viewInformation "No type selected yet" [] Nothing
+ Just SerialDevice = getSerialDevice @ pure
+ Just TCPDevice = getTDevice @ pure
+ >>* [OnValue (ifValue isJust fromJust)]
+ where
+ getSD :: Task SerialDevice
+ getSD = entermTaskDevice
+ getTD :: Task TCPDevice
+ getTD = entermTaskDevice
+
+instance mTaskDevice TCPDevice where
+ entermTaskDevice = enterInformation "" []
+ viewmTaskDevice = viewInformation "" []
+ syncTask d ch = catchAll (
+ tcpconnect d.host d.port ch {ConnectionHandlers|
+ onConnect=onConnect,
+ whileConnected=whileConnected,
+ onDisconnect=onDisconnect} @! ())
+ (\v->traceValue v @! ())
+ where
+ onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
+ onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
+
+ whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
+ whileConnected Nothing acc (msgs,send,sendStopped) = (Ok acc, Nothing, [], False)
+ whileConnected (Just newData) acc (msgs,send,sendStopped) = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
+
+ onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
+ onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)
+
+instance mTaskDevice SerialDevice where
+ entermTaskDevice = enterTTYSettings >>= \s->{SerialDevice|settings=s}
+ viewmTaskDevice = viewInformation "" []
+ syncTask d ch = syncSerialSettings d.settings encode decode ch