-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscreteInputChannel.cpp
More file actions
83 lines (75 loc) · 2.72 KB
/
DiscreteInputChannel.cpp
File metadata and controls
83 lines (75 loc) · 2.72 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
#include "DiscreteInputChannel.h"
namespace MonitoringComponents {
bool DiscreteInputChannel::isTriggered() {
if(this->connected){
return (this->triggerOn==TriggerOn::Low) ? this->inputPin.isLow():this->inputPin.isHigh();
}
return false;
}
void DiscreteInputChannel::Initialize() {
/* this->printTimer.onInterval([&](){
switch(this->configuration.triggerOn){
case TriggerOn::High:
std::cout<<"D"<<this->modbusAddress.address<<" TriggerOn: "<<"High"<<" IsTriggered: "<<this->isTriggered()<<std::endl;
break;
case TriggerOn::Low:
std::cout<<"D"<<this->modbusAddress.address<<" TriggerOn: "<<"Low"<<" IsTriggered: "<<this->isTriggered()<<std::endl;
break;
default:
std::cout<<"D"<<this->modbusAddress.address<<" TriggerOn: "<<"Error"<<" IsTriggered: "<<this->isTriggered()<<std::endl;
break;
}
},1000);
RegisterChild(this->printTimer); */
bool state = this->isTriggered();
ModbusService::Update(this->modbusAddress,state);
if(this->connected && this->alert.enabled){
if (state) {
ChannelMessage msg;
msg.actionId = this->alert.actionId;
msg.channel = this->inputPin.Address();
msg.type = this->alert.actionType;
msg.channelAction = ChannelAction::Trigger;
ModbusService::Update(this->alertModAddress,uint16_t(this->alert.actionType));
cout<<"Alert Mod Updated: Channel: "<<this->inputPin.Address().channel<<" Alert: "<<int(this->alert.actionType)<<endl;
this->alert.activated = true;
this->_on_state_change(msg);
}else{
ModbusService::Update(this->alertModAddress,uint16_t(ActionType::Okay));
}
}else{
ModbusService::Update(this->modbusAddress,uint16_t(0));
ModbusService::Update(this->alertModAddress,uint16_t(0));
}
this->triggered = state;
}
int DiscreteInputChannel::Channel() {
return this->configuration.channel;
}
void DiscreteInputChannel::OnStateChange(ChannelCallback cbk) {
this->_on_state_change = cbk;
}
void DiscreteInputChannel::privateLoop() {
bool state = this->isTriggered();
ModbusService::Update(this->modbusAddress,state);
if (state!= this->triggered) {
if (this->alert.enabled) {
ChannelMessage message;
message.actionId = this->alert.actionId;
message.channel = this->inputPin.Address();
message.type = this->alert.actionType;
if (state) {
message.channelAction = ChannelAction::Trigger;
this->alert.activated = true;
ModbusService::Update(this->alertModAddress,uint16_t(this->alert.actionType));
} else {
message.channelAction = ChannelAction::Clear;
this->alert.activated = false;
ModbusService::Update(this->alertModAddress,uint16_t(ActionType::Okay));
}
this->_on_state_change(message);
}
this->triggered = state;
}
}
};