diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-23 10:25:31 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-23 12:55:33 -0800 |
commit | b6c9301e584722b9b46dffd4d759e8c60df520ad (patch) | |
tree | 2f963ec75672389692e532a8264dc83396900eb2 | |
parent | 3e5a508b15fe28083dfdf5a049d33e8769616395 (diff) | |
download | subsurface-b6c9301e584722b9b46dffd4d759e8c60df520ad.tar.gz |
Move more dive computer filled data to the divecomputer structure
This moves the fields 'duration', 'surfacetime', 'maxdepth',
'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure'
to the per-divecomputer data structure. They are filled in by the dive
computer, and normally not edited.
NOTE! All actual *use* of this data was then changed from dive->field to
dive->dc.field programmatically with a shell-script and sed, and the
result then edited for details. So while the XML save and restore code
has been updated, all the displaying etc will currently always just show
the first dive computer entry.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | deco.c | 2 | ||||
-rw-r--r-- | dive.c | 37 | ||||
-rw-r--r-- | dive.h | 22 | ||||
-rw-r--r-- | divelist.c | 46 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | info.c | 16 | ||||
-rw-r--r-- | libdivecomputer.c | 6 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | parse-xml.c | 76 | ||||
-rw-r--r-- | planner.c | 6 | ||||
-rw-r--r-- | print.c | 8 | ||||
-rw-r--r-- | profile.c | 14 | ||||
-rw-r--r-- | save-xml.c | 43 | ||||
-rw-r--r-- | statistics.c | 58 | ||||
-rw-r--r-- | uemis-downloader.c | 6 | ||||
-rw-r--r-- | uemis.c | 14 |
16 files changed, 183 insertions, 175 deletions
@@ -96,7 +96,7 @@ static double tissue_tolerance_calc(const struct dive *dive) double ret_tolerance_limit_ambient_pressure = 0.0; double gf_high = buehlmann_config.gf_high; double gf_low = buehlmann_config.gf_low; - double surface = dive->surface_pressure.mbar / 1000.0; + double surface = dive->dc.surface_pressure.mbar / 1000.0; double lowest_ceiling; for (ci = 0; ci < 16; ci++) @@ -516,9 +516,9 @@ struct dive *fixup_dive(struct dive *dive) } if (end < 0) { /* Assume an ascent/descent rate of 9 m/min */ - int depth = dive->maxdepth.mm; + int depth = dive->dc.maxdepth.mm; int asc_desc_time = depth*60/9000; - int duration = dive->duration.seconds; + int duration = dive->dc.duration.seconds; /* Some sanity checks against insane dives */ if (duration < 2) @@ -526,17 +526,17 @@ struct dive *fixup_dive(struct dive *dive) if (asc_desc_time * 2 >= duration) asc_desc_time = duration/2; - dive->meandepth.mm = depth*(duration-asc_desc_time)/duration; + dive->dc.meandepth.mm = depth*(duration-asc_desc_time)/duration; return dive; } - update_duration(&dive->duration, end - start); + update_duration(&dive->dc.duration, end - start); if (start != end) depthtime /= (end - start); - update_depth(&dive->meandepth, depthtime); - update_temperature(&dive->watertemp, mintemp); - update_depth(&dive->maxdepth, maxdepth); + update_depth(&dive->dc.meandepth, depthtime); + update_temperature(&dive->dc.watertemp, mintemp); + update_depth(&dive->dc.maxdepth, maxdepth); for (i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = dive->cylinder + i; @@ -596,9 +596,6 @@ struct dive *fixup_dive(struct dive *dive) #define MERGE_TXT(res, a, b, n) res->n = merge_text(a->n, b->n) #define MERGE_NONZERO(res, a, b, n) res->n = a->n ? a->n : b->n -#define MERGE_MAX_PREFDL(res, dl, a, b, n) res->n = (dl && dl->n) ? dl->n : MAX(a->n, b->n) -#define MERGE_MIN_PREFDL(res, dl, a, b, n) res->n = (dl && dl->n) ? dl->n : (a->n)?(b->n)?MIN(a->n, b->n):(a->n):(b->n) - static struct sample *add_sample(struct sample *sample, int time, struct divecomputer *dc) { struct sample *p = prepare_sample(dc); @@ -1219,9 +1216,9 @@ static int likely_same_dive(struct dive *a, struct dive *b) * Do some basic sanity testing of the values we * have filled in during 'fixup_dive()' */ - if (!similar(a->maxdepth.mm, b->maxdepth.mm, 1000) || - !similar(a->meandepth.mm, b->meandepth.mm, 1000) || - !similar(a->duration.seconds, b->duration.seconds, 5*60)) + if (!similar(a->dc.maxdepth.mm, b->dc.maxdepth.mm, 1000) || + !similar(a->dc.meandepth.mm, b->dc.meandepth.mm, 1000) || + !similar(a->dc.duration.seconds, b->dc.duration.seconds, 5*60)) return 0; /* See if we can get an exact match on the dive computer */ @@ -1233,7 +1230,7 @@ static int likely_same_dive(struct dive *a, struct dive *b) * Allow a time difference due to dive computer time * setting etc. Check if they overlap. */ - fuzz = max_time(a->duration, b->duration) / 2; + fuzz = max_time(a->dc.duration, b->dc.duration) / 2; if (fuzz < 60) fuzz = 60; @@ -1395,9 +1392,8 @@ static void interleave_dive_computers(struct divecomputer *res, do { struct divecomputer *match; + *res = *a; res->model = a->model ? strdup(a->model) : NULL; - res->deviceid = a->deviceid; - res->diveid = a->diveid; res->next = NULL; match = find_matching_computer(a, b); @@ -1488,16 +1484,9 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr MERGE_MAX(res, a, b, rating); MERGE_TXT(res, a, b, suit); MERGE_MAX(res, a, b, number); - MERGE_MAX_PREFDL(res, dl, a, b, maxdepth.mm); - res->meandepth.mm = 0; - MERGE_NONZERO(res, a, b, salinity); + res->dc.meandepth.mm = 0; MERGE_NONZERO(res, a, b, cns); MERGE_NONZERO(res, a, b, visibility); - MERGE_NONZERO(res, a, b, surface_pressure.mbar); - MERGE_MAX_PREFDL(res, dl, a, b, duration.seconds); - MERGE_MAX_PREFDL(res, dl, a, b, surfacetime.seconds); - MERGE_MAX_PREFDL(res, dl, a, b, airtemp.mkelvin); - MERGE_MIN_PREFDL(res, dl, a, b, watertemp.mkelvin); merge_equipment(res, a, b); if (dl) { /* If we prefer downloaded, do those first, and get rid of "might be same" computers */ @@ -284,6 +284,11 @@ struct event { */ struct divecomputer { timestamp_t when; + duration_t duration, surfacetime; + depth_t maxdepth, meandepth; + temperature_t airtemp, watertemp; + pressure_t surface_pressure; + int salinity; // kg per 10000 l const char *model; uint32_t deviceid, diveid; int samples, alloc_samples; @@ -327,12 +332,7 @@ struct dive { char *divemaster, *buddy; int rating; degrees_t latitude, longitude; - depth_t maxdepth, meandepth; - int salinity; // kg per 10000 l - duration_t duration, surfacetime; int visibility; /* 0 - 5 star rating */ - temperature_t airtemp, watertemp; - pressure_t surface_pressure; cylinder_t cylinder[MAX_CYLINDERS]; weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS]; char *suit; @@ -354,10 +354,10 @@ static inline int depth_to_mbar(int depth, struct dive *dive) { double specific_weight = 1.03 * 0.981; int surface_pressure = SURFACE_PRESSURE; - if (dive->salinity) - specific_weight = dive->salinity / 10000.0 * 0.981; - if (dive->surface_pressure.mbar) - surface_pressure = dive->surface_pressure.mbar; + if (dive->dc.salinity) + specific_weight = dive->dc.salinity / 10000.0 * 0.981; + if (dive->dc.surface_pressure.mbar) + surface_pressure = dive->dc.surface_pressure.mbar; return depth / 10.0 * specific_weight + surface_pressure + 0.5; } @@ -369,8 +369,8 @@ static inline int rel_mbar_to_depth(int mbar, struct dive *dive) { int cm; double specific_weight = 1.03 * 0.981; - if (dive->salinity) - specific_weight = dive->salinity / 10000.0 * 0.981; + if (dive->dc.salinity) + specific_weight = dive->dc.salinity / 10000.0 * 0.981; /* whole mbar gives us cm precision */ cm = mbar / specific_weight + 0.5; return cm * 10; diff --git a/divelist.c b/divelist.c index bd3897dca..8aa957d1e 100644 --- a/divelist.c +++ b/divelist.c @@ -55,7 +55,7 @@ enum { DIVE_NR, /* int: dive->nr */ DIVE_DATE, /* timestamp_t: dive->when */ DIVE_RATING, /* int: 0-5 stars */ - DIVE_DEPTH, /* int: dive->maxdepth in mm */ + DIVE_DEPTH, /* int: dive->dc.maxdepth in mm */ DIVE_DURATION, /* int: in seconds */ DIVE_TEMPERATURE, /* int: in mkelvin */ DIVE_TOTALWEIGHT, /* int: in grams */ @@ -808,11 +808,11 @@ static int calculate_sac(struct dive *dive, struct divecomputer *dc) airuse = calculate_airuse(dive); if (!airuse) return 0; - if (!dive->duration.seconds) + if (!dive->dc.duration.seconds) return 0; /* find and eliminate long surface intervals */ - duration = dive->duration.seconds; + duration = dive->dc.duration.seconds; for (i = 0; i < dc->samples; i++) { if (dc->sample[i].depth.mm < 100) { /* less than 10cm */ int end = i + 1; @@ -828,7 +828,7 @@ static int calculate_sac(struct dive *dive, struct divecomputer *dc) } } /* Mean pressure in bar (SAC calculations are in bar*l/min) */ - pressure = depth_to_mbar(dive->meandepth.mm, dive) / 1000.0; + pressure = depth_to_mbar(dive->dc.meandepth.mm, dive) / 1000.0; sac = airuse / pressure * 60 / duration; /* milliliters per minute.. */ @@ -888,17 +888,17 @@ double init_decompression(struct dive *dive) * for how far back we need to go */ if (dive->divetrip && pdive->divetrip != dive->divetrip) continue; - if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when) + if (!pdive || pdive->when > when || pdive->when + pdive->dc.duration.seconds + 48 * 60 * 60 < when) break; when = pdive->when; - lasttime = when + pdive->duration.seconds; + lasttime = when + pdive->dc.duration.seconds; } while (++i < divenr) { struct dive* pdive = get_dive(i); /* again skip dives from different trips */ if (dive->divetrip && dive->divetrip != pdive->divetrip) continue; - surface_pressure = (pdive->surface_pressure.mbar ? pdive->surface_pressure.mbar : SURFACE_PRESSURE) / 1000; + surface_pressure = (pdive->dc.surface_pressure.mbar ? pdive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000; if (!deco_init) { clear_deco(surface_pressure); deco_init = TRUE; @@ -913,7 +913,7 @@ double init_decompression(struct dive *dive) #endif if (pdive->when > lasttime) { surface_time = pdive->when - lasttime; - lasttime = pdive->when + pdive->duration.seconds; + lasttime = pdive->when + pdive->dc.duration.seconds; tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive); #if DECO_CALC_DEBUG & 2 printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); @@ -924,7 +924,7 @@ double init_decompression(struct dive *dive) /* add the final surface time */ if (lasttime && dive->when > lasttime) { surface_time = dive->when - lasttime; - surface_pressure = (dive->surface_pressure.mbar ? dive->surface_pressure.mbar : SURFACE_PRESSURE) / 1000; + surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000; tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0.0, dive); #if DECO_CALC_DEBUG & 2 printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); @@ -932,7 +932,7 @@ double init_decompression(struct dive *dive) #endif } if (!deco_init) { - double surface_pressure = (dive->surface_pressure.mbar ? dive->surface_pressure.mbar : SURFACE_PRESSURE) / 1000; + double surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000; clear_deco(surface_pressure); #if DECO_CALC_DEBUG & 2 printf("no previous dive\n"); @@ -1418,12 +1418,12 @@ static void fill_dive_list(void) DIVE_INDEX, i, DIVE_NR, dive->number, DIVE_DATE, dive->when, - DIVE_DEPTH, dive->maxdepth, - DIVE_DURATION, dive->duration.seconds, + DIVE_DEPTH, dive->dc.maxdepth, + DIVE_DURATION, dive->dc.duration.seconds, DIVE_LOCATION, dive->location, DIVE_LOC_ICON, icon, DIVE_RATING, dive->rating, - DIVE_TEMPERATURE, dive->watertemp.mkelvin, + DIVE_TEMPERATURE, dive->dc.watertemp.mkelvin, DIVE_SAC, 0, -1); gtk_tree_store_append(liststore, &iter, NULL); @@ -1431,12 +1431,12 @@ static void fill_dive_list(void) DIVE_INDEX, i, DIVE_NR, dive->number, DIVE_DATE, dive->when, - DIVE_DEPTH, dive->maxdepth, - DIVE_DURATION, dive->duration.seconds, + DIVE_DEPTH, dive->dc.maxdepth, + DIVE_DURATION, dive->dc.duration.seconds, DIVE_LOCATION, dive->location, DIVE_LOC_ICON, icon, DIVE_RATING, dive->rating, - DIVE_TEMPERATURE, dive->watertemp.mkelvin, + DIVE_TEMPERATURE, dive->dc.watertemp.mkelvin, DIVE_TOTALWEIGHT, 0, DIVE_SUIT, dive->suit, DIVE_SAC, 0, @@ -1748,9 +1748,9 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b) DIVE_NR, &store_dive.number, DIVE_DATE, &store_dive.when, DIVE_RATING, &store_dive.rating, - DIVE_DEPTH, &store_dive.maxdepth, - DIVE_DURATION, &store_dive.duration, - DIVE_TEMPERATURE, &store_dive.watertemp.mkelvin, + DIVE_DEPTH, &store_dive.dc.maxdepth, + DIVE_DURATION, &store_dive.dc.duration, + DIVE_TEMPERATURE, &store_dive.dc.watertemp.mkelvin, DIVE_TOTALWEIGHT, &totalweight, DIVE_SUIT, &store_dive.suit, DIVE_CYLINDER, &cylinder_text, @@ -1765,9 +1765,9 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b) DIVE_NR, store_dive.number, DIVE_DATE, store_dive.when, DIVE_RATING, store_dive.rating, - DIVE_DEPTH, store_dive.maxdepth, - DIVE_DURATION, store_dive.duration, - DIVE_TEMPERATURE, store_dive.watertemp.mkelvin, + DIVE_DEPTH, store_dive.dc.maxdepth, + DIVE_DURATION, store_dive.dc.duration, + DIVE_TEMPERATURE, store_dive.dc.watertemp.mkelvin, DIVE_TOTALWEIGHT, totalweight, DIVE_SUIT, store_dive.suit, DIVE_CYLINDER, cylinder_text, @@ -2436,7 +2436,7 @@ static void add_dive_merge_label(int idx, GtkMenuShell *menu) return; /* .. and if the surface interval is excessive, you must be kidding us */ - if (b->when > a->when + a->duration.seconds + 30*60) + if (b->when > a->when + a->dc.duration.seconds + 30*60) return; /* If so, we can add a "merge dive" menu entry */ @@ -210,7 +210,7 @@ static int try_to_open_csv(const char *filename, struct memblock *mem, enum csv_ finish_sample(&dive->dc); time++; - dive->duration.seconds = time; + dive->dc.duration.seconds = time; if (*end != ',') break; p = end+1; @@ -460,8 +460,8 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc default: mkelvin = 0; } - if (mkelvin != dive->airtemp.mkelvin) { - dive->airtemp.mkelvin = mkelvin; + if (mkelvin != dive->dc.airtemp.mkelvin) { + dive->dc.airtemp.mkelvin = mkelvin; changed = 1; } } @@ -532,9 +532,9 @@ static void dive_info_widget(GtkWidget *box, struct dive *dive, struct dive_info info->viz = text_entry(hbox, _("Visibility"), star_list, star_strings[dive->visibility]); - value = get_temp_units(dive->airtemp.mkelvin, &unit); + value = get_temp_units(dive->dc.airtemp.mkelvin, &unit); snprintf(buffer, sizeof(buffer), _("Air Temp in %s"), unit); - if (dive->airtemp.mkelvin) + if (dive->dc.airtemp.mkelvin) snprintf(airtemp, sizeof(airtemp), "%.1f", value); else airtemp[0] = '\0'; @@ -873,7 +873,7 @@ static timestamp_t dive_time_widget(struct dive *dive) */ if (amount_selected == 1) { timestamp_t when = current_dive->when; - when += current_dive->duration.seconds; + when += current_dive->dc.duration.seconds; when += 60*60; utc_mkdate(when, &tm); time = &tm; @@ -923,12 +923,12 @@ static timestamp_t dive_time_widget(struct dive *dive) val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth)); if (prefs.units.length == FEET) { - dive->maxdepth.mm = feet_to_mm(val); + dive->dc.maxdepth.mm = feet_to_mm(val); } else { - dive->maxdepth.mm = val * 1000 + 0.5; + dive->dc.maxdepth.mm = val * 1000 + 0.5; } - dive->duration.seconds = gtk_spin_button_get_value(GTK_SPIN_BUTTON(duration))*60; + dive->dc.duration.seconds = gtk_spin_button_get_value(GTK_SPIN_BUTTON(duration))*60; gtk_widget_destroy(dialog); dive->when = utc_mktime(&tm); diff --git a/libdivecomputer.c b/libdivecomputer.c index cb4789f49..8345c859f 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -441,7 +441,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, dc_parser_destroy(parser); return rc; } - dive->duration.seconds = divetime; + dive->dc.duration.seconds = divetime; // Parse the maxdepth. double maxdepth = 0.0; @@ -451,7 +451,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, dc_parser_destroy(parser); return rc; } - dive->maxdepth.mm = maxdepth * 1000 + 0.5; + dive->dc.maxdepth.mm = maxdepth * 1000 + 0.5; // Parse the gas mixes. unsigned int ngases = 0; @@ -497,7 +497,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, /* Various libdivecomputer interface fixups */ if (first_temp_is_air && dive->dc.samples) { - dive->airtemp = dive->dc.sample[0].temperature; + dive->dc.airtemp = dive->dc.sample[0].temperature; dive->dc.sample[0].temperature.mkelvin = 0; } @@ -165,7 +165,7 @@ void report_dives(gboolean is_imported, gboolean prefer_imported) struct dive *dive = pp[1]; struct dive *merged; - if (prev->when + prev->duration.seconds < dive->when) + if (prev->when + prev->dc.duration.seconds < dive->when) continue; merged = try_to_merge(prev, dive, prefer_imported); diff --git a/parse-xml.c b/parse-xml.c index 35ebf0446..0aa4b7bf0 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -657,6 +657,40 @@ static struct divecomputer *get_dc(void) return cur_dc ? : &cur_dive->dc; } +static int match_dc_data_fields(struct divecomputer *dc, const char *name, int len, char *buf) +{ + if (MATCH(".maxdepth", depth, &dc->maxdepth)) + return 1; + if (MATCH(".meandepth", depth, &dc->meandepth)) + return 1; + if (MATCH(".depth.max", depth, &dc->maxdepth)) + return 1; + if (MATCH(".depth.mean", depth, &dc->meandepth)) + return 1; + if (MATCH(".duration", duration, &dc->duration)) + return 1; + if (MATCH(".divetime", duration, &dc->duration)) + return 1; + if (MATCH(".divetimesec", duration, &dc->duration)) + return 1; + if (MATCH(".surfacetime", duration, &dc->surfacetime)) + return 1; + if (MATCH(".airtemp", temperature, &dc->airtemp)) + return 1; + if (MATCH(".watertemp", temperature, &dc->watertemp)) + return 1; + if (MATCH(".temperature.air", temperature, &dc->airtemp)) + return 1; + if (MATCH(".temperature.water", temperature, &dc->watertemp)) + return 1; + if (MATCH(".surface.pressure", pressure, &dc->surface_pressure)) + return 1; + if (MATCH(".water.salinity", salinity, &dc->salinity)) + return 1; + + return 0; +} + /* We're in the top-level dive xml. Try to convert whatever value to a dive value */ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf) { @@ -675,6 +709,9 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf) if (MATCH(".diveid", hex_value, &dc->diveid)) return; + if (match_dc_data_fields(dc, name, len, buf)) + return; + nonmatch("divecomputer", name, buf); } @@ -797,7 +834,7 @@ static int divinglog_dive_match(struct dive *dive, const char *name, int len, ch { return MATCH(".divedate", divedate, &dive->when) || MATCH(".entrytime", divetime, &dive->when) || - MATCH(".depth", depth, &dive->maxdepth) || + MATCH(".depth", depth, &dive->dc.maxdepth) || MATCH(".tanktype", utf8_string, &dive->cylinder[0].type.description) || MATCH(".tanksize", cylindersize, &dive->cylinder[0].type.size) || MATCH(".presw", pressure, &dive->cylinder[0].type.workingpressure) || @@ -856,8 +893,8 @@ success: static int uddf_dive_match(struct dive *dive, const char *name, int len, char *buf) { return MATCH(".datetime", uddf_datetime, &dive->when) || - MATCH(".diveduration", duration, &dive->duration) || - MATCH(".greatestdepth", depth, &dive->maxdepth) || + MATCH(".diveduration", duration, &dive->dc.duration) || + MATCH(".greatestdepth", depth, &dive->dc.maxdepth) || 0; } @@ -950,34 +987,13 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf) return; if (MATCH(".datetime", divedatetime, &dive->when)) return; - if (MATCH(".maxdepth", depth, &dive->maxdepth)) - return; - if (MATCH(".meandepth", depth, &dive->meandepth)) - return; - if (MATCH(".depth.max", depth, &dive->maxdepth)) - return; - if (MATCH(".depth.mean", depth, &dive->meandepth)) - return; - if (MATCH(".duration", duration, &dive->duration)) - return; - if (MATCH(".divetime", duration, &dive->duration)) - return; - if (MATCH(".divetimesec", duration, &dive->duration)) - return; - if (MATCH(".surfacetime", duration, &dive->surfacetime)) - return; - if (MATCH(".airtemp", temperature, &dive->airtemp)) - return; - if (MATCH(".watertemp", temperature, &dive->watertemp)) - return; - if (MATCH(".temperature.air", temperature, &dive->airtemp)) - return; - if (MATCH(".temperature.water", temperature, &dive->watertemp)) - return; - if (MATCH(".surface.pressure", pressure, &dive->surface_pressure)) - return; - if (MATCH(".water.salinity", salinity, &dive->salinity)) + /* + * Legacy format note: per-dive depths and duration get saved + * in the first dive computer entry + */ + if (match_dc_data_fields(&dive->dc, name, len, buf)) return; + if (MATCH(".cylinderstartpressure", pressure, &dive->cylinder[0].start)) return; if (MATCH(".cylinderendpressure", pressure, &dive->cylinder[0].end)) @@ -34,7 +34,7 @@ void dump_plan(struct diveplan *diveplan) printf("\nDiveplan @ %04d-%02d-%02d %02d:%02d:%02d (surfpres %dmbar):\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, - diveplan->surface_pressure); + diveplan->dc.surface_pressure); dp = diveplan->dp; while (dp) { printf("\t%3u:%02u: %dmm gas: %d o2 %d h2\n", FRACTION(dp->time, 60), dp->depth, dp->o2, dp->he); @@ -130,7 +130,7 @@ int time_at_last_depth(struct dive *dive, int next_stop, char **cached_data_p) if (!dive) return 0; - surface_pressure = dive->surface_pressure.mbar / 1000.0; + surface_pressure = dive->dc.surface_pressure.mbar / 1000.0; tissue_tolerance = tissue_at_end(dive, cached_data_p); sample = &dive->dc.sample[dive->dc.samples - 1]; depth = sample->depth.mm; @@ -184,7 +184,7 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan) #endif dive = alloc_dive(); dive->when = diveplan->when; - dive->surface_pressure.mbar = diveplan->surface_pressure; + dive->dc.surface_pressure.mbar = diveplan->surface_pressure; dc = &dive->dc; dc->model = strdup("Simulated Dive"); dp = diveplan->dp; @@ -98,11 +98,11 @@ static void show_dive_header(struct dive *dive, cairo_t *cr, double w, people = ""; } - depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit); + depth = get_depth_units(dive->dc.maxdepth.mm, &decimals, &unit); snprintf(buffer, sizeof(buffer), _("Max depth: %.*f %s\nDuration: %d min\n%s"), decimals, depth, unit, - (dive->duration.seconds+59) / 60, + (dive->dc.duration.seconds+59) / 60, people); set_font(layout, font, FONT_SMALL, PANGO_ALIGN_RIGHT); @@ -591,7 +591,7 @@ static void show_dive_table(struct dive *dive, cairo_t *cr, double w, curwidth = curwidth + colwidth; // Col 3: Depth - depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit); + depth = get_depth_units(dive->dc.maxdepth.mm, &decimals, &unit); len = snprintf(buffer, sizeof(buffer), "%.*f %s", decimals, depth, unit); cairo_move_to(cr, curwidth / PANGO_SCALE, 0); @@ -603,7 +603,7 @@ static void show_dive_table(struct dive *dive, cairo_t *cr, double w, // Col 4: Time len = snprintf(buffer, sizeof(buffer), - _("%d min"),(dive->duration.seconds+59) / 60); + _("%d min"),(dive->dc.duration.seconds+59) / 60); cairo_move_to(cr, curwidth / PANGO_SCALE, 0); pango_layout_set_width(layout, colwidth/ (double) 2); pango_layout_set_text(layout, buffer, len); @@ -1540,8 +1540,8 @@ static void calculate_max_limits(struct dive *dive, struct divecomputer *dc, str memset(pi, 0, sizeof(*pi)); /* This should probably have been per-dive-computer */ - maxdepth = dive->maxdepth.mm; - mintemp = maxtemp = dive->watertemp.mkelvin; + maxdepth = dive->dc.maxdepth.mm; + mintemp = maxtemp = dive->dc.watertemp.mkelvin; /* Get the per-cylinder maximum pressure if they are manual */ for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { @@ -1815,7 +1815,7 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d { int i; double amb_pressure; - double surface_pressure = (dive->surface_pressure.mbar ? dive->surface_pressure.mbar : SURFACE_PRESSURE) / 1000.0; + double surface_pressure = (dive->dc.surface_pressure.mbar ? dive->dc.surface_pressure.mbar : SURFACE_PRESSURE) / 1000.0; for (i = 1; i < pi->nr; i++) { int fo2, fhe, j, t0, t1; @@ -1925,7 +1925,7 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer /* Then, calculate partial pressures and deco information */ calculate_deco_information(dive, dc, pi); - pi->meandepth = dive->meandepth.mm; + pi->meandepth = dive->dc.meandepth.mm; if (0) /* awesome for debugging - not useful otherwise */ dump_pi(pi); @@ -1991,9 +1991,9 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) /* The dive has no samples, so create a few fake ones. This assumes an ascent/descent rate of 9 m/min, which is just below the limit for FAST. */ - int duration = dive->duration.seconds; - int maxdepth = dive->maxdepth.mm; - int asc_desc_time = dive->maxdepth.mm*60/9000; + int duration = dive->dc.duration.seconds; + int maxdepth = dive->dc.maxdepth.mm; + int asc_desc_time = dive->dc.maxdepth.mm*60/9000; if (asc_desc_time * 2 >= duration) asc_desc_time = duration / 2; fake[1].time.seconds = asc_desc_time; diff --git a/save-xml.c b/save-xml.c index 0fa0aee2a..690a92777 100644 --- a/save-xml.c +++ b/save-xml.c @@ -138,44 +138,44 @@ static void show_utf8(FILE *f, const char *text, const char *pre, const char *po fputs(post, f); } -static void save_depths(FILE *f, struct dive *dive) +static void save_depths(FILE *f, struct divecomputer *dc) { /* What's the point of this dive entry again? */ - if (!dive->maxdepth.mm && !dive->meandepth.mm) + if (!dc->maxdepth.mm && !dc->meandepth.mm) return; fputs(" <depth", f); - show_depth(f, dive->maxdepth, " max='", "'"); - show_depth(f, dive->meandepth, " mean='", "'"); + show_depth(f, dc->maxdepth, " max='", "'"); + show_depth(f, dc->meandepth, " mean='", "'"); fputs(" />\n", f); } -static void save_temperatures(FILE *f, struct dive *dive) +static void save_temperatures(FILE *f, struct divecomputer *dc) { - if (!dive->airtemp.mkelvin && !dive->watertemp.mkelvin) + if (!dc->airtemp.mkelvin && !dc->watertemp.mkelvin) return; fputs(" <temperature", f); - show_temperature(f, dive->airtemp, " air='", "'"); - show_temperature(f, dive->watertemp, " water='", "'"); + show_temperature(f, dc->airtemp, " air='", "'"); + show_temperature(f, dc->watertemp, " water='", "'"); fputs(" />\n", f); } -static void save_airpressure(FILE *f, struct dive *dive) +static void save_airpressure(FILE *f, struct divecomputer *dc) { - if (!dive->surface_pressure.mbar) + if (!dc->surface_pressure.mbar) return; fputs(" <surface", f); - show_pressure(f, dive->surface_pressure, " pressure='", "'"); + show_pressure(f, dc->surface_pressure, " pressure='", "'"); fputs(" />\n", f); } -static void save_salinity(FILE *f, struct dive *dive) +static void save_salinity(FILE *f, struct divecomputer *dc) { /* only save if we have a value that isn't the default of sea water */ - if (!dive->salinity || dive->salinity == 10300) + if (!dc->salinity || dc->salinity == 10300) return; fputs(" <water", f); - show_salinity(f, dive->salinity, " salinity='", "'"); + show_salinity(f, dc->salinity, " salinity='", "'"); fputs(" />\n", f); } @@ -240,11 +240,6 @@ static void show_location(FILE *f, struct dive *dive) static void save_overview(FILE *f, struct dive *dive) { - save_depths(f, dive); - save_temperatures(f, dive); - save_airpressure(f, dive); - save_salinity(f, dive); - show_duration(f, dive->surfacetime, " <surfacetime>", "</surfacetime>\n"); show_location(f, dive); show_utf8(f, dive->divemaster, " <divemaster>","</divemaster>\n", 0); show_utf8(f, dive->buddy, " <buddy>","</buddy>\n", 0); @@ -419,7 +414,15 @@ static void save_dc(FILE *f, struct dive *dive, struct divecomputer *dc) fprintf(f, " diveid='%08x'", dc->diveid); if (dc->when && dc->when != dive->when) show_date(f, dc->when); + if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) + show_duration(f, dc->duration, " duration='", "'"); fprintf(f, ">\n"); + save_depths(f, dc); + save_temperatures(f, dc); + save_airpressure(f, dc); + save_salinity(f, dc); + show_duration(f, dc->surfacetime, " <surfacetime>", "</surfacetime>\n"); + save_events(f, dc->events); save_samples(f, dc->samples, dc->sample); @@ -441,7 +444,7 @@ void save_dive(FILE *f, struct dive *dive) fprintf(f, " visibility='%d'", dive->visibility); show_date(f, dive->when); fprintf(f, " duration='%u:%02u min'>\n", - FRACTION(dive->duration.seconds, 60)); + FRACTION(dive->dc.duration.seconds, 60)); save_overview(f, dive); save_cylinder_info(f, dive); save_weightsystem_info(f, dive); diff --git a/statistics.c b/statistics.c index 472ca783c..1050b39ad 100644 --- a/statistics.c +++ b/statistics.c @@ -113,33 +113,33 @@ static void process_dive(struct dive *dp, stats_t *stats) const char *unit; old_tt = stats->total_time.seconds; - stats->total_time.seconds += dp->duration.seconds; - if (dp->duration.seconds > stats->longest_time.seconds) - stats->longest_time.seconds = dp->duration.seconds; - if (stats->shortest_time.seconds == 0 || dp->duration.seconds < stats->shortest_time.seconds) - stats->shortest_time.seconds = dp->duration.seconds; - if (dp->maxdepth.mm > stats->max_depth.mm) - stats->max_depth.mm = dp->maxdepth.mm; - if (stats->min_depth.mm == 0 || dp->maxdepth.mm < stats->min_depth.mm) - stats->min_depth.mm = dp->maxdepth.mm; - if (dp->watertemp.mkelvin) { - if (stats->min_temp == 0 || dp->watertemp.mkelvin < stats->min_temp) - stats->min_temp = dp->watertemp.mkelvin; - if (dp->watertemp.mkelvin > stats->max_temp) - stats->max_temp = dp->watertemp.mkelvin; - stats->combined_temp += get_temp_units(dp->watertemp.mkelvin, &unit); + stats->total_time.seconds += dp->dc.duration.seconds; + if (dp->dc.duration.seconds > stats->longest_time.seconds) + stats->longest_time.seconds = dp->dc.duration.seconds; + if (stats->shortest_time.seconds == 0 || dp->dc.duration.seconds < stats->shortest_time.seconds) + stats->shortest_time.seconds = dp->dc.duration.seconds; + if (dp->dc.maxdepth.mm > stats->max_depth.mm) + stats->max_depth.mm = dp->dc.maxdepth.mm; + if (stats->min_depth.mm == 0 || dp->dc.maxdepth.mm < stats->min_depth.mm) + stats->min_depth.mm = dp->dc.maxdepth.mm; + if (dp->dc.watertemp.mkelvin) { + if (stats->min_temp == 0 || dp->dc.watertemp.mkelvin < stats->min_temp) + stats->min_temp = dp->dc.watertemp.mkelvin; + if (dp->dc.watertemp.mkelvin > stats->max_temp) + stats->max_temp = dp->dc.watertemp.mkelvin; + stats->combined_temp += get_temp_units(dp->dc.watertemp.mkelvin, &unit); stats->combined_count++; } /* Maybe we should drop zero-duration dives */ - if (!dp->duration.seconds) + if (!dp->dc.duration.seconds) return; stats->avg_depth.mm = (1.0 * old_tt * stats->avg_depth.mm + - dp->duration.seconds * dp->meandepth.mm) / stats->total_time.seconds; + dp->dc.duration.seconds * dp->dc.meandepth.mm) / stats->total_time.seconds; if (dp->sac > 2800) { /* less than .1 cuft/min (2800ml/min) is bogus */ - sac_time = stats->total_sac_time + dp->duration.seconds; + sac_time = stats->total_sac_time + dp->dc.duration.seconds; stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter + - dp->duration.seconds * dp->sac) / sac_time ; + dp->dc.duration.seconds * dp->sac) / sac_time ; if (dp->sac > stats->max_sac.mliter) stats->max_sac.mliter = dp->sac; if (stats->min_sac.mliter == 0 || dp->sac < stats->min_sac.mliter) @@ -403,8 +403,8 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive) *prev_dive = NULL; memset(&stats, 0, sizeof(stats)); if (dive_table.nr > 0) { - stats.shortest_time.seconds = dive_table.dives[0]->duration.seconds; - stats.min_depth.mm = dive_table.dives[0]->maxdepth.mm; + stats.shortest_time.seconds = dive_table.dives[0]->dc.duration.seconds; + stats.min_depth.mm = dive_table.dives[0]->dc.maxdepth.mm; stats.selection_size = dive_table.nr; } @@ -537,24 +537,24 @@ static void show_single_dive_stats(struct dive *dive) tm.tm_hour, tm.tm_min); set_label(single_w.date, buf); - set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60); + set_label(single_w.dive_time, _("%d min"), (dive->dc.duration.seconds + 30) / 60); if (prev_dive) set_label(single_w.surf_intv, - get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); + get_time_string(dive->when - (prev_dive->when + prev_dive->dc.duration.seconds), 4)); else set_label(single_w.surf_intv, _("unknown")); - value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); + value = get_depth_units(dive->dc.maxdepth.mm, &decimals, &unit); set_label(single_w.max_depth, "%.*f %s", decimals, value, unit); - value = get_depth_units(dive->meandepth.mm, &decimals, &unit); + value = get_depth_units(dive->dc.meandepth.mm, &decimals, &unit); set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit); set_label(single_w.viz, star_strings[dive->visibility]); - if (dive->watertemp.mkelvin) { - value = get_temp_units(dive->watertemp.mkelvin, &unit); + if (dive->dc.watertemp.mkelvin) { + value = get_temp_units(dive->dc.watertemp.mkelvin, &unit); set_label(single_w.water_temp, "%.1f %s", value, unit); } else set_label(single_w.water_temp, ""); - if (dive->airtemp.mkelvin) { - value = get_temp_units(dive->airtemp.mkelvin, &unit); + if (dive->dc.airtemp.mkelvin) { + value = get_temp_units(dive->dc.airtemp.mkelvin, &unit); set_label(single_w.air_temp, "%.1f %s", value, unit); } else set_label(single_w.air_temp, ""); diff --git a/uemis-downloader.c b/uemis-downloader.c index 631bb23f1..6a20a0af1 100644 --- a/uemis-downloader.c +++ b/uemis-downloader.c @@ -598,13 +598,13 @@ static void parse_tag(struct dive *dive, char *tag, char *val) if (! strcmp(tag, "date")) uemis_ts(val, &dive->when); else if (!strcmp(tag, "duration")) - uemis_duration(val, &dive->duration); + uemis_duration(val, &dive->dc.duration); else if (!strcmp(tag, "depth")) - uemis_depth(val, &dive->maxdepth); + uemis_depth(val, &dive->dc.maxdepth); else if (!strcmp(tag, "file_content")) uemis_parse_divelog_binary(val, dive); else if (!strcmp(tag, "altitude")) - uemis_get_index(val, &dive->surface_pressure.mbar); + uemis_get_index(val, &dive->dc.surface_pressure.mbar); else if (!strcmp(tag, "f32Weight")) uemis_get_weight(val, &dive->weightsystem[0], dive->dc.diveid); else if (!strcmp(tag, "notes")) @@ -276,7 +276,7 @@ static void uemis_event(struct dive *dive, struct divecomputer *dc, struct sampl } #if UEMIS_DEBUG & 32 printf("%dm:%ds: p_amb_tol:%d surface:%d holdtime:%d holddepth:%d/%d ---> stopdepth:%d stoptime:%d ndl:%d\n", - sample->time.seconds / 60, sample->time.seconds % 60, u_sample->p_amb_tol, dive->surface_pressure.mbar, + sample->time.seconds / 60, sample->time.seconds % 60, u_sample->p_amb_tol, dive->dc.surface_pressure.mbar, u_sample->hold_time, u_sample->hold_depth, stopdepth, sample->stopdepth.mm, sample->stoptime.seconds, sample->ndl.seconds); #endif } @@ -297,12 +297,12 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { datalen = uemis_convert_base64(base64, &data); - dive->airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150; - dive->surface_pressure.mbar = *(uint16_t *)(data + 43); + dive->dc.airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150; + dive->dc.surface_pressure.mbar = *(uint16_t *)(data + 43); if (*(uint8_t *)(data + 19)) - dive->salinity = 10300; /* avg grams per 10l sea water */ + dive->dc.salinity = 10300; /* avg grams per 10l sea water */ else - dive->salinity = 10000; /* grams per 10l fresh water */ + dive->dc.salinity = 10000; /* grams per 10l fresh water */ /* this will allow us to find the last dive read so far from this computer */ dc->model = strdup("Uemis Zurich"); @@ -346,7 +346,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { /* the SDA usually records more samples after the end of the dive -- * we want to discard those, but not cut the dive short; sadly the dive * duration in the header is a) in minutes and b) up to 3 minutes short */ - if (u_sample->dive_time > dive->duration.seconds + 180) + if (u_sample->dive_time > dive->dc.duration.seconds + 180) break; if (u_sample->active_tank != active) { active = u_sample->active_tank; @@ -365,6 +365,6 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { i += 0x25; u_sample++; } - dive->duration.seconds = sample->time.seconds - 1; + dive->dc.duration.seconds = sample->time.seconds - 1; return; } |