#include #include /* mass1_16p3.c */ /* Copyright (C) 2013 Joseph Rosevear */ /* This needs standard input from "cat /dev/ttyUSB0" where a Hobby King Eco AC/DC charger is connected to /dev/ttyUSB0 on a linux computer. For example, cat /dev/ttyUSB0 | ./mass */ int main(int argc, char *argv[]) { int c, count, byte7, byte8, byte15, byte16; float float15, float16, volts; float float7, float8, mahs; count = 0; while ((c = getchar()) != EOF ) { if (c == '{') { count = 0; } else if (c != '{') { count++; switch(count) { /* byte 1 */ case 1: printf("%d ", c-128 ); break; /* byte 2 */ case 2: printf("%d ", c-128 ); break; /* byte 3 */ case 3: printf("%d ", c-128 ); break; /* byte 4 */ case 4: printf("%d ", c-128 ); break; /* byte 5 */ case 5: printf("%d ", c-128 ); break; /* byte 6 */ case 6: printf("%d ", c-128 ); break; /* Mahs = byte7*100 + byte8 */ /* byte 7 */ case 7: byte7 = c - 128; float7 = (float)byte7; break; /* byte 8 */ case 8: byte8 = c-128; float8 = (float)byte8; mahs = float7*100. + float8; printf("%5.0f ", mahs); break; /* byte 9 */ case 9: printf ("%d ", c-128 ); break; /* Byte10 tells the (truncated) minutes. */ /* byte 10 */ case 10: printf("%d ", c-128); break; /* byte 11 */ case 11: printf("%d ", c-128 ); break; /* Byte12 tells the Amps*100. I have corrected it here by dividing by 100. */ /* byte 12 */ case 12: printf("%1.2f ", (c-128)/100. ); break; /* byte 13 */ case 13: printf("%d ", c-128 ); break; /* byte 14 */ case 14: printf("%d ", c-128 ); break; /* Volts = byte15 + byte16/100. */ /* byte 15 */ case 15: /* printf("%d ", c-128 ); */ byte15 = c - 128; float15 = (float)byte15; break; /* byte 16 */ case 16: byte16 = c - 128; float16 = (float)byte16; volts = float15 + float16/100.; printf("%2.2f ", volts); break; /* byte 109 */ case 109: printf("%d ", c); break; /* byte 110 */ case 110: printf("%d\n", c); break; } } } return(0); }