diff options
author | Jef Driesen <jefdriesen@telenet.be> | 2014-01-07 20:38:36 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-08 05:53:42 +0800 |
commit | 58f6a01a220bcdc25de2aac84a4eb5e49562d739 (patch) | |
tree | e53014c3cf78d0a44224d0681e61a3689d77fdce | |
parent | a32462c26b55ff1d28ec9d126655828511a89c35 (diff) | |
download | subsurface-58f6a01a220bcdc25de2aac84a4eb5e49562d739.tar.gz |
Write the event data to the libdivecomputer log.
For some devices, the event data contains important data that is
required for parsing the dives, but which is not present in the full
memory dump.
Signed-off-by: Jef Driesen <jefdriesen@telenet.be>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | libdivecomputer.c | 23 | ||||
-rw-r--r-- | libdivecomputer.h | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c index 78d3808f9..48b8151d2 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -610,6 +610,7 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat const dc_event_progress_t *progress = data; const dc_event_devinfo_t *devinfo = data; const dc_event_clock_t *clock = data; + const dc_event_vendor_t *vendor = data; device_data_t *devdata = userdata; unsigned int serial; @@ -627,6 +628,12 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat devinfo->model, devinfo->model, devinfo->firmware, devinfo->firmware, devinfo->serial, devinfo->serial); + if (devdata->libdc_logfile) { + fprintf(devdata->libdc_logfile, "Event: model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)\n", + devinfo->model, devinfo->model, + devinfo->firmware, devinfo->firmware, + devinfo->serial, devinfo->serial); + } /* * libdivecomputer doesn't give serial numbers in the proper string form, * so we have to see if we can do some vendor-specific munging. @@ -640,6 +647,18 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat case DC_EVENT_CLOCK: dev_info(devdata, translate("gettextFromC","Event: systime=%"PRId64", devtime=%u\n"), (uint64_t)clock->systime, clock->devtime); + if (devdata->libdc_logfile) { + fprintf(devdata->libdc_logfile, "Event: systime=%"PRId64", devtime=%u\n", + (uint64_t)clock->systime, clock->devtime); + } + break; + case DC_EVENT_VENDOR: + if (devdata->libdc_logfile) { + fprintf(devdata->libdc_logfile, "Event: vendor="); + for (unsigned int i = 0; i < vendor->size; ++i) + fprintf(devdata->libdc_logfile, "%02X", vendor->data[i]); + fprintf(devdata->libdc_logfile,"\n"); + } break; default: break; @@ -662,7 +681,7 @@ static const char *do_device_import(device_data_t *data) data->model = str_printf("%s %s", data->vendor, data->product); // Register the event handler. - int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK; + int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR; rc = dc_device_set_events(device, events, event_cb, data); if (rc != DC_STATUS_SUCCESS) return translate("gettextFromC","Error registering the event handler."); @@ -724,6 +743,8 @@ const char *do_libdivecomputer_import(device_data_t *data) if (data->libdc_log && logfile_name) fp = subsurface_fopen(logfile_name, "w"); + data->libdc_logfile = fp; + rc = dc_context_new(&data->context); if (rc != DC_STATUS_SUCCESS) return translate("gettextFromC","Unable to create libdivecomputer context"); diff --git a/libdivecomputer.h b/libdivecomputer.h index 754a98f44..8285f5a9f 100644 --- a/libdivecomputer.h +++ b/libdivecomputer.h @@ -26,6 +26,7 @@ typedef struct device_data_t { bool force_download; bool libdc_log; bool libdc_dump; + FILE *libdc_logfile; } device_data_t; const char *do_libdivecomputer_import(device_data_t *data); |