72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "serial.h"
|
|
|
|
extern int verbosity;
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
int parseXvalue(char *line, char cflag)
|
|
{
|
|
int value, foo;
|
|
int vrd[4];
|
|
|
|
value=0;
|
|
|
|
if ( cflag != *line ) {
|
|
if (verbosity) {
|
|
fprintf(stderr, "%s : line[0] 0x%x bad\n",
|
|
__func__, *line);
|
|
}
|
|
return -777;
|
|
}
|
|
|
|
foo = sscanf(line+1, "%d %d %d %d", vrd, vrd+1, vrd+2, vrd+3);
|
|
#if DEBUG_LEVEL
|
|
fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
|
|
#endif
|
|
if (4 != foo) {
|
|
return -666;
|
|
}
|
|
for (foo=0; foo<4; foo++) {
|
|
value += vrd[foo];
|
|
}
|
|
return value;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|
|
int values2temps(float array[4])
|
|
{
|
|
int foo;
|
|
for (foo=0; foo<4; foo++) {
|
|
array[foo] *= (5.0 / 1023.0 * 100.0);
|
|
}
|
|
return 0;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|
|
int parse4values(char *line, char cflag, float array[4])
|
|
{
|
|
float ftmp[4];
|
|
int foo;
|
|
|
|
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));
|
|
|
|
return 4;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|