From 2f120fa6836871aa5c0dd46e297d168d197e42e9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 23 Jun 2012 14:25:08 -0300 Subject: [PATCH] tools/antorcha.c (samples): move reading of X/Y samples to shared function --- tools/antorcha.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/antorcha.c b/tools/antorcha.c index f47c87c..3cbb5a3 100644 --- a/tools/antorcha.c +++ b/tools/antorcha.c @@ -280,6 +280,22 @@ static void image(struct atrf_dsc *dsc, const char *name) /* ----- Samples ----------------------------------------------------------- */ +static int read_sample(uint8_t **s, uint16_t *t_high, uint16_t *t_low, + uint16_t *last) +{ + int v; + + *t_low = *(*s)++; + *t_low |= *(*s)++ << 8; + if (*t_low < *last) + (*t_high)++; + *last = *t_low; + v = *(*s)++; + v |= *(*s)++ << 8; + return v; +} + + static void samples(struct atrf_dsc *dsc) { uint8_t buf[MAX_PSDU] = { 0, }; @@ -311,26 +327,12 @@ static void samples(struct atrf_dsc *dsc) t_high |= *s++ << 8; last = 0; while (s < buf+got-2) { - t_low = *s++; - t_low |= *s++ << 8; - if (t_low < last) - t_high++; - last = t_low; - x = *s++; - x |= *s++ << 8; - + x = read_sample(&s, &t_high, &t_low, &last); if (debug) fprintf(stderr, "\t%11.6f %d", (t_high << 16 | t_low)/1000000.0, x); - t_low = *s++; - t_low |= *s++ << 8; - if (t_low < last) - t_high++; - last = t_low; - y = *s++; - y |= *s++ << 8; - + y = read_sample(&s, &t_high, &t_low, &last); if (debug) fprintf(stderr, "\t%11.6f %d\n", (t_high << 16 | t_low)/1000000.0, y);