2018-12-30 03:07:23 +11:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2019-01-06 02:15:48 +11:00
|
|
|
#include <string.h>
|
2018-12-30 03:07:23 +11:00
|
|
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-29 00:42:33 +11:00
|
|
|
/*
|
|
|
|
* compute the integer mean value of a four values
|
|
|
|
* tagged lines.
|
|
|
|
*/
|
2018-12-30 03:07:23 +11:00
|
|
|
int parseXvalue(char *line, char cflag)
|
|
|
|
{
|
|
|
|
int value, foo;
|
|
|
|
int vrd[4];
|
|
|
|
|
|
|
|
value=0;
|
|
|
|
|
2019-01-01 03:19:52 +11:00
|
|
|
if ( cflag != *line ) {
|
2018-12-30 03:45:31 +11:00
|
|
|
if (verbosity) {
|
2019-01-06 02:15:48 +11:00
|
|
|
fprintf(stderr, "%s : line[0] 0x%x bad\n",
|
2018-12-30 03:45:31 +11:00
|
|
|
__func__, *line);
|
|
|
|
}
|
|
|
|
return -777;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = sscanf(line+1, "%d %d %d %d", vrd, vrd+1, vrd+2, vrd+3);
|
2019-01-01 03:19:52 +11:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
|
|
|
|
#endif
|
2018-12-30 03:07:23 +11:00
|
|
|
if (4 != foo) {
|
|
|
|
return -666;
|
|
|
|
}
|
|
|
|
for (foo=0; foo<4; foo++) {
|
|
|
|
value += vrd[foo];
|
|
|
|
}
|
2019-01-29 00:42:33 +11:00
|
|
|
|
|
|
|
value /= 4;
|
|
|
|
|
2018-12-30 03:07:23 +11:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-29 00:42:33 +11:00
|
|
|
/*
|
|
|
|
* this fonction is specific to the LM35 thermo-sensor
|
|
|
|
* connected to a ADC pin of an Arduino Mega
|
2019-02-07 20:18:10 +11:00
|
|
|
*
|
|
|
|
* WARNING !
|
|
|
|
* this function _must_ be modofied if you change the
|
|
|
|
* Vref of the Analog to Digital converter on the
|
|
|
|
* Arduino !
|
|
|
|
*
|
2019-01-29 00:42:33 +11:00
|
|
|
*/
|
|
|
|
int values2temperature(float array[4])
|
2019-01-13 03:13:30 +11:00
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
for (foo=0; foo<4; foo++) {
|
2019-02-07 20:18:10 +11:00
|
|
|
array[foo] *= (1.1 / 1023.0 * 100.0);
|
2019-01-13 03:13:30 +11:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-05 21:47:51 +11:00
|
|
|
int parse4values(char *line, char cflag, float array[4])
|
|
|
|
{
|
2019-01-06 02:15:48 +11:00
|
|
|
float ftmp[4];
|
|
|
|
int foo;
|
2019-01-05 21:47:51 +11:00
|
|
|
|
2019-01-06 02:15:48 +11:00
|
|
|
if ( cflag != *line ) {
|
|
|
|
if (verbosity) {
|
|
|
|
fprintf(stderr, "%s : line[0] 0x%x bad\n",
|
|
|
|
__func__, *line);
|
|
|
|
}
|
|
|
|
return -777;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = sscanf(line+1, "%f %f %f %f", ftmp, ftmp+1, ftmp+2, ftmp+3);
|
|
|
|
if (4 != foo) {
|
|
|
|
fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
|
|
|
|
return -666;
|
|
|
|
}
|
|
|
|
// fprintf(stderr, "\tV %f\n", ftmp[0]);
|
|
|
|
|
|
|
|
memcpy(array, ftmp, 4*sizeof(float));
|
2019-01-05 21:47:51 +11:00
|
|
|
|
2019-01-06 02:15:48 +11:00
|
|
|
return 4;
|
2019-01-05 21:47:51 +11:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|