From eb61dc4c75e72839520f63854e840c705bb6b1a0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 13 Oct 2015 19:21:56 -0700 Subject: [PATCH 01/12] Add tank size reporting for Suunto EON Steel Sadly the data we get from the EON Steel is a bit of a mess. It doesn't really tell us if the data is metric or imperial (it always sends both wet volume and working pressure). And in imperial mode the Suunto engineers seem a bit confused. The pressure given (entered on the dive computer in psi) is sent to us not in bar, not in atm... it's "something". As far as I can tell it's a constant factor of 1.00069182389937 different from bar. And the wet sizes are a bit to small to get the cuft size the user entered. But instead of trying to guess and fix the mess, we just pass it through... So this is somewhat useful, but not really what most users will want. Linus started this commit with a few lines that parsed the right values out of the data stream from the Suunto EON Steel. I then added the implementation of the infrastructure to convert the raw data and report it back to the caller. Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 82 +++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 19fbf99..b64400e 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -82,6 +83,9 @@ typedef struct suunto_eonsteel_parser_t { dc_gasmix_t gasmix[MAXGASES]; dc_salinity_t salinity; double surface_pressure; + dc_tankvolume_t tankinfo[MAXGASES]; + double tanksize[MAXGASES]; + double tankworkingpressure[MAXGASES]; } cache; } suunto_eonsteel_parser_t; @@ -879,6 +883,8 @@ 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 >> type)) @@ -895,6 +901,7 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi field_value(value, eon->cache.avgdepth); break; case DC_FIELD_GASMIX_COUNT: + case DC_FIELD_TANK_COUNT: field_value(value, eon->cache.ngases); break; case DC_FIELD_GASMIX: @@ -908,6 +915,35 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi case DC_FIELD_ATMOSPHERIC: field_value(value, eon->cache.surface_pressure); break; + case DC_FIELD_TANK: + /* + * Sadly it seems that the EON Steel doesn't tell us whether + * we get imperial or metric data - the only indication is + * that metric is (at least so far) always whole liters + */ + tank->volume = eon->cache.tanksize[flags]; + + /* + * The pressure reported is NOT the pressure the user enters. + * + * So 3000psi turns into 206.700 bar instead of 206.843 bar; + * We report it as we get it and let the application figure out + * what to do with that + */ + tank->workpressure = eon->cache.tankworkingpressure[flags]; + tank->type = eon->cache.tankinfo[flags]; + + /* + * See if we should call this imperial instead. + * + * We need to have workpressure and a valid tank. In that case, + * a fractional tank size implies imperial. + */ + if (tank->workpressure && (tank->type == DC_TANKVOLUME_METRIC)) { + if (fabs(tank->volume - rint(tank->volume)) > 0.001) + tank->type = DC_TANKVOLUME_IMPERIAL; + } + break; default: return DC_STATUS_UNSUPPORTED; } @@ -953,10 +989,30 @@ static void set_depth_field(suunto_eonsteel_parser_t *eon, unsigned short d) // Two versions so far: // "enum:0=Off,1=Primary,2=?,3=Diluent" // "enum:0=Off,1=Primary,3=Diluent,4=Oxygen" +// +// We turn that into the DC_TANKVOLUME data here, but +// initially consider all non-off tanks to me METRIC. +// +// We may later turn the METRIC tank size into IMPERIAL if we +// get a working pressure and non-integral size static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *desc, unsigned char type) { - if (eon->cache.ngases < MAXGASES) - eon->cache.ngases++; + int idx = eon->cache.ngases; + dc_tankvolume_t tankinfo = DC_TANKVOLUME_METRIC; + + if (idx >= MAXGASES) + return 0; + + eon->cache.ngases = idx+1; + switch (type) { + case 0: + tankinfo = 0; + break; + default: + break; + } + eon->cache.tankinfo[idx] = tankinfo; + eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT; return 0; } @@ -983,6 +1039,22 @@ static int add_gas_he(suunto_eonsteel_parser_t *eon, unsigned char he) return 0; } +static int add_gas_size(suunto_eonsteel_parser_t *eon, float l) +{ + int idx = eon->cache.ngases-1; + if (idx >= 0) + eon->cache.tanksize[idx] = l; + return 0; +} + +static int add_gas_workpressure(suunto_eonsteel_parser_t *eon, float wp) +{ + int idx = eon->cache.ngases-1; + if (idx >= 0) + eon->cache.tankworkingpressure[idx] = wp; + return 0; +} + static float get_le32_float(const unsigned char *src) { union { @@ -1066,6 +1138,12 @@ static int traverse_diving_fields(suunto_eonsteel_parser_t *eon, const struct ty if (!strcmp(name, "Gases.Gas.Helium")) return add_gas_he(eon, data[0]); + if (!strcmp(name, "Gases.Gas.TankSize")) + return add_gas_size(eon, get_le32_float(data)); + + if (!strcmp(name, "Gases.Gas.TankFillPressure")) + return add_gas_workpressure(eon, get_le32_float(data)); + if (!strcmp(name, "SurfacePressure")) { unsigned int pressure = array_uint32_le(data); // in SI units - Pascal eon->cache.surface_pressure = pressure / 100000.0; // bar From 84111fe6061591ae023e5fcb95a9c687a28f589a Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 20 Jun 2016 22:04:27 -0700 Subject: [PATCH 02/12] Suunto EON Steel: add descriptor debugging output .. every time I look for a new feature I add debug code to print out all the descriptors. So let's just do it once and for all. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index b64400e..3fdaaaa 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -95,6 +95,7 @@ static const struct { const char *name; enum eon_sample type; } type_translation[] = { + { "+Time", ES_dtime }, { "Depth", ES_depth }, { "Temperature", ES_temp }, { "NoDecTime", ES_ndl }, @@ -152,6 +153,16 @@ static enum eon_sample lookup_descriptor_type(suunto_eonsteel_parser_t *eon, str return ES_none; } +static const char *desc_type_name(enum eon_sample type) +{ + int i; + for (i = 0; i < C_ARRAY_SIZE(type_translation); i++) { + if (type == type_translation[i].type) + return type_translation[i].name; + } + return "Unknown"; +} + static int lookup_descriptor_size(suunto_eonsteel_parser_t *eon, struct type_desc *desc) { const char *format = desc->format; @@ -1252,6 +1263,31 @@ static void initialize_field_caches(suunto_eonsteel_parser_t *eon) eon->cache.divetime /= 1000; } +static void show_descriptor(suunto_eonsteel_parser_t *eon, int nr, struct type_desc *desc) +{ + int i; + + if (!desc->desc) + return; + DEBUG(eon->base.context, "Descriptor %d: '%s', size %d bytes", nr, desc->desc, desc->size); + if (desc->format) + DEBUG(eon->base.context, " format '%s'", desc->format); + if (desc->mod) + DEBUG(eon->base.context, " mod '%s'", desc->mod); + for (i = 0; i < EON_MAX_GROUP; i++) { + enum eon_sample type = desc->type[i]; + if (!type) + continue; + DEBUG(eon->base.context, " %d: %d (%s)", i, type, desc_type_name(type)); + } +} + +static void show_all_descriptors(suunto_eonsteel_parser_t *eon) +{ + for (unsigned int i = 0; i < MAXTYPE; ++i) + show_descriptor(eon, i, eon->type_desc+i); +} + static dc_status_t suunto_eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, unsigned int size) { @@ -1260,6 +1296,7 @@ suunto_eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, desc_free(eon->type_desc, MAXTYPE); memset(eon->type_desc, 0, sizeof(eon->type_desc)); initialize_field_caches(eon); + show_all_descriptors(eon); return DC_STATUS_SUCCESS; } From c6b681a75398adfee04ffecec15a01002f782aec Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 20 Jun 2016 22:51:52 -0700 Subject: [PATCH 03/12] Initial Suunto EON Steel CCR support This does the basic divemode and setpoint parsing for the EON Steel, and gets the CCR download right in the big picture. The cylinder information is still confusing and incorrect, but this is a big step in the right direction. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 124 +++++++++++++++++++++++++++++------ 1 file changed, 105 insertions(+), 19 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 3fdaaaa..1d7e9e1 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -35,27 +35,30 @@ enum eon_sample { ES_none = 0, - ES_dtime, // duint16,precision=3 (time delta in ms) - ES_depth, // uint16,precision=2,nillable=65535 (depth in cm) - ES_temp, // int16,precision=2,nillable=-3000 (temp in deci-Celsius) - ES_ndl, // int16,nillable=-1 (ndl in minutes) - ES_ceiling, // uint16,precision=2,nillable=65535 (ceiling in cm) - ES_tts, // uint16,nillable=65535 (time to surface) - ES_heading, // uint16,precision=4,nillable=65535 (heading in degrees) - ES_abspressure, // uint16,precision=0,nillable=65535 (abs presure in centibar) - ES_gastime, // int16,nillable=-1 (remaining gas time in minutes) - ES_ventilation, // uint16,precision=6,nillable=65535 ("x/6000000,x"? No idea) - ES_gasnr, // uint8 - ES_pressure, // uint16,nillable=65535 (cylinder pressure in centibar) - ES_state, - ES_state_active, - ES_notify, - ES_notify_active, - ES_warning, - ES_warning_active, + ES_dtime, // duint16,precision=3 (time delta in ms) + ES_depth, // uint16,precision=2,nillable=65535 (depth in cm) + ES_temp, // int16,precision=2,nillable=-3000 (temp in deci-Celsius) + ES_ndl, // int16,nillable=-1 (ndl in minutes) + ES_ceiling, // uint16,precision=2,nillable=65535 (ceiling in cm) + ES_tts, // uint16,nillable=65535 (time to surface) + ES_heading, // uint16,precision=4,nillable=65535 (heading in degrees) + ES_abspressure, // uint16,precision=0,nillable=65535 (abs presure in centibar) + ES_gastime, // int16,nillable=-1 (remaining gas time in minutes) + ES_ventilation, // uint16,precision=6,nillable=65535 ("x/6000000,x"? No idea) + ES_gasnr, // uint8 + ES_pressure, // uint16,nillable=65535 (cylinder pressure in centibar) + ES_state, // enum:0=Wet Outside,1=Below Wet Activation Depth,2=Below Surface,3=Dive Active,4=Surface Calculation,5=Tank pressure available,6=Closed Circuit Mode + ES_state_active, // bool + ES_notify, // enum:0=NoFly Time,1=Depth,2=Surface Time,3=Tissue Level,4=Deco,5=Deco Window,6=Safety Stop Ahead,7=Safety Stop,8=Safety Stop Broken,9=Deep Stop Ahead,10=Deep Stop,11=Dive Time,12=Gas Available,13=SetPoint Switch,14=Diluent Hypoxia,15=Air Time,16=Tank Pressure + ES_notify_active, // bool + ES_warning, // enum:0=ICD Penalty,1=Deep Stop Penalty,2=Mandatory Safety Stop,3=OTU250,4=OTU300,5=CNS80%,6=CNS100%,7=Max.Depth,8=Air Time,9=Tank Pressure,10=Safety Stop Broken,11=Deep Stop Broken,12=Ceiling Broken,13=PO2 High + ES_warning_active, // bool ES_alarm, ES_alarm_active, - ES_gasswitch, // uint16 + ES_gasswitch, // uint16 + ES_setpoint_type, // enum:0=Low,1=High,2=Custom + ES_setpoint_po2, // uint32 + ES_setpoint_automatic, // bool ES_bookmark, }; @@ -83,6 +86,10 @@ typedef struct suunto_eonsteel_parser_t { dc_gasmix_t gasmix[MAXGASES]; dc_salinity_t salinity; double surface_pressure; + dc_divemode_t divemode; + double lowsetpoint; + double highsetpoint; + double customsetpoint; dc_tankvolume_t tankinfo[MAXGASES]; double tanksize[MAXGASES]; double tankworkingpressure[MAXGASES]; @@ -117,6 +124,9 @@ static const struct { { "Events.Alarm.Active", ES_alarm_active }, { "Events.Bookmark.Name", ES_bookmark }, { "Events.GasSwitch.GasNumber", ES_gasswitch }, + { "Events.SetPoint.Type", ES_setpoint_type }, + { "Events.Events.SetPoint.PO2", ES_setpoint_po2 }, + { "Events.SetPoint.Automatic", ES_setpoint_automatic }, { "Events.DiveTimer.Active", ES_none }, { "Events.DiveTimer.Time", ES_none }, }; @@ -737,6 +747,41 @@ static void sample_event_alarm_value(struct sample_data *info, unsigned char val if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } +// enum:0=Low,1=High,2=Custom +static void sample_setpoint_type(struct sample_data *info, unsigned char value) +{ + dc_sample_value_t sample = {0}; + + 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); + return; + } + if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata); +} + +// uint32 +static void sample_setpoint_po2(struct sample_data *info, unsigned int pressure) +{ + // I *think* this just sets the custom SP, and then + // we'll get a setpoint_type(2) later. + info->eon->cache.customsetpoint = pressure / 100000.0; // Pascal to bar +} + +static void sample_setpoint_automatic(struct sample_data *info, unsigned char value) +{ + DEBUG(info->eon->base.context, "sample_setpoint_automatic(%u)", value); +} + static int handle_sample_type(struct sample_data *info, enum eon_sample type, const unsigned char *data) { switch (type) { @@ -828,6 +873,18 @@ static int handle_sample_type(struct sample_data *info, enum eon_sample type, co sample_gas_switch_event(info, array_uint16_le(data)); return 2; + case ES_setpoint_type: + sample_setpoint_type(info, data[0]); + return 1; + + case ES_setpoint_po2: + sample_setpoint_po2(info, array_uint32_le(data)); + return 4; + + case ES_setpoint_automatic: // bool + sample_setpoint_automatic(info, data[0]); + return 1; + default: return 0; } @@ -926,6 +983,9 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi case DC_FIELD_ATMOSPHERIC: field_value(value, eon->cache.surface_pressure); break; + case DC_FIELD_DIVEMODE: + field_value(value, eon->cache.divemode); + break; case DC_FIELD_TANK: /* * Sadly it seems that the EON Steel doesn't tell us whether @@ -1115,6 +1175,12 @@ static int traverse_device_fields(suunto_eonsteel_parser_t *eon, const struct ty // AlgorithmTransitionDepth (uint8) // DaysInSeries (uint32) // PreviousDiveDepth (float32,precision=2) +// LowSetPoint (uint32) +// HighSetPoint (uint32) +// SwitchHighSetPoint.Enabled (bool) +// SwitchHighSetPoint.Depth (float32,precision=1) +// SwitchLowSetPoint.Enabled (bool) +// SwitchLowSetPoint.Depth (float32,precision=1) // StartTissue.CNS (float32,precision=3) // StartTissue.OTU (float32) // StartTissue.OLF (float32,precision=3) @@ -1162,6 +1228,26 @@ static int traverse_diving_fields(suunto_eonsteel_parser_t *eon, const struct ty return 0; } + if (!strcmp(name, "DiveMode")) { + if (!strncmp(data, "CCR", 3)) { + eon->cache.divemode = DC_DIVEMODE_CC; + eon->cache.initialized |= 1 << DC_FIELD_DIVEMODE; + } + return 0; + } + + if (!strcmp(name, "LowSetPoint")) { + unsigned int pressure = array_uint32_le(data); // in SI units - Pascal + eon->cache.lowsetpoint = pressure / 100000.0; // bar + return 0; + } + + if (!strcmp(name, "HighSetPoint")) { + unsigned int pressure = array_uint32_le(data); // in SI units - Pascal + eon->cache.highsetpoint = pressure / 100000.0; // bar + return 0; + } + return 0; } From 42601825aa24ff75dee8796b5ad7d4a7e8ba4d1a Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Jul 2016 15:39:19 +0900 Subject: [PATCH 04/12] EON Steel: fix uninitialized field cache entries The check for whether we had initialized a field in the EON Steel cache data structure was wrong, causing some entries to be returned successfully even if their field had never been initialized. In most cases, it didn't matter, since the cache data was initialized to zero (which is a fine default for uninitialized data), so most of the time it didn't matter. But for the recently added dive mode field, this caused OC dives to be returned as freedives, for example. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 1d7e9e1..8d213bc 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -955,7 +955,7 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)parser; - if (!(eon->cache.initialized >> type)) + if (!(eon->cache.initialized & (1 << type))) return DC_STATUS_UNSUPPORTED; switch (type) { From 8ade60304de874c2456ab808a7d25a84311b84bd Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 17 Jul 2016 09:08:04 +0900 Subject: [PATCH 05/12] EON Steel: mark tank cache initialized when filling it in The previous commit fixed the cache initialization testing, and uncovered the fact that the tank size cache initialization didn't set the initialized bit correctly. That oversight had been hidden by the fact that we then tested the bit wrongly, so not setting it right didn't use to matter as long as there were other higher cache bits that were set. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 8d213bc..ee90b4f 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -1085,6 +1085,7 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d eon->cache.tankinfo[idx] = tankinfo; eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT; + eon->cache.initialized |= 1 << DC_FIELD_TANK_COUNT; return 0; } @@ -1115,6 +1116,7 @@ static int add_gas_size(suunto_eonsteel_parser_t *eon, float l) int idx = eon->cache.ngases-1; if (idx >= 0) eon->cache.tanksize[idx] = l; + eon->cache.initialized |= 1 << DC_FIELD_TANK; return 0; } From a1947f3fb0f937cd31cd4dcb6c9c12a84e5755d8 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 20 Jul 2016 11:58:00 +0900 Subject: [PATCH 06/12] EON Steel: pass in the type descriptor to samples that need it The samples that take 'enum' types need the type descriptor to parse what the enum type means. This doesn't actually use the data yet, I need to add parsing of the enum descriptor string. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index ee90b4f..368aa47 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -619,12 +619,12 @@ static void sample_gas_switch_event(struct sample_data *info, unsigned short idx * * FIXME! This needs to parse the actual type descriptor enum */ -static void sample_event_state_type(struct sample_data *info, unsigned char type) +static void sample_event_state_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { info->state_type = type; } -static void sample_event_state_value(struct sample_data *info, unsigned char value) +static void sample_event_state_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { /* * We could turn these into sample events, but they don't actually @@ -638,14 +638,14 @@ static void sample_event_state_value(struct sample_data *info, unsigned char val */ } -static void sample_event_notify_type(struct sample_data *info, unsigned char type) +static void sample_event_notify_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { info->notify_type = type; } // FIXME! This needs to parse the actual type descriptor enum -static void sample_event_notify_value(struct sample_data *info, unsigned char value) +static void sample_event_notify_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; static const enum parser_sample_event_t translate_notification[] = { @@ -679,13 +679,13 @@ static void sample_event_notify_value(struct sample_data *info, unsigned char va } -static void sample_event_warning_type(struct sample_data *info, unsigned char type) +static void sample_event_warning_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { info->warning_type = type; } -static void sample_event_warning_value(struct sample_data *info, unsigned char value) +static void sample_event_warning_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; static const enum parser_sample_event_t translate_warning[] = { @@ -716,14 +716,14 @@ static void sample_event_warning_value(struct sample_data *info, unsigned char v if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } -static void sample_event_alarm_type(struct sample_data *info, unsigned char type) +static void sample_event_alarm_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { info->alarm_type = type; } // FIXME! This needs to parse the actual type descriptor enum -static void sample_event_alarm_value(struct sample_data *info, unsigned char value) +static void sample_event_alarm_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; static const enum parser_sample_event_t translate_alarm[] = { @@ -748,7 +748,7 @@ static void sample_event_alarm_value(struct sample_data *info, unsigned char val } // enum:0=Low,1=High,2=Custom -static void sample_setpoint_type(struct sample_data *info, unsigned char value) +static void sample_setpoint_type(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; @@ -782,7 +782,7 @@ static void sample_setpoint_automatic(struct sample_data *info, unsigned char va DEBUG(info->eon->base.context, "sample_setpoint_automatic(%u)", value); } -static int handle_sample_type(struct sample_data *info, enum eon_sample type, const unsigned char *data) +static int handle_sample_type(const struct type_desc *desc, struct sample_data *info, enum eon_sample type, const unsigned char *data) { switch (type) { case ES_dtime: @@ -834,35 +834,35 @@ static int handle_sample_type(struct sample_data *info, enum eon_sample type, co return 2; case ES_state: - sample_event_state_type(info, data[0]); + sample_event_state_type(desc, info, data[0]); return 1; case ES_state_active: - sample_event_state_value(info, data[0]); + sample_event_state_value(desc, info, data[0]); return 1; case ES_notify: - sample_event_notify_type(info, data[0]); + sample_event_notify_type(desc, info, data[0]); return 1; case ES_notify_active: - sample_event_notify_value(info, data[0]); + sample_event_notify_value(desc, info, data[0]); return 1; case ES_warning: - sample_event_warning_type(info, data[0]); + sample_event_warning_type(desc, info, data[0]); return 1; case ES_warning_active: - sample_event_warning_value(info, data[0]); + sample_event_warning_value(desc, info, data[0]); return 1; case ES_alarm: - sample_event_alarm_type(info, data[0]); + sample_event_alarm_type(desc, info, data[0]); return 1; case ES_alarm_active: - sample_event_alarm_value(info, data[0]); + sample_event_alarm_value(desc, info, data[0]); return 1; case ES_bookmark: @@ -874,7 +874,7 @@ static int handle_sample_type(struct sample_data *info, enum eon_sample type, co return 2; case ES_setpoint_type: - sample_setpoint_type(info, data[0]); + sample_setpoint_type(desc, info, data[0]); return 1; case ES_setpoint_po2: @@ -905,7 +905,7 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c for (i = 0; i < EON_MAX_GROUP; i++) { enum eon_sample type = desc->type[i]; - int bytes = handle_sample_type(info, type, data); + int bytes = handle_sample_type(desc, info, type, data); if (!bytes) break; From 864b46603963ea2f70f5166bb7a738a12fc280fc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 20 Jul 2016 15:12:46 +0900 Subject: [PATCH 07/12] EON Steel: look up enum descriptor strings It turns out you can't hardcode the enum numbers either, since they change from dive to dive (or possibly firmware version to firmware version). So do it right, and actually parse the string descriptor for the enum. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 179 +++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 84 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 368aa47..4590ca9 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -449,8 +449,8 @@ struct sample_data { dc_sample_callback_t callback; void *userdata; unsigned int time; - unsigned char state_type, notify_type; - unsigned char warning_type, alarm_type; + const char *state_type, *notify_type; + const char *warning_type, *alarm_type; /* We gather up deco and cylinder pressure information */ int gasnr; @@ -600,77 +600,111 @@ static void sample_gas_switch_event(struct sample_data *info, unsigned short idx #endif } +/* + * Look up the string from an enumeration. + * + * Enumerations have the enum values in the "format" string, + * and all start with "enum:" followed by a comma-separated list + * of enumeration values and strings. Example: + * + * "enum:0=NoFly Time,1=Depth,2=Surface Time,3=..." + */ +static const char *lookup_enum(const struct type_desc *desc, unsigned char value) +{ + const char *str = desc->format; + unsigned char c; + + if (!str) + return NULL; + if (strncmp(str, "enum:", 5)) + return NULL; + str += 5; + + while ((c = *str) != 0) { + unsigned char n; + const char *begin, *end; + char *ret; + + str++; + if (!isdigit(c)) + continue; + n = c - '0'; + + // We only handle one or two digits + if (isdigit(*str)) { + n = n*10 + *str - '0'; + str++; + } + + begin = end = str; + while ((c = *str) != 0) { + str++; + if (c == ',') + break; + end = str; + } + + // Verify that it has the 'n=string' format and skip the equals sign + if (*begin != '=') + continue; + begin++; + + // Is it the value we're looking for? + if (n != value) + continue; + + ret = malloc(end - begin + 1); + if (!ret) + break; + + memcpy(ret, begin, end-begin); + ret[end-begin] = 0; + return ret; + } + return NULL; +} + /* * The EON Steel has four different sample events: "state", "notification", * "warning" and "alarm". All end up having two fields: type and a boolean value. - * - * The type enumerations are available as part of the type descriptor, and we - * *should* probably parse them dynamically, but this hardcodes the different - * type values. - * - * For event states, the types are: - * - * 0=Wet Outside - * 1=Below Wet Activation Depth - * 2=Below Surface - * 3=Dive Active - * 4=Surface Calculation - * 5=Tank pressure available - * - * FIXME! This needs to parse the actual type descriptor enum */ static void sample_event_state_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { - info->state_type = type; + info->state_type = lookup_enum(desc, type); } static void sample_event_state_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { - /* - * We could turn these into sample events, but they don't actually - * match any libdivecomputer events. - * - * unsigned int state = info->state_type; - * dc_sample_value_t sample = {0}; - * sample.event.type = ... - * sample.event.value = value; - * if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); - */ + dc_sample_value_t sample = {0}; + const char *name; + + name = info->state_type; + if (!name) + return; + + sample.event.type = SAMPLE_EVENT_NONE; + if (sample.event.type == SAMPLE_EVENT_NONE) + return; + + sample.event.value = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; + if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } static void sample_event_notify_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { - info->notify_type = type; + info->notify_type = lookup_enum(desc, type); } - -// FIXME! This needs to parse the actual type descriptor enum static void sample_event_notify_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; - static const enum parser_sample_event_t translate_notification[] = { - SAMPLE_EVENT_NONE, // 0=NoFly Time - SAMPLE_EVENT_NONE, // 1=Depth - SAMPLE_EVENT_NONE, // 2=Surface Time - SAMPLE_EVENT_TISSUELEVEL, // 3=Tissue Level - SAMPLE_EVENT_NONE, // 4=Deco - SAMPLE_EVENT_NONE, // 5=Deco Window - SAMPLE_EVENT_SAFETYSTOP_VOLUNTARY, // 6=Safety Stop Ahead - SAMPLE_EVENT_SAFETYSTOP, // 7=Safety Stop - SAMPLE_EVENT_CEILING_SAFETYSTOP, // 8=Safety Stop Broken - SAMPLE_EVENT_NONE, // 9=Deep Stop Ahead - SAMPLE_EVENT_DEEPSTOP, // 10=Deep Stop - SAMPLE_EVENT_DIVETIME, // 11=Dive Time - SAMPLE_EVENT_NONE, // 12=Gas Available - SAMPLE_EVENT_NONE, // 13=SetPoint Switch - SAMPLE_EVENT_NONE, // 14=Diluent Hypoxia - SAMPLE_EVENT_NONE, // 15=Tank Pressure - }; + const char *name; - if (info->notify_type > 15) + name = info->notify_type; + if (!name) return; - sample.event.type = translate_notification[info->notify_type]; + sample.event.type = SAMPLE_EVENT_NONE; if (sample.event.type == SAMPLE_EVENT_NONE) return; @@ -681,34 +715,19 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl static void sample_event_warning_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { - info->warning_type = type; + info->warning_type = lookup_enum(desc, type); } - static void sample_event_warning_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; - static const enum parser_sample_event_t translate_warning[] = { - SAMPLE_EVENT_NONE, // 0=ICD Penalty ("Isobaric counterdiffusion") - SAMPLE_EVENT_VIOLATION, // 1=Deep Stop Penalty - SAMPLE_EVENT_SAFETYSTOP_MANDATORY, // 2=Mandatory Safety Stop - SAMPLE_EVENT_NONE, // 3=OTU250 - SAMPLE_EVENT_NONE, // 4=OTU300 - SAMPLE_EVENT_NONE, // 5=CNS80% - SAMPLE_EVENT_NONE, // 6=CNS100% - SAMPLE_EVENT_AIRTIME, // 7=Air Time - SAMPLE_EVENT_MAXDEPTH, // 8=Max.Depth - SAMPLE_EVENT_AIRTIME, // 9=Tank Pressure - SAMPLE_EVENT_CEILING_SAFETYSTOP, // 10=Safety Stop Broken - SAMPLE_EVENT_CEILING_SAFETYSTOP, // 11=Deep Stop Broken - SAMPLE_EVENT_CEILING, // 12=Ceiling Broken - SAMPLE_EVENT_PO2, // 13=PO2 High - }; + const char *name; - if (info->warning_type > 13) + name = info->warning_type; + if (!name) return; - sample.event.type = translate_warning[info->warning_type]; + sample.event.type = SAMPLE_EVENT_NONE; if (sample.event.type == SAMPLE_EVENT_NONE) return; @@ -718,28 +737,20 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp static void sample_event_alarm_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) { - info->alarm_type = type; + info->alarm_type = lookup_enum(desc, type); } -// FIXME! This needs to parse the actual type descriptor enum static void sample_event_alarm_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; - static const enum parser_sample_event_t translate_alarm[] = { - SAMPLE_EVENT_CEILING_SAFETYSTOP, // 0=Mandatory Safety Stop Broken - SAMPLE_EVENT_ASCENT, // 1=Ascent Speed - SAMPLE_EVENT_NONE, // 2=Diluent Hyperoxia - SAMPLE_EVENT_VIOLATION, // 3=Violated Deep Stop - SAMPLE_EVENT_CEILING, // 4=Ceiling Broken - SAMPLE_EVENT_PO2, // 5=PO2 High - SAMPLE_EVENT_PO2, // 6=PO2 Low - }; + const char *name; - if (info->alarm_type > 6) + name = info->alarm_type; + if (!name) return; - sample.event.type = translate_alarm[info->alarm_type]; + sample.event.type = SAMPLE_EVENT_NONE; if (sample.event.type == SAMPLE_EVENT_NONE) return; From 2b57b1181dc1e97918072dec7fa400c982ae26a5 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 21 Jul 2016 19:39:51 +0900 Subject: [PATCH 08/12] Suunto EON Steel: split out gas info parsing The dive gas parsing cases can be split out into a helper function to keep things more manageable. Especially since there will be a couple more cases coming up. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 64 ++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 4590ca9..99fbed9 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -1166,19 +1166,45 @@ static int traverse_device_fields(suunto_eonsteel_parser_t *eon, const struct ty return 0; } +// "sml.DeviceLog.Header.Diving.Gases" +// +// +Gas.State (enum:0=Off,1=Primary,3=Diluent,4=Oxygen) +// .Gas.Oxygen (uint8,precision=2) +// .Gas.Helium (uint8,precision=2) +// .Gas.PO2 (uint32) +// .Gas.TransmitterID (utf8) +// .Gas.TankSize (float32,precision=5) +// .Gas.TankFillPressure (float32,precision=0) +// .Gas.StartPressure (float32,precision=0) +// .Gas.EndPressure (float32,precision=0) +// .Gas.TransmitterStartBatteryCharge (int8,precision=2) +// .Gas.TransmitterEndBatteryCharge (int8,precision=2) +static int traverse_gas_fields(suunto_eonsteel_parser_t *eon, const struct type_desc *desc, + const unsigned char *data, int len) +{ + const char *name = desc->desc + strlen("sml.DeviceLog.Header.Diving.Gases"); + + if (!strcmp(name, "+Gas.State")) + return add_gas_type(eon, desc, data[0]); + + if (!strcmp(name, ".Gas.Oxygen")) + return add_gas_o2(eon, data[0]); + + if (!strcmp(name, ".Gas.Helium")) + return add_gas_he(eon, data[0]); + + if (!strcmp(name, ".Gas.TankSize")) + return add_gas_size(eon, get_le32_float(data)); + + if (!strcmp(name, ".Gas.TankFillPressure")) + return add_gas_workpressure(eon, get_le32_float(data)); + + return 0; +} + + // "sml.DeviceLog.Header.Diving." // -// Gases+Gas.State (enum:0=Off,1=Primary,3=Diluent,4=Oxygen) -// Gases.Gas.Oxygen (uint8,precision=2) -// Gases.Gas.Helium (uint8,precision=2) -// Gases.Gas.PO2 (uint32) -// Gases.Gas.TransmitterID (utf8) -// Gases.Gas.TankSize (float32,precision=5) -// Gases.Gas.TankFillPressure (float32,precision=0) -// Gases.Gas.StartPressure (float32,precision=0) -// Gases.Gas.EndPressure (float32,precision=0) -// Gases.Gas.TransmitterStartBatteryCharge (int8,precision=2) -// Gases.Gas.TransmitterEndBatteryCharge (int8,precision=2) // SurfaceTime (uint32) // NumberInSeries (uint32) // Algorithm (utf8) @@ -1219,20 +1245,8 @@ static int traverse_diving_fields(suunto_eonsteel_parser_t *eon, const struct ty { const char *name = desc->desc + strlen("sml.DeviceLog.Header.Diving."); - if (!strcmp(name, "Gases+Gas.State")) - return add_gas_type(eon, desc, data[0]); - - if (!strcmp(name, "Gases.Gas.Oxygen")) - return add_gas_o2(eon, data[0]); - - if (!strcmp(name, "Gases.Gas.Helium")) - return add_gas_he(eon, data[0]); - - if (!strcmp(name, "Gases.Gas.TankSize")) - return add_gas_size(eon, get_le32_float(data)); - - if (!strcmp(name, "Gases.Gas.TankFillPressure")) - return add_gas_workpressure(eon, get_le32_float(data)); + if (!strncmp(name, "Gases", 5)) + return traverse_gas_fields(eon, desc, data, len); if (!strcmp(name, "SurfacePressure")) { unsigned int pressure = array_uint32_le(data); // in SI units - Pascal From 6352b90a34703be057e808696fd0e776085ea25b Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 23 Jul 2016 15:32:50 +0900 Subject: [PATCH 09/12] Suunto EON Steel: fix the event begin/end flag This fixes a bug where the begin/end marker was mistakenly added as the value instead of as flag. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 99fbed9..5e3ee7b 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -686,7 +686,7 @@ static void sample_event_state_value(const struct type_desc *desc, struct sample if (sample.event.type == SAMPLE_EVENT_NONE) return; - sample.event.value = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; + sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } @@ -708,7 +708,7 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl if (sample.event.type == SAMPLE_EVENT_NONE) return; - sample.event.value = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; + sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } @@ -731,7 +731,7 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp if (sample.event.type == SAMPLE_EVENT_NONE) return; - sample.event.value = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; + sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } @@ -754,7 +754,7 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample if (sample.event.type == SAMPLE_EVENT_NONE) return; - sample.event.value = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; + sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); } From 40bc67d8ffc50446f9e0d81cfd7cd355dbce281e Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 28 Aug 2016 12:56:09 -0700 Subject: [PATCH 10/12] 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 | 45 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 5e3ee7b..8442cca 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -762,21 +762,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); } @@ -1081,18 +1084,24 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d { int idx = eon->cache.ngases; dc_tankvolume_t tankinfo = DC_TANKVOLUME_METRIC; + const char *name; if (idx >= MAXGASES) return 0; eon->cache.ngases = idx+1; - switch (type) { - case 0: + 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")) + ; + else if (!strcasecmp(name, "Oxygen")) + ; + else if (!strcasecmp(name, "None")) tankinfo = 0; - break; - default: - break; - } + 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; From 5e8b4dd6dccde5b57f293dd2b147d06b5d8cc6a6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 29 Aug 2016 15:03:02 -0700 Subject: [PATCH 11/12] Suunto EON Steel: initialize the tank 'gasmix' index The gasmix query interface considers cylinders and gas mixes independent things, so the tank data structure has a pointer to the gasmix index. But the EON Steel treats cylinders as just having a gasmix (and so does subsurface, for that matter), so the gasmix index for the tank is just the same as the tank index. But we never filled it in, so you'd always see a "gas index" of zero, and subsurface would end up warning each time about how the gasmix index doesn't match the cylinder index (but because subsurface actually agreed with EON Steel, it worked despite the warning). Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel_parser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 8442cca..0501a30 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -1007,6 +1007,7 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi * that metric is (at least so far) always whole liters */ tank->volume = eon->cache.tanksize[flags]; + tank->gasmix = flags; /* * The pressure reported is NOT the pressure the user enters. From ec473feabff7b25d4d206f474209080041a4f5a1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 7 Sep 2016 15:53:07 +0200 Subject: [PATCH 12/12] Restore the sample events. In commit 864b46603963ea2f70f5166bb7a738a12fc280fc, the sample events have been removed because we need to parse the enum string descriptor instead of the numeric value. --- src/suunto_eonsteel_parser.c | 76 ++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 0501a30..64a01ca 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -98,6 +98,11 @@ typedef struct suunto_eonsteel_parser_t { typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user); +typedef struct eon_event_t { + const char *name; + parser_sample_event_t type; +} eon_event_t; + static const struct { const char *name; enum eon_sample type; @@ -163,6 +168,16 @@ static enum eon_sample lookup_descriptor_type(suunto_eonsteel_parser_t *eon, str return ES_none; } +static parser_sample_event_t lookup_event(const char *name, const eon_event_t events[], size_t n) +{ + for (size_t i = 0; i < n; ++i) { + if (!strcasecmp(name, events[i].name)) + return events[i].type; + } + + return SAMPLE_EVENT_NONE; +} + static const char *desc_type_name(enum eon_sample type) { int i; @@ -676,13 +691,22 @@ static void sample_event_state_type(const struct type_desc *desc, struct sample_ static void sample_event_state_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { dc_sample_value_t sample = {0}; + static const eon_event_t states[] = { + {"Wet Outside", SAMPLE_EVENT_NONE}, + {"Below Wet Activation Depth", SAMPLE_EVENT_NONE}, + {"Below Surface", SAMPLE_EVENT_NONE}, + {"Dive Active", SAMPLE_EVENT_NONE}, + {"Surface Calculation", SAMPLE_EVENT_NONE}, + {"Tank pressure available", SAMPLE_EVENT_NONE}, + {"Closed Circuit Mode", SAMPLE_EVENT_NONE}, + }; const char *name; name = info->state_type; if (!name) return; - sample.event.type = SAMPLE_EVENT_NONE; + sample.event.type = lookup_event(name, states, C_ARRAY_SIZE(states)); if (sample.event.type == SAMPLE_EVENT_NONE) return; @@ -697,6 +721,25 @@ static void sample_event_notify_type(const struct type_desc *desc, struct sample static void sample_event_notify_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { + static const eon_event_t notifications[] = { + {"NoFly Time", SAMPLE_EVENT_NONE}, + {"Depth", SAMPLE_EVENT_NONE}, + {"Surface Time", SAMPLE_EVENT_NONE}, + {"Tissue Level", SAMPLE_EVENT_TISSUELEVEL}, + {"Deco", SAMPLE_EVENT_NONE}, + {"Deco Window", SAMPLE_EVENT_NONE}, + {"Safety Stop Ahead", SAMPLE_EVENT_NONE}, + {"Safety Stop", SAMPLE_EVENT_SAFETYSTOP}, + {"Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP}, + {"Deep Stop Ahead", SAMPLE_EVENT_NONE}, + {"Deep Stop", SAMPLE_EVENT_DEEPSTOP}, + {"Dive Time", SAMPLE_EVENT_DIVETIME}, + {"Gas Available", SAMPLE_EVENT_NONE}, + {"SetPoint Switch", SAMPLE_EVENT_NONE}, + {"Diluent Hypoxia", SAMPLE_EVENT_NONE}, + {"Air Time", SAMPLE_EVENT_NONE}, + {"Tank Pressure", SAMPLE_EVENT_NONE}, + }; dc_sample_value_t sample = {0}; const char *name; @@ -704,7 +747,7 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl if (!name) return; - sample.event.type = SAMPLE_EVENT_NONE; + sample.event.type = lookup_event(name, notifications, C_ARRAY_SIZE(notifications)); if (sample.event.type == SAMPLE_EVENT_NONE) return; @@ -720,6 +763,22 @@ static void sample_event_warning_type(const struct type_desc *desc, struct sampl static void sample_event_warning_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { + static const eon_event_t warnings[] = { + {"ICD Penalty", SAMPLE_EVENT_NONE}, + {"Deep Stop Penalty", SAMPLE_EVENT_VIOLATION}, + {"Mandatory Safety Stop", SAMPLE_EVENT_SAFETYSTOP_MANDATORY}, + {"OTU250", SAMPLE_EVENT_NONE}, + {"OTU300", SAMPLE_EVENT_NONE}, + {"CNS80%", SAMPLE_EVENT_NONE}, + {"CNS100%", SAMPLE_EVENT_NONE}, + {"Max.Depth", SAMPLE_EVENT_MAXDEPTH}, + {"Air Time", SAMPLE_EVENT_AIRTIME}, + {"Tank Pressure", SAMPLE_EVENT_NONE}, + {"Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP}, + {"Deep Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP}, + {"Ceiling Broken", SAMPLE_EVENT_CEILING}, + {"PO2 High", SAMPLE_EVENT_PO2}, + }; dc_sample_value_t sample = {0}; const char *name; @@ -727,7 +786,7 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp if (!name) return; - sample.event.type = SAMPLE_EVENT_NONE; + sample.event.type = lookup_event(name, warnings, C_ARRAY_SIZE(warnings)); if (sample.event.type == SAMPLE_EVENT_NONE) return; @@ -743,6 +802,15 @@ static void sample_event_alarm_type(const struct type_desc *desc, struct sample_ static void sample_event_alarm_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) { + static const eon_event_t alarms[] = { + {"Mandatory Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP}, + {"Ascent Speed", SAMPLE_EVENT_ASCENT}, + {"Diluent Hyperoxia", SAMPLE_EVENT_NONE}, + {"Violated Deep Stop", SAMPLE_EVENT_VIOLATION}, + {"Ceiling Broken", SAMPLE_EVENT_CEILING}, + {"PO2 High", SAMPLE_EVENT_PO2}, + {"PO2 Low", SAMPLE_EVENT_PO2}, + }; dc_sample_value_t sample = {0}; const char *name; @@ -750,7 +818,7 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample if (!name) return; - sample.event.type = SAMPLE_EVENT_NONE; + sample.event.type = lookup_event(name, alarms, C_ARRAY_SIZE(alarms)); if (sample.event.type == SAMPLE_EVENT_NONE) return;