X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mTaskInterpret.icl;h=306f93d6884f8ffa0c14228319b879647df5b0c5;hb=0efbd98973520d55ec4e80e443911f43b3c28a0d;hp=58760472c440c90a1017205826760befce96e570;hpb=1383ec4c1733cc6f07fe68e0619446d60fe5277e;p=mTask.git diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 5876047..306f93d 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -22,33 +22,33 @@ from Text import class Text(concat,join,toUpperCase), instance Text String import qualified Data.Map as DM import Text.Encodings.Base64 -encode :: MTaskMessage -> String +encode :: MTaskMSGSend -> String encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n" -encode (MTPub i v) = "u" +++ to16bit i +++ v +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" -encode MTEmpty = "" -decode :: String -> MTaskMessage +decode :: String -> MTaskMSGRecv decode x | size x == 0 = MTEmpty = case x.[0] of '\0' = MTEmpty - 'u' = MTUpd (from16bit (x % (1,3))) (x % (3,5)) + 'm' = MTMessage x + 'u' = MTPub (from16bit (x % (1,3))) (x % (3,5)) _ = abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n") safePrint :== toString o toJSON -derive gPrint MTaskMessage -instance toString MTaskMessage where +instance toString MTaskMSGSend where toString (MTSds i v) = "Sds id: " +++ toString i +++ " value " +++ safePrint v toString (MTTask to data) = "Task timeout: " +++ toString to +++ " data " +++ safePrint data - toString (MTPub i v) = "Publish id: " +++ toString i - +++ " value " +++ safePrint v toString (MTUpd i v) = "Update id: " +++ toString i +++ " value " +++ safePrint v + +instance toString MTaskMSGRecv where + toString (MTPub i v) = "Publish id: " +++ toString i + +++ " value " +++ safePrint v toString MTEmpty = "Empty message" bclength :: BC -> Int @@ -68,7 +68,7 @@ bclength _ = 1 toByteVal :: BC -> [Char] toByteVal b -# bt = toChar $ consIndex{|*|} b +# bt = toChar $ consIndex{|*|} b + 1 = [bt:case b of (BCPush i) = i (BCLab i) = [toChar i] @@ -146,10 +146,10 @@ instance digitalIO ByteCode where 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 x y Expr 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 (?) b t = BCIfStmt b t $ retrn [] @@ -243,8 +243,11 @@ toReadableByteCode x // where // bc :: ByteCode Int Expr // bc = (lit 36 +. lit 42) +. lit 44 -toMessages :: Int (String, BCState) -> [MTaskMessage] -toMessages interval (bytes, {sdss}) = [MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes] +toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState) +toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes], st) + +toSDSUpdate :: Int Int -> [MTaskMSGSend] +toSDSUpdate i v = [MTUpd i (to16bit v)] Start = toMessages 500 $ toRealByteCode (unMain bc) //Start = fst $ toReadableByteCode $ unMain bc