From: Mart Lubbers Date: Tue, 24 Jan 2017 07:18:49 +0000 (+0100) Subject: fixed communication X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8c4fb11d9a590d3f9d361c36e0cb476568c00735;p=mTask.git fixed communication --- diff --git a/int/interpret.c b/int/interpret.c index 06f46a0..683638f 100644 --- a/int/interpret.c +++ b/int/interpret.c @@ -10,7 +10,8 @@ #ifdef STM #define trace(op, ...) {}; #else -#define trace(op, ...) printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__); +#define trace(op, ...) {}; +//#define trace(op, ...) printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__); #endif #define f16(p) program[pc]*265+program[pc+1] @@ -24,10 +25,10 @@ void run_task(struct task *t) char stack[STACKSIZE] = {0}; debug("Running task with length: %d", plen); while(pc < plen){ - debug("program: %d", program[pc]); - debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - stack[0], stack[1], stack[2], stack[3], stack[4], - stack[5], stack[6], stack[7], stack[8], stack[9]); +// debug("program: %d", program[pc]); +// debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", +// 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"); diff --git a/miTask.icl b/miTask.icl index 2e80bb3..a698ddd 100644 --- a/miTask.icl +++ b/miTask.icl @@ -71,13 +71,12 @@ deviceSelector ch = enterInformation "Type" [] isTTY s = not (isEmpty (filter (flip startsWith s) prefixes)) prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"] - mTaskTask :: Task () -mTaskTask = let (msgs, sdsShares) = makeMsgs 500 bc in +mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in withShared ([], msgs, False) (\ch-> deviceSelector ch // ||- sendTasks msgs ch//sendMsg msgs ch -// ||- (whileUnchanged ch (process sdsShares messageShare ch)) + ||- processMessages ch messageShare sdsShares ||- viewSharedInformation "channels" [ViewWith lens] ch ||- viewSharedInformation "messages" [] messageShare ||- viewSh sdsShares ch @@ -87,6 +86,14 @@ mTaskTask = let (msgs, sdsShares) = makeMsgs 500 bc in messageShare :: Shared [String] messageShare = sharedStore "mTaskMessagesRecv" [] + processMessages ch msgs sdss = forever (watch ch + >>* [OnValue (ifValue (not o isEmpty o fst3) (process ch))]) + where + process :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> Task () + process ch (r,_,_) = upd (appFst3 (const [])) ch >>| process` r + where + process` = foldr (\r t->updateSDSs sdss msgs r >>| t) (return ()) + makeMsgs :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)]) makeMsgs timeout bc # (msgs, st) = toMessages timeout (toRealByteCode (unMain bc)) @@ -183,10 +190,13 @@ syncNetworkChannel server port channel = (Ok "", Just (msgs,[],sendStopped), map encode send, False) whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) - whileConnected maybeNewData acc (msgs,send,sendStopped) - # l = map decode (maybeToList maybeNewData) - # send = if (not sendStopped) [] (map encode send) - = (Ok acc, Just (msgs ++ l,[],sendStopped), send, False) + whileConnected Nothing acc (msgs,send,sendStopped) + = (Ok acc, Nothing, [], False) +// = (Ok acc, Just (msgs,[],sendStopped), map encode send, False) + + whileConnected (Just newData) acc (msgs,send,sendStopped) + | sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False) + = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False) onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool)) onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)