Subversion Repositories heating

Rev

Rev 17 | Rev 46 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 andreas 1
/*
2
 * Copyright (C) 2015 by Andreas Theofilu. All rights reserved!
3
 *
4
 * All rights reserved. No warranty, explicit or implicit, provided.
5
 *
6
 * NOTICE:  All information contained herein is, and remains
7
 * the property of Andreas Theofilu and his suppliers, if any.
8
 * The intellectual and technical concepts contained
9
 * herein are proprietary to Andreas Theofilu and its suppliers and
10
 * may be covered by European and Foreign Patents, patents in process,
11
 * and are protected by trade secret or copyright law.
12
 * Dissemination of this information or reproduction of this material
13
 * is strictly forbidden unless prior written permission is obtained
14
 * from Andreas Theofilu.
15
 * 
16
 * Author: Andreas Theofilu <andreas@theosys.at>
17
 */
18
#ifndef __HEATING_H__
19
#define __HEATING_H__
20
 
21
#include "helper.h"
5 andreas 22
#include "temperature.h"
3 andreas 23
 
24
/*
25
 * Purpose:
26
 * There can be an unlimited number of rooms defined. For every room you can
27
 * define different temperatures. The type "HSTAT" defines the actual status
28
 * of the room.
29
 * 
30
 * Status NORMAL: This is the normal operating of the heating during the day.
31
 *                The heating will hold the temperature set in "soll"
32
 * 
33
 * Status NIGHT:  This is the mode for the night. the heating will hold the
34
 *                temperature set in "night".
35
 * 
36
 * Status OFF:    This indicates, the heating for a particular room was switched
37
 *                off. In this case the heating makes sure, that the temperature
38
 *                will not fall beyond the temperature set in "minimal".
39
 * 
40
 * There are global settingsto sitch the heating off or on. If the heating was
41
 * set globaly off, a globaly defined minimal temperature will be hold.
42
 * 
43
 * If the heating is switched on, it operated individually for every room and
44
 * tries to hold the temperature set individual in a room.
45
 */
5 andreas 46
class heating : private temperature
3 andreas 47
{
48
	public:
49
		enum HSTAT
50
		{
51
			NORMAL,
52
			NIGHT,
53
			OFF
54
		};
55
 
8 andreas 56
		typedef struct HTABLE
57
		{
58
			double tempDifferOut;	// Difference of outside temperature to soll temperature
59
			double tempDifferIn;	// Difference off current temperature in the room to soll temperature
60
			time_t heat;			// time in seconds needed to heat up to soll temperature
61
			time_t start;			// start time of heating in case we've no time already
62
			HTABLE *next;			// Pointer to next element of table
63
		}HTABLE;
64
 
3 andreas 65
		typedef struct HCONF
66
		{
4 andreas 67
			// By config file set variables
3 andreas 68
			char rname[32];
69
			int rnum;
70
			int tempsensor;			// Number of temperature sensor (depends on method of how temperature is meassured)
71
			int gpio;				// GPIO number where relais for valve is connected
72
			double soll;			// The temperature that should be
73
			double night;			// The reduced temperature for night
74
			double minimal;			// The minimal temperature
4 andreas 75
			time_t start;			// The time the heating should have reached the "soll" temperature (if normal is set)
76
			time_t end;				// The time the heating should end normal mode and start "night" mode.
35 andreas 77
			time_t wstart;			// The time the work day start and heating is reduced to night mode (if normal is set)
78
			time_t wend;			// The time the heating should start normal mode again.
4 andreas 79
			// Internal used variables
80
			double ist;				// The real temperature
3 andreas 81
			HSTAT status;			// The status of the room
82
			bool valve;				// true = valve is open
8 andreas 83
			HTABLE *hTable;			// Pointer to heating table
3 andreas 84
			HCONF *next;
85
		}HCONF;
86
 
87
	public:
4 andreas 88
		heating();
89
		~heating();
3 andreas 90
 
5 andreas 91
		void run();										// Ask for actual temperature in every room all the time
92
		void stopRun() { rstop = true; }				// Stop asking for temperature
93
		bool statusRun()  { return rrun; }				// true = temperature request is running
4 andreas 94
 
5 andreas 95
		time_t strToTime(char *str);					// Convert a time string into a time value
96
		bool isInitialized() { return initialized; }	// Is true as soon as the class was initialized successfuly
97
		double incSoll(int room);						// Increment soll by 1/2 °C
98
		double decSoll(int room);						// Decrement soll by 1/2 °C
9 andreas 99
		void setSoll(int room, double val);				// Set temperature soll in room "room"
5 andreas 100
		void setNight(int room, double val);			// Set temperature for night mode
101
		void setMinimal(int room, double val);			// Set temperature for off mode. This is a minimal temperature.
102
		bool switchOnOff(bool what);					// false = off; this is the off mode with minimal temperature. true = normal operating
103
		bool getOnOff() { return onoff; }				// Is the heating activated? true = yes
104
		double getGlbNight() { return glb_night; }		// Retrieve the global temperature for night mode
105
		double getGlbMinimal() { return glb_minimal; }	// Retrieve the global temperature for off mode
106
		double getNight(int room);						// Retrieve the optional temperature in a particular room for night mode
107
		double getMinimal(int room);					// Retrieve the optional temperature in a particular room for off mode
108
		void setHandle(int fd);							// Add the handle to a connected client to return messages directly
109
		void removeHandle(int fd);						// Remove a previous added handle
110
		void getConfig(int s1);							// Returns the configuration of all rooms to a connected client
4 andreas 111
 
9 andreas 112
		void pthrTemps();								// Thread function to request all temperatures
17 andreas 113
		void pthrHtml();								// Thread function for a HTML server
8 andreas 114
 
3 andreas 115
	private:
4 andreas 116
		enum CNFSTAT
117
		{
118
			NONE,
119
			GLOBAL,
120
			ROOM
121
		};
122
 
123
	private:
3 andreas 124
		bool readConf();
125
		HCONF *appendHConf();
8 andreas 126
		HTABLE* appendHTable(HCONF *ht);
3 andreas 127
		void destroyHConf();
4 andreas 128
		bool buildDB();
129
		HCONF *findRoom(int room);
5 andreas 130
		void answer(std::string msg);
131
		std::string timeToStr(time_t t);
8 andreas 132
		time_t getTime();
12 andreas 133
		void startHeat(int room) { controlHeat(room, true); }
134
		void stopHeat(int room) { controlHeat(room, false); }
135
		void controlHeat(int room, bool stst);			// Controles the valves via the GPIO ports
8 andreas 136
		bool evaluateTemp(int room, double temp);		// Evaluates the current temperature and calculates the time
137
														// to reach the soll temperature. It return true if the heating
138
														// should start. Otherwise it returns false.
12 andreas 139
		HCONF *HeatConf;								// Pointer to the heating configuration for every room
140
		double glb_minimal;								// The global temperature for normal (day) mode
141
		double glb_night;								// The global temperature for night mode
142
		bool onoff;										// True if heating is in normal or night mode
143
		int rm;											// Counter for room numbers
144
		bool initialized;								// True if everything was successfully initialized
145
		bool rstop;										// True if runtime loop should stop
146
		bool rrun;										// True if runtime loop is active
147
		int s1[100];									// Handle to connected client(s)
148
		int outSensor;									// The number of the outside temperature sensor
3 andreas 149
};
150
 
151
#endif