From 8246c6551faa818be7a58638dbbc2e521f21c454 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 3 Apr 2017 16:00:36 +0200 Subject: [PATCH] separated devices --- client/client.c | 16 +++++++++-- client/interface.h | 13 +++++++-- client/interpret.c | 5 ---- client/interpret.h | 7 +++++ client/linux/client | Bin 37704 -> 37712 bytes client/linux/interface.c | 2 +- client/nodemcu/interface.c | 1 - client/nodemcu/interface.cpp | 53 +++++++++++++++++++++++++++++++++++ client/sds.h | 7 +++++ client/spec.h | 8 ++++++ client/stm32/interface.c | 2 +- client/task.h | 7 +++++ 12 files changed, 107 insertions(+), 14 deletions(-) delete mode 100644 client/nodemcu/interface.c create mode 100644 client/nodemcu/interface.cpp 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 4b9b9842554078ae1dbfd09c7c55b74c6d6586fe..b269fc2426cdf10b7d7f99a5cc5cf001ea469782 100755 GIT binary patch delta 1426 zcmZ8hX-rgC6u#%p0!+(vMrVAy7Sb7^vZw`GN-gOE7-E|=1W^`Yw3$?l1`?KzZ37~p zU1&+E%t?tMO@lEpB>hu(@}tH!jHYHni5;7mmiR-dbsVeyASA}xB|Z1uL(*`6ocrFl zoO924OZ<$MIHR2?0MB$`tLD?YpMLbL?ca`MPGsGdGjyiLH<% z*1HAkn{#2re7Cs|v`i|Ugl>oou<<@qHV@0S2w&7sN2e054p>p^K z7eb%IiW%CQ*nrPP-gNb}g*)DQr!8{0%j}O-fO-D#f&;GMCw)8M8NAY$v)(OQ^XXu; zKGM{F4&jIn3o;tlX>99+TU^+vI6K|T^*fdldzaZibcN0^`vAj7ic2-hC%sFBiv3P) zBAxNCiWIPg@l1?S-74%pszU&mDSrVg;{hdUXJr`%`*oKwE<^inEVG_p%is3rOD4xY-QqHmRQm#tBo2&eQ!9m^l zk=ZyW_=!)rXr19Mv(Zh;RKnf|I5eo2{>AK@sqdLN#`C8}FY zpPAJ3a_>#7c?rEkI=p5n8?5;sBBh+e6we`@m7Nwl#CeMN>3q-Z2%Z|EDKQ%fD!7)1 zc-r#L%FOiaZmfBBG3$ia*n6LQ4{+w2Sb9u1?lbFVmOl*f5W~c}=*ySgMe>v>%w8Xk z5j$bc?J@DXi(%eMFm_CbS8#S zEH67qEavIM{WTo!I^8w75Z^~6BY2LyEBK5^Il(W4dhjFK&mDYB-aE675V043lL%tZ zDgve#H;SYYGn+Y_#-BG=1im9U|Gfr+XZiAPxoEBR624wr4bSj+Z5h0emukE6<`QYf zV)%)w{&~1@%gb=YIk2S}j8PMx*6o8Ia7TR@3Y}y16#zGItYHs~;mSlMlwmp%fO0&U zSO$OM^+YfH;v}|aW}5HrN;U1rg{dm1E42bJ3#RjZ({&Rv_+j%}D8ljP5_Go|z$iis zhnpB};nr=MlaE;}TVYeX|5+B3#Ce2=S|ZUuh*QAw*}br;U(~d}HGX!10v2i9!0J{G z%W#tPg9g1G=}%~VF*so*7;5EKSXPTzy55%PR5c(@>K=NqkJu+QJAk9@ z;!JM0N372X^Rc4;oyjnU(%kx1>s6L2p@`NS!Rj1DHYR4d^L+w^mlM;3FShMtx;rz7+o30r}a)KitX zvSJ2tTY&TR?eJljx{FRz_XIc_j%IT`&*`>H>l-M<_5H>07Vhr<0Ge>J Qf4S$&ZdI$tp`O|Q0u+G~R{#J2 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 -- 2.20.1