diff --git a/src/mares_iconhd.h b/src/mares_iconhd.h index 55a50d0..1354f77 100644 --- a/src/mares_iconhd.h +++ b/src/mares_iconhd.h @@ -35,7 +35,7 @@ dc_status_t mares_iconhd_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial); #ifdef __cplusplus } diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 34d39c7..e878619 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -20,6 +20,8 @@ */ #include +#include /* for snprintf */ +#include /* for strdup */ #include @@ -147,6 +149,7 @@ struct mares_iconhd_parser_t { unsigned int samplerate; unsigned int ntanks; unsigned int ngasmixes; + unsigned int serial; mares_iconhd_gasmix_t gasmix[NGASMIXES]; mares_iconhd_tank_t tank[NTANKS]; }; @@ -506,7 +509,7 @@ mares_iconhd_parser_cache (mares_iconhd_parser_t *parser) } dc_status_t -mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial) { mares_iconhd_parser_t *parser = NULL; @@ -533,6 +536,7 @@ mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i parser->samplerate = 0; parser->ntanks = 0; parser->ngasmixes = 0; + parser->serial = serial; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; @@ -635,6 +639,7 @@ mares_iconhd_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime return DC_STATUS_SUCCESS; } +#define BUFLEN 16 static dc_status_t mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) @@ -667,6 +672,8 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_tank_t *tank = (dc_tank_t *) value; dc_salinity_t *water = (dc_salinity_t *) value; + dc_field_string_t *string = (dc_field_string_t *) value; + char buf[BUFLEN]; if (value) { switch (type) { @@ -834,6 +841,17 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi } } break; + case DC_FIELD_STRING: + switch(flags) { + case 0: /* serial */ + string->desc = "Serial"; + snprintf(buf, BUFLEN, "%u", parser->serial); + break; + default: + return DC_STATUS_UNSUPPORTED; + } + string->value = strdup(buf); + break; default: return DC_STATUS_UNSUPPORTED; } diff --git a/src/parser.c b/src/parser.c index f1e1ebc..61bad59 100644 --- a/src/parser.c +++ b/src/parser.c @@ -92,7 +92,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa if (model == 0x01) rc = suunto_eon_parser_create (&parser, context, 1); else - rc = suunto_vyper_parser_create (&parser, context); + rc = suunto_vyper_parser_create (&parser, context, serial); break; case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_D9: @@ -137,7 +137,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa rc = mares_darwin_parser_create (&parser, context, model); break; case DC_FAMILY_MARES_ICONHD: - rc = mares_iconhd_parser_create (&parser, context, model); + rc = mares_iconhd_parser_create (&parser, context, model, serial); break; case DC_FAMILY_HW_OSTC: rc = hw_ostc_parser_create (&parser, context, serial); diff --git a/src/suunto_vyper.h b/src/suunto_vyper.h index 858520f..e6f8812 100644 --- a/src/suunto_vyper.h +++ b/src/suunto_vyper.h @@ -35,7 +35,7 @@ dc_status_t suunto_vyper_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context); +suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int serial); #ifdef __cplusplus } diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 369ad5c..bf4134a 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -20,6 +20,8 @@ */ #include +#include /* for snprintf */ +#include /* for strdup */ #include @@ -41,6 +43,7 @@ struct suunto_vyper_parser_t { unsigned int maxdepth; unsigned int marker; unsigned int ngasmixes; + unsigned int serial; unsigned int oxygen[NGASMIXES]; }; @@ -159,7 +162,7 @@ suunto_vyper_parser_cache (suunto_vyper_parser_t *parser) dc_status_t -suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context) +suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int serial) { suunto_vyper_parser_t *parser = NULL; @@ -179,6 +182,7 @@ suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context) parser->maxdepth = 0; parser->marker = 0; parser->ngasmixes = 0; + parser->serial = serial; for (unsigned int i = 0; i < NGASMIXES; ++i) { parser->oxygen[i] = 0; } @@ -229,6 +233,7 @@ suunto_vyper_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime return DC_STATUS_SUCCESS; } +#define BUFLEN 16 static dc_status_t suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) @@ -238,6 +243,8 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi dc_gasmix_t *gas = (dc_gasmix_t *) value; dc_tank_t *tank = (dc_tank_t *) value; + dc_field_string_t *string = (dc_field_string_t *) value; + char buf[BUFLEN]; // Cache the data. dc_status_t rc = suunto_vyper_parser_cache (parser); @@ -297,6 +304,17 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi *((dc_divemode_t *) value) = DC_DIVEMODE_OC; } break; + case DC_FIELD_STRING: + switch(flags) { + case 0: /* serial */ + string->desc = "Serial"; + snprintf(buf, BUFLEN, "%u", parser->serial); + break; + default: + return DC_STATUS_UNSUPPORTED; + } + string->value = strdup(buf); + break; default: return DC_STATUS_UNSUPPORTED; }