From: Mart Lubbers Date: Mon, 3 Apr 2017 14:00:36 +0000 (+0200) Subject: separated devices X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8246c6551faa818be7a58638dbbc2e521f21c454;p=mTask.git separated devices --- diff --git a/client/client.c b/client/client.c index 8fa596f..0218fb7 100644 --- a/client/client.c +++ b/client/client.c @@ -21,6 +21,8 @@ #define MSG_SDS_UPD 'u' #define MSG_SPEC 'c' +#define LOOPDELAY 100 + void read_message(void) { //Find next task @@ -64,8 +66,15 @@ void read_message(void) } } +unsigned long loopmillis = 0; void loop(void) { +#ifdef ARDUINO_ESP8266_NODEMCU + if(getmillis()-loopmillis < LOOPDELAY){ + return; + } +#endif + int ct; long cyclestart; struct task *curtask; @@ -109,17 +118,18 @@ int main(int argc, char *argv[]){ #endif //Initialize systems - setup(); + real_setup(); sds_init(); task_init(); debug("sending device spec"); + +#ifndef ARDUINO_ESP8266_NODEMCU while(true){ //Check for newtasks loop(); - msdelay(100); + msdelay(LOOPDELAY); } -#ifndef ARDUINO_ESP8266_NODEMCU return 0; #endif } diff --git a/client/interface.h b/client/interface.h index 0982d4c..9e16292 100644 --- a/client/interface.h +++ b/client/interface.h @@ -1,6 +1,10 @@ #ifndef INTERFACE_H #define INTERFACE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -59,13 +63,16 @@ void led_off(uint8_t i); #endif /* Delay and communication */ -long getmillis(void); -void msdelay(long ms); +unsigned long getmillis(void); +void msdelay(unsigned long ms); /* Auxilliary */ -void setup(void); +void real_setup(void); void debug(char *fmt, ...); void pdie(char *s); void die(char *fmt, ...); +#ifdef __cplusplus +} +#endif #endif diff --git a/client/interpret.c b/client/interpret.c index b9d0c88..9862e7b 100644 --- a/client/interpret.c +++ b/client/interpret.c @@ -25,11 +25,6 @@ void run_task(struct task *t) char stack[STACKSIZE] = {0}; debug("Running task with length: %d", plen); while(pc < plen){ -// debug("program: %d", program[pc]); -// debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", -// stack[0], stack[1], stack[2], stack[3], stack[4], -// stack[5], stack[6], stack[7], stack[8], stack[9]); - switch(program[pc++]){ case BCNOP: trace("nop"); break; diff --git a/client/interpret.h b/client/interpret.h index d2effe7..726ebf6 100644 --- a/client/interpret.h +++ b/client/interpret.h @@ -3,6 +3,10 @@ #define STACKSIZE 1024 +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -10,4 +14,7 @@ void run_task(struct task *task); +#ifdef __cplusplus +} +#endif #endif diff --git a/client/linux/client b/client/linux/client index 4b9b984..b269fc2 100755 Binary files a/client/linux/client and b/client/linux/client differ diff --git a/client/linux/interface.c b/client/linux/interface.c index 971fb0f..36d2a86 100644 --- a/client/linux/interface.c +++ b/client/linux/interface.c @@ -109,7 +109,7 @@ void led_off(uint8_t i) (void)i; } -void setup(void) +void real_setup(void) { int port = 8123, opti = 1; //Register signal handler diff --git a/client/nodemcu/interface.c b/client/nodemcu/interface.c deleted file mode 100644 index 8b13789..0000000 --- a/client/nodemcu/interface.c +++ /dev/null @@ -1 +0,0 @@ - diff --git a/client/nodemcu/interface.cpp b/client/nodemcu/interface.cpp new file mode 100644 index 0000000..3ac929c --- /dev/null +++ b/client/nodemcu/interface.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +unsigned long getmillis(void) +{ + return millis(); +} + +void msdelay(unsigned long ms) +{ + delay(ms); +} + +bool input_available(void) +{ + return Serial.available(); +} + +uint8_t read_byte(void) +{ + return Serial.read(); +} + +void write_byte(uint8_t b) +{ + Serial.write(b); +} + +void real_setup(void) +{ + Serial.begin(115200); + Serial.println("Hello world!"); +} + +void debug(char *fmt, ...) +{ + Serial.print(fmt); +} + +void die(char *fmt, ...) +{ + Serial.print(fmt); + while(1){ + msdelay(100); + Serial.print("die"); + } +} + +void pdie(char *s) +{ + die(s); +} diff --git a/client/sds.h b/client/sds.h index 4179f47..f99bb1e 100644 --- a/client/sds.h +++ b/client/sds.h @@ -1,6 +1,10 @@ #ifndef SDS_H #define SDS_H +#ifdef __cplusplus +extern "C" { +#endif + #include struct sds { @@ -18,4 +22,7 @@ void sds_publish(int id); int sds_fetch(int id); void sds_store(int id, int val); +#ifdef __cplusplus +} +#endif #endif diff --git a/client/spec.h b/client/spec.h index a7adebc..18828db 100644 --- a/client/spec.h +++ b/client/spec.h @@ -1,6 +1,14 @@ #ifndef SPEC_H #define SPEC_H +#ifdef __cplusplus +extern "C" { +#endif + void spec_send(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/client/stm32/interface.c b/client/stm32/interface.c index 4caf47e..374a583 100644 --- a/client/stm32/interface.c +++ b/client/stm32/interface.c @@ -86,7 +86,7 @@ void msdelay(long ms) chThdSleepMilliseconds(ms); } -void setup(void) +void real_setup(void) { // palSetPadMode(GPIOG, 9, PAL_MODE_ALTERNATE(8)); // USART6 TX // palSetPadMode(GPIOG, 14, PAL_MODE_ALTERNATE(8)); // USART6 RX diff --git a/client/task.h b/client/task.h index a6c02b7..6542b1c 100644 --- a/client/task.h +++ b/client/task.h @@ -3,6 +3,10 @@ #define MAXTASKSIZE 1024 +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -22,4 +26,7 @@ void task_register(void); void task_delete(void); struct task *task_get(int num); +#ifdef __cplusplus +} +#endif #endif