-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhmi-alarm.js
More file actions
executable file
·85 lines (74 loc) · 2.12 KB
/
hmi-alarm.js
File metadata and controls
executable file
·85 lines (74 loc) · 2.12 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
module.exports = function(RED)
{
function AlarmNodeOut(config)
{
RED.nodes.createNode(this, config);
var flow = this.context().global;
var globalNodes = flow.get("nodes");
this.all = config.all;
if (typeof(this.all) == "undefined" || this.all == false)
this.hmiID = config.hmiID;
else
this.hmiID = "*";
this.configSSE = RED.nodes.getNode(config.sse);
this.configSSE.subscription(this, this.configSSE, this.id, this.hmiID, "alarm");
if (typeof(globalNodes) === "undefined")
{
globalNodes = [];
}
outNode = this;
globalNodes.push(outNode);
flow.set("nodes", globalNodes);
outNode.manageData = function(data, node)
{
var msg = {"topic": "alarms", "payload" : data};
node.send(msg);
}
this.on('close', function()
{
outNode.configSSE.closeConnection(globalNodes);
flow.set("nodes", []);
});
}
RED.nodes.registerType("hmi-alarm out", AlarmNodeOut);
RED.httpAdmin.post("/hmi-alarm/:id/:state", RED.auth.needsPermission("hmi-alarm.write"), function(req, res)
{
var node = RED.nodes.getNode(req.params.id);
var state = req.params.state;
if (node != null && typeof node !== "undefined")
{
if (state === "enable")
{
node.configSSE.subscription(node, node.configSSE, node.id, node.hmiID, "alarm");
res.sendStatus(200);
}
else if(state === "disable")
{
node.configSSE.unsubscription(node.configSSE, node.id, node.hmiID, "alarm");
res.sendStatus(201);
}
else
{
res.sendStatus(404);
}
}
else
{
res.sendStatus(404);
}
});
function AlarmNodeIn(config)
{
RED.nodes.createNode(this, config);
this.hmiID = config.hmiID;
this.configSSE = RED.nodes.getNode(config.sse);
node = this;
this.on('input', function (msg)
{
var payload = JSON.parse(msg.payload);
if (payload.tag == param.hmiID)
node.configSSE.writeTag(node.configSSE, payload.tag, payload.value);
});
}
RED.nodes.registerType("hmi-alarm in", AlarmNodeIn);
}