diff --git a/core/dive.h b/core/dive.h index 0e0678c20..b3be9fa91 100644 --- a/core/dive.h +++ b/core/dive.h @@ -905,12 +905,15 @@ struct divedatapoint *create_dp(int time_incr, int depth, int cylinderid, int po #if DEBUG_PLAN void dump_plan(struct diveplan *diveplan); #endif -bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer); +struct decostop { + int depth; + int time; +}; +bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer); void calc_crushing_pressure(double pressure); void vpmb_start_gradient(); void clear_vpmb_state(); - void delete_single_dive(int idx); struct event *get_next_event(struct event *event, const char *name); diff --git a/core/planner.c b/core/planner.c index 61022d914..892000773 100644 --- a/core/planner.c +++ b/core/planner.c @@ -639,7 +639,16 @@ int wait_until(struct dive *dive, int clock, int min, int leap, int stepsize, in // Work out the stops. Return value is if there were any mandatory stops. -bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer) + +void printdecotable(struct decostop *table) +{ + while (table->depth) { + printf("depth=%d time=%d\n", table->depth, table->time); + ++table; + } +} + +bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer) { int bottom_depth; int bottom_gi; @@ -674,6 +683,7 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec int first_stop_depth = 0; int laststoptime = timestep; bool o2breaking = false; + int decostopcounter = 0; set_gf(diveplan->gflow, diveplan->gfhigh, prefs.gf_low_at_maxdepth); set_vpmb_conservatism(diveplan->vpmb_conservatism); @@ -830,6 +840,7 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec //CVA do { + decostopcounter = 0; is_final_plan = (decoMode() == BUEHLMANN) || (previous_deco_time - deco_time < 10); // CVA time converges if (deco_time != 10000000) vpmb_next_gradient(deco_time, diveplan->surface_pressure / 1000.0); @@ -975,6 +986,9 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec int new_clock = wait_until(dive, clock, clock, laststoptime * 2, timestep, depth, stoplevels[stopidx], avg_depth, bottom_time, &dive->cylinder[current_cylinder].gasmix, po2, diveplan->surface_pressure / 1000.0); laststoptime = new_clock - clock; + decostoptable[decostopcounter].depth = depth; + decostoptable[decostopcounter].time = laststoptime; + ++decostopcounter; /* Finish infinite deco */ if (clock >= 48 * 3600 && depth >= 6000) { error = LONGDECO; @@ -1031,6 +1045,7 @@ bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct dec deco_time = clock - bottom_time; } while (!is_final_plan); + decostoptable[decostopcounter].depth = 0; plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false); if (decoMode() == VPMB) { diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index a997c08a1..473076586 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -842,7 +842,8 @@ void DivePlannerPointsModel::createTemporaryPlan() dump_plan(&diveplan); #endif if (recalcQ() && !diveplan_empty(&diveplan)) { - plan(&diveplan, &displayed_dive, DECOTIMESTEP, &cache, isPlanner(), false); + struct decostop stoptable[60]; + plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false); emit calculatedPlanNotes(); } // throw away the cache @@ -878,7 +879,8 @@ void DivePlannerPointsModel::createPlan(bool replanCopy) setRecalc(oldRecalc); //TODO: C-based function here? - plan(&diveplan, &displayed_dive, DECOTIMESTEP, &cache, isPlanner(), true); + struct decostop stoptable[60]; + plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), true); free(cache); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on diff --git a/tests/testplan.cpp b/tests/testplan.cpp index c67b365e9..5dbcf89b9 100644 --- a/tests/testplan.cpp +++ b/tests/testplan.cpp @@ -10,7 +10,8 @@ #define DEBUG 1 // testing the dive plan algorithm -extern bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer); +struct decostop stoptable[60]; +extern bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer); extern pressure_t first_ceiling_pressure; @@ -364,7 +365,7 @@ void TestPlan::testMetric() struct diveplan testPlan = {}; setupPlan(&testPlan); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -404,7 +405,7 @@ void TestPlan::testImperial() struct diveplan testPlan = {}; setupPlan(&testPlan); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -444,7 +445,7 @@ void TestPlan::testVpmbMetric45m30minTx() setupPlanVpmb45m30mTx(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -474,7 +475,7 @@ void TestPlan::testVpmbMetric60m10minTx() setupPlanVpmb60m10mTx(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -504,7 +505,7 @@ void TestPlan::testVpmbMetric60m30minAir() setupPlanVpmb60m30minAir(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -534,7 +535,7 @@ void TestPlan::testVpmbMetric60m30minEan50() setupPlanVpmb60m30minEan50(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -570,7 +571,7 @@ void TestPlan::testVpmbMetric60m30minTx() setupPlanVpmb60m30minTx(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -606,7 +607,7 @@ void TestPlan::testVpmbMetric100m60min() setupPlanVpmb100m60min(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -648,7 +649,7 @@ void TestPlan::testVpmbMetricMultiLevelAir() setupPlanVpmbMultiLevelAir(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -678,7 +679,7 @@ void TestPlan::testVpmbMetric100m10min() setupPlanVpmb100m10min(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -724,7 +725,7 @@ void TestPlan::testVpmbMetricRepeat() setupPlanVpmb30m20min(&testPlan); setCurrentAppState("PlanDive"); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -744,7 +745,7 @@ void TestPlan::testVpmbMetricRepeat() int firstDiveRunTimeSeconds = displayed_dive.dc.duration.seconds; setupPlanVpmb100mTo70m30min(&testPlan); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes); @@ -780,7 +781,7 @@ void TestPlan::testVpmbMetricRepeat() QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 127u * 60u + 20u, 127u * 60u + 20u)); setupPlanVpmb30m20min(&testPlan); - plan(&testPlan, &displayed_dive, 60, &cache, 1, 0); + plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0); #if DEBUG free(displayed_dive.notes);