update device name instead of record
[mTask.git] / client / task.c
index 4ac8ce5..1c16ce5 100644 (file)
@@ -1,12 +1,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#ifndef STM
-#include <unistd.h>
-#include <stdio.h>
-#endif
-
 #include "task.h"
+#include "spec.h"
 #include "interface.h"
 
 struct task tasks[MAXTASKS];
@@ -16,9 +12,10 @@ void task_init(void)
        memset(&tasks, 0, sizeof(struct task)*MAXTASKS);
 }
 
-int task_register(void)
+void task_register(void)
 {
        uint8_t ct;
+       uint16_t i;
 
        for(ct = 0; ct<MAXTASKS; ct++)
                if(!tasks[ct].used)
@@ -29,6 +26,13 @@ int task_register(void)
        memset(&tasks[ct], 0, sizeof(struct task));
        //Read interval
        tasks[ct].interval = read16();
+       debug("interval: %d\n", tasks[ct].interval);
+
+       //Interrupt task
+       if(is_interrupt_task(&tasks[ct])) {
+
+       }
+
        //Read tasklength
        tasks[ct].tlen = read16();
        debug("task interval: %d, length: %d\n",
@@ -37,22 +41,38 @@ int task_register(void)
        if(tasks[ct].tlen > MAXTASKSIZE)
                die("Task is too long: %d", tasks[ct].tlen);
        //Read task bytecode
-       for(unsigned int i = 0; i<tasks[ct].tlen; i++){
+       for(i = 0; i<tasks[ct].tlen; i++){
                tasks[ct].bc[i] = read_byte();
-//             debug("t[][%i]: 0x%02x %d", i,
-//                     tasks[ct].bc[i], tasks[ct].bc[i]);
        }
        //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;
 
-       return ct;
+       write_byte('t');
+       write16(ct);
+       write_byte('\n');
+}
+
+bool is_interrupt_task(struct task *t)
+{
+       return t->interval & (2 <<14);
+}
+
+bool had_interrupt(struct task* t)
+{
+       //Not implemented yet...
+       return false;
+       (void)t;
 }
 
 void task_delete(void)
 {
-       tasks[read_byte()].used = false;
+       uint8_t c = read16();
+       tasks[c].used = false;
+       write_byte('d');
+       write16(c);
+       write_byte('\n');
 }
 
 struct task *task_get(int num)