diff --git a/.gitignore b/.gitignore index 5a276e4..b0aef2a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ doc/*.idx doc/*.ilg doc/*.ind +*/foo.dat + + diff --git a/serial/Makefile b/serial/Makefile index 984dabe..492d6af 100644 --- a/serial/Makefile +++ b/serial/Makefile @@ -4,6 +4,9 @@ OPT = -Wall -DDEBUG_LEVEL=1 serial.o: serial.c serial.h Makefile gcc ${OPT} -c $< -t: t.c serial.o Makefile - gcc ${OPT} $< serial.o -o $@ +funcs.o: funcs.c serial.h Makefile + gcc ${OPT} -c $< + +t: t.c serial.o funcs.o Makefile + gcc ${OPT} $< serial.o funcs.o -o $@ diff --git a/serial/funcs.c b/serial/funcs.c new file mode 100644 index 0000000..52eb1b3 --- /dev/null +++ b/serial/funcs.c @@ -0,0 +1,26 @@ + +#include + +#include "serial.h" + +extern int verbosity; + +/* ---------------------------------------------------------------- */ +int parseXvalue(char *line, char cflag) +{ +int value, foo; +int vrd[4]; + +value=0; + +foo = sscanf(data+1, "%d %d %d %d", vrd, vrd+1, vrd+2, vrd+3); +fprintf(stderr, "sscanf -> %d\n", foo); +if (4 != foo) { + return -666; + } +for (foo=0; foo<4; foo++) { + value += vrd[foo]; + } +return value; +} +/* ---------------------------------------------------------------- */ diff --git a/serial/serial.c b/serial/serial.c index ac2abc3..4854e65 100644 --- a/serial/serial.c +++ b/serial/serial.c @@ -148,7 +148,7 @@ FD_SET (fd, &rfds); retval = select(1, &rfds, NULL, NULL, &timeout); #if DEBUG_LEVEL -fprintf(stderr, "%s : select on %d -> %d\n", __func__, fd, retval); +fprintf(stderr, "%s : select on fd %d -> %d\n", __func__, fd, retval); #endif switch (retval) { @@ -187,12 +187,22 @@ int getline_to(int fd, char *where, int szm, int to_ms) { int curpos, byte, retval; +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %d %p %d %d )\n", __func__, + fd, where, szm, to_ms); +#endif + curpos = 0; retval = -7; /* magic number powa */ where[0] = '\0'; /* erase all the bs */ for(;;) { - byte = getbyte_to (fd, to_ms); + if (to_ms) { + byte = getbyte_to (fd, to_ms); + } + else { + byte = getbyte(fd); + } if (byte < 0) { fprintf(stderr, "%s : somthing is wrong %d\n", @@ -204,6 +214,7 @@ for(;;) { if ('\n' == byte) { /* got an EOL ? */ where[curpos] = '\0'; retval = curpos; + break; } if (curpos < szm) { /* ya de la place */ diff --git a/serial/serial.h b/serial/serial.h index a13d292..294d3c4 100644 --- a/serial/serial.h +++ b/serial/serial.h @@ -14,4 +14,8 @@ int getbyte_to (int fd, int to_ms); int getline_to(int fd, char *where, int szm, int to_ms); +/* auxiliary and test functions */ + +int parseXvalue(char *asciidatas, char id); + diff --git a/serial/t.c b/serial/t.c index 25e0cf7..84d5d05 100644 --- a/serial/t.c +++ b/serial/t.c @@ -17,10 +17,12 @@ int verbosity; +/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */ int main (int argc, char *argv[]) { -int serial_in, foo; +int serial_in, foo, count; +char ligne[200]; if (2 != argc) { fprintf(stderr, "give me a device name, please.\n"); @@ -31,17 +33,15 @@ serial_in = prepare_UART(argv[1], 9600); fprintf(stderr, "going to listen on %d\n", serial_in); -for (;;) { - foo = getbyte_to(serial_in, 50000); - if (foo < 0) { - fprintf(stderr, "get byte : got %d, err is %d\n", - foo, errno); - } - else { - printf("%9ld $%02x ", time(NULL), foo); - if (isprint(foo)) putchar(foo); - puts(""); - if ('\n'==foo) puts(""); +for (count=0; count<10000; count++) { + foo = getline_to(serial_in, ligne, 100, 0); + fprintf(stderr, "getline #%d -> %d\n", count, foo); + fprintf(stderr, "%s\n", ligne); + foo = parseXvalue(ligne); + fprintf(stderr, "parse -> %d\n", foo); + if (foo>= 0) { + printf("%d %d\n", count, foo); + fflush(stdout); } } diff --git a/simulator/send-random/send-random.ino b/simulator/send-random/send-random.ino index f387759..8496b28 100644 --- a/simulator/send-random/send-random.ino +++ b/simulator/send-random/send-random.ino @@ -26,7 +26,7 @@ void updatevalues(void) values[foo] += (foo + 1); } if (values[foo] > 1023) { - values[foo] = rand()%15; + values[foo] = rand()%25; } } } @@ -48,7 +48,7 @@ void sendvalues(void) void loop() { updatevalues(); sendvalues(); - delay(2500); + delay(800); } /* -------------------------------------------------- */