-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbacnet_read.js
More file actions
147 lines (118 loc) · 4.7 KB
/
Copy pathbacnet_read.js
File metadata and controls
147 lines (118 loc) · 4.7 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
MIT License Copyright 2021, 2022 - Bitpool Pty Ltd
*/
module.exports = function (RED) {
const { ReadCommandConfig } = require('./common');
const baEnum = require('./resources/node-bacstack-ts/dist/index.js').enum;
function BitpoolBacnetReadDevice(config) {
RED.nodes.createNode(this, config);
var node = this;
this.json = config.json;
this.mqtt = config.mqtt;
this.pointJson = config.pointJson;
this.roundDecimal = config.roundDecimal;
this.pointsToRead = config.pointsToRead;
this.readDevices = config.readDevices;
this.id = config.id;
this.nodeName = config.name;
this.object_property_simplePayload = config.object_property_simplePayload;
this.object_property_simpleWithStatus = config.object_property_simpleWithStatus;
this.object_property_fullObject = config.object_property_fullObject;
this.useDeviceName = config.useDeviceName;
this.object_props = getObjectProps(this);
function getObjectProps(node) {
var propArr = [];
if (node.object_property_simplePayload == true) {
propArr.push({ id: baEnum.PropertyIdentifier.PRESENT_VALUE });
}
if (node.object_property_fullObject == true) {
propArr.push(
{ id: baEnum.PropertyIdentifier.PRESENT_VALUE },
{ id: baEnum.PropertyIdentifier.DESCRIPTION },
{ id: baEnum.PropertyIdentifier.STATUS_FLAGS },
{ id: baEnum.PropertyIdentifier.RELIABILITY },
{ id: baEnum.PropertyIdentifier.OUT_OF_SERVICE },
{ id: baEnum.PropertyIdentifier.UNITS }
);
}
//add object name for every request as its used in formatting
propArr.push({ id: baEnum.PropertyIdentifier.OBJECT_NAME });
return propArr;
};
node.on('input', function (msg) {
if (msg.applyDisplayNames) {
msg.pointsToRead = node.pointsToRead;
node.send(msg);
} else {
node.status({ fill: "blue", shape: "dot", text: "Reading values" });
let object_property_simplePayload = false;
let object_property_simpleWithStatus = false;
let object_property_fullObject = false;
let jsonType = false;
let mqttType = false;
let pointJsonType = false;
let useDeviceName = false;
if (msg.simplePayload) {
object_property_simplePayload = msg.simplePayload;
} else if (msg.simpleWithStatus) {
object_property_simpleWithStatus = msg.simpleWithStatus;
} else if (msg.fullObject) {
object_property_fullObject = msg.fullObject;
} else {
object_property_simplePayload = node.object_property_simplePayload;
object_property_simpleWithStatus = node.object_property_simpleWithStatus;
object_property_fullObject = node.object_property_fullObject;
}
if (msg.json) {
jsonType = msg.json;
} else if (msg.mqtt) {
mqttType = msg.mqtt;
} else if (msg.pointJson) {
pointJsonType = msg.pointJson;
} else {
jsonType = node.json;
mqttType = node.mqtt;
pointJsonType = node.pointJson
}
if (msg.useDeviceName) {
useDeviceName = msg.useDeviceName;
} else {
useDeviceName = node.useDeviceName;
}
// Ensure pointsToRead has the latest display names before processing
let pointsToReadWithDisplayNames = JSON.parse(JSON.stringify(node.pointsToRead));
// Apply any stored display names from the backend data model
for (let deviceKey in pointsToReadWithDisplayNames) {
for (let pointKey in pointsToReadWithDisplayNames[deviceKey]) {
let point = pointsToReadWithDisplayNames[deviceKey][pointKey];
// The display name should already be preserved in the point object
// from the setPointDisplayName operations and addPointClicked enhancements
}
}
let readConfig = new ReadCommandConfig(pointsToReadWithDisplayNames, node.object_props, node.roundDecimal);
let output = {
type: "Read",
id: node.id,
readNodeName: node.nodeName,
options: readConfig,
objectPropertyType: {
simplePayload: object_property_simplePayload,
simpleWithStatus: object_property_simpleWithStatus,
fullObject: object_property_fullObject
},
outputType: {
json: jsonType,
mqtt: mqttType,
pointJson: pointJsonType,
useDeviceName: useDeviceName
}
};
node.send(output);
setTimeout(() => {
node.status({});
}, 3000);
}
});
};
RED.nodes.registerType('Bacnet-Discovery', BitpoolBacnetReadDevice);
};