Merge branch 'master' of gitlab.science.ru.nl:mlubbers/mTask
[mTask.git] / mTaskInterpret.icl
index aeceb92..ef75b9a 100644 (file)
@@ -43,8 +43,9 @@ import Tasks.Examples
 encode :: MTaskMSGSend -> String
 encode (MTTask to data) = "t" +++ toByteCode to +++ to16bit (size data) +++ data +++ "\n"
 encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n"
-encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n"
-encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n"
+encode (MTSds i v) = "s" +++ to16bit i +++ toByteCode v +++ "\n"
+encode (MTUpd i v) = "u" +++ to16bit i +++ toByteCode v +++ "\n"
+encode (MTSpec) = "c\n"
 
 import StdDebug
 decode :: String -> MTaskMSGRecv
@@ -138,7 +139,7 @@ instance fromByteCode UserLED where fromByteCode s = conses{|*|} !! toInt s.[1]
 instance fromByteCode BCValue where fromByteCode s = parseBCValue s.[0] s
 
 instance toByteCode MTaskInterval where
-       toByteCode OneShot = toByteCode 0
+       toByteCode OneShot = toByteCode (OnInterval 0)
        //Intervals have the first bit 0 and the rest is a 15 bit unsigned int
        toByteCode (OnInterval i) = {toChar $ i/256 bitand 127, toChar $ i rem 256}
        //Intervals have the first bit 1 and the rest is a 15 bit unsigned int
@@ -328,13 +329,19 @@ toReadableByteCode x s
                        where
                                (ex, newls) = splitAt (bclength b - 1) ls
 
-toMessages :: MTaskInterval (String, BCState) -> ([MTaskMSGSend], BCState)
-toMessages interval (bytes, st=:{sdss}) = (
-       [MTSds sdsi $ toByteCode e\\{sdsi,sdsval=(BCValue e)}<-sdss] ++
-       [MTTask interval bytes], st)
+derive gPrint BCShare
 
-toSDSUpdate :: Int Int -> [MTaskMSGSend]
-toSDSUpdate i v = [MTUpd i (to16bit v)]
+toMessages :: MTaskInterval (Main (ByteCode a b)) BCState -> ([MTaskMSGSend], BCState)
+toMessages interval x s
+# (bc, newstate) = toRealByteCode (unMain x) s
+# newsdss = 'DL'.difference newstate.sdss s.sdss 
+| not (trace_tn $ printToString s.sdss) = undef
+| not (trace_tn $ printToString newstate.sdss) = undef
+| not (trace_tn $ printToString newsdss) = undef
+= ([MTSds sdsi e\\{sdsi,sdsval=e}<-newsdss] ++
+       [MTTask interval bc], newstate)
+
+instance == BCShare where (==) a b = a.sdsi == b.sdsi
 
 //Start = toMessages (OnInterval 500) $ toRealByteCode (unMain bc) zero
 Start = fst $ toReadableByteCode (unMain $ countAndLed) zero