#include #include #include #include #include // data via $1, output to STDOUT // begin = 255 followed by 12 bytes 2*(4*i + 1*u) + PowerH:PowerL int main (int argc, char* argv[]) { u_int8_t tmp = 0; u_int8_t buffer[12]; u_int16_t power = 0; int infile_fd = -1; if (argc > 1) { infile_fd = open(argv[1], O_RDONLY); if(infile_fd < 0) { perror("open error"); return 1; } } else { infile_fd = STDIN_FILENO; } while (read(infile_fd, &tmp, 1) == 1) { if (tmp == 255) { if (read(infile_fd, &buffer, sizeof(buffer)) != sizeof(buffer)) { perror("read error:"); return 2; } power = (buffer[10]<<8) + buffer[11]; printf("%5d (", power); int i; for(i=0; i<10; i++) printf("%3d ", buffer[i]); power = (((u_int16_t)buffer[0] + (u_int16_t)buffer[1] + (u_int16_t)buffer[2] + (u_int16_t)buffer[3]) * (u_int16_t)buffer[4]) + (((u_int16_t)buffer[5] + (u_int16_t)buffer[6] + (u_int16_t)buffer[7] + (u_int16_t)buffer[8]) * (u_int16_t)buffer[9]); printf(") -> %5d\r", power); } } printf("\n"); return 0; }