From f2a656246d786494116564a3cd373d26392e13a5 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 7 Dec 2012 13:11:39 -0800 Subject: [PATCH] Add support for setpoint, ppO2 and CNS So far only OSTC and Shearwater Predator are supported. For the OSTC we support CNS and setpoint changes in the samples (the current hardware doesn't actually support ppO2 sensors and for the older hw that does I don't have the correct encoding information). For the Predator we support only the "average ppO2 during the sample". The Predator also gives us a CNS value at the end of the dive - I don't quite know yet how to deliver that back to the consumer. Possibly as CNS value in the very last sample? That would at least be consistent. Signed-off-by: Dirk Hohndel --- include/libdivecomputer/parser.h | 8 +++++++- src/hw_ostc_parser.c | 13 +++++++++++++ src/shearwater_predator_parser.c | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 01ded99..c69a887 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -39,7 +39,10 @@ typedef enum dc_sample_type_t { DC_SAMPLE_RBT, DC_SAMPLE_HEARTBEAT, DC_SAMPLE_BEARING, - DC_SAMPLE_VENDOR + DC_SAMPLE_VENDOR, + DC_SAMPLE_SETPOINT, + DC_SAMPLE_PPO2, + DC_SAMPLE_CNS } dc_sample_type_t; typedef enum dc_field_type_t { @@ -141,6 +144,9 @@ typedef union dc_sample_value_t { unsigned int size; const void *data; } vendor; + double setpoint; + double ppo2; + double cns; } dc_sample_value_t; typedef struct dc_parser_t dc_parser_t; diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index ffeba04..cce8f03 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -302,6 +302,10 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call if (info[i].size != 2) return DC_STATUS_DATAFORMAT; break; + case 5: // CNS + if (info[i].size != 1) + return DC_STATUS_DATAFORMAT; + break; default: // Not yet used. break; } @@ -419,6 +423,11 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call sample.event.time = 0; sample.event.flags = 0; if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + break; + case 5: // CNS + sample.cns = data[offset] / 100.0; + if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + break; default: // Not yet used. break; } @@ -429,6 +438,10 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // SetPoint Change if (events & 0x40) { + if (offset + 1 > size) + return DC_STATUS_DATAFORMAT; + sample.setpoint = data[offset] / 100.0; + if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); offset++; } } diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 0cbf369..a514ada 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -231,6 +231,10 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.temperature = temperature; if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + // PPO2 + sample.ppo2 = data[offset + 6] / 100.0; + if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); + // Gaschange. unsigned int o2 = data[offset + 7]; unsigned int he = data[offset + 8];