X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mTaskInterpret.icl;h=21b53c901927d632134b09e60a53d76293c2589b;hb=3cac8340c7c822ecda3783286196c6bc4cdec66a;hp=1cd7c7085e0f931cf507cd196005a090c0152afe;hpb=955c4eb992b45e48a1a3dad6418236431ddcd095;p=mTask.git diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 1cd7c70..21b53c9 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -22,33 +22,34 @@ 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)) - _ = abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n") + '\n' = MTEmpty + 'm' = MTMessage x + 'u' = MTPub (from16bit (x % (1,3))) (x % (3,5)) + _ = MTMessage x//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 @@ -104,8 +105,8 @@ fmp :: ([BC] -> [BC]) (ByteCode a p) -> ByteCode a q fmp f b = BC \s->let (bc, s`) = runBC b s in (f bc, s`) instance toByteCode Bool where - toByteCode True = [toChar 1] - toByteCode False = [toChar 0] + toByteCode True = [toChar 0, toChar 1] + toByteCode False = [toChar 0, toChar 0] instance toByteCode Int where toByteCode n = map toChar [n/256,n rem 256] instance toByteCode Long where toByteCode (L n) = toByteCode n instance toByteCode Char where toByteCode c = [c] @@ -113,8 +114,8 @@ instance toByteCode String where toByteCode s = undef instance toByteCode Button where toByteCode s = [toChar $ consIndex{|*|} s] instance toChar Pin where - toChar (Digital p) = toChar $ consIndex{|*|} p + 1 - toChar (Analog p) = toChar $ consIndex{|*|} p + 1 + toChar (Digital p) = toChar $ consIndex{|*|} p + toChar (Analog p) = toChar $ consIndex{|*|} p derive gPrint BC, AnalogPin, Pin, DigitalPin derive consIndex BC, Pin, Button @@ -146,10 +147,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 +244,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