Fixed crash after profile is finished. Fixed error in UNIT GET output.

Thu, 17 Sep 2015 13:09:29 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 17 Sep 2015 13:09:29 +0200
changeset 398
efdfef1677d1
parent 397
00ca08f5a6f8
child 399
2f472a9081c9

Fixed crash after profile is finished. Fixed error in UNIT GET output.

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- 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);
--- 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;
 }
 

mercurial