From 820b3c0ff5d543641c3003f6f1cb49f5b36f406e Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 17 Apr 2018 09:59:57 -0700 Subject: [PATCH] Add subsurface-specific event extension: event strings and severity We _really_ find the standard libdivecomputer event enumeration much too inflexible and not giving us enough useful information. This is particularly noticeable with the Suunto EON Steel/Core, where there are no fixed event enumerations, but instead the dive computer literally gives you event strings. Do the same thing in the libdivecomputer interface: allow an event of type SAMPLE_EVENT_STRING which instead of the useless "value" gives an actual string describing the event. Also, extend the "flags" field to have not just a NONE/BEGIN/END marker, but a severity level. The severity level is 3 bits, so 0-7, with the meaning being 0 - 'no severity info' 1 - state change (so 'surface' event or similar - don't even show it by default) 2 - notification (informational, eg "safety stop", "tank change") 3 - warning ("ascent speed") 4 - alarm (some actual dive violation). 5-7: future expansion? Think of 0 as "legacy - missing information", 1 as "internal DC thing", and 2-4 as (green-yellow-red). This makes it possible for the dive computer back-end to give the user actual useful information for events. Signed-off-by: Linus Torvalds --- include/libdivecomputer/parser.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 1b53fd3..98827f1 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -92,17 +92,30 @@ typedef enum parser_sample_event_t { SAMPLE_EVENT_HEADING, SAMPLE_EVENT_TISSUELEVEL, SAMPLE_EVENT_GASCHANGE2, /* Deprecated: replaced by DC_SAMPLE_GASMIX. */ + SAMPLE_EVENT_STRING, } parser_sample_event_t; +/* To let the compile know we have this */ +#define SAMPLE_EVENT_STRING SAMPLE_EVENT_STRING + /* For backwards compatibility */ #define SAMPLE_EVENT_UNKNOWN SAMPLE_EVENT_FLOOR typedef enum parser_sample_flags_t { SAMPLE_FLAGS_NONE = 0, SAMPLE_FLAGS_BEGIN = (1 << 0), - SAMPLE_FLAGS_END = (1 << 1) + SAMPLE_FLAGS_END = (1 << 1), + SAMPLE_FLAGS_SEVERITY_MASK = (7 << 2), } parser_sample_flags_t; +#define SAMPLE_FLAGS_SEVERITY_SHIFT 2 + +#define SAMPLE_FLAGS_SEVERITY_MISSING (0 << SAMPLE_FLAGS_SEVERITY_SHIFT) +#define SAMPLE_FLAGS_SEVERITY_STATE (1 << SAMPLE_FLAGS_SEVERITY_SHIFT) +#define SAMPLE_FLAGS_SEVERITY_INFO (2 << SAMPLE_FLAGS_SEVERITY_SHIFT) +#define SAMPLE_FLAGS_SEVERITY_WARN (3 << SAMPLE_FLAGS_SEVERITY_SHIFT) +#define SAMPLE_FLAGS_SEVERITY_ALARM (4 << SAMPLE_FLAGS_SEVERITY_SHIFT) + typedef enum parser_sample_vendor_t { SAMPLE_VENDOR_NONE, SAMPLE_VENDOR_UWATEC_ALADIN, @@ -199,6 +212,7 @@ typedef union dc_sample_value_t { unsigned int time; unsigned int flags; unsigned int value; + const char *name; } event; unsigned int rbt; unsigned int heartbeat;