improve install script, add debug to the linux client, update jenkins behaviour
[mTask.git] / client / main.c
1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #ifdef STM
7 #else
8 #include <stdio.h>
9 #endif
10
11 #include "interpret.h"
12 #include "mTaskSymbols.h"
13 #include "sds.h"
14 #include "task.h"
15 #include "interface.h"
16
17 #define MSG_GET_TASK 't'
18 #define MSG_DEL_TASK 'd'
19 #define MSG_SDS_SPEC 's'
20 #define MSG_SDS_DEL 'a'
21 #define MSG_SDS_UPD 'u'
22
23 void read_message(void)
24 {
25 //Find next task
26 if(input_available()){
27 uint8_t c = read_byte();
28 debug("Receiving input: %c %02x\n", c, c);
29 switch(c){
30 case MSG_SDS_SPEC:
31 debug("Receiving an sds");
32 sds_register();
33 break;
34 case MSG_SDS_UPD:
35 debug("Receiving an sds update");
36 //TODO do something with the return value
37 sds_update();
38 break;
39 case MSG_SDS_DEL:
40 debug("Receiving a delete SDS request");
41 sds_delete();
42 break;
43 case MSG_DEL_TASK:
44 debug("Receiving a delete task request");
45 task_delete();
46 break;
47 case MSG_GET_TASK:
48 debug("Receiving a task");
49 task_register();
50 break;
51 case '\0':
52 break;
53 case '\n':
54 break;
55 default:
56 debug("Unknown message: %X", c);
57 }
58 } else {
59 delay(1000);
60 printf("no input...\n");
61 }
62 }
63
64 void loop(void)
65 {
66 int ct;
67 long cyclestart;
68 struct task *curtask;
69
70 read_message();
71
72 //Run tasks
73 cyclestart = millis();
74 for(ct = 0; ct<MAXTASKS; ct++){
75 //See whether the task is even in use
76 if((curtask = task_get(ct)) == NULL){
77 // debug("Task %d not implemented\n", ct);
78 continue;
79 }
80 //See whether the task interval has passed
81 if(cyclestart-curtask->lastrun < curtask->interval){
82 // debug("Task %d not scheduled\n", ct);
83 continue;
84 }
85 debug("Current task to run: %d", ct);
86 run_task(curtask);
87 curtask->lastrun = cyclestart;
88 if(curtask->interval == 0){
89 curtask->used = false;
90 write_byte('m');
91 write_byte('d');
92 write_byte('\n');
93 }
94 write_byte('\n');
95 }
96 }
97
98 #ifdef STM
99 int main(void){
100 #else
101 int main(int argc, char *argv[]){
102 gargc = argc;
103 gargv = argv;
104 #endif
105
106 //Initialize systems
107 setup();
108 sds_init();
109 task_init();
110 debug("booting up");
111 while(true){
112 //Check for newetasks
113 write_byte('\n');
114 loop();
115 delay(50);
116 }
117 return 0;
118 }