blob: c4cb48676349ba21d95883ec95a14a1f41439dd0 (
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
38
39
40
41
42
43
|
#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*5.6f/1.89f
int main (int argc, char* argv[])
{
unsigned char tmp = 0;
unsigned char buffer[9];
float pow;
float pow_sum;
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 ("%5.2fV", buffer[8] * UFAC);
pow_sum = 0.0f;
for (i = 0; i<8; i++)
{
pow = (buffer[i] / 2.099f) * (buffer[8] * UFAC);
printf (" %6.2fmW", pow);
pow_sum += pow;
}
printf (" %6.2fmW", pow_sum);
printf ("\r");
}
}
printf ("\n");
return 0;
}
|