-sendToDevice :: String (Main (ByteCode () Stmt)) (MTaskDevice, MTaskInterval) -> Task ()
-sendToDevice wta mTask (device, timeout) =
- get bcStateStore @ toMessages timeout o toRealByteCode (unMain mTask)
- >>= \(msgs, st1)->set st1 bcStateStore @ toSDSRecords
- >>= \sdss->upd ((++)sdss) sdsStore//MTaskShareaddToSDSShare
- >>| makeShares sdss
- >>| sendMessage device msgs
- >>| makeTask wta -1
- >>= withDevices device o addTask
- @! ()
- where
- sharename i = device.deviceChannels +++ "-" +++ toString i
- toSDSRecords st = [{MTaskShare |
- initValue=toInt d1*265 + toInt d2,
- withTask=wta,
- identifier=i,
- realShare="mTaskSDS-" +++ toString i}
- \\(i,[d1,d2])<-st.sdss]
- makeShares = foldr (\sh t->set sh.initValue (getSDSStore sh) >>| t) (treturn ())
-
- 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) @! ()
-
-withDevices :: MTaskDevice (MTaskDevice -> MTaskDevice) -> Task ()
-withDevices a trans = upd (map \b->if (b == a) (trans b) b) deviceStore @! ()
-
-deviceTaskAcked :: MTaskDevice Int -> Task ()
-deviceTaskAcked dev i
- = withDevices dev (\d->{d&deviceTasks=ackFirst d.deviceTasks})
+sendMessages :: [MTaskMSGSend] MTaskDevice -> Task Channels
+sendMessages msgs dev = upd (realMessageSend msgs) $ channels dev
+
+sendMessagesIW :: [MTaskMSGSend] MTaskDevice *IWorld -> *(MaybeError TaskException (), *IWorld)
+sendMessagesIW msgs dev iworld
+ = modify (tuple () o realMessageSend msgs) (channels dev) iworld
+
+realMessageSend :: [MTaskMSGSend] Channels -> Channels
+realMessageSend msgs (r,s,ss) = (r,msgs++s,ss)
+
+withDevices :: MTaskDevice (MTaskDevice -> MTaskDevice) -> Task [MTaskDevice]
+withDevices a trans = upd (map \b->if (b == a) (trans b) b) deviceStoreNP
+
+deviceTaskAcked :: MTaskDevice Int Int -> Task [MTaskDevice]
+deviceTaskAcked dev i mem
+ = withDevices dev (\d->{d
+ &deviceTasks=ackFirst d.deviceTasks
+ ,deviceSpec=Just {fromJust d.deviceSpec & bytesMemory=mem}})