Changeset 0e7d899 in subsurface


Ignore:
Timestamp:
Feb 9, 2017, 9:30:49 PM (7 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
9470278e
Parents:
e2bbd0c
git-author:
Linus Torvalds <torvalds@…> (02/08/17 15:00:04)
git-committer:
Dirk Hohndel <dirk@…> (02/09/17 21:30:49)
Message:

Make cylinder merging a bit more careful

This makes some further updates to the new cylinder merging code:

  • avoid re-using the cylinder if the usage type (OC/diluent/O2) is different between the two dives, even if the gasmix might be the same.
  • avoid re-using a cylinder if the user has manually added pressure data for it (and the pressures don't match)
  • when deciding to reuse a cylinder, make sure that we merge as much of the type information as makes sense.

This will potentially result in more cylinders that might need manual
cleanup, but at least we won't be throwing out user data. And in most
cases where merging happens, none of this is an issue (because the data
comes fresh from a dive computer, and won't have been manually edited to
trigger the new rules).

Signed-off-by: Linus Torvalds <torvalds@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/dive.c

    re2bbd0c r0e7d899  
    20162016}
    20172017
     2018static int pdiff(pressure_t a, pressure_t b)
     2019{
     2020        return a.mbar && b.mbar && a.mbar != b.mbar;
     2021}
     2022
     2023static int different_manual_pressures(cylinder_t *a, cylinder_t *b)
     2024{
     2025        return pdiff(a->start, b->start) || pdiff(a->end, b->end);
     2026}
     2027
    20182028/*
    20192029 * Can we find an exact match for a cylinder in another dive?
    20202030 * Take the "already matched" map into account, so that we
    20212031 * don't match multiple similar cylinders to one target.
     2032 *
     2033 * To match, the cylinders have to have the same gasmix and the
     2034 * same cylinder use (ie OC/Diluent/Oxygen), and if pressures
     2035 * have been added manually they need to match.
    20222036 */
    20232037static int match_cylinder(cylinder_t *cyl, struct dive *dive, unsigned int available)
     
    20322046                target = dive->cylinder + i;
    20332047                if (!same_gasmix(&cyl->gasmix, &target->gasmix))
     2048                        continue;
     2049                if (cyl->cylinder_use != target->cylinder_use)
     2050                        continue;
     2051                if (different_manual_pressures(cyl, target))
    20342052                        continue;
    20352053
     
    20592077
    20602078/*
     2079 * We matched things up so that they have the same gasmix and
     2080 * use, but we might want to fill in any missing cylinder details
     2081 * in 'a' if we had it from 'b'.
     2082 */
     2083static void merge_one_cylinder(cylinder_t *a, cylinder_t *b)
     2084{
     2085        if (!a->type.size.mliter)
     2086                a->type.size.mliter = b->type.size.mliter;
     2087        if (!a->type.workingpressure.mbar)
     2088                a->type.workingpressure.mbar = b->type.workingpressure.mbar;
     2089        if (!a->type.description && b->type.description)
     2090                a->type.description = strdup(b->type.description);
     2091        if (!a->start.mbar)
     2092                a->start.mbar = b->start.mbar;
     2093        if (!a->end.mbar)
     2094                a->end.mbar = b->end.mbar;
     2095}
     2096
     2097/*
    20612098 * Merging cylinder information is non-trivial, because the two dive computers
    20622099 * may have different ideas of what the different cylinder indexing is.
     
    20942131                /*
    20952132                 * If we had a successful match, we:
     2133                 *
     2134                 *  - try to merge individual cylinder data from both cases
    20962135                 *
    20972136                 *  - save that in the mapping table
     
    21022141                 *  - mark 'b' as needing renumbering if the index changed
    21032142                 */
     2143                merge_one_cylinder(a->cylinder + j, b->cylinder + i);
    21042144                mapping[i] = j;
    21052145                matched |= 1u << j;
Note: See TracChangeset for help on using the changeset viewer.