summaryrefslogtreecommitdiff
path: root/tools/solarmeter/solarmeter.c
blob: e2c76e1048ad42c9d120504b614b4260a82c9e34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <unistd.h>

// data via stdin
// begin = 255 followed by 9 byte  8 mal i + 1 mal u
// u = input * 5/256  // u in V
// i = input / 2.099  // i in mA

#define UFAC 5.0f/256.0f

int main (int argc, char* argv[])
{
    unsigned char tmp = 0;
    unsigned char buffer[9];
    int i;

    // printf ("blah\n");
    while (read (STDIN_FILENO, &tmp, 1) == 1)
    {
        if (tmp == 255)
        {
            if (read (STDIN_FILENO, &buffer, 9) != 9)
            {
                printf ("read error\n");
                return 0;
            }
            printf ("%02.2fV ", buffer[8] * UFAC);
            for (i = 0; i<8; i++)
            {
                printf ("%02.2fmW ", (buffer[i] / 2.099f) * (buffer[8] * UFAC));
            }
            printf ("\r");
        }
    }
    printf ("\n");
    return 0;
}