DD2-monitor/essai.c

136 lines
2.7 KiB
C
Raw Normal View History

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