Subversion Repositories heating

Rev

Rev 53 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2015 by Andreas Theofilu. All rights reserved!
 *
 * All rights reserved. No warranty, explicit or implicit, provided.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Andreas Theofilu and his suppliers, if any.
 * The intellectual and technical concepts contained
 * herein are proprietary to Andreas Theofilu and its suppliers and
 * may be covered by European and Foreign Patents, patents in process,
 * and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Andreas Theofilu.
 * 
 * Author: Andreas Theofilu <andreas@theosys.at>
 */
#ifndef __HEATING_H__
#define __HEATING_H__

#include "helper.h"
#include "temperature.h"
#include "html.h"

/*
 * Purpose:
 * There can be an unlimited number of rooms defined. For every room you can
 * define different temperatures. The type "HSTAT" defines the actual status
 * of the room.
 * 
 * Status NORMAL: This is the normal operating of the heating during the day.
 *                The heating will hold the temperature set in "soll"
 * 
 * Status NIGHT:  This is the mode for the night. the heating will hold the
 *                temperature set in "night".
 * 
 * Status OFF:    This indicates, the heating for a particular room was switched
 *                off. In this case the heating makes sure, that the temperature
 *                will not fall beyond the temperature set in "minimal".
 * 
 * There are global settingsto sitch the heating off or on. If the heating was
 * set globaly off, a globaly defined minimal temperature will be hold.
 * 
 * If the heating is switched on, it operated individually for every room and
 * tries to hold the temperature set individual in a room.
 */
class heating : private temperature
{
        public:
                enum HSTAT
                {
                        NORMAL,
                        NIGHT,
                        OFF
                };

                typedef struct HTABLE
                {
                        double tempDifferOut;   // Difference of outside temperature to soll temperature
                        double tempDifferIn;    // Difference off current temperature in the room to soll temperature
                        time_t heat;                    // time in seconds needed to heat up to soll temperature
                        time_t start;                   // start time of heating in case we've no time already
                        HTABLE *next;                   // Pointer to next element of table
                }HTABLE;

                typedef struct HCONF
                {
                        // By config file set variables
                        char rname[32];
                        int rnum;
                        int tempsensor;                 // Number of temperature sensor (depends on method of how temperature is meassured)
                        int gpio;                               // GPIO number where relais for valve is connected
                        double soll;                    // The temperature that should be
                        double night;                   // The reduced temperature for night
                        double minimal;                 // The minimal temperature
                        time_t start;                   // The time the heating should have reached the "soll" temperature (if normal is set)
                        time_t end;                             // The time the heating should end normal mode and start "night" mode.
                        time_t wstart;                  // The time the work day start and heating is reduced to night mode (if normal is set)
                        time_t wend;                    // The time the heating should start normal mode again.
                        // Internal used variables
                        double ist;                             // The real temperature
                        HSTAT status;                   // The status of the room
                        bool valve;                             // true = valve is open
                        HTABLE *hTable;                 // Pointer to heating table
                        HCONF *next;
                }HCONF;

        public:
                heating();
                ~heating();

                void run();                                                                             // Ask for actual temperature in every room all the time
                void stopRun() { rstop = true; }                                // Stop asking for temperature
                bool statusRun()  { return rrun; }                              // true = temperature request is running

                time_t strToTime(char *str);                                    // Convert a time string into a time value
                bool isInitialized() { return initialized; }    // Is true as soon as the class was initialized successfuly
                double incSoll(int room);                                               // Increment soll by 1/2 °C
                double decSoll(int room);                                               // Decrement soll by 1/2 °C
                void setSoll(int room, double val);                             // Set temperature soll in room "room"
                void setNight(int room, double val);                    // Set temperature for night mode
                void setMinimal(int room, double val);                  // Set temperature for off mode. This is a minimal temperature.
                bool switchOnOff(bool what);                                    // false = off; this is the off mode with minimal temperature. true = normal operating
                bool getOnOff() { return onoff; }                               // Is the heating activated? true = yes
                double getGlbNight() { return glb_night; }              // Retrieve the global temperature for night mode
                double getGlbMinimal() { return glb_minimal; }  // Retrieve the global temperature for off mode
                double getNight(int room);                                              // Retrieve the optional temperature in a particular room for night mode
                double getMinimal(int room);                                    // Retrieve the optional temperature in a particular room for off mode
                void setHandle(int fd);                                                 // Add the handle to a connected client to return messages directly
                void removeHandle(int fd);                                              // Remove a previous added handle
                void getConfig(int s1);                                                 // Returns the configuration of all rooms to a connected client
                bool isHeating();                                                               // Returns true if one room needs to be heated

                void pthrTemps();                                                               // Thread function to request all temperatures
                void pthrHtml();                                                                // Thread function for a HTML server

        private:
                enum CNFSTAT
                {
                        NONE,
                        GLOBAL,
                        ROOM
                };

        private:
                bool readConf();
                HCONF *appendHConf();
                HTABLE* appendHTable(HCONF *ht);
                void destroyHConf();
                bool buildDB();
                HCONF *findRoom(int room);
                void answer(std::string msg);
                std::string timeToStr(time_t t);
                time_t getTime();
                void applyConfig();                                                             // Transfers the actual configuration to HTML server
                void startHeat(int room) { controlHeat(room, true); }
                void stopHeat(int room) { controlHeat(room, false); }
                void controlHeat(int room, bool stst);                  // Controles the valves via the GPIO ports
                time_t calcTime(double soll, double ist);
                bool evaluateTemp(int room, double temp);               // Evaluates the current temperature and calculates the time
                                                                                                                // to reach the soll temperature. It return true if the heating
                                                                                                                // should start. Otherwise it returns false.
                HCONF *HeatConf;                                                                // Pointer to the heating configuration for every room
                double glb_minimal;                                                             // The global temperature for normal (day) mode
                double glb_night;                                                               // The global temperature for night mode
                bool onoff;                                                                             // True if heating is in normal or night mode
                int rm;                                                                                 // Counter for room numbers
                bool initialized;                                                               // True if everything was successfully initialized
                bool rstop;                                                                             // True if runtime loop should stop
                bool rrun;                                                                              // True if runtime loop is active
                int s1[100];                                                                    // Handle to connected client(s)
                int outSensor;                                                                  // The number of the outside temperature sensor
                int heatIO;                                                                             // The GPIO pin to control heating (switching it on or off)
                html *HtmlServer;                                                               // Pointer to HTML server running in background
};

#endif