From: Mart Lubbers Date: Mon, 23 Jan 2017 12:22:02 +0000 (+0100) Subject: not working again. X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=e09afe083f9077d63a8bd6c27ed8fa5da60430a8;p=mTask.git not working again. --- diff --git a/int/interface.c b/int/interface.c index 3ee568f..ba4446f 100644 --- a/int/interface.c +++ b/int/interface.c @@ -86,6 +86,12 @@ void debug(char *fmt, ...) (void)fmt; } +void debugi(int i) +{ + char m[10]; + debug(itoa(i, m, 10)); +} + void pdie(char *s) { (void)s; diff --git a/int/interface.h b/int/interface.h index 2d54bdf..1c77b7a 100644 --- a/int/interface.h +++ b/int/interface.h @@ -26,6 +26,7 @@ void delay(long ms); void setup(void); void debug(char *fmt, ...); +void debugi(int i); void pdie(char *s); void die(char *fmt, ...); diff --git a/int/interpret.c b/int/interpret.c index 6c43852..dedf688 100644 --- a/int/interpret.c +++ b/int/interpret.c @@ -22,10 +22,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/int/main.c b/int/main.c index dc28e0b..7840876 100644 --- a/int/main.c +++ b/int/main.c @@ -30,7 +30,7 @@ void read_message(void) sds_register(); break; case MSG_SDS_UPD: - debug("Receiving an sds"); + debug("Receiving an sds update"); //TODO do something with the return value sds_update(); break; @@ -40,9 +40,9 @@ void read_message(void) break; case MSG_GET_TASK: debug("Receiving a task"); - write_dpin(0, true); + // write_dpin(0, true); task_register(); - write_dpin(0, false); + // write_dpin(0, false); break; case '\0': break; @@ -50,6 +50,7 @@ void read_message(void) break; default: debug("Unknown message: %X", c); + debugi(c); } } } @@ -61,7 +62,6 @@ void loop(void) struct task *curtask; read_message(); - write_byte('\n'); //Run tasks cyclestart = millis(); @@ -79,6 +79,7 @@ void loop(void) debug("Current task to run: %d", ct); run_task(curtask); curtask->lastrun = cyclestart; + write_byte('\n'); } } @@ -98,7 +99,7 @@ int main(int argc, char *argv[]){ debug("booting up"); while(true){ //Check for newetasks - debug("loop"); +// debug("loop"); loop(); delay(100); } diff --git a/int/task.c b/int/task.c index 567fd9f..8fde866 100644 --- a/int/task.c +++ b/int/task.c @@ -29,14 +29,20 @@ int task_register(void) memset(&tasks[ct], 0, sizeof(struct task)); //Read interval tasks[ct].interval = read16(); + debug("interval"); + debugi(tasks[ct].interval); //Read tasklength tasks[ct].tlen = read16(); + debug("length"); + debugi(tasks[ct].tlen); if(tasks[ct].tlen > MAXTASKSIZE) die("Task is too long: %d", tasks[ct].tlen); //Read task bytecode for(unsigned int i = 0; i Int bclength (BCPush _) = 3 bclength (BCLab _) = 2 -bclength (BCSdsStore _) = 2 -bclength (BCSdsFetch _) = 2 -bclength (BCSdsPublish _) = 2 +bclength (BCSdsStore _) = 3 +bclength (BCSdsFetch _) = 3 +bclength (BCSdsPublish _) = 3 bclength (BCAnalogRead _) = 2 bclength (BCAnalogWrite _) = 2 bclength (BCDigitalRead _) = 2 @@ -73,9 +73,9 @@ toByteVal b = [bt:case b of (BCPush i) = i (BCLab i) = [toChar i] - (BCSdsStore i) = [toChar i] - (BCSdsFetch i) = [toChar i] - (BCSdsPublish i) = [toChar i] + (BCSdsStore i) = [c\\c<-:to16bit i] + (BCSdsFetch i) = [c\\c<-:to16bit i] + (BCSdsPublish i) = [c\\c<-:to16bit i] (BCAnalogRead i) = [toChar i] (BCAnalogWrite i) = [toChar i] (BCDigitalRead i) = [toChar i] diff --git a/miTask.icl b/miTask.icl index 46c2b99..5df0450 100644 --- a/miTask.icl +++ b/miTask.icl @@ -51,21 +51,19 @@ derive class iTask SerTCP :: SerTCP = Serial | TCP mTaskTask :: (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task () -mTaskTask ch = -// (enterInformation "Choose" [] >>= \st->case st of -// Serial = deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch -// TCP = deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch -// ) ||- - deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch ||- -// deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch ||- - (sendMsg msgs ch >>= \_-> ( - ( +mTaskTask ch = + (enterInformation "Choose" [] >>= \st->case st of + Serial = deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch + TCP = deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch + ) ||- + ( + sendMsg msgs ch >>= \_->( consumeNetworkStream (processSDSs sdsShares messageShare) ch ||- viewSharedInformation "channels" [ViewWith lens] ch ||- viewSharedInformation "messages" [] messageShare ||- viewSh sdsShares ch - ) >>* [OnAction ActionFinish (always shutDown)] - )) + ) + ) >>* [OnAction ActionFinish (always shutDown)] where messageShare :: Shared [String] messageShare = sharedStore "mTaskMessagesRecv" [] @@ -106,7 +104,8 @@ mTaskTask ch = ) ) ||- viewSh xs ch - (msgs, sdsShares) = makeBytecode 500 bc + sdsShares = makeShares st + (msgs, st) = toMessages 1000 (toRealByteCode (unMain bc)) bc :: Main (ByteCode () Stmt) bc = sds \x=1 In sds \pinnetje=1 In {main = @@ -132,14 +131,19 @@ mTaskTask ch = ) )} -makeBytecode :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)]) -makeBytecode timeout bc -# (msgs, st) = toMessages timeout (toRealByteCode (unMain bc)) -# shares = map (\(i,d)->(i, sharedStore (s i) (dd d))) st.sdss -= (msgs, shares) - where - s i = "mTaskSDS-" +++ toString i - dd [x,y] = (toInt x)*265+(toInt y) +makeShares :: BCState -> [(Int, Shared Int)] +makeShares {sdss=[]} = [] +makeShares s=:{sdss=[(i,d):xs]} = + [(i, sharedStore ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}] + +//makeBytecode :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)]) +//makeBytecode timeout bc +//# (msgs, st) = toMessages timeout (toRealByteCode (unMain bc)) +//# shares = map (\(i,d)->(i, sharedStore (s i) (dd d))) st.sdss +//= (msgs, shares) +// where +// s i = "mTaskSDS-" +++ toString i +// dd [x,y] = (toInt x)*265+(toInt y) sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task () @@ -201,8 +205,10 @@ syncNetworkChannel server port msgSeparator decodeFun encodeFun channel onConnect _ (received,receiveStopped,send,sendStopped) = (Ok "",if (not (isEmpty send)) (Just (received,False,[],sendStopped)) Nothing, map encodeFun send,False) whileConnected Nothing acc (received,receiveStopped,send,sendStopped) + | not (trace_tn "whilec nothing") = undef = (Ok acc, Nothing, [], False) whileConnected (Just newData) acc (received,receiveStopped,send,sendStopped) + | not (trace_tn "whilec just") = undef # [acc:msgs] = reverse (split msgSeparator (concat [acc,newData])) # write = if (not (isEmpty msgs && isEmpty send)) (Just (received ++ map decodeFun (reverse msgs),receiveStopped,[],sendStopped))