Claire arrive dans le brotch...
This commit is contained in:
69
serial/t.c
69
serial/t.c
@@ -18,16 +18,51 @@
|
||||
|
||||
int verbosity;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int read_temps(char *buff, int k)
|
||||
{
|
||||
float datas[4];
|
||||
int raw[4], foo;
|
||||
long temps;
|
||||
|
||||
foo = parse4_Ivalues(buff, 'T', raw);
|
||||
//
|
||||
if (foo >= 0) {
|
||||
temps = time(NULL);
|
||||
values2temperature(raw, 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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int read_light(char *buff, int k)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (1 == sscanf(buff+1, "%d", &val)) {
|
||||
printf("--------- %04X ----------\n", val);
|
||||
return 0;
|
||||
}
|
||||
return -3;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int loop(int sfd, int iters)
|
||||
{
|
||||
int count, foo;
|
||||
long temps;
|
||||
char ligne[200], buff[200];
|
||||
float datas[4];
|
||||
struct tm *p_tms;
|
||||
|
||||
for (count=0; count<iters; count++) {
|
||||
//
|
||||
foo = getline_to(sfd, ligne, 100, 0);
|
||||
//
|
||||
if (verbosity) {
|
||||
@@ -42,19 +77,29 @@ for (count=0; count<iters; count++) {
|
||||
(void)strftime(buff, 19, "%H:%M:%S", p_tms);
|
||||
fprintf(stderr, "%s %6d / %d\n", buff, count, iters);
|
||||
}
|
||||
//
|
||||
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);
|
||||
|
||||
foo = 0;
|
||||
switch (ligne[0]) {
|
||||
case 'L':
|
||||
foo = read_light(ligne, 0);
|
||||
break;
|
||||
case 'T':
|
||||
foo = read_temps(ligne, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "*** WTF '%s' ?\n", ligne);
|
||||
foo = -1;
|
||||
break;
|
||||
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
|
||||
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : error %d after switch\n",
|
||||
__func__, foo);
|
||||
}
|
||||
if (verbosity) puts("");
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user