136 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  *		essai.c
 | |
|  */
 | |
| 
 | |
| #include	<stdio.h>
 | |
| #include	<unistd.h>
 | |
| #include	<stdlib.h>
 | |
| #include	<string.h>
 | |
| #include	<curses.h>
 | |
| #include	<time.h>
 | |
| 
 | |
| #include	"core/utils.h"
 | |
| #include	"core/sysmetrics.h"
 | |
| #include	"serial/serial.h"
 | |
| #include	"viz/curses/ecran.h"
 | |
| 
 | |
| int	verbosity;
 | |
| 
 | |
| /* --------------------------------------------------------------- */
 | |
| int affiche_valeurs(int sfd, int nbloops)
 | |
| {
 | |
| int		idx, foo;
 | |
| char		ligne[200];
 | |
| int		Idatas[4];
 | |
| float		Fdatas[4];
 | |
| FILE		*fp;
 | |
| time_t		temps,
 | |
| 		old_temps = (time_t)0L;
 | |
| 
 | |
| 
 | |
| /* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */
 | |
| fp = fopen("serial/foo.dat", "a");
 | |
| if (NULL==fp) {
 | |
| 	fprintf(stderr, "***** error fopen datafile *****\n");
 | |
| 	return -1;
 | |
| 	}
 | |
| /* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */
 | |
| 
 | |
| for (idx=0; idx<nbloops; idx++) {
 | |
| 
 | |
| 	foo = getline_to(sfd, ligne, 100, 0);
 | |
| 	if (verbosity) message(ligne);
 | |
| 	
 | |
| #if DEBUG_LEVEL
 | |
| 	if (foo) fprintf(stderr, "get values -> %d\n", foo);
 | |
| #endif
 | |
| 
 | |
| 	foo = parse4_Ivalues(ligne, 'T', Idatas);
 | |
| #if DEBUG_LEVEL
 | |
| 	if (foo) fprintf(stderr, "parse I val -> %d\n", foo); 
 | |
| #endif
 | |
| 
 | |
| 	values2temperature(Idatas, Fdatas);
 | |
| 
 | |
| 	for (foo=0; foo<3; foo++) {
 | |
| 		sprintf(ligne, "%4d", Idatas[foo]);
 | |
| 		minidigit_affstr(stdscr, 12+(12*foo), 8, ligne);
 | |
| 		aff7segs_float(stdscr, 8+(12*foo), 55, Fdatas[foo]);
 | |
| 		}
 | |
| 
 | |
| 	/* here we are trying to log all that temps values */
 | |
| 	if (NULL!=fp) {	
 | |
| 		temps = time(NULL);
 | |
| 		if ((temps-old_temps) > 60) {
 | |
| 			fprintf(fp, "%ld %f %f %f %f\n", temps,
 | |
| 				Fdatas[0], Fdatas[1], Fdatas[2], Fdatas[3]);
 | |
| 			fflush(fp);
 | |
| 			old_temps = temps;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 	}
 | |
| 
 | |
| fclose(fp);
 | |
| 
 | |
| return 0;
 | |
| }
 | |
| /* --------------------------------------------------------------- */
 | |
| static void finish(int signal)
 | |
| {
 | |
| endwin();       
 | |
| fprintf(stderr, "end of pid %d\n", getpid());
 | |
| exit(0);
 | |
| }
 | |
| /* --------------------------------------------------------------- */
 | |
| void help(int k)
 | |
| {
 | |
| puts("options : ");
 | |
| puts("\t-d\tserial device to read.");
 | |
| puts("\t-v\tincrease verbosity.");
 | |
| exit(0);
 | |
| }
 | |
| /* --------------------------------------------------------------- */
 | |
| 
 | |
| int main(int argc, char *argv[])
 | |
| {
 | |
| int		opt, foo;
 | |
| int		serial_in;
 | |
| char		*device = "/dev/ttyACM0";
 | |
| 
 | |
| while ((opt = getopt(argc, argv, "d:hv")) != -1) {
 | |
| 	switch (opt) {
 | |
| 		case 'd':	device = optarg;	break;
 | |
| 		case 'h':	help(0);		break;
 | |
| 		case 'v':	verbosity++;		break;
 | |
| 		default:				break;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 
 | |
| serial_in = prepare_UART(device, 9600);
 | |
| if (serial_in < 0) {
 | |
| 	fprintf(stderr, "%s : open device : error %d on %s\n",
 | |
| 				argv[0], serial_in, device);
 | |
| 	exit(1);
 | |
| 	}
 | |
| 
 | |
| 
 | |
| initscr();
 | |
| nonl();         cbreak();       noecho();
 | |
| keypad(stdscr, TRUE);           /* acces aux touches 'curseur' */
 | |
| fond_ecran(" Demonstrator ");
 | |
| 
 | |
| affiche_valeurs(serial_in, 10000);
 | |
| 
 | |
| /*
 | |
|  *      plop, on a fini, il faut restaurer la console
 | |
|  */
 | |
| finish(0);
 | |
| 
 | |
| 
 | |
| return 0;
 | |
| }
 | |
| 
 | |
| /* --------------------------------------------------------------- */
 | 
