# HG changeset patch # User Michiel Broek # Date 1442488169 -7200 # Node ID efdfef1677d1b360b51a2a5df5992864908dbaac # Parent 00ca08f5a6f8d78baef408e585ec5f2ced1a437f Fixed crash after profile is finished. Fixed error in UNIT GET output. diff -r 00ca08f5a6f8 -r efdfef1677d1 thermferm/server.c --- a/thermferm/server.c Wed Sep 16 22:05:05 2015 +0200 +++ b/thermferm/server.c Thu Sep 17 13:09:29 2015 +0200 @@ -2132,7 +2132,7 @@ } srv_send((char *)"PROF_TARGET_LO,%.3f", unit->prof_target_lo); srv_send((char *)"PROF_TARGET_HI,%.3f", unit->prof_target_hi); - srv_send((char *)"PROF_FRIDGE_MODE,%.3f", unit->prof_fridge_mode); + srv_send((char *)"PROF_FRIDGE_MODE,%d", unit->prof_fridge_mode); srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); diff -r 00ca08f5a6f8 -r efdfef1677d1 thermferm/thermferm.c --- a/thermferm/thermferm.c Wed Sep 16 22:05:05 2015 +0200 +++ b/thermferm/thermferm.c Thu Sep 17 13:09:29 2015 +0200 @@ -825,7 +825,7 @@ #else long t = 0; #endif - int current_step, valid_step, time_until_now; + int current_step, valid_step, time_until_now, previous_fridge_mode; float previous_target_lo, previous_target_hi; @@ -1142,11 +1142,18 @@ for (profile = Config.profiles; profile; profile = profile->next) { if (strcmp(unit->profile, profile->uuid) == 0) { + /* + * Safe defaults + */ + unit->prof_target_lo = profile->inittemp_lo; + unit->prof_target_hi = profile->inittemp_hi; + unit->prof_fridge_mode = 0; + switch (unit->prof_state) { case PROFILE_OFF: - unit->prof_target_lo = profile->inittemp_lo; - unit->prof_target_hi = profile->inittemp_hi; - unit->prof_fridge_mode = 0; +// unit->prof_target_lo = profile->inittemp_lo; +// unit->prof_target_hi = profile->inittemp_hi; +// unit->prof_fridge_mode = 0; unit->prof_percent = 0; break; case PROFILE_PAUSE: @@ -1162,6 +1169,7 @@ */ previous_target_lo = profile->inittemp_lo; previous_target_hi = profile->inittemp_hi; + previous_fridge_mode = profile->fridge_mode; time_until_now = current_step = 0; run_seconds = (int)(now - unit->prof_started - unit->prof_paused); run_minutes = run_seconds / 60; @@ -1227,6 +1235,7 @@ if ((run_hours - time_until_now) < step->steptime) { unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo)); unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi)); + // FIXME: shift fridge_mode if (debug) fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ", step->target_lo - previous_target_lo, @@ -1236,6 +1245,7 @@ } else { unit->prof_target_lo = step->target_lo; unit->prof_target_hi = step->target_hi; + unit->prof_fridge_mode = step->fridge_mode; if (debug) fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi); } @@ -1244,6 +1254,7 @@ time_until_now += step->steptime + step->resttime; previous_target_lo = step->target_lo; previous_target_hi = step->target_hi; + previous_fridge_mode = step->fridge_mode; } if (debug) fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds); @@ -1272,18 +1283,18 @@ */ previous_target_lo = profile->inittemp_lo; previous_target_hi = profile->inittemp_hi; - unit->prof_fridge_mode = profile->fridge_mode; + previous_fridge_mode = profile->fridge_mode; for (step = profile->steps; step; step = step->next) { - if (step->steptime == 0) + if ((step->steptime + step->resttime) == 0) break; previous_target_lo = step->target_lo; previous_target_hi = step->target_hi; - unit->prof_fridge_mode = step->fridge_mode; + previous_fridge_mode = step->fridge_mode; } unit->prof_target_lo = previous_target_lo; unit->prof_target_hi = previous_target_hi; - unit->prof_fridge_mode = step->fridge_mode; + unit->prof_fridge_mode = previous_fridge_mode; unit->prof_percent = 100; break; } /* switch */ @@ -1650,12 +1661,7 @@ #endif wrconfig(); - ulockprog((char *)"thermferm"); - - if (debug) - fprintf(stdout, "Goodbye\n"); - return 0; }