[PATCH 1/3] Suunto EON Steel: do the proper enum lookup for a few more cases
Linus Torvalds
torvalds at linux-foundation.org
Mon Aug 29 15:33:54 PDT 2016
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sun, 28 Aug 2016 12:56:09 -0700
Subject: [PATCH 1/3] 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 <torvalds at linux-foundation.org>
---
src/suunto_eonsteel_parser.c | 43 +++++++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 20 deletions(-)
diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c
index 2be21cf0483a..bba26ef71fda 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:
+ 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;
- break;
- case 1:
+ else if (!strcasecmp(type, "High"))
sample.ppo2 = info->eon->cache.highsetpoint;
- break;
- case 2:
+ else if (!strcasecmp(type, "Custom"))
sample.ppo2 = info->eon->cache.customsetpoint;
- break;
- default:
- DEBUG(info->eon->base.context, "sample_setpoint_type(%u)", value);
+ 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;
--
2.10.0.rc0.2.g0a9fa47
More information about the devel
mailing list