summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/datatrak.c11
-rw-r--r--core/file.c4
-rw-r--r--core/file.h3
-rw-r--r--core/load-git.c14
-rw-r--r--core/parse-xml.c3
-rw-r--r--core/parse.c2
6 files changed, 23 insertions, 14 deletions
diff --git a/core/datatrak.c b/core/datatrak.c
index 720b631b3..b10ef55ad 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -159,7 +159,8 @@ static dc_status_t dt_libdc_buffer(unsigned char *ptr, int prf_length, int dc_mo
* Parses a mem buffer extracting its data and filling a subsurface's dive structure.
* Returns a pointer to last position in buffer, or NULL on failure.
*/
-static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites, long maxbuf)
+static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites,
+ struct device_table *devices, long maxbuf)
{
int rc, profile_length, libdc_model;
char *tmp_notes_str = NULL;
@@ -565,7 +566,7 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
dt_dive->dc.deviceid = 0;
else
dt_dive->dc.deviceid = 0xffffffff;
- create_device_node(&device_table, dt_dive->dc.model, dt_dive->dc.deviceid, "", "", dt_dive->dc.model);
+ create_device_node(devices, dt_dive->dc.model, dt_dive->dc.deviceid, "", "", dt_dive->dc.model);
dt_dive->dc.next = NULL;
if (!is_SCR && dt_dive->cylinders.nr > 0) {
get_cylinder(dt_dive, 0)->end.mbar = get_cylinder(dt_dive, 0)->start.mbar -
@@ -578,6 +579,7 @@ bail:
free(devdata);
return NULL;
}
+
/*
* Parses the header of the .add file, returns the number of dives in
* the archive (must be the same than number of dives in .log file).
@@ -675,7 +677,8 @@ static void wlog_compl_parser(struct memblock *wl_mem, struct dive *dt_dive, int
* Main function call from file.c memblock is allocated (and freed) there.
* If parsing is aborted due to errors, stores correctly parsed dives.
*/
-int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
+int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
+ struct dive_site_table *sites, struct device_table *devices)
{
UNUSED(trips);
unsigned char *runner;
@@ -707,7 +710,7 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
while ((i < numdives) && ((long) runner < maxbuf)) {
struct dive *ptdive = alloc_dive();
- runner = dt_dive_parser(runner, ptdive, sites, maxbuf);
+ runner = dt_dive_parser(runner, ptdive, sites, devices, maxbuf);
if (wl_mem)
wlog_compl_parser(wl_mem, ptdive, i);
if (runner == NULL) {
diff --git a/core/file.c b/core/file.c
index 85537868f..d1cbc3c62 100644
--- a/core/file.c
+++ b/core/file.c
@@ -361,9 +361,9 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
wl_name = strcat(wl_name, ".add");
if((ret = readfile(wl_name, &wl_mem)) < 0) {
fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name);
- ret = datatrak_import(&mem, NULL, table, trips, sites);
+ ret = datatrak_import(&mem, NULL, table, trips, sites, devices);
} else {
- ret = datatrak_import(&mem, &wl_mem, table, trips, sites);
+ ret = datatrak_import(&mem, &wl_mem, table, trips, sites, devices);
free(wl_mem.buffer);
}
free(mem.buffer);
diff --git a/core/file.h b/core/file.h
index e479cdaac..f0e001d34 100644
--- a/core/file.h
+++ b/core/file.h
@@ -23,7 +23,8 @@ extern "C" {
#endif
extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
-extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
+ struct dive_site_table *sites, struct device_table *devices);
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int readfile(const char *filename, struct memblock *mem);
diff --git a/core/load-git.c b/core/load-git.c
index dc7a3e8dc..2f2da1efb 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -713,7 +713,12 @@ static void parse_dc_date(char *line, struct membuffer *str, struct git_parser_s
{ UNUSED(str); update_date(&state->active_dc->when, line); }
static void parse_dc_deviceid(char *line, struct membuffer *str, struct git_parser_state *state)
-{ UNUSED(str); set_dc_deviceid(state->active_dc, get_hex(line), &device_table); }
+{
+ UNUSED(str);
+ int id = get_hex(line);
+ set_dc_deviceid(state->active_dc, id, &device_table); // prefer already known serial/firmware over those from the loaded log
+ set_dc_deviceid(state->active_dc, id, state->devices);
+}
static void parse_dc_diveid(char *line, struct membuffer *str, struct git_parser_state *state)
{ UNUSED(str); state->active_dc->diveid = get_hex(line); }
@@ -984,9 +989,8 @@ static void parse_divecomputerid_keyvalue(void *_cid, const char *key, const cha
* it can have multiple strings (but see the tag parsing for another example of
* that) in addition to the non-string entries.
*/
-static void parse_settings_divecomputerid(char *line, struct membuffer *str, struct git_parser_state *_unused)
+static void parse_settings_divecomputerid(char *line, struct membuffer *str, struct git_parser_state *state)
{
- UNUSED(_unused);
struct divecomputerid id = { pop_cstring(str, line) };
/* Skip the '"' that stood for the model string */
@@ -1001,7 +1005,7 @@ static void parse_settings_divecomputerid(char *line, struct membuffer *str, str
break;
line = parse_keyvalue_entry(parse_divecomputerid_keyvalue, &id, line, str);
}
- create_device_node(&device_table, id.model, id.deviceid, id.serial, id.firmware, id.nickname);
+ create_device_node(state->devices, id.model, id.deviceid, id.serial, id.firmware, id.nickname);
}
static void parse_picture_filename(char *line, struct membuffer *str, struct git_parser_state *state)
@@ -1699,7 +1703,7 @@ static int parse_settings_entry(struct git_parser_state *state, const git_tree_e
git_blob *blob = git_tree_entry_blob(state->repo, entry);
if (!blob)
return report_error("Unable to read settings file");
- for_each_line(blob, settings_parser, NULL);
+ for_each_line(blob, settings_parser, state);
git_blob_free(blob);
return 0;
}
diff --git a/core/parse-xml.c b/core/parse-xml.c
index b5b66c181..b50a7b582 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -830,7 +830,8 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf,
if (MATCH("model", utf8_string, &dc->model))
return;
if (MATCH("deviceid", hex_value, &deviceid)) {
- set_dc_deviceid(dc, deviceid, &device_table);
+ set_dc_deviceid(dc, deviceid, &device_table); // prefer already known serial/firmware over those from the loaded log
+ set_dc_deviceid(dc, deviceid, state->devices);
return;
}
if (MATCH("diveid", hex_value, &dc->diveid))
diff --git a/core/parse.c b/core/parse.c
index a1b906bfb..8de69e499 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -201,7 +201,7 @@ void dc_settings_start(struct parser_state *state)
void dc_settings_end(struct parser_state *state)
{
- create_device_node(&device_table, state->cur_settings.dc.model, state->cur_settings.dc.deviceid, state->cur_settings.dc.serial_nr,
+ create_device_node(state->devices, state->cur_settings.dc.model, state->cur_settings.dc.deviceid, state->cur_settings.dc.serial_nr,
state->cur_settings.dc.firmware, state->cur_settings.dc.nickname);
reset_dc_settings(state);
}