From 9db9e970cfc227f4d8c3e97518b659095352bbb4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 24 Sep 2014 19:47:09 +0200 Subject: [PATCH] Convert the gasmix id into an array index. The gasmix value in the sample data is the id of the gasmix. Depending how the user manipulated the gasmix settings, this id is not necessary identical to the index into the gasmix array. The array index can be found by searching the array for a mix with the correct id. --- src/atomics_cobalt_parser.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 108e381..8378028 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -237,12 +237,19 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Current gas mix unsigned int gasmix = data[offset + 4]; - if (gasmix >= ngasmixes) { - return DC_STATUS_DATAFORMAT; - } if (gasmix != gasmix_previous) { - unsigned int o2 = data[SZ_HEADER + SZ_GASMIX * gasmix + 4]; - unsigned int he = data[SZ_HEADER + SZ_GASMIX * gasmix + 5]; + unsigned int idx = 0; + while (idx < ngasmixes) { + if (data[SZ_HEADER + SZ_GASMIX * idx + 0] == gasmix) + break; + idx++; + } + if (idx >= ngasmixes) { + ERROR (abstract->context, "Invalid gas mix index."); + return DC_STATUS_DATAFORMAT; + } + unsigned int o2 = data[SZ_HEADER + SZ_GASMIX * idx + 4]; + unsigned int he = data[SZ_HEADER + SZ_GASMIX * idx + 5]; sample.event.type = SAMPLE_EVENT_GASCHANGE2; sample.event.time = 0; sample.event.flags = 0;