/* * Experiments with the serial input * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #include #include #include #include #include #include //Used for UART #include //Used for UART #include #include //Used for UART #include #include "serial.h" int verbosity; /* ---------------------------------------------------------------- */ int loop(int sfd, int iters) { int count, foo; long temps; char ligne[200]; float datas[4]; struct tm *p_tms; for (count=0; count %d\n", count, iters, foo); */ fprintf(stderr, "%s\n", ligne); } foo = parse4values(ligne, 'T', datas); // if (foo >= 0) { temps = time(NULL); values2temperature(datas); 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 > 1) { p_tms = localtime(&temps); (void)strftime(ligne, 19, "%H:%M:%S", p_tms); fprintf(stderr, "\t%s\n", ligne); } } return 0; } /* ---------------------------------------------------------------- */ void help(int k) { puts("options : "); puts("\t-d\tserial device to read."); puts("\t-n\tnumber of records to grab."); puts("\t-v\tincrease verbosity."); } /* ---------------------------------------------------------------- */ int main (int argc, char *argv[]) { int serial_in; char *device = "/dev/ttyACM0"; int nbre, speed, opt; /* set some default values */ verbosity = 0; nbre = 25; speed = 9600; while ((opt = getopt(argc, argv, "d:n:vh")) != -1) { switch (opt) { case 'v': verbosity++; break; case 'n': nbre = atoi(optarg); break; case 'd': device = optarg; break; case 'h': help(0); exit(0); default: fprintf(stderr, "%s : uh ?", argv[0]); exit(1); break; } } 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", argv[0], serial_in, device); exit(1); } fprintf(stderr, "going to listen on %d\n", serial_in); (void)loop(serial_in, nbre); return 0; } /* ---------------------------------------------------------------- */