import Generics.gCons
import iTasksTTY
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend
+derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
derive conses MTaskResource, TCPSettings
derive consName MTaskResource, TCPSettings
from Data.Func import $
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend
+derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
derive conses MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
derive consName MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
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
+ >>= \(msgs, st1)->set st1 bcStateStore @ toSDSRecords
>>= \sdss->set sdss sdsStore//MTaskShareaddToSDSShare
>>| makeShares sdss
>>| sendMessage device msgs
where
sharename i = device.deviceChannels +++ "-" +++ toString i
toSDSRecords st = [{MTaskShare |
- initValue=toInt d1*265 + toInt d2,
+ initValue=toInt (sdsval!!0)*265 + toInt (sdsval!!1),
withTask=wta,
- identifier=i,
- realShare="mTaskSDS-" +++ toString i}
- \\(i,[d1,d2])<-st.sdss]
+ identifier=sdsi,
+ //We skip the only/local shares
+ realShare="mTaskSDS-" +++ toString sdsi}
+ \\{sdsi,sdspub,sdsval}<-st.sdss | sdspub]
makeShares = foldr (\sh t->set sh.initValue (getSDSStore sh) >>| t) (treturn ())
addTask :: MTaskTask MTaskDevice -> MTaskDevice
import qualified Data.Map as DM
import mTask
+import Devices.mTaskDevice
import iTasks._Framework.Serialization
-derive class iTask UserLED, Main, ByteCode, Stmt, BC, BCState
+derive class iTask UserLED
countAndLed :: Main (ByteCode () Stmt)
countAndLed = sds \x=1 In sds \pinnetje=1 In {main =
definition module Tasks.mTaskTask
+import Devices.mTaskDevice
import mTask
import iTasks
instance Semigroup (ByteCode a p)
instance Monoid (ByteCode a p)
+:: BCShare = {
+ sdsi :: Int,
+ sdspub :: Bool,
+ sdsval :: [Char]
+ }
+
:: BCState = {
freshl :: [Int],
freshs :: [Int],
- sdss :: [(Int, [Char])]
+ sdss :: [BCShare]
}
instance zero BCState
digitalRead p = retrn [BCDigitalRead $ pin p]
digitalWrite p b = b <+-> [BCDigitalWrite $ pin p]
-//instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
-//instance If ByteCode e Stmt Stmt where If b t e = BCIfStmt b t e
-//instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
+instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
+instance If ByteCode e Stmt Stmt where If b t e = BCIfStmt b t e
+instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
instance If ByteCode x y Stmt where If b t e = BCIfStmt b t e
instance IF ByteCode where
IF b t e = BCIfStmt b t e
in runBC (f fresh) {s & freshs=fs}
setSDS :: Int v -> ByteCode b q | toByteCode v
-setSDS ident val = BC \s->([], {s & sdss = [(ident, toByteCode val):s.sdss]})
+setSDS ident val = BC \s->([], {s & sdss=[
+ {BCShare|sdsi=ident,sdspub=False,sdsval=toByteCode val}:s.sdss]})
instance sds ByteCode where
sds f = {main = withSDS \sds->
in setSDS sds v <++> unMain body
}
con f = undef
- pub x = fmp makePub x
+ pub x = BC \s-> let ((i, bc), s`) = appFst makePub $ runBC x s
+ in (bc, {s` & sdss=map (publish i) s`.sdss})
+ where
+ publish i s = if (i == s.sdsi) {s & sdspub=True} s
+ makePub [BCSdsFetch i:xs] = (i, [BCSdsPublish i:xs])
instance assign ByteCode where
(=.) v e = e <++> fmp makeStore v
-
-makePub [] = []
-makePub [x:xs] = case x of
- BCSdsFetch i = [BCSdsPublish i:xs]
- y = [y:xs]
-
-makeStore [] = []
-makeStore [x:xs] = case x of
- BCSdsFetch i = [BCSdsStore i:xs]
- y = [y:xs]
+ where makeStore [BCSdsFetch i:xs] = [BCSdsStore i:xs]
instance seq ByteCode where
(>>=.) _ _ = abort "undef on >>=."
= (join "\n" $ map readable (map (implGotos gtmap) bc), st)
toMessages :: MTaskInterval (String, BCState) -> ([MTaskMSGSend], BCState)
-toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes], st)
+toMessages interval (bytes, st=:{sdss}) = (
+ [MTSds s.sdsi (toString s.sdsval)\\s<-sdss] ++
+ [MTTask interval bytes], st)
toSDSUpdate :: Int Int -> [MTaskMSGSend]
toSDSUpdate i v = [MTUpd i (to16bit v)]