3-phase PV router
Loading...
Searching...
No Matches
dualtariff.h
Go to the documentation of this file.
1
12#ifndef DUALTARIFF_H
13#define DUALTARIFF_H
14
15#include "config.h"
16
27template< uint8_t N, uint8_t OffPeakDuration = 8 >
29{
30public:
31 constexpr _rg_OffsetForce()
32 {
33 constexpr uint16_t uiPeakDurationInSec{ OffPeakDuration * 3600 };
34 // calculates offsets for force start and stop of each load
35 for (uint8_t i = 0; i != N; ++i)
36 {
37 const bool bOffsetInMinutes{ rg_ForceLoad[i].getStartOffset() > 24 || rg_ForceLoad[i].getStartOffset() < -24 };
38 const bool bDurationInMinutes{ rg_ForceLoad[i].getDuration() > 24 && UINT16_MAX != rg_ForceLoad[i].getDuration() };
39
40 _rg[i][0] = ((rg_ForceLoad[i].getStartOffset() >= 0) ? 0 : uiPeakDurationInSec) + rg_ForceLoad[i].getStartOffset() * (bOffsetInMinutes ? 60ul : 3600ul);
41 _rg[i][0] *= 1000ul; // convert in milli-seconds
42
43 if (UINT8_MAX == rg_ForceLoad[i].getDuration())
44 {
46 }
47 else
48 {
49 _rg[i][1] = _rg[i][0] + rg_ForceLoad[i].getDuration() * (bDurationInMinutes ? 60ul : 3600ul) * 1000ul;
50 }
51 }
52 }
53 const auto (&operator[](uint8_t i) const)
54 {
55 return _rg[i];
56 }
57
58private:
59 uint32_t _rg[N][2]{};
60};
61
62inline uint32_t ul_TimeOffPeak;
72{
73 Serial.print(F("\tDuration of off-peak period is "));
74 Serial.print(ul_OFF_PEAK_DURATION);
75 Serial.println(F(" hours."));
76
77 Serial.print(F("\tTemperature threshold is "));
78 Serial.print(iTemperatureThreshold);
79 Serial.println(F("°C."));
80
81 for (uint8_t i = 0; i < NO_OF_DUMPLOADS; ++i)
82 {
83 Serial.print(F("\tLoad #"));
84 Serial.print(i + 1);
85 Serial.println(F(":"));
86
87 Serial.print(F("\t\tStart "));
88 if (rg_ForceLoad[i].getStartOffset() >= 0)
89 {
90 Serial.print(rg_ForceLoad[i].getStartOffset());
91 Serial.print(F(" hours/minutes after begin of off-peak period "));
92 }
93 else
94 {
95 Serial.print(-rg_ForceLoad[i].getStartOffset());
96 Serial.print(F(" hours/minutes before the end of off-peak period "));
97 }
98 if (rg_ForceLoad[i].getDuration() == UINT16_MAX)
99 {
100 Serial.println(F("till the end of the period."));
101 }
102 else
103 {
104 Serial.print(F("for a duration of "));
105 Serial.print(rg_ForceLoad[i].getDuration());
106 Serial.println(F(" hour/minute(s)."));
107 }
108 Serial.print(F("\t\tCalculated offset in seconds: "));
109 Serial.println(rg_OffsetForce[i][0] * 0.001F);
110 Serial.print(F("\t\tCalculated duration in seconds: "));
111 Serial.println(rg_OffsetForce[i][1] * 0.001F);
112 }
113}
114
115#endif /* DUALTARIFF_H */
Template class for Load-Overriding.
Definition: dualtariff.h:29
const auto & operator[](uint8_t i) const
Definition: dualtariff.h:53
constexpr _rg_OffsetForce()
Definition: dualtariff.h:31
uint32_t _rg[N][2]
Definition: dualtariff.h:59
constexpr uint16_t getDuration() const
constexpr int16_t getStartOffset() const
Configuration values to be set by the end-user.
constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]
Definition: config.h:87
constexpr uint8_t NO_OF_DUMPLOADS
Definition: config.h:38
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition: config.h:86
constexpr int16_t iTemperatureThreshold
Definition: config.h:89
constexpr uint16_t
Definition: config_system.h:32
uint32_t ul_TimeOffPeak
Definition: dualtariff.h:62
constexpr auto rg_OffsetForce
Definition: dualtariff.h:64
void printDualTariffConfiguration()
Print the settings for off-peak period.
Definition: dualtariff.h:71
uint8_t i
Definition: test_main.cpp:94