From f46e9f571e92156cd764d6711cac671c053260a1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 30 Aug 2011 16:42:05 -0700 Subject: [PATCH] Start actually reporting the numbers we parsed .. which also showed that the sampletime thing had gotten a bit too much copy-paste from the temperature parsing ;) Signed-off-by: Linus Torvalds --- parse.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/parse.c b/parse.c index 4f7ba64..52609a6 100644 --- a/parse.c +++ b/parse.c @@ -83,6 +83,21 @@ typedef struct { pressure_t pressure; } tank_type_t; +static int to_feet(depth_t depth) +{ + return depth.mm * 0.00328084 + 0.5; +} + +static int to_C(temperature_t temp) +{ + return (temp.mkelvin + 272150) / 1000; +} + +static int to_PSI(pressure_t pressure) +{ + return pressure.mbar * 0.0145037738 + 0.5; +} + struct sample { duration_t time; depth_t depth; @@ -104,6 +119,7 @@ struct dive { static void record_dive(struct dive *dive) { + int i; static int nr; struct tm *tm; @@ -113,6 +129,16 @@ static void record_dive(struct dive *dive) ++nr, dive->samples, tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); + for (i = 0; i < dive->samples; i++) { + struct sample *s = dive->sample + i; + + printf("%4d:%02d: %3d ft, %2d C, %4d PSI\n", + s->time.seconds / 60, + s->time.seconds % 60, + to_feet(s->depth), + to_C(s->temperature), + to_PSI(s->tankpressure)); + } } static void nonmatch(const char *type, const char *fullname, const char *name, char *buffer) @@ -338,9 +364,8 @@ static void sampletime(char *buffer, void *_time) union int_or_float val; switch (integer_or_float(buffer, &val)) { - /* C or F? Who knows? Let's default to Celsius */ case INTEGER: - time->seconds = val.i * 1000; + time->seconds = val.i; break; default: printf("Strange sample time reading %s\n", buffer); -- 2.45.2