From 5ff699e2aacd37539f76e069524862dac401a303 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 30 Apr 2017 19:55:22 +0200 Subject: [PATCH] update client --- client/Makefile | 5 ++ client/nodemcu/Makefile | 2 + client/nodemcu/mem.c | 1 + client/nodemcu/mem.h | 1 + client/stm32/Makefile | 3 +- client/stm32/client.c | 1 - client/stm32/main.c | 137 ++++++++++++++++++++++++++++++++++++++++ client/stm32/mem.c | 1 + client/stm32/mem.h | 1 + 9 files changed, 149 insertions(+), 3 deletions(-) create mode 120000 client/nodemcu/mem.c create mode 120000 client/nodemcu/mem.h delete mode 120000 client/stm32/client.c create mode 100644 client/stm32/main.c create mode 120000 client/stm32/mem.c create mode 120000 client/stm32/mem.h diff --git a/client/Makefile b/client/Makefile index 652910b..0bf9b51 100644 --- a/client/Makefile +++ b/client/Makefile @@ -2,3 +2,8 @@ all: make -C nodemcu make -C stm32 make -C linux + +clean: + make -C nodemcu clean + make -C stm32 clean + make -C linux clean diff --git a/client/nodemcu/Makefile b/client/nodemcu/Makefile index ffd72dd..82fa2ef 100644 --- a/client/nodemcu/Makefile +++ b/client/nodemcu/Makefile @@ -1,2 +1,4 @@ all: +clean: + diff --git a/client/nodemcu/mem.c b/client/nodemcu/mem.c new file mode 120000 index 0000000..d01a49b --- /dev/null +++ b/client/nodemcu/mem.c @@ -0,0 +1 @@ +../mem.c \ No newline at end of file diff --git a/client/nodemcu/mem.h b/client/nodemcu/mem.h new file mode 120000 index 0000000..2e72483 --- /dev/null +++ b/client/nodemcu/mem.h @@ -0,0 +1 @@ +../mem.h \ No newline at end of file diff --git a/client/stm32/Makefile b/client/stm32/Makefile index 99a26a5..58fb87d 100644 --- a/client/stm32/Makefile +++ b/client/stm32/Makefile @@ -119,8 +119,7 @@ CSRC = $(STARTUPSRC) \ $(BOARDSRC) \ $(TESTSRC) \ $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ - $(filter-out interface_nodemcu.c,$(filter-out interface_linux.c,$(wildcard *.c))) + $(CHIBIOS)/os/hal/lib/streams/chprintf.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global # setting. diff --git a/client/stm32/client.c b/client/stm32/client.c deleted file mode 120000 index e47e797..0000000 --- a/client/stm32/client.c +++ /dev/null @@ -1 +0,0 @@ -../client.c \ No newline at end of file diff --git a/client/stm32/main.c b/client/stm32/main.c new file mode 100644 index 0000000..869d026 --- /dev/null +++ b/client/stm32/main.c @@ -0,0 +1,137 @@ +#include +#include +#include +#include + +#ifdef LINUX +#include +#endif + +#include "interpret.h" +#include "mTaskSymbols.h" +#include "sds.h" +#include "spec.h" +#include "task.h" +#include "interface.h" + +#define MSG_GET_TASK 't' +#define MSG_DEL_TASK 'd' +#define MSG_SDS_SPEC 's' +#define MSG_SDS_DEL 'a' +#define MSG_SDS_UPD 'u' +#define MSG_SPEC 'c' + +#define LOOPDELAY 100 + +void read_message(void) +{ + //Find next task + if(input_available()){ + uint8_t c = read_byte(); + debug("Receiving input: %c %02x\n", c, c); + switch(c){ + case MSG_SDS_SPEC: + debug("Receiving an sds"); + sds_register(); + break; + case MSG_SDS_UPD: + debug("Receiving an sds update"); + //TODO do something with the return value + c = read16(); + sds_update(c); + break; + case MSG_SDS_DEL: + debug("Receiving a delete SDS request"); + c = read16(); + sds_delete(c); + write_byte('a'); + write16(c); + write_byte('\n'); + break; + case MSG_DEL_TASK: + debug("Receiving a delete task request"); + c = read16(); + task_delete(c); + //Write acknowledgement + write_byte('d'); + write16(c); + write_byte('\n'); + break; + case MSG_GET_TASK: + debug("Receiving a task"); + task_register(); + break; + case MSG_SPEC: + debug("Receiving a spec request"); + spec_send(); + break; + case '\0': + debug("Server closed connection"); + break; + case '\n': + break; + default: + debug("Unknown message: %X", c); + } + } else { +// debug("No input"); + } +} + +unsigned long loopmillis = 0; +void loop(void) +{ +#ifdef ARDUINO_ESP8266_NODEMCU + if(getmillis()-loopmillis < LOOPDELAY){ + return; + } + loopmillis = getmillis(); +#endif + debug("Loop"); + + read_message(); + + //Run tasks + unsigned long cyclestart = getmillis(); + for(struct task *t = task_head(); t != NULL; t = task_next(t)){ + //interrupt task + if(is_interrupt_task(t) && had_interrupt(t)){ + debug("Interrupt task %d not implemented", t->taskid); + run_task(t); + //Interval task, and interval passed + } else if(cyclestart-t->lastrun > t->interval){ + debug("Running interval task: %d", t->taskid); + run_task(t); + + //Oneshot task, thus disable + if(t->interval == 0){ + task_delete(t->taskid); + } + t->lastrun = cyclestart; + } + } +} + +#ifdef STM +int main(void){ +#elif defined ARDUINO_ESP8266_NODEMCU +void setup(){ +#elif defined LINUX +int main(int argc, char *argv[]){ + gargc = argc; + gargv = argv; +#endif + + //Initialize device independant functionality + real_setup(); + +#ifndef ARDUINO_ESP8266_NODEMCU + while(true){ + //Check for newtasks + loop(); + msdelay(LOOPDELAY); + } + + return 0; +#endif +} diff --git a/client/stm32/mem.c b/client/stm32/mem.c new file mode 120000 index 0000000..d01a49b --- /dev/null +++ b/client/stm32/mem.c @@ -0,0 +1 @@ +../mem.c \ No newline at end of file diff --git a/client/stm32/mem.h b/client/stm32/mem.h new file mode 120000 index 0000000..2e72483 --- /dev/null +++ b/client/stm32/mem.h @@ -0,0 +1 @@ +../mem.h \ No newline at end of file -- 2.20.1