-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitoringController.h
More file actions
125 lines (113 loc) · 2.71 KB
/
MonitoringController.h
File metadata and controls
125 lines (113 loc) · 2.71 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include <ArduinoSTL.h>
#include <map>
#include <vector>
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#include "AnalogInputChannel.h"
#include "DiscreteOutputChannel.h"
#include "DiscreteInputChannel.h"
#include "DiscreteVirtualChannel.h"
#include "Timer.h"
#include "Configuration.h"
#include "ConfigurationReader.h"
#include "Action.h"
#include "ModbusService.h"
#include "MonitoringLogger.h"
namespace MonitoringComponents {
enum class ControllerState {
Alarming,Warning,Maintenance,Okay
};
enum class Transition {
To,
From
};
struct SystemActionIds {
int alarmIndex = 0;
int warningIndex = 0;
int okayIndex = 0;
int softWarnIndex = 0;
int maintenanceIndex = 0;
void setId(ActionType type,int i) {
switch (type) {
case ActionType::Alarm: {
this->alarmIndex = i;
break;
}
case ActionType::Maintenance: {
this->maintenanceIndex = i;
break;
}
case ActionType::Warning: {
this->warningIndex = i;
break;
}
case ActionType::SoftWarn: {
this->softWarnIndex = i;
break;
}
case ActionType::Okay: {
this->okayIndex = i;
break;
}
default: {
break;
}
}
}
int getId(ActionType type) {
switch (type) {
case ActionType::Alarm: {
return this->alarmIndex;
}
case ActionType::Maintenance: {
return this->maintenanceIndex;
}
case ActionType::Warning: {
return this->warningIndex;
}
case ActionType::SoftWarn: {
return this->softWarnIndex;
}
case ActionType::Okay: {
return this->okayIndex;
}
default: {
return -1;
}
}
}
};
class MonitoringController:public MonitoringComponent {
public:
MonitoringController() :MonitoringComponent(), _on_channel_cbk([](ChannelMessage) {}){}
void Setup();
void Run();
void Initialize();
bool CheckController();
private:
void Build();
void OnChannelCallback(ChannelCallback cbk);
void ProcessChannelMessage(ChannelMessage channelMessage);
void ProcessStateChanges();
void InvokeSystemAction(ActionType actionType);
void ClearSystemAction(ActionType actionType);
void Print();
private:
std::vector<DiscreteInputChannel*> discreteInputs;
std::vector<AnalogInputChannel*> analogInputs;
std::vector<DiscreteOutputChannel*> outputChannels;
std::vector<DiscreteVirtualChannel*> virtualInputs;
std::vector<const char*> modules;
std::vector<Action*> actions;
std::map<int, int*> tracking;
std::map<ActionType, int> systemActMap;
std::map<ActionType, bool> systemActionLatches;
ChannelCallback _on_channel_cbk;
ControllerState controllerState;
ControllerState nextState;
ModbusAddress controllerRegister;
Timer printTimer;
void privateLoop();
};
};