summaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
diff options
context:
space:
mode:
authorGravatar Salvador Cuñat <salvador.cunat@gmail.com>2015-04-04 00:51:38 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-04-04 10:31:43 -0700
commit094d0d96997a89601a82c98bb084089355e59446 (patch)
tree3f4b09a3f6299d9f1da4643de2fc851254810a1b /libdivecomputer.c
parent0fe21637ad753a87dc0dc4d44564a613b2b693d2 (diff)
downloadsubsurface-094d0d96997a89601a82c98bb084089355e59446.tar.gz
libdivecomputer.c: Add support for raw data buffer parse using libdc
Add function libdc_buffer_parser() intended to parse raw data buffers prepared for libdivecomputer. We have to commit elsewhere the necesary assembly tasks to achieve consistent data. Actually only OSTCTools import makes use of this feature. Uwatec families have been included as I expect to make use of this function for sample parsing in datatrak import (and, may be in a far future, smartrak). Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r--libdivecomputer.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 690cde09f..2b724617f 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -9,6 +9,9 @@
#include "display.h"
#include "libdivecomputer.h"
+#include <libdivecomputer/uwatec.h>
+#include <libdivecomputer/hw.h>
+
/* Christ. Libdivecomputer has the worst configuration system ever. */
#ifdef HW_FROG_H
@@ -930,3 +933,63 @@ const char *do_libdivecomputer_import(device_data_t *data)
return err;
}
+
+/*
+ * Parse data buffers instead of dc devices downloaded data.
+ * Intended to be used to parse profile data from binary files during import tasks.
+ * Actually included Uwatec families because of works on datatrak and smartrak logs
+ * and OSTC families for OSTCTools logs import.
+ * For others, simply include them in the switch (check parameters).
+ * Note that dc_descriptor_t in data *must* have been filled using dc_descriptor_iterator()
+ * calls.
+ */
+dc_status_t libdc_buffer_parser(struct dive *dive, device_data_t *data, unsigned char *buffer, int size)
+{
+ dc_status_t rc;
+ dc_parser_t *parser = NULL;
+
+ switch (data->descriptor->type) {
+ case DC_FAMILY_UWATEC_ALADIN:
+ case DC_FAMILY_UWATEC_MEMOMOUSE:
+ rc = uwatec_memomouse_parser_create(&parser, data->context, 0, 0);
+ break;
+ case DC_FAMILY_UWATEC_SMART:
+ case DC_FAMILY_UWATEC_MERIDIAN:
+ rc = uwatec_smart_parser_create (&parser, data->context, data->descriptor->model, 0, 0);
+ break;
+ case DC_FAMILY_HW_OSTC:
+ rc = hw_ostc_parser_create (&parser, data->context, data->deviceid, 0);
+ break;
+ case DC_FAMILY_HW_FROG:
+ case DC_FAMILY_HW_OSTC3:
+ rc = hw_ostc_parser_create (&parser, data->context, data->deviceid, 1);
+ break;
+ }
+ if (rc != DC_STATUS_SUCCESS) {
+ report_error("Error creating parser.");
+ dc_parser_destroy (parser);
+ return rc;
+ }
+ rc = dc_parser_set_data(parser, buffer, size);
+ if (rc != DC_STATUS_SUCCESS) {
+ report_error("Error registering the data.");
+ dc_parser_destroy (parser);
+ return rc;
+ }
+ // Do not parse Aladin/Memomouse headers as they are fakes
+ // Do not return on error, we can still parse the samples
+ if (data->descriptor->type != DC_FAMILY_UWATEC_ALADIN && data->descriptor->type != DC_FAMILY_UWATEC_MEMOMOUSE) {
+ rc = libdc_header_parser (parser, data, dive);
+ if (rc != DC_STATUS_SUCCESS) {
+ report_error("Error parsing the dive header data. Dive # %d\nStatus = %s", dive->number, errmsg(rc));
+ }
+ }
+ rc = dc_parser_samples_foreach (parser, sample_cb, &dive->dc);
+ if (rc != DC_STATUS_SUCCESS) {
+ report_error("Error parsing the sample data. Dive # %d\nStatus = %s", dive->number, errmsg(rc));
+ dc_parser_destroy (parser);
+ return rc;
+ }
+ dc_parser_destroy(parser);
+ return(DC_STATUS_SUCCESS);
+}