Support serial number for Suuntu Vyper2 family of devices

We have the correct firmware in the devinfo, but that's the firmware the
dive computer is on NOW, not necessarily the firmware it was using when
recording the dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-11-21 14:29:53 -08:00
parent 06426af656
commit b85f2333be
3 changed files with 24 additions and 4 deletions

View File

@ -42,7 +42,7 @@ dc_status_t
suunto_d9_device_reset_maxdepth (dc_device_t *device);
dc_status_t
suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial);
#ifdef __cplusplus
}

View File

@ -66,7 +66,7 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device)
break;
case DC_FAMILY_SUUNTO_VYPER2:
case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_parser_create (&parser, context, device->devinfo.model);
rc = suunto_d9_parser_create (&parser, context, device->devinfo.model, device->devinfo.serial);
break;
case DC_FAMILY_SUUNTO_EONSTEEL:
rc = suunto_eonsteel_parser_create(&parser, context, device->devinfo.model);

View File

@ -20,7 +20,8 @@
*/
#include <stdlib.h>
#include <string.h> // memcmp
#include <string.h> // memcmp, strdup
#include <stdio.h> // snprintf
#include <libdivecomputer/suunto_d9.h>
@ -62,6 +63,7 @@ typedef struct suunto_d9_parser_t suunto_d9_parser_t;
struct suunto_d9_parser_t {
dc_parser_t base;
unsigned int model;
unsigned int serial;
// Cached fields.
unsigned int cached;
unsigned int mode;
@ -188,7 +190,7 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser)
}
dc_status_t
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -205,6 +207,7 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
// Set the default values.
parser->model = model;
parser->serial = serial;
parser->cached = 0;
parser->mode = AIR;
parser->ngasmixes = 0;
@ -289,6 +292,7 @@ suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
return DC_STATUS_SUCCESS;
}
#define BUFLEN 16
static dc_status_t
suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
@ -304,6 +308,9 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return rc;
dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
char buf[BUFLEN];
if (value) {
switch (type) {
@ -349,6 +356,19 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return DC_STATUS_DATAFORMAT;
}
break;
case DC_FIELD_STRING:
switch (flags) {
case 0: /* serial */
string->desc = "Serial";
snprintf(buf, BUFLEN, "%02d%02d%02d%02d", (parser->serial >> 24) & 0xff,
(parser->serial >> 16) & 0xff, (parser->serial >> 8) & 0xff,
parser->serial & 0xff);
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default:
return DC_STATUS_UNSUPPORTED;
}