From 8f9878a1c08c8776d9c4287aec51ed74d375b8a0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 21 Oct 2014 21:05:41 +0200 Subject: [PATCH] Add support for parsing tank data in the dive header. --- examples/universal.c | 41 ++++++++++++++++++++++++++++++++ include/libdivecomputer/parser.h | 21 +++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/examples/universal.c b/examples/universal.c index 9d07088..2f5d616 100644 --- a/examples/universal.c +++ b/examples/universal.c @@ -426,6 +426,47 @@ doparse (FILE *fp, dc_device_t *device, const unsigned char data[], unsigned int gasmix.nitrogen * 100.0); } + // Parse the tanks. + message ("Parsing the tanks.\n"); + unsigned int ntanks = 0; + rc = dc_parser_get_field (parser, DC_FIELD_TANK_COUNT, 0, &ntanks); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the tank count."); + dc_parser_destroy (parser); + return rc; + } + + for (unsigned int i = 0; i < ntanks; ++i) { + const char *names[] = {"none", "metric", "imperial"}; + + dc_tank_t tank = {0}; + rc = dc_parser_get_field (parser, DC_FIELD_TANK, i, &tank); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the tank."); + dc_parser_destroy (parser); + return rc; + } + + fprintf (fp, "\n"); + if (tank.gasmix != DC_GASMIX_UNKNOWN) { + fprintf (fp, + " %u\n", + tank.gasmix); + } + if (tank.type != DC_TANKVOLUME_NONE) { + fprintf (fp, + " %s\n" + " %.1f\n" + " %.2f\n", + names[tank.type], tank.volume, tank.workpressure); + } + fprintf (fp, + " %.2f\n" + " %.2f\n" + "\n", + tank.beginpressure, tank.endpressure); + } + // Parse the salinity. message ("Parsing the salinity.\n"); dc_salinity_t salinity = {DC_WATER_FRESH, 0.0}; diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 526173a..63dc113 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -56,7 +56,9 @@ typedef enum dc_field_type_t { DC_FIELD_ATMOSPHERIC, DC_FIELD_TEMPERATURE_SURFACE, DC_FIELD_TEMPERATURE_MINIMUM, - DC_FIELD_TEMPERATURE_MAXIMUM + DC_FIELD_TEMPERATURE_MAXIMUM, + DC_FIELD_TANK_COUNT, + DC_FIELD_TANK } dc_field_type_t; typedef enum parser_sample_event_t { @@ -131,6 +133,23 @@ typedef struct dc_gasmix_t { double nitrogen; } dc_gasmix_t; +#define DC_GASMIX_UNKNOWN 0xFFFFFFFF + +typedef enum dc_tankvolume_t { + DC_TANKVOLUME_NONE, + DC_TANKVOLUME_METRIC, + DC_TANKVOLUME_IMPERIAL, +} dc_tankvolume_t; + +typedef struct dc_tank_t { + unsigned int gasmix; /* Index of the gas mix, or DC_GASMIX_UNKNOWN */ + dc_tankvolume_t type; + double volume; /* Wet or air volume (depending on the type) in liter */ + double workpressure; /* Pressure in bar */ + double beginpressure; + double endpressure; +} dc_tank_t; + typedef union dc_sample_value_t { unsigned int time; double depth;