import Generics.gCons
import iTasksTTY
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
+derive class iTask MTaskDevice, MTaskDeviceSpec, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
derive conses MTaskResource, TCPSettings
derive consName MTaskResource, TCPSettings
= TCPDevice TCPSettings
| SerialDevice TTYSettings
-:: MTaskDevice = {
- deviceTask :: Maybe TaskId
- ,deviceError :: Maybe String
- ,deviceChannels :: String
- ,deviceName :: String
- ,deviceTasks :: [MTaskTask]
- ,deviceData :: MTaskResource
+:: MTaskDevice =
+ { deviceTask :: Maybe TaskId
+ , deviceError :: Maybe String
+ , deviceChannels :: String
+ , deviceName :: String
+ , deviceTasks :: [MTaskTask]
+ , deviceData :: MTaskResource
+ , deviceSpec :: Maybe MTaskDeviceSpec
}
instance == MTaskDevice
deviceTaskDelete :: MTaskDevice MTaskTask -> Task ()
deviceTaskAcked :: MTaskDevice Int -> Task ()
deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
+deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task ()
from Data.Func import $
-derive class iTask MTaskDevice, MTaskResource, MTaskMSGRecv, MTaskMSGSend, BCShare
+derive class iTask MTaskDevice, MTaskResource, MTaskDeviceSpec, MTaskMSGRecv, MTaskMSGSend, BCShare
derive conses MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
derive consName MTaskResource, TTYSettings, BaudRate, Parity, ByteSize, TCPSettings
,deviceTasks=[]
,deviceTask=Nothing
,deviceError=Nothing
- ,deviceData=res}
+ ,deviceData=res
+ ,deviceSpec=Nothing}
getSynFun :: MTaskResource -> ((Shared Channels) -> Task ())
getSynFun (TCPDevice t) = synFun t
deviceTaskDeleteAcked :: MTaskDevice Int -> Task ()
deviceTaskDeleteAcked d i = withDevices d $ deleteTask
where deleteTask d = {d & deviceTasks=[s\\s<-d.deviceTasks | i <> s.ident]}
+
+deviceAddSpec :: MTaskDevice MTaskDeviceSpec -> Task ()
+deviceAddSpec d s = withDevices d $ \r->{r&deviceSpec=Just s}
///makeShare :: String Int Dynamic -> Task MTaskShare
makeShare :: String Int BCValue -> Task MTaskShare
-updateShare :: Int String -> Task ()
+updateShare :: Int BCValue -> Task ()
,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
} >>= \sh->set value (getSDSShare sh) >>| treturn sh
-updateShare :: Int String -> Task ()
+updateShare :: Int BCValue -> Task ()
updateShare ident val = get sdsStore
>>= \sh->(case find (\s->s.identifier==ident) sh of
Nothing = abort "Help, no share found with this ident"
- Just mts = set (fromByteCode val) (getSDSShare mts))
+ Just mts = set val (getSDSShare mts))
>>| traceValue "Updated" @! ()
CFLAGS:=-g -Wall -Wextra -DDEBUG
PROG:=main
-OBJS:=interpret.o sds.o task.o main.o interface.o
+OBJS:=interpret.o sds.o task.o main.o interface.o spec.o
all: mTaskSymbols.h $(PROG)
#include "interpret.h"
#include "mTaskSymbols.h"
#include "sds.h"
+#include "spec.h"
#include "task.h"
#include "interface.h"
setup();
sds_init();
task_init();
- debug("booting up");
+ debug("sending device spec");
+ spec_send();
while(true){
//Check for newetasks
loop();
--- /dev/null
+//TODO
+void spec_send(void){
+
+}
--- /dev/null
+#ifndef SPEC_H
+#define SPEC_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+struct device_spec {
+ bool have_led;
+ bool have_aio;
+ bool have_dio;
+ uint8_t max_tasks;
+ uint8_t max_sds;
+};
+
+void spec_send(void);
+
+#endif
| MTTaskDelAck Int
| MTSDSAck Int
| MTSDSDelAck Int
- | MTPub Int String
+ | MTPub Int BCValue
| MTMessage String
+ | MTDevSpec MTaskDeviceSpec
| MTEmpty
:: MTaskMSGSend
| OnInterval Int
| OnInterrupt Int
+:: MTaskDeviceSpec =
+ {haveLed :: Bool
+ ,haveAio :: Bool
+ ,haveDio :: Bool
+ ,maxTask :: Int //Should be number of bytes reserved in total for shares, tasks and functions
+ ,maxSDS :: Int
+ }
+
:: BCValue = E.e: BCValue e & mTaskType e
instance toString MTaskInterval
| BCDigitalWrite Pin
| BCTest AnalogPin
-derive gPrint BCValue
+derive gPrint BCValue, MTaskDeviceSpec
derive consIndex BCValue
derive consName BCValue
derive conses BCValue
instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
instance toByteCode MTaskInterval
-instance fromByteCode MTaskInterval
+instance fromByteCode MTaskInterval, MTaskDeviceSpec
instance arith ByteCode
instance boolExpr ByteCode
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")
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
MTPub i val = updateShare i val
MTTaskAck i = deviceTaskAcked device i
MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
+ MTDevSpec s = deviceAddSpec device s @! ()
_ = treturn ()
) >>| proc ms