DD2-monitor/essai.c

136 lines
2.7 KiB
C
Raw Normal View History

2018-12-08 23:02:24 +11:00
/*
* essai.c
*/
2019-02-07 03:22:32 +11:00
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
2019-01-31 05:14:40 +11:00
#include <curses.h>
2019-02-07 03:22:32 +11:00
#include <time.h>
2018-12-08 23:02:24 +11:00
2019-02-07 03:22:32 +11:00
#include "core/utils.h"
#include "core/sysmetrics.h"
2019-03-28 22:04:40 +11:00
#include "serial/serial.h"
2019-02-07 03:22:32 +11:00
#include "viz/curses/ecran.h"
2018-12-08 23:02:24 +11:00
2019-01-18 04:37:30 +11:00
int verbosity;
/* --------------------------------------------------------------- */
2019-03-28 22:04:40 +11:00
int affiche_valeurs(int sfd, int nbloops)
2019-01-31 05:14:40 +11:00
{
int idx, foo;
2019-04-04 01:25:38 +11:00
char ligne[200];
int Idatas[4];
float Fdatas[4];
FILE *fp;
2019-04-11 02:13:54 +11:00
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 */
2019-01-31 05:14:40 +11:00
for (idx=0; idx<nbloops; idx++) {
2019-03-28 22:04:40 +11:00
foo = getline_to(sfd, ligne, 100, 0);
2019-04-04 01:25:38 +11:00
if (verbosity) message(ligne);
2019-03-28 22:04:40 +11:00
#if DEBUG_LEVEL
if (foo) fprintf(stderr, "get values -> %d\n", foo);
#endif
2019-01-31 05:14:40 +11:00
2019-04-04 01:25:38 +11:00
foo = parse4_Ivalues(ligne, 'T', Idatas);
2019-03-28 22:04:40 +11:00
#if DEBUG_LEVEL
2019-04-04 01:25:38 +11:00
if (foo) fprintf(stderr, "parse I val -> %d\n", foo);
2019-03-28 22:04:40 +11:00
#endif
2019-04-04 01:25:38 +11:00
values2temperature(Idatas, Fdatas);
2019-03-28 22:04:40 +11:00
2019-04-04 01:25:38 +11:00
for (foo=0; foo<3; foo++) {
sprintf(ligne, "%4d", Idatas[foo]);
2019-04-11 02:13:54 +11:00
minidigit_affstr(stdscr, 12+(12*foo), 8, ligne);
aff7segs_float(stdscr, 8+(12*foo), 55, Fdatas[foo]);
2019-04-04 01:25:38 +11:00
}
2019-04-11 02:13:54 +11:00
/* here we are trying to log all that temps values */
if (NULL!=fp) {
temps = time(NULL);
2019-04-14 20:33:52 +11:00
if ((temps-old_temps) > 50) {
2019-04-11 02:13:54 +11:00
fprintf(fp, "%ld %f %f %f %f\n", temps,
Fdatas[0], Fdatas[1], Fdatas[2], Fdatas[3]);
fflush(fp);
old_temps = temps;
}
}
2019-01-31 05:14:40 +11:00
}
2019-04-11 02:13:54 +11:00
fclose(fp);
2019-01-31 05:14:40 +11:00
return 0;
}
/* --------------------------------------------------------------- */
static void finish(int signal)
{
2019-02-02 13:52:30 +11:00
endwin();
fprintf(stderr, "end of pid %d\n", getpid());
exit(0);
2019-01-31 05:14:40 +11:00
}
2018-12-08 23:02:24 +11:00
/* --------------------------------------------------------------- */
2019-03-28 22:04:40 +11:00
void help(int k)
{
puts("options : ");
puts("\t-d\tserial device to read.");
puts("\t-v\tincrease verbosity.");
exit(0);
}
/* --------------------------------------------------------------- */
2018-12-08 23:02:24 +11:00
int main(int argc, char *argv[])
{
int opt, foo;
2019-03-28 22:04:40 +11:00
int serial_in;
char *device = "/dev/ttyACM0";
2018-12-08 23:02:24 +11:00
2019-03-28 22:04:40 +11:00
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
2018-12-08 23:02:24 +11:00
switch (opt) {
2019-03-28 22:04:40 +11:00
case 'd': device = optarg; break;
case 'h': help(0); break;
2018-12-08 23:02:24 +11:00
case 'v': verbosity++; break;
default: break;
}
}
2019-03-28 22:04:40 +11:00
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);
}
2019-01-31 05:14:40 +11:00
initscr();
nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran(" Demonstrator ");
2019-04-28 06:44:48 +11:00
affiche_valeurs(serial_in, 50000000);
2019-01-31 05:14:40 +11:00
/*
* plop, on a fini, il faut restaurer la console
*/
finish(0);
2018-12-08 23:02:24 +11:00
return 0;
}
/* --------------------------------------------------------------- */