From: Mart Lubbers Date: Wed, 5 Apr 2017 09:13:11 +0000 (+0200) Subject: update X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=f39868397acdc4cdcb71b58926dee62327933336;p=mTask.git update --- diff --git a/client/.gitignore b/client/.gitignore index e6a8598..9308325 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -3,3 +3,4 @@ main build *.bin .dep +linux/client diff --git a/client/client.c b/client/client.c index 6502fb7..59c611f 100644 --- a/client/client.c +++ b/client/client.c @@ -79,34 +79,28 @@ void loop(void) #endif debug("Loop"); - int ct; + struct task *t; long cyclestart; - struct task *curtask; read_message(); //Run tasks cyclestart = getmillis(); - for(ct = 0; cttaskid); + run_task(t); //Interval task, and interval passed - } else if(cyclestart-curtask->lastrun > curtask->interval){ - debug("Running interval task: %d", ct); - run_task(curtask); + } else if(cyclestart-t->lastrun > t->interval){ + debug("Running interval task: %d", t->taskid); + run_task(t); //Oneshot task, thus disable - if(curtask->interval == 0){ - curtask->used = false; - } - curtask->lastrun = cyclestart; +// if(t->interval == 0){ +// curtask->used = false; +// } + t->lastrun = cyclestart; } } } diff --git a/client/linux/client b/client/linux/client deleted file mode 100755 index b269fc2..0000000 Binary files a/client/linux/client and /dev/null differ diff --git a/client/mem.c b/client/mem.c new file mode 100644 index 0000000..38bd6bd --- /dev/null +++ b/client/mem.c @@ -0,0 +1,3 @@ +#include + +struct task *task_head = NULL; diff --git a/client/task.c b/client/task.c index 1c16ce5..12789ce 100644 --- a/client/task.c +++ b/client/task.c @@ -5,52 +5,62 @@ #include "spec.h" #include "interface.h" -struct task tasks[MAXTASKS]; +#define TASKSPACE 128 + +uint8_t taskspace[TASKSPACE] = {0}; +uint8_t *spacepointer = (uint8_t *)&taskspace; +uint8_t taskid = 0; +struct task *head = NULL; void task_init(void) { - memset(&tasks, 0, sizeof(struct task)*MAXTASKS); + memset(&taskspace, 0, TASKSPACE); + head = NULL; } void task_register(void) { - uint8_t ct; - uint16_t i; + int i; + if(spacepointer+sizeof(struct task) > taskspace+TASKSPACE){ + die("Out of memory... Not enough to allocate taskstruct"); + } - for(ct = 0; ctinterval = read16(); + debug("interval: %d\n", t->interval); //Interrupt task - if(is_interrupt_task(&tasks[ct])) { + if(is_interrupt_task(t)) { } //Read tasklength - tasks[ct].tlen = read16(); - debug("task interval: %d, length: %d\n", - tasks[ct].interval, tasks[ct].tlen); + t->tasklength = read16(); + debug("task interval: %d, length: %d\n", t->interval, t->tasklength); + + if(spacepointer+t->tasklength > taskspace+TASKSPACE){ + die("Out of memory... Not enough to allocate bytes"); + } + + spacepointer += t->tasklength; - if(tasks[ct].tlen > MAXTASKSIZE) - die("Task is too long: %d", tasks[ct].tlen); //Read task bytecode - for(i = 0; itasklength; i++){ + t->bc[i] = read_byte(); } //Return the task number for later removal - debug("Received a task of length %d", tasks[ct].tlen); - tasks[ct].used = true; - tasks[ct].lastrun = 0L; + debug("Received a task of length %d", t->tasklength); + t->lastrun = 0L; + t->taskid = taskid++; write_byte('t'); - write16(ct); + write16(t->taskid); write_byte('\n'); } @@ -66,16 +76,54 @@ bool had_interrupt(struct task* t) (void)t; } -void task_delete(void) +struct task *task_head(void) { - uint8_t c = read16(); - tasks[c].used = false; - write_byte('d'); - write16(c); - write_byte('\n'); + return head; +} + +struct task *task_next(struct task *t) +{ + if(t == NULL){ + return NULL; + } + + uint8_t *next = (uint8_t *)t; + next += sizeof(struct task); + next += t->tasklength; + + return next > spacepointer ? NULL : (struct task *)next; } -struct task *task_get(int num) +void task_delete(void) { - return tasks[num].used ? &tasks[num] : NULL; + uint8_t c = read16(); + struct task *t = NULL; + while(t != NULL){ + if(t->taskid == c){ + break; + } + t = task_next(t); + } + if(t != NULL){ + //We found the task, now we move everything from the end of the task up + //to the spacepointer right + uint8_t *start = (uint8_t *)t; + uint8_t *end = start + sizeof(struct task) + t->tasklength; + debug("Moving %lu bytes\n", spacepointer-end); + for(int i = 0; i struct task { - uint8_t bc[MAXTASKSIZE]; - uint16_t tlen; + uint16_t tasklength; uint16_t interval; - long lastrun; - bool used; + unsigned long lastrun; + uint8_t taskid; + struct task *next; + uint8_t *bc; }; bool is_interrupt_task(struct task* t); bool had_interrupt(struct task* t); +struct task *task_head(void); +struct task *task_next(struct task *t); void task_init(void); void task_register(void); void task_delete(void); -struct task *task_get(int num); #ifdef __cplusplus }