From: Martin Mares Date: Mon, 26 Dec 2011 20:44:51 +0000 (+0100) Subject: Better displaying of cooked data X-Git-Tag: v1.0~13 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=8545d5c05e0153ad5cc0a88cba1a87e4fe1a7ac5;p=arexx.git Better displaying of cooked data --- diff --git a/arexx.c b/arexx.c index 04825ce..1ab341c 100644 --- a/arexx.c +++ b/arexx.c @@ -10,6 +10,7 @@ #include #include #include +#include #include typedef unsigned char byte; @@ -17,6 +18,7 @@ static libusb_context *usb_ctxt; static libusb_device_handle *devh; static int debug_packets = 0; +static int debug_raw_data = 0; #define TIME_OFFSET 946681200 // Timestamp of 2000-01-01 00:00:00 @@ -119,7 +121,18 @@ static void put_le32(byte *p, unsigned int x) put_le16(p+2, x>>16); } -static void raw_point(int t, int id, int raw) +static void cooked_point(time_t t, int id, double val, char *unit, int q) +{ + struct tm tm; + localtime_r(&t, &tm); + + char tbuf[64]; + strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &tm); + + printf("== %s id=%d val=%.3f unit=%s q=%d\n", tbuf, id, val, unit, q); +} + +static void raw_point(int t, int id, int raw, int q) { /* * The binary blob provided by Arexx contains an embedded XML fragment @@ -147,7 +160,8 @@ static void raw_point(int t, int id, int raw) * - drop if outside the interval [vLo,vUp] * * This function applies the necessary transform for sensors we've - * seen in the wild. + * seen in the wild. We deliberately ignore the "dm" parameter as we want + * to report different channels of a single sensor as multiple sensors. */ double z = raw; @@ -207,7 +221,7 @@ static void raw_point(int t, int id, int raw) return; } - printf("\t-> %f %s\n", z, unit); + cooked_point(t + TIME_OFFSET, id, z, unit, q); } static int parse_packet(byte *reply) @@ -225,21 +239,24 @@ static int parse_packet(byte *reply) if (!len || len == 0xff) break; if (len < 9 || len > 10) { - printf("### Unknown packet length %02x\n", len); + printf("### Unknown tuple length %02x\n", len); break; } if (pos + len > 64) { - printf("### Packet truncated\n"); + printf("### Tuple truncated\n"); break; } int id = get_le16(p+1); int raw = get_be16(p+3); int t = get_le32(p+5); - printf("... %02x: id=%d raw=%d t=%d", len, id, raw, t); - if (len > 9) - printf(" q=%d", p[9]); - printf("\n"); - raw_point(t, id, raw); + int q = (len > 9) ? p[9] : -1; + if (debug_raw_data) { + printf("... %02x: id=%d raw=%d t=%d", len, id, raw, t); + if (len > 9) + printf(" q=%d", q); + printf("\n"); + } + raw_point(t, id, raw, q); pos += len; points++; }