From a6637442b7f4d4123fe48bdea21af6bdcf67d187 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 17 Apr 2018 11:10:34 -0700 Subject: [PATCH] Make dc_parser_new() pass in the serial number to +dc_parser_new_internal The libdivecomputer serial number handling is very very messy. There are multiple issues that make it messy: - it's not actually figured out at parse-time, it's figured out at download time and passed up through the DC_EVENT_DEVINFO as part of the devinfo structure. - it's passed around as an "unsigned in" in the devinfo structure, which is entirely useless to anybody but libdivecomputer, since a serial number isn't actually a number, but a string, and the format of the string depends on the dive computer. - it is *not* passed to the parser, so the parser can't do a better job at it later. But it turns out that the sane "create new parser" helper function does actually get it, as part of the "devinfo" that is passed to it. So as long as you use that sane interface, we can now pass it in to the actual parser creation, and then the dive computer parsers that want to do a reasonable job of actually generating a real serial number string can now save it off and do so. This just adds the infrastructure to make this possible. I'll do the dive computers one by one. Signed-off-by: Linus Torvalds --- src/parser.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parser.c b/src/parser.c index 29a5d41..2c982f5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -64,7 +64,7 @@ #define REACTPROWHITE 0x4354 static dc_status_t -dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model, unsigned int devtime, dc_ticks_t systime) +dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model, unsigned int serial, unsigned int devtime, dc_ticks_t systime) { dc_status_t rc = DC_STATUS_SUCCESS; dc_parser_t *parser = NULL; @@ -183,7 +183,9 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device) return DC_STATUS_INVALIDARGS; return dc_parser_new_internal (out, device->context, - dc_device_get_type (device), device->devinfo.model, + dc_device_get_type (device), + device->devinfo.model, + device->devinfo.serial, device->clock.devtime, device->clock.systime); } @@ -191,7 +193,9 @@ dc_status_t dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime) { return dc_parser_new_internal (out, context, - dc_descriptor_get_type (descriptor), dc_descriptor_get_model (descriptor), + dc_descriptor_get_type (descriptor), + dc_descriptor_get_model (descriptor), + 0, devtime, systime); }