reading 4 values from arduino
This commit is contained in:
		
							parent
							
								
									dd359c9f82
								
							
						
					
					
						commit
						0826568604
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -15,6 +15,6 @@ doc/*.ind | ||||
| */*.dat | ||||
| 
 | ||||
| rrdb/*.png | ||||
| 
 | ||||
| serial/*.png | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -1,10 +1,25 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| DEVICE="/dev/ttyACM0" | ||||
| DATAFILE="foo.dat" | ||||
| IMAGE="graphe.png" | ||||
| NB_READ=1000 | ||||
| 
 | ||||
| ./t -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} | ||||
| 
 | ||||
| gnuplot << __EOC__ | ||||
| set term png 	size 1024,512 | ||||
| set output 	"${IMAGE}" | ||||
| set grid | ||||
| set xdata 	time | ||||
| set timefmt 	"%s" | ||||
| set format x 	"%H:%M:S" | ||||
| plot	"${DATAFILE}" using 1:2 title "foo" with lines,	\ | ||||
| 	"${DATAFILE}" using 1:3 title "bar" with lines,	\ | ||||
| 	"${DATAFILE}" using 1:4 title "quux" with lines, \ | ||||
| 	"${DATAFILE}" using 1:5 title "booz" with lines | ||||
| __EOC__ | ||||
| 
 | ||||
| # display ${IMAGE} | ||||
| 
 | ||||
| 
 | ||||
| for p in {0..15} | ||||
| do | ||||
| 	echo pass $p | ||||
| 	./t ${DEVICE} | tee -a foo.dat | ||||
| 	sleep 8 | ||||
| done | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| 
 | ||||
| #include  <stdio.h> | ||||
| #include  <string.h> | ||||
| 
 | ||||
| #include  "serial.h" | ||||
| 
 | ||||
| @ -15,7 +16,7 @@ value=0; | ||||
| 
 | ||||
| if ( cflag != *line ) { | ||||
| 	if (verbosity) { | ||||
| 		fprintf(stderr, "%s line[0] 0x%x bad\n", | ||||
| 		fprintf(stderr, "%s : line[0] 0x%x bad\n", | ||||
| 					__func__, *line); | ||||
| 		} | ||||
| 	return -777; | ||||
| @ -36,8 +37,26 @@ return value; | ||||
| /* ---------------------------------------------------------------- */ | ||||
| int parse4values(char *line, char cflag, float array[4]) | ||||
| { | ||||
| float		ftmp[4]; | ||||
| int		foo; | ||||
| 
 | ||||
| 
 | ||||
| if ( cflag != *line ) { | ||||
| 	if (verbosity) { | ||||
| 		fprintf(stderr, "%s : line[0] 0x%x bad\n", | ||||
| 					__func__, *line); | ||||
| 		} | ||||
| 	return -777; | ||||
| 	} | ||||
| 
 | ||||
| foo = sscanf(line+1, "%f %f %f %f", ftmp, ftmp+1, ftmp+2, ftmp+3); | ||||
| if (4 != foo) { | ||||
| 	fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo); | ||||
| 	return -666; | ||||
| 	} | ||||
| // fprintf(stderr, "\tV %f\n", ftmp[0]);
 | ||||
| 
 | ||||
| memcpy(array, ftmp, 4*sizeof(float)); | ||||
| 
 | ||||
| return 4; | ||||
| } | ||||
| /* ---------------------------------------------------------------- */ | ||||
|  | ||||
| @ -41,7 +41,7 @@ int		baudbits; | ||||
| struct termios	options; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "%s ( %s %d )\n", __func__, port, baudrate); | ||||
| fprintf(stderr, ">>> %s ( %s %d )\n", __func__, port, baudrate); | ||||
| #endif | ||||
| // OPEN THE UART
 | ||||
| // The flags (defined in fcntl.h):
 | ||||
| @ -103,6 +103,8 @@ options.c_cc[VMIN] = 1;			/* ask for blocking read */ | ||||
| tcflush(uart0, TCIFLUSH); | ||||
| tcsetattr(uart0, TCSANOW, &options); | ||||
| 
 | ||||
| tcflush(uart0, TCIFLUSH);		/* do it again, sam */ | ||||
| 
 | ||||
| return uart0; | ||||
| } | ||||
| /* -------------------------------------------------------------------- */ | ||||
|  | ||||
| @ -24,6 +24,7 @@ int loop(int sfd, int iters) | ||||
| int		count, foo; | ||||
| long		temps; | ||||
| char		ligne[200]; | ||||
| float		datas[4]; | ||||
| 
 | ||||
| for (count=0; count<iters; count++) { | ||||
| 	foo = getline_to(sfd, ligne, 100, 0); | ||||
| @ -32,16 +33,18 @@ for (count=0; count<iters; count++) { | ||||
| 		fprintf(stderr, "getline #%d -> %d\n", count, foo); | ||||
| 		fprintf(stderr, "%s\n", ligne); | ||||
| 		} | ||||
| 	foo = parseXvalue(ligne, 'X'); | ||||
| 	foo = parse4values(ligne, 'X', datas); | ||||
| 	// 
 | ||||
| 	if (foo >= 0) { | ||||
| 		temps = time(NULL); | ||||
| 		printf("%ld %d\n", temps, foo); | ||||
| 		printf("%ld %f %f %f %f\n", temps, | ||||
| 				datas[0], datas[1], datas[2], datas[3]); | ||||
| 		fflush(stdout); | ||||
| 		} | ||||
| 	else	{ | ||||
| 		fprintf(stderr, "%s: parse -> %d\n", __func__, foo); | ||||
| 		} | ||||
| 	if (verbosity) fprintf(stderr, "\n"); | ||||
| 	} | ||||
| return 0; | ||||
| } | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| /* -------------------------------------------------- */ | ||||
| 
 | ||||
| #define NBVAL   4 | ||||
| #define DELAI   1664 | ||||
| 
 | ||||
| int   values[NBVAL]; | ||||
| 
 | ||||
| @ -48,7 +49,7 @@ void sendvalues(void) | ||||
| void loop() { | ||||
|   updatevalues(); | ||||
|   sendvalues(); | ||||
|   delay(800); | ||||
|   delay(DELAI); | ||||
| } | ||||
| 
 | ||||
| /* -------------------------------------------------- */ | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user