diff --git a/src/deepblu_parser.c b/src/deepblu_parser.c index bf2f4cc..eff1b35 100644 --- a/src/deepblu_parser.c +++ b/src/deepblu_parser.c @@ -205,38 +205,7 @@ deepblu_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned if (!value) return DC_STATUS_INVALIDARGS; - /* This whole sequence should be standardized */ - if (!(deepblu->cache.initialized & (1 << type))) - return DC_STATUS_UNSUPPORTED; - - switch (type) { - case DC_FIELD_DIVETIME: - return DC_FIELD_VALUE(deepblu->cache, value, DIVETIME); - case DC_FIELD_MAXDEPTH: - return DC_FIELD_VALUE(deepblu->cache, value, MAXDEPTH); - case DC_FIELD_AVGDEPTH: - return DC_FIELD_VALUE(deepblu->cache, value, AVGDEPTH); - case DC_FIELD_GASMIX_COUNT: - case DC_FIELD_TANK_COUNT: - return DC_FIELD_VALUE(deepblu->cache, value, GASMIX_COUNT); - case DC_FIELD_GASMIX: - if (flags >= MAXGASES) - return DC_STATUS_UNSUPPORTED; - return DC_FIELD_INDEX(deepblu->cache, value, GASMIX, flags); - case DC_FIELD_SALINITY: - return DC_FIELD_VALUE(deepblu->cache, value, SALINITY); - case DC_FIELD_ATMOSPHERIC: - return DC_FIELD_VALUE(deepblu->cache, value, ATMOSPHERIC); - case DC_FIELD_DIVEMODE: - return DC_FIELD_VALUE(deepblu->cache, value, DIVEMODE); - case DC_FIELD_TANK: - return DC_STATUS_UNSUPPORTED; - case DC_FIELD_STRING: - return dc_field_get_string(&deepblu->cache, flags, (dc_field_string_t *)value); - default: - return DC_STATUS_UNSUPPORTED; - } - return DC_STATUS_SUCCESS; + return dc_field_get(&deepblu->cache, type, flags, value); } static dc_status_t diff --git a/src/field-cache.c b/src/field-cache.c index c3b4238..7f6ccd8 100644 --- a/src/field-cache.c +++ b/src/field-cache.c @@ -93,8 +93,22 @@ dc_field_get(dc_field_cache_t *cache, dc_field_type_t type, unsigned int flags, return DC_FIELD_INDEX(*cache, value, GASMIX, flags); case DC_FIELD_SALINITY: return DC_FIELD_VALUE(*cache, value, SALINITY); + case DC_FIELD_ATMOSPHERIC: + return DC_FIELD_VALUE(*cache, value, ATMOSPHERIC); case DC_FIELD_DIVEMODE: return DC_FIELD_VALUE(*cache, value, DIVEMODE); + case DC_FIELD_TANK: + if (flags >= MAXGASES) + break; + + dc_tank_t *tank = (dc_tank_t *) value; + + tank->volume = cache->tanksize[flags]; + tank->gasmix = flags; + tank->workpressure = cache->tankworkingpressure[flags]; + tank->type = cache->tankinfo[flags]; + + return DC_STATUS_SUCCESS; case DC_FIELD_STRING: return dc_field_get_string(cache, flags, (dc_field_string_t *)value); default: diff --git a/src/field-cache.h b/src/field-cache.h index 6f5c487..1a869ad 100644 --- a/src/field-cache.h +++ b/src/field-cache.h @@ -22,7 +22,7 @@ typedef struct dc_field_cache { double highsetpoint; double customsetpoint; - // This (slong with GASMIX) should be something like + // This (along with GASMIX) should be something like // dc_tank_t TANK[MAXGASES] // but that's for later dc_tankinfo_t tankinfo[MAXGASES]; diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 2ee89a8..752250e 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -1008,36 +1008,18 @@ suunto_eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback static dc_status_t suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value) { - dc_tank_t *tank = (dc_tank_t *) value; - suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)parser; if (!(eon->cache.initialized & (1 << type))) return DC_STATUS_UNSUPPORTED; - switch (type) { - case DC_FIELD_DIVETIME: - return DC_FIELD_VALUE(eon->cache, value, DIVETIME); - case DC_FIELD_MAXDEPTH: - return DC_FIELD_VALUE(eon->cache, value, MAXDEPTH); - case DC_FIELD_AVGDEPTH: - return DC_FIELD_VALUE(eon->cache, value, AVGDEPTH); - case DC_FIELD_GASMIX_COUNT: - case DC_FIELD_TANK_COUNT: - return DC_FIELD_VALUE(eon->cache, value, GASMIX_COUNT); - case DC_FIELD_GASMIX: - if (flags >= MAXGASES) - return DC_STATUS_UNSUPPORTED; - return DC_FIELD_INDEX(eon->cache, value, GASMIX, flags); - case DC_FIELD_SALINITY: - return DC_FIELD_VALUE(eon->cache, value, SALINITY); - case DC_FIELD_ATMOSPHERIC: - return DC_FIELD_VALUE(eon->cache, value, ATMOSPHERIC); - case DC_FIELD_DIVEMODE: - return DC_FIELD_VALUE(eon->cache, value, DIVEMODE); - case DC_FIELD_TANK: + /* Fix up the cylinder info before using dc_field_get() */ + if (type == DC_FIELD_TANK) { if (flags >= MAXGASES) return DC_STATUS_UNSUPPORTED; + + dc_tank_t *tank = (dc_tank_t *) value; + /* * Sadly it seems that the EON Steel doesn't tell us whether * we get imperial or metric data - the only indication is @@ -1066,13 +1048,9 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi if (fabs(tank->volume - rint(tank->volume)) > 0.001) tank->type += DC_TANKINFO_IMPERIAL - DC_TANKINFO_METRIC; } - break; - case DC_FIELD_STRING: - return dc_field_get_string(&eon->cache, flags, (dc_field_string_t *)value); - default: - return DC_STATUS_UNSUPPORTED; } - return DC_STATUS_SUCCESS; + + return dc_field_get(&eon->cache, type, flags, value); } /*