CLM:=clm
override CLMFLAGS+=-dynamics -h 200M -nt -l -no-pie
CLMLIBS:=\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Dynamics\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Generics\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/StdEnv\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/TCPIP\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Server\
+ -I ./iTasks-SDK/Patches/Dynamics\
+ -I ./iTasks-SDK/Patches/Generics\
+ -I ./iTasks-SDK/Patches/StdEnv\
+ -I ./iTasks-SDK/Patches/TCPIP\
+ -I ./iTasks-SDK/Server\
-I ./clean-platform/src/libraries/OS-Independent\
-I ./clean-platform/src/libraries/OS-Independent/Deprecated/StdLib\
-I ./clean-platform/src/libraries/OS-Posix\
-I ./clean-platform/src/libraries/OS-Linux\
-I ./clean-platform/src/libraries/OS-Linux-64\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/linux64\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/common\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/SAPL\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-sapl/src\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Server/lib\
+ -I ./iTasks-SDK/Dependencies/graph_copy/linux64\
+ -I ./iTasks-SDK/Dependencies/graph_copy/common\
+ -I ./iTasks-SDK/Dependencies/SAPL\
+ -I ./iTasks-SDK/Dependencies/clean-sapl/src\
+ -I ./iTasks-SDK/Server/lib\
-I $(CLEAN_HOME)/lib/StdEnv\
-I $(CLEAN_HOME)/lib/Generics\
-I $(CLEAN_HOME)/lib/Dynamics\
#include "mTaskSymbols.h"
#include "interpret.h"
-#include "misc.h"
+#include "interface.h"
#include "task.h"
#include "sds.h"
int pc = 0;
int sp = 0;
char stack[STACKSIZE] = {0};
- printf("Running task with length: %d\n", plen);
+ debug("Running task with length: %d\n", plen);
while(pc != plen){
- //printf("program: %d\n", program[pc]);
- //printf("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
- // stack[0], stack[1], stack[2], stack[3], stack[4],
- // stack[5], stack[6], stack[7], stack[8], stack[9]);
+ debug("program: %d\n", program[pc]);
+ debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+ stack[0], stack[1], stack[2], stack[3], stack[4],
+ stack[5], stack[6], stack[7], stack[8], stack[9]);
switch(program[pc++]){
case BCNOP: trace("nop\n");
case BCSERIALPARSEINT: trace("SerialParseInt()\n");
break;
case BCANALOGREAD: trace("AnalogRead(%d)\n", program[pc]);
- pc++;
+ stack[sp++] = read_apin(program[pc++]);
break;
case BCANALOGWRITE: trace("AnalogWrite(%d)\n", program[pc]);
- pc++;
+ write_apin(program[pc++], stack[sp-1]);
+ sp--;
break;
case BCDIGITALREAD: trace("DigitalRead(%d)\n", program[pc]);
- pc++;
+ stack[sp++] = read_dpin(program[pc++]);
break;
case BCDIGITALWRITE: trace("DigitalWrite(%d)\n", program[pc]);
- pc++;
+ write_dpin(program[pc++], stack[sp-1]);
+ sp--;
break;
default:
trace("unrecognized\n");
module miTask
import StdDebug, StdMisc
-
-from Text import class Text(concat,join,split), instance Text String
+from StdFunc import flip
import iTasks
import mTask
+from Text import class Text(startsWith,concat,split,join), instance Text String
+
+import Data.Tuple
+import System.Directory
+
+import iTasks.UI.Definition
+
+import iTasks._Framework.TaskState
+import iTasks._Framework.TaskServer
+import iTasks._Framework.IWorld
+import iTasks._Framework.Store
+
+import TTY
+
+derive class iTask Queue, TTYSettings, Parity, BaudRate, ByteSize
derive class iTask MTaskMSGRecv, MTaskMSGSend
+:: *Resource | TTYd !*TTY
+
Start :: *World -> *World
-Start world = startEngine (
- enterInformation "Port Number?" []
- >>= \port->withShared ([], False, [], False) (mTaskTask port)
- ) world
+Start world = startEngine (withShared ([], False, [], False) mTaskTask) world
//Start world = startEngine mTaskTask world
+//
+deviceSelectorNetwork :: Task (Int, String)
+deviceSelectorNetwork = enterInformation "Port Number?" []
+ -&&- enterInformation "Network address" []
+
+deviceSelectorSerial :: Task (String, TTYSettings)
+deviceSelectorSerial = accWorld getDevices
+ >>= \dl->(enterChoice "Device" [] dl -&&- deviceSettings)
+ where
+ deviceSettings = updateInformation "Settings" [] zero
-mTaskTask :: Int (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
-mTaskTask port ch =
- syncNetworkChannel "localhost" port "\n" decode encode` ch ||-
+ getDevices :: !*World -> *(![String], !*World)
+ getDevices w = case readDirectory "/dev" w of
+ (Error (errcode, errmsg), w) = abort errmsg
+ (Ok entries, w) = (map ((+++) "/dev/") (filter isTTY entries), w)
+ where
+ isTTY s = not (isEmpty (filter (flip startsWith s) prefixes))
+ prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"]
+
+mTaskTask :: (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
+mTaskTask ch =
+ deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode` ch ||-
+// deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode` encode` ch ||-
sendMsg msgs ch ||-
(
(
| not (trace_tn (toString (toJSON m))) = undef
= encode m
+ decode` m
+ | not (trace_tn (toString (toJSON m))) = undef
+ = decode m
+
messageShare :: Shared [String]
messageShare = sharedStore "mTaskMessagesRecv" []
sdsShares = makeShares st
- (msgs, st) = toMessages 500 (toRealByteCode (unMain bc))
+ (msgs, st) = toMessages 1000 (toRealByteCode (unMain bc))
bc :: Main (ByteCode () Stmt)
bc = sds \x=1 In sds \pinnetje=1 In {main =
- x =. x +. lit 1 :.
+ x =. x +. pinnetje :.
pub x :.
IF (pinnetje ==. lit 1) (
analogWrite A0 (lit 1) :.
makeShares :: BCState -> [(Int, Shared Int)]
makeShares {sdss=[]} = []
makeShares s=:{sdss=[(i,d):xs]} =
- [(i, sharedStore ("mTaskSDS-" +++ toString i) 0):makeShares {s & sdss=xs}]
+ [(i, sharedStore ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}]
sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! ()
+syncSerialChannel :: String TTYSettings (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
+syncSerialChannel dev opts decodeFun encodeFun rw = Task eval
+ where
+ eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world}
+ = case TTYopen dev opts world of
+ (False, _, world)
+ # (err, world) = TTYerror world
+ = (ExceptionResult (exception err), {iworld & world=world})
+ (True, tty, world)
+ # iworld = {iworld & world=world, resources=Just (TTYd tty)}
+ = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw decodeFun encodeFun)) iworld of
+ (Error e, iworld) = (ExceptionResult (exception "h"), iworld)
+ (Ok _, iworld) = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=True} NoRep (TCBasic taskId ts JSONNull False), iworld)
+
+ eval _ _ tree=:(TCBasic _ ts _ _) iworld
+ = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=False} NoRep tree, iworld)
+
+ eval event evalOpts tree=:(TCDestroy _) iworld=:{IWorld|resources,world}
+ # (TTYd tty) = fromJust resources
+ # (ok, world) = TTYclose tty world
+ # iworld = {iworld & world=world,resources=Nothing}
+ = case removeBackgroundTask 42 iworld of
+ (Error e, iworld) = (ExceptionResult (exception "h"), iworld)
+ (Ok _, iworld) = (DestroyedResult, iworld)
+
+serialDeviceBackgroundTask :: (Shared ([m],Bool,[n],Bool)) (String -> m) (n -> String) !*IWorld -> *IWorld
+serialDeviceBackgroundTask rw en de iworld
+ = case read rw iworld of
+ (Error e, iworld) = iworld
+ (Ok (r,rs,s,ss), iworld)
+ # (Just (TTYd tty)) = iworld.resources
+ # tty = writet (map de s) tty
+ = case TTYavailable tty of
+ (False, tty) = {iworld & resources=Just (TTYd tty)}
+ (_, tty)
+ # (l, tty) = appFst en (TTYreadline tty)
+ # iworld = {iworld & resources=Just (TTYd tty)}
+ = snd (write (r ++ [l],rs,[],ss) rw iworld)
+ where
+ writet :: [String] !*TTY -> *TTY
+ writet [] t = t
+ writet [x:xs] t = writet xs (TTYwrite t x)
+
+
syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
syncNetworkChannel server port msgSeparator decodeFun encodeFun channel
= tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! ()