started with device handshake
[mTask.git] / mTaskInterpret.icl
index e603f82..b6ab929 100644 (file)
@@ -55,12 +55,13 @@ decode :: String -> MTaskMSGRecv
 decode x
 | size x == 0 = MTEmpty
 = case x.[0] of
-       't' = MTTaskAck (from16bit (x % (1,3)))
-       'd' = MTTaskDelAck (from16bit (x % (1,3)))
+       't' = MTTaskAck $ fromByteCode x
+       'd' = MTTaskDelAck $ fromByteCode x
        'm' = MTMessage x
-       's' = MTSDSAck (from16bit (x % (1,3)))
-       'a' = MTSDSDelAck (from16bit (x % (1,3)))
-       'p' = MTPub (from16bit (x % (1,3))) (x % (3,size x))
+       's' = MTSDSAck $ fromByteCode x
+       'a' = MTSDSDelAck $ fromByteCode x
+       'p' = MTPub (fromByteCode x) $ fromByteCode $ x % (3,size x)
+       'c'     = MTDevSpec $ fromByteCode (x % (1, size x))
        '\0' = MTEmpty
        '\n' = MTEmpty
        _ = MTMessage x//abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n")
@@ -152,8 +153,17 @@ instance fromByteCode MTaskInterval
                        0 = OneShot
                        i = OnInterval i
                = OnInterrupt $ fromByteCode s bitand 127
-
-derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC
+instance fromByteCode MTaskDeviceSpec where
+       fromByteCode s = let c = toInt s.[0] in
+               {MTaskDeviceSpec
+               |haveLed=c bitand 1 > 0
+               ,haveAio=c bitand 2 > 0
+               ,haveDio=c bitand 4 > 0
+               ,maxTask=toInt s.[1]
+               ,maxSDS =toInt s.[2]
+               }
+
+derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC, MTaskDeviceSpec
 derive class gCons BC
 
 consIndex{|BCValue|} _ = 0