From eac8e98ee7bfcd06ac5c2b874ec4567734e166b9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 22 Oct 2014 11:23:09 -0700 Subject: [PATCH] parser: add DC_FIELD_STRING field type for parse-time information This can be used to return almost arbitrary information to the dive log application at dive parse time, by returning a number of strings (with a descriptor) for dive state. NOTE! The strings are supposed to be human-readable, so that the dive log application can just show them unedited - and without understanding them - to the user, together with the description. So if your dive computer supports returning a battery voltage, for example, you can return it as a { "Voltage", "4.449V" } descriptor/value string pair, and the application could then put these string pairs together and show (somewhere) an informational line like "Voltage: 4.449V" along with the other information you return. Some dive log applications migth recognize particular descriptor strings and use them specially to fill in other information (ie serial numbers, weight and suit information etc), but in general the interface is very much meant to be informational free-form for a human user. So do *not* use this interface to encode things that are not human- readable. Serial numbers or version information that is meaningful to humans are fine. But random encoded data structures are not. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- include/libdivecomputer/parser.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 774e5e3..dbd9d2d 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -59,9 +59,13 @@ typedef enum dc_field_type_t { DC_FIELD_TEMPERATURE_MAXIMUM, DC_FIELD_TANK_COUNT, DC_FIELD_TANK, - DC_FIELD_DIVEMODE + DC_FIELD_DIVEMODE, + DC_FIELD_STRING, } dc_field_type_t; +// Make it easy to test support compile-time with "#ifdef DC_FIELD_STRING" +#define DC_FIELD_STRING DC_FIELD_STRING + typedef enum parser_sample_event_t { SAMPLE_EVENT_NONE, SAMPLE_EVENT_DECOSTOP, @@ -181,6 +185,11 @@ typedef struct dc_tank_t { double endpressure; /* End pressure (bar) */ } dc_tank_t; +typedef struct dc_field_string_t { + const char *desc; + const char *value; +} dc_field_string_t; + typedef union dc_sample_value_t { unsigned int time; double depth;