[PATCH] Initial support for Divesoft Freedom

Miika Turkia miika.turkia at gmail.com
Sat Dec 27 12:10:44 PST 2014


This parses the dive profile from Divesoft Freedom log file. Only the
depth profile is currently supported. There is also something wrong as
the log file cannot be given as parameter but must be opened or imported
once Subsurface is running. Note that so far no metadata is parsed.

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 dive.h      |  1 +
 file.c      |  9 +++++++++
 parse-xml.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/dive.h b/dive.h
index 795db22..30aa8d9 100644
--- a/dive.h
+++ b/dive.h
@@ -627,6 +627,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, i
 extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
 extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
 extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
+extern int parse_dlf_buffer(char *buffer, size_t size);
 
 extern int parse_file(const char *filename);
 extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units);
diff --git a/file.c b/file.c
index 4b7a9d5..4ef2233 100644
--- a/file.c
+++ b/file.c
@@ -442,6 +442,15 @@ int parse_file(const char *filename)
 		}
 	}
 
+	/* Divesoft Freedom */
+	if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
+		if (!parse_dlf_buffer(mem.buffer, mem.size)) {
+			free(mem.buffer);
+			return 0;
+		}
+		return -1;
+	}
+
 	ret = parse_file_buffer(filename, &mem);
 	free(mem.buffer);
 	return ret;
diff --git a/parse-xml.c b/parse-xml.c
index ac78209..218268d 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2531,6 +2531,34 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
 	return 0;
 }
 
+int parse_dlf_buffer(char *buffer, size_t size)
+{
+	char *ptr = (char *)buffer;
+	bool event;
+
+	/* Skipping the dive header for now */
+	ptr += 32;
+
+	dive_start();
+
+	while (ptr < buffer + size) {
+		event = ptr[0] & 0x0f;
+		if (event == 1) {
+			/* dive event */
+		} else {
+			sample_start();
+			cur_sample->time.seconds = ((ptr[0] >> 4) & 0x0f) +
+				((ptr[1] << 4) & 0xff0) +
+				(ptr[2] & 0x0f) * 3600; /* hours */
+			cur_sample->depth.mm = ((ptr[4] & 0xff) + ((ptr[5] << 8) & 0xff00)) * 10;
+			sample_end();
+		}
+		ptr += 16;
+	}
+	dive_end();
+}
+
+
 void parse_xml_init(void)
 {
 	LIBXML_TEST_VERSION
-- 
1.9.1



More information about the subsurface mailing list