-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolarPowerMgrApp.h
75 lines (55 loc) · 2.44 KB
/
SolarPowerMgrApp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef SOLAR_POWER_MGR_APP_H
#define SOLAR_POWER_MGR_APP_H
#include "automation/Automation.h"
#include "automation/constraint/ConstraintEventHandler.h"
#include "automation/device/Device.h"
#include "automation/sensor/Sensor.h"
#include <Poco/Util/Application.h>
using namespace std;
using namespace automation;
using namespace Poco;
#define DEFAULT_APPLIANCE_WATTS 465 // air conditioner
//#define DEFAULT_APPLIANCE_WATTS 520 // heater
#define DEFAULT_MIN_VOLTS 24.70
#define LIGHTS_SET_1_WATTS 120
#define LIGHTS_SET_2_WATTS 160
#define FULL_SOC_PERCENT 98.00
class SolarPowerMgrApp : public Poco::Util::Application, ConstraintEventHandler {
public:
void resultDeferred(Constraint* pConstraint,bool bNext,unsigned long delayMs) const override {
//logBuffer << "DEFERRED(next=" << bNext << ",delay=" << delayMs/1000.0 << "s): " << pConstraint->getTitle() << endl;
};
void resultChanged(Constraint* pConstraint,bool bNew,unsigned long lastDurationMs) const override {
logBuffer << "CHANGED(new=" << bNew << ",lastDuration=" << lastDurationMs/1000.0 << "s): ";
// Print device name if not current device
if ( pConstraint && currentDevice && !currentDevice->findConstraint(pConstraint->id) ) {
Device* pDevice = devices.findConstraintOwner(pConstraint->id);
if ( pDevice ) {
logBuffer << "DEVICE: '" << pDevice->getTitle() << "' CONSTRAINT: ";
}
}
printConstraintTitleAndValue(logBuffer,pConstraint);
logBuffer << endl;
//logBuffer << pConstraint->getTitle() << endl;
};
//void resultSame(Constraint* pConstraint,bool bVal,unsigned long lastDurationMs) const override {
// logBuffer << "SAME(value=" << bVal << ",duration=" << lastDurationMs << "ms): " << pConstraint->getTitle() << endl;
//};
void deferralCancelled(Constraint* pConstraint,bool bCurrent,unsigned long lastDurationMs) const override {
//logBuffer << "DEFERRAL CANCELED(current=" << bCurrent << ",duration=" << lastDurationMs/1000.0 << "s): " << pConstraint->getTitle() << endl;
};
static SolarPowerMgrApp* pInstance;
static bool iSignalCaught;
static void signalHandlerFn (int val);
Devices devices;
Sensors sensors;
automation::Device* currentDevice = nullptr;
bool bEnabled;
SolarPowerMgrApp() : bEnabled(true) {
pInstance = this;
}
virtual int main(const std::vector<std::string> &args);
protected:
std::ostream& printConstraintTitleAndValue(std::ostream& os, Constraint* pConstraint) const;
};
#endif