From: Mart Lubbers Date: Wed, 14 Dec 2016 14:31:19 +0000 (+0100) Subject: added sds operators, timing and task deletion X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=73d6866bdbab8f393b53c9951b05b62005a5423a;p=mTask.git added sds operators, timing and task deletion --- diff --git a/int/int.c b/int/int.c index 37859cc..c89a6a8 100644 --- a/int/int.c +++ b/int/int.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "mTaskSymbols.h" @@ -18,6 +19,7 @@ #define STACKSIZE 1024 #define MSG_TASK 't' +#define MSG_DELTASK 'd' #define MSG_SDS 's' #define DEBUG @@ -36,9 +38,12 @@ struct task { uint8_t bc[MAXTASKSIZE]; uint16_t tlen; + uint16_t interval; + long lastrun; bool used; }; +struct timeval tv1; struct task tasks[MAXTASKS] = {0}; int sock_fd = -1; int fd = -1; @@ -62,6 +67,12 @@ bool input_available(int fd){ return FD_ISSET(fd, &fds); } +long millis() { + if (gettimeofday(&tv1, NULL) == -1) + pdie("gettimeofday"); + return tv1.tv_sec*1000 + tv1.tv_usec/1000; +} + void read_message(int fd_in, int fd_out) { //Find next task @@ -79,13 +90,28 @@ void read_message(int fd_in, int fd_out) case MSG_SDS: debug("Receiving an sds\n"); break; + case MSG_DELTASK: + debug("Receiving a delete task request\n"); + //Read task number and set unused + read(fd_in, &c, 1); + tasks[ct].used = false; + break; case MSG_TASK: + debug("Receiving a task\n"); + bzero(&tasks[ct], sizeof(struct task)); + //Read interval + read(fd_in, &c, 1); + tasks[ct].interval = 256*c; + read(fd_in, &c, 1); + tasks[ct].interval += c; + //Read tasklength read(fd_in, &c, 1); tasks[ct].tlen = 256*c; read(fd_in, &c, 1); tasks[ct].tlen += c; if(tasks[ct].tlen > MAXTASKSIZE) die("Task is too long: %d\n", tasks[ct].tlen); + //Read task bytecode for(int i = 0; i 0 ? 0 : 1; break; - case BCADD: - trace("add\n"); + case BCADD: trace("add\n"); stack[sp-1] = stack[sp] + stack[sp-1]; sp -= 1; break; - case BCSUB: - trace("sub\n"); + case BCSUB: trace("sub\n"); stack[sp-1] = stack[sp] - stack[sp-1]; sp -= 1; break; - case BCMUL: - trace("mul\n"); + case BCMUL: trace("mul\n"); stack[sp-1] = stack[sp] * stack[sp-1]; sp -= 1; break; - case BCDIV: - trace("div\n"); + case BCDIV: trace("div\n"); stack[sp-1] = stack[sp] / stack[sp-1]; sp -= 1; break; - case BCAND: - trace("and\n"); + case BCAND: trace("and\n"); stack[sp-1] = stack[sp] && stack[sp-1]; sp -= 1; break; - case BCOR: - trace("or\n"); + case BCOR: trace("or\n"); stack[sp-1] = stack[sp] || stack[sp-1]; sp -= 1; break; - case BCEQ: - trace("eq\n"); + case BCEQ: trace("eq\n"); stack[sp-1] = stack[sp] == stack[sp-1]; sp -= 1; break; - case BCNEQ: - trace("neq\n"); + case BCNEQ: trace("neq\n"); stack[sp-1] = stack[sp] != stack[sp-1]; sp -= 1; break; - case BCLES: - trace("les\n"); + case BCLES: trace("les\n"); stack[sp-1] = stack[sp] < stack[sp-1]; sp -= 1; break; - case BCGRE: - trace("gre\n"); + case BCGRE: trace("gre\n"); stack[sp-1] = stack[sp] > stack[sp-1]; sp -= 1; break; - case BCLEQ: - trace("leq\n"); + case BCLEQ: trace("leq\n"); stack[sp-1] = stack[sp] <= stack[sp-1]; sp -= 1; break; - case BCGEQ: - trace("geq\n"); + case BCGEQ: trace("geq\n"); stack[sp-1] = stack[sp] >= stack[sp-1]; sp -= 1; break; - case BCJMP: - trace("jmp to %d\n", program[pc]); + case BCJMP: trace("jmp to %d\n", program[pc]); pc = pc + program[pc]; break; - case BCJMPT: - trace("jmpt to %d\n", program[pc]); + case BCJMPT: trace("jmpt to %d\n", program[pc]); pc += stack[sp] ? program[pc] : 1; break; - case BCJMPF: - trace("jmpf to %d\n", program[pc]); + case BCJMPF: trace("jmpf to %d\n", program[pc]); pc += stack[sp] ? 1 : program[pc]; break; - case BCSERIALAVAIL: - trace("SerialAvailable()\n"); + case BCSERIALAVAIL: trace("SerialAvailable()\n"); break; - case BCSERIALPRINT: - trace("SerialPrint()\n"); + case BCSERIALPRINT: trace("SerialPrint()\n"); break; - case BCSERIALPRINTLN: - trace("SerialPrintln()\n"); + case BCSERIALPRINTLN: trace("SerialPrintln()\n"); break; - case BCSERIALREAD: - trace("SerialRead()\n"); + case BCSERIALREAD: trace("SerialRead()\n"); break; - case BCSERIALPARSEINT: - trace("SerialParseInt()\n"); + case BCSERIALPARSEINT: trace("SerialParseInt()\n"); break; - case BCANALOGREAD: - trace("AnalogRead(%d)\n", program[pc]); + case BCANALOGREAD: trace("AnalogRead(%d)\n", program[pc]); pc++; break; - case BCANALOGWRITE: - trace("AnalogWrite(%d)\n", program[pc]); + case BCANALOGWRITE: trace("AnalogWrite(%d)\n", program[pc]); pc++; break; - case BCDIGITALREAD: - trace("DigitalRead(%d)\n", program[pc]); + case BCDIGITALREAD: trace("DigitalRead(%d)\n", program[pc]); pc++; break; - case BCDIGITALWRITE: - trace("DigitalWrite(%d)\n", program[pc]); + case BCDIGITALWRITE: trace("DigitalWrite(%d)\n", program[pc]); pc++; break; default: @@ -302,16 +306,24 @@ int main(int argc, char *argv[]) open_filedescriptors(); + long cyclestart; while(true){ //Check for new tasks if(input_available(fd)) read_message(fd, fd); //Run tasks + cyclestart = millis(); for(ct = 0; ct [BCJmpF $ length <$> t + 1] <++> t instance noOp ByteCode where noOp = BC [] instance sds ByteCode where - sds f = {main = + sds f = undef/*{main = let var = 42 (v In body) = f var in unMain body - } + }*/ con f = undef instance serial ByteCode where