From 15c6cbd8aea47cdab3b58f4614c54fd1b9538357 Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 28 Jan 2019 14:42:33 +0100 Subject: [PATCH] working on serial protocol --- serial/README.md | 2 ++ serial/essai.sh | 8 ++++---- serial/funcs.c | 13 ++++++++++++- serial/serial.h | 2 +- serial/t.c | 7 ++++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/serial/README.md b/serial/README.md index a89a80a..7d76e1e 100644 --- a/serial/README.md +++ b/serial/README.md @@ -28,6 +28,8 @@ ne bloque pas, c'est un peu ironique. Après un peu plus d'investigation, j'en arrive à conclure qu'il y a plein de subtilités entre les diverses variantes d'Arduino. Mais pas que. +Je pense que les quatre ports série supplémentaires de l'Arduino Mega +seront moins capricieux. diff --git a/serial/essai.sh b/serial/essai.sh index 2526c3e..6c5d337 100755 --- a/serial/essai.sh +++ b/serial/essai.sh @@ -5,18 +5,18 @@ DATAFILE="foo.dat" TMPFILE="/tmp/dd2data" IMAGE="graphe.png" -NB_READ=25000 +NB_READ=25 -./t -v -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} +./t -vv -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} gnuplot << __EOC__ set term png size 3200,512 set output "${IMAGE}" set grid -set title "Dans le Double Dragon 2" +set title "Temperature dans le Double Dragon 2" set xdata time set timefmt "%s" -set format x "%H:%M:%S" +set format x "%a, %H:%M:%S" set yrange [ 5.0 : 30.0] plot "${DATAFILE}" using 1:2 title " foo" with lines, \ "${DATAFILE}" using 1:3 title " bar" with lines, \ diff --git a/serial/funcs.c b/serial/funcs.c index bc59658..cfd1808 100644 --- a/serial/funcs.c +++ b/serial/funcs.c @@ -7,6 +7,10 @@ extern int verbosity; /* ---------------------------------------------------------------- */ +/* + * compute the integer mean value of a four values + * tagged lines. + */ int parseXvalue(char *line, char cflag) { int value, foo; @@ -32,10 +36,17 @@ if (4 != foo) { for (foo=0; foo<4; foo++) { value += vrd[foo]; } + +value /= 4; + return value; } /* ---------------------------------------------------------------- */ -int values2temps(float array[4]) +/* + * this fonction is specific to the LM35 thermo-sensor + * connected to a ADC pin of an Arduino Mega + */ +int values2temperature(float array[4]) { int foo; for (foo=0; foo<4; foo++) { diff --git a/serial/serial.h b/serial/serial.h index 158a2d1..bf6977c 100644 --- a/serial/serial.h +++ b/serial/serial.h @@ -17,7 +17,7 @@ int getline_to(int fd, char *where, int szm, int to_ms); /* auxiliary and test functions */ int parseXvalue(char *asciidatas, char id); -int values2temps(float array[4]); +int values2temperature(float array[4]); int parse4values(char *line, char cflag, float array[4]); diff --git a/serial/t.c b/serial/t.c index eed23c6..69af8a7 100644 --- a/serial/t.c +++ b/serial/t.c @@ -37,7 +37,7 @@ for (count=0; count= 0) { temps = time(NULL); - values2temps(datas); + values2temperature(datas); printf("%ld %f %f %f %f\n", temps, datas[0], datas[1], datas[2], datas[3]); fflush(stdout); @@ -75,6 +75,11 @@ while ((opt = getopt(argc, argv, "d:n:v")) != -1) { } +if (verbosity) { + fprintf(stderr, "Testing Serial Software - compiled " \ + __DATE__ " " __TIME__ "\n"); + } + serial_in = prepare_UART(device, speed); if (serial_in < 0) { fprintf(stderr, "%s : open device : error %d on %s\n",