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