Added some ideas about profiles.

Thu, 07 Aug 2014 22:06:18 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 07 Aug 2014 22:06:18 +0200
changeset 194
9eaaba49450f
parent 193
4136193a0c22
child 195
b34a1b2421fb

Added some ideas about profiles.

thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/rdconfig.c	Thu Aug 07 21:19:30 2014 +0200
+++ b/thermferm/rdconfig.c	Thu Aug 07 22:06:18 2014 +0200
@@ -389,6 +389,10 @@
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		    return 1;
 		}
+		if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PAUSED", "%d", (unsigned int)tmp3->prof_paused)) < 0) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
 		if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_STATE", "%s", PROFSTATE[tmp3->prof_state] )) < 0) {
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		    return 1;
@@ -683,7 +687,7 @@
     unit->temp_set_max = 30.0;
     unit->idle_rangeH = 1.0;
     unit->idle_rangeL = -1.0;
-    unit->prof_started = (time_t)0;
+    unit->prof_started = unit->prof_paused = (time_t)0;
     unit->PID_err_old = unit->PID_I_err = 0.0;
 
     cur = cur->xmlChildrenNode;
@@ -806,6 +810,12 @@
 		unit->prof_started = ival;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROF_PAUSED"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->prof_paused = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROF_STATE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    for (i = 0; i < 4; i++) {
--- a/thermferm/server.c	Thu Aug 07 21:19:30 2014 +0200
+++ b/thermferm/server.c	Thu Aug 07 22:06:18 2014 +0200
@@ -910,7 +910,7 @@
 	unit->temp_set_max = 30.0;
 	unit->idle_rangeH = 1.0;
 	unit->idle_rangeL = -1.0;
-	unit->prof_started = (time_t)0;
+	unit->prof_started = unit->prof_paused = (time_t)0;
 	unit->PID_err_old = unit->PID_I_err = 0.0;
 
 	if (Config.units == NULL) {
--- a/thermferm/thermferm.c	Thu Aug 07 21:19:30 2014 +0200
+++ b/thermferm/thermferm.c	Thu Aug 07 22:06:18 2014 +0200
@@ -248,7 +248,10 @@
     char                buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40];
     time_t		now, last = (time_t)0;
     units_list		*unit;
+    profiles_list	*profile;
+    prof_step		*step;
     int			rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation;
+    int			run_seconds, run_minutes, run_hours;
     float		err = 0.0, sp, pv, P_err, D_err, Out;
 #ifdef HAVE_WIRINGPI_H
     struct tm		*tm;
@@ -421,11 +424,47 @@
 		     * unit->prof_started	- start time or 0 if not yet running.
 		     * unit->prof_state		- PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
 		     * unit->prof_target	- Calculated target temperature.
+		     * unit->prof_paused	- Internal pause counter.
 		     */
-		    // off.  Target is ??
-		    // pause Target is keep target.
-		    // run.  Target must be calculated using steps.
-		    // done. Target is last target.
+		    for (profile = Config.profiles; profile; profile = profile->next) {
+			if (strcmp(unit->profile, profile->uuid) == 0) {
+			    /*
+			     * Set initial temperature for this profile.
+			     */
+			    switch (unit->prof_state) {
+				case PROFILE_OFF:
+						/*
+						 * Setup initial temperature.
+						 */
+			    			unit->prof_target = profile->inittemp;
+						break;
+				case PROFILE_PAUSE:
+						/*
+						 * Keep current temperature, measure pause time.
+						 */
+						break;
+				case PROFILE_RUN:
+						/*
+						 * Calculate current profile step en desired temperature.
+						 * When all done, set state to PROFILE_DONE.
+						 */
+						run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
+						run_minutes = run_seconds / 60;
+						run_hours = run_minutes / 60;
+						if (debug)
+						    fprintf(stdout, "run_hours=%d minutes=%d seconds=%d\n", run_hours, run_minutes, run_seconds);
+
+						for (step = profile->steps; step; step = step->next) {
+						}
+						break;
+				case PROFILE_DONE:
+						/*
+						 * Keep this state.
+						 */
+						break;
+			    } /* switch */
+			}
+		    }
 		}
 
 		/*
--- a/thermferm/thermferm.h	Thu Aug 07 21:19:30 2014 +0200
+++ b/thermferm/thermferm.h	Thu Aug 07 22:06:18 2014 +0200
@@ -91,6 +91,7 @@
     time_t		prof_started;		/* Profile start time		*/
     int			prof_state;		/* Profile OFF|PAUSE|RUN|DONE	*/
     float		prof_target;		/* Profile current target temp	*/
+    time_t		prof_paused;		/* Profile total pause time	*/
     float		PID_I_err;		/* PID Intergal error		*/
     float		PID_err_old;		/* PID old error value		*/
 } units_list;

mercurial