#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]
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");
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
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))
= (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)