From d11d30999bcfd2d592ff809841f164b2938f44f7 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 28 Aug 2016 12:56:09 -0700 Subject: [PATCH] Suunto EON Steel: do the proper enum lookup for a few more cases Instead of hardcoding the enum values for setpoint type and gas type, use "lookup_enum()" to actually parse the enum data and use that. I don't think this matters right now, since the numeric translations haven't changed, but it is the RigthThing(tm) to do. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 2be21cf..bba26ef 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -776,21 +776,24 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample static void sample_setpoint_type(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; + const char *type = lookup_enum(desc, value); - switch (value) { - case 0: - sample.ppo2 = info->eon->cache.lowsetpoint; - break; - case 1: - sample.ppo2 = info->eon->cache.highsetpoint; - break; - case 2: - sample.ppo2 = info->eon->cache.customsetpoint; - break; - default: - DEBUG(info->eon->base.context, "sample_setpoint_type(%u)", value); + if (!type) { + DEBUG(info->eon->base.context, "sample_setpoint_type(%u) did not match anything in %s", value, desc->format); return; } + + if (!strcasecmp(type, "Low")) + sample.ppo2 = info->eon->cache.lowsetpoint; + else if (!strcasecmp(type, "High")) + sample.ppo2 = info->eon->cache.highsetpoint; + else if (!strcasecmp(type, "Custom")) + sample.ppo2 = info->eon->cache.customsetpoint; + else { + DEBUG(info->eon->base.context, "sample_setpoint_type(%u) unknown type '%s'", value, type); + return; + } + if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata); } @@ -1110,24 +1113,24 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d { int idx = eon->cache.ngases; dc_tankinfo_t tankinfo = DC_TANKINFO_METRIC; + const char *name; if (idx >= MAXGASES) return 0; eon->cache.ngases = idx+1; - switch (type) { - case 0: - tankinfo = 0; - break; - case 3: + name = lookup_enum(desc, type); + if (!name) + DEBUG(eon->base.context, "Unable to look up gas type %u in %s", type, desc->format); + else if (!strcasecmp(name, "Diluent")) tankinfo |= DC_TANKINFO_CC_DILUENT; - break; - case 4: + else if (!strcasecmp(name, "Oxygen")) tankinfo |= DC_TANKINFO_CC_O2; - break; - default: - break; - } + else if (!strcasecmp(name, "None")) + tankinfo = 0; + else if (strcasecmp(name, "Primary")) + DEBUG(eon->base.context, "Unknown gas type %u (%s)", type, name); + eon->cache.tankinfo[idx] = tankinfo; eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT;