import iTasks
import Devices.mTaskSerial
import Devices.mTaskTCP
+import Tasks.mTaskTask
import mTaskInterpret
import Generics.gCons
import iTasksTTY
deviceTask :: Maybe TaskId
,deviceChannels :: String
,deviceName :: String
- ,deviceTasks :: [(String, Int)]
+ ,deviceTasks :: [MTaskTask]
,deviceData :: MTaskResource
}
manageDevices :: (MTaskDevice (Shared Channels) -> Task ()) [MTaskDevice] -> Task ()
sendToDevice :: (Map String (Main (ByteCode () Stmt))) String (MTaskDevice, Int) -> Task ()
-deviceTaskDelete :: MTaskDevice Int -> Task ()
+deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
deviceTaskAcked :: MTaskDevice Int -> Task ()
deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
[viewInformation "Device settings" [] d @! ()
,viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
,forever $
- enterChoice "Delete task on device" [ChooseFromList fst] d.deviceTasks
- >>* [OnAction (Action "Delete") $ ifValue (\(_,i)->i <> -1) (deviceTaskDelete d o snd)]
+ enterChoice "Delete task on device" [ChooseFromGrid id] d.deviceTasks
+ >>* [OnAction (Action "Delete") $ ifValue (\t->t.ident <> -1) (deviceTaskDelete d)]
@! ()
] <<@ ArrangeHorizontal
where
>>= \sdss->upd ((++)sdss) sdsStore//MTaskShareaddToSDSShare
>>| makeShares sdss
>>| sendMessage device msgs
- >>| withDevices device (addTask timeout)
+ >>| makeTask mTask -1
+ >>= \task->withDevices device (addTask timeout task)
@! ()
where
createBytecode st = toMessages timeout $ toRealByteCode (unMain $ fromJust ('DM'.get mTask tmap)) st
\\(i,[d1,d2])<-st.sdss]
makeShares = foldr (\sh t->set sh.initValue (getSDSStore sh) >>| t) (treturn ())
- addTask :: Int MTaskDevice -> MTaskDevice
- addTask timeout device = {device & deviceTasks=[(mTask, -1):device.deviceTasks]}
+ addTask :: Int MTaskTask MTaskDevice -> MTaskDevice
+ addTask timeout task device = {device & deviceTasks=[task:device.deviceTasks]}
sendMessage :: MTaskDevice [MTaskMSGSend] -> Task ()
sendMessage dev msgs = upd (\(r,s,ss)->(r,msgs++s,ss)) (channels dev) @! ()
deviceTaskAcked :: MTaskDevice Int -> Task ()
deviceTaskAcked dev i
- = withDevices dev (\d->{d&deviceTasks=ackFirst i d.deviceTasks})
+ = withDevices dev (\d->{d&deviceTasks=ackFirst d.deviceTasks})
where
- ackFirst :: Int [(String, Int)] -> [(String, Int)]
- ackFirst _ [] = []
- ackFirst a [(s,i):ts] = if (i == -1) [(s,a):ts] [(s,i):ackFirst a ts]
+ ackFirst :: [MTaskTask] -> [MTaskTask]
+ ackFirst [] = []
+ ackFirst [t:ts] = if (t.ident == -1)
+ [{t & ident=i}:ts] [t:ackFirst ts]
-deviceTaskDelete :: MTaskDevice Int -> Task ()
-deviceTaskDelete dev tid = sendMessage dev [MTTaskDel tid]
+deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
+deviceTaskDelete dev task = sendMessage dev [MTTaskDel task.ident]
deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
deviceTaskDeleteAcked d i = withDevices d $ deleteTask
- where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> snd s]}
+ where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> s.ident]}