Browse Source

reading 4 values from arduino

tth 1 year ago
parent
commit
0826568604
6 changed files with 53 additions and 13 deletions
  1. 1
    1
      .gitignore
  2. 21
    6
      serial/essai.sh
  3. 21
    2
      serial/funcs.c
  4. 3
    1
      serial/serial.c
  5. 5
    2
      serial/t.c
  6. 2
    1
      simulator/send-random/send-random.ino

+ 1
- 1
.gitignore View File

@@ -15,6 +15,6 @@ doc/*.ind
15 15
 */*.dat
16 16
 
17 17
 rrdb/*.png
18
-
18
+serial/*.png
19 19
 
20 20
 

+ 21
- 6
serial/essai.sh View File

@@ -1,10 +1,25 @@
1 1
 #!/bin/bash
2 2
 
3 3
 DEVICE="/dev/ttyACM0"
4
+DATAFILE="foo.dat"
5
+IMAGE="graphe.png"
6
+NB_READ=1000
7
+
8
+./t -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE}
9
+
10
+gnuplot << __EOC__
11
+set term png 	size 1024,512
12
+set output 	"${IMAGE}"
13
+set grid
14
+set xdata 	time
15
+set timefmt 	"%s"
16
+set format x 	"%H:%M:S"
17
+plot	"${DATAFILE}" using 1:2 title "foo" with lines,	\
18
+	"${DATAFILE}" using 1:3 title "bar" with lines,	\
19
+	"${DATAFILE}" using 1:4 title "quux" with lines, \
20
+	"${DATAFILE}" using 1:5 title "booz" with lines
21
+__EOC__
22
+
23
+# display ${IMAGE}
24
+
4 25
 
5
-for p in {0..15}
6
-do
7
-	echo pass $p
8
-	./t ${DEVICE} | tee -a foo.dat
9
-	sleep 8
10
-done

+ 21
- 2
serial/funcs.c View File

@@ -1,5 +1,6 @@
1 1
 
2 2
 #include  <stdio.h>
3
+#include  <string.h>
3 4
 
4 5
 #include  "serial.h"
5 6
 
@@ -15,7 +16,7 @@ value=0;
15 16
 
16 17
 if ( cflag != *line ) {
17 18
 	if (verbosity) {
18
-		fprintf(stderr, "%s line[0] 0x%x bad\n",
19
+		fprintf(stderr, "%s : line[0] 0x%x bad\n",
19 20
 					__func__, *line);
20 21
 		}
21 22
 	return -777;
@@ -36,8 +37,26 @@ return value;
36 37
 /* ---------------------------------------------------------------- */
37 38
 int parse4values(char *line, char cflag, float array[4])
38 39
 {
40
+float		ftmp[4];
41
+int		foo;
39 42
 
43
+if ( cflag != *line ) {
44
+	if (verbosity) {
45
+		fprintf(stderr, "%s : line[0] 0x%x bad\n",
46
+					__func__, *line);
47
+		}
48
+	return -777;
49
+	}
50
+
51
+foo = sscanf(line+1, "%f %f %f %f", ftmp, ftmp+1, ftmp+2, ftmp+3);
52
+if (4 != foo) {
53
+	fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
54
+	return -666;
55
+	}
56
+// fprintf(stderr, "\tV %f\n", ftmp[0]);
57
+
58
+memcpy(array, ftmp, 4*sizeof(float));
40 59
 
41
-return -777;
60
+return 4;
42 61
 }
43 62
 /* ---------------------------------------------------------------- */

+ 3
- 1
serial/serial.c View File

@@ -41,7 +41,7 @@ int		baudbits;
41 41
 struct termios	options;
42 42
 
43 43
 #if DEBUG_LEVEL
44
-fprintf(stderr, "%s ( %s %d )\n", __func__, port, baudrate);
44
+fprintf(stderr, ">>> %s ( %s %d )\n", __func__, port, baudrate);
45 45
 #endif
46 46
 // OPEN THE UART
47 47
 // The flags (defined in fcntl.h):
@@ -103,6 +103,8 @@ options.c_cc[VMIN] = 1;			/* ask for blocking read */
103 103
 tcflush(uart0, TCIFLUSH);
104 104
 tcsetattr(uart0, TCSANOW, &options);
105 105
 
106
+tcflush(uart0, TCIFLUSH);		/* do it again, sam */
107
+
106 108
 return uart0;
107 109
 }
108 110
 /* -------------------------------------------------------------------- */

+ 5
- 2
serial/t.c View File

@@ -24,6 +24,7 @@ int loop(int sfd, int iters)
24 24
 int		count, foo;
25 25
 long		temps;
26 26
 char		ligne[200];
27
+float		datas[4];
27 28
 
28 29
 for (count=0; count<iters; count++) {
29 30
 	foo = getline_to(sfd, ligne, 100, 0);
@@ -32,16 +33,18 @@ for (count=0; count<iters; count++) {
32 33
 		fprintf(stderr, "getline #%d -> %d\n", count, foo);
33 34
 		fprintf(stderr, "%s\n", ligne);
34 35
 		}
35
-	foo = parseXvalue(ligne, 'X');
36
+	foo = parse4values(ligne, 'X', datas);
36 37
 	// 
37 38
 	if (foo >= 0) {
38 39
 		temps = time(NULL);
39
-		printf("%ld %d\n", temps, foo);
40
+		printf("%ld %f %f %f %f\n", temps,
41
+				datas[0], datas[1], datas[2], datas[3]);
40 42
 		fflush(stdout);
41 43
 		}
42 44
 	else	{
43 45
 		fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
44 46
 		}
47
+	if (verbosity) fprintf(stderr, "\n");
45 48
 	}
46 49
 return 0;
47 50
 }

+ 2
- 1
simulator/send-random/send-random.ino View File

@@ -5,6 +5,7 @@
5 5
 /* -------------------------------------------------- */
6 6
 
7 7
 #define NBVAL   4
8
+#define DELAI   1664
8 9
 
9 10
 int   values[NBVAL];
10 11
 
@@ -48,7 +49,7 @@ void sendvalues(void)
48 49
 void loop() {
49 50
   updatevalues();
50 51
   sendvalues();
51
-  delay(800);
52
+  delay(DELAI);
52 53
 }
53 54
 
54 55
 /* -------------------------------------------------- */

Loading…
Cancel
Save