derive conses MTaskResource, TCPSettings
derive consName MTaskResource, TCPSettings
-channels :: MTaskDevice -> Shared Channels
-
:: Channels :== ([MTaskMSGRecv], [MTaskMSGSend], Bool)
:: MTaskResource
manageDevices :: (MTaskDevice (Shared Channels) -> Task ()) [MTaskDevice] -> Task ()
sendToDevice :: String (Main (ByteCode () Stmt)) (MTaskDevice, MTaskInterval) -> Task ()
+sendMessages :: [MTaskMSGSend] -> (MTaskDevice -> Task Channels)
deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
deviceTaskAcked :: MTaskDevice Int -> Task ()
import TTY
import qualified Data.Map as DM
import Utils.SDS
+import Utils.Devices
import GenBimap
import Devices.mTaskSerial
instance == MTaskDevice where
(==) a b = a.deviceChannels == b.deviceChannels
-channels :: MTaskDevice -> Shared Channels
-channels d = memoryShare d.deviceChannels ([], [], False)
-
makeDevice :: String MTaskResource -> Task MTaskDevice
makeDevice name res = get randomInt @ \rand->{MTaskDevice
|deviceChannels=name +++ toString rand
>>= \(msgs, st1)->set st1 bcStateStore @ toSDSRecords
>>= \sdss->set sdss sdsStore//MTaskShareaddToSDSShare
>>| makeShares sdss
- >>| sendMessage device msgs
+ >>| sendMessages msgs device
>>| makeTask wta -1
>>= withDevices device o addTask
@! ()
addTask :: MTaskTask MTaskDevice -> MTaskDevice
addTask task device = {device & deviceTasks=[task:device.deviceTasks]}
-sendMessage :: MTaskDevice [MTaskMSGSend] -> Task ()
-sendMessage dev msgs = upd (\(r,s,ss)->(r,msgs++s,ss)) (channels dev) @! ()
+sendMessages :: [MTaskMSGSend] -> (MTaskDevice -> Task Channels)
+sendMessages msgs = upd (\(r,s,ss)->(r,msgs++s,ss)) o channels
withDevices :: MTaskDevice (MTaskDevice -> MTaskDevice) -> Task ()
withDevices a trans = upd (map \b->if (b == a) (trans b) b) deviceStore @! ()
[{t & ident=i}:ts] [t:ackFirst ts]
deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
-deviceTaskDelete dev task = sendMessage dev [MTTaskDel task.ident]
+deviceTaskDelete dev task = sendMessages [MTTaskDel task.ident] dev @! ()
deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
deviceTaskDeleteAcked d i = withDevices d $ deleteTask
implementation module Shares.mTaskShare
import Utils.SDS
+import Utils.Devices
import iTasks
+import mTask
from Data.Func import $
manageShares :: [MTaskShare] -> Task ()
Nothing = viewShares shares @! zero
Just sh = forever (
viewSharedInformation "View value" [] (getSDSStore sh)
- >>* [OnAction (Action "Update") (withValue $ Just $ updateInformation "New value" [])]
+ >>* [OnAction (Action "Update") (withValue (Just o updateInformation "New value" []))]
>>= updateShare sh
)
) @! ()
-updateShare :: MTaskShare Int -> Task MTaskShare
-updateShare sh=:{withTask} i = return sh
+updateShare :: MTaskShare a -> Task MTaskShare | toByteCode a
+updateShare sh=:{withTask,identifier} a = getDeviceByName withTask
+ >>= sendMessages [MTUpd identifier $ toString $ toByteCode a]
+ >>| treturn sh
viewShares :: [MTaskShare] -> Task ()
--- /dev/null
+definition module Utils.Devices
+
+import iTasks
+import Devices.mTaskDevice
+
+getDeviceByName :: String -> Task MTaskDevice
+channels :: MTaskDevice -> Shared Channels
--- /dev/null
+implementation module Utils.Devices
+
+import iTasks
+import mTask
+import Utils.SDS
+import Data.List
+
+getDeviceByName :: String -> Task MTaskDevice
+getDeviceByName nm = get deviceStore @ find (\d->d.deviceChannels == nm)
+ >>= maybe (throw "Help, device not found") treturn
+
+channels :: MTaskDevice -> Shared Channels
+channels d = memoryShare d.deviceChannels ([], [], False)
+