@bitpoolos/edge-bacnet 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bacnet_client.js +37 -34
- package/bacnet_read.html +1 -1
- package/package.json +1 -1
package/bacnet_client.js
CHANGED
|
@@ -96,6 +96,7 @@ class BacnetClient extends EventEmitter {
|
|
|
96
96
|
|
|
97
97
|
setTimeout(() => {
|
|
98
98
|
that.queryDevices();
|
|
99
|
+
that.sanitizeDeviceList();
|
|
99
100
|
}, "5000")
|
|
100
101
|
|
|
101
102
|
} catch(e) {
|
|
@@ -132,7 +133,6 @@ class BacnetClient extends EventEmitter {
|
|
|
132
133
|
newBacnetDevice.setLastSeen(Date.now());
|
|
133
134
|
that.updateDeviceName(newBacnetDevice);
|
|
134
135
|
that.deviceList.push(newBacnetDevice);
|
|
135
|
-
|
|
136
136
|
} else if(foundIndex !== -1) {
|
|
137
137
|
that.deviceList[foundIndex].updateDeviceConfig(device);
|
|
138
138
|
that.deviceList[foundIndex].setLastSeen(Date.now());
|
|
@@ -189,7 +189,6 @@ class BacnetClient extends EventEmitter {
|
|
|
189
189
|
.acquire()
|
|
190
190
|
.then(function(release) {
|
|
191
191
|
try {
|
|
192
|
-
|
|
193
192
|
that.getDevicePointList(device).then(function() {
|
|
194
193
|
that.buildJsonObject(device).then(function() {
|
|
195
194
|
release();
|
|
@@ -208,7 +207,6 @@ class BacnetClient extends EventEmitter {
|
|
|
208
207
|
});
|
|
209
208
|
release();
|
|
210
209
|
});
|
|
211
|
-
|
|
212
210
|
} catch(e) {
|
|
213
211
|
that.logOut("Error while querying devices: ", e);
|
|
214
212
|
release();
|
|
@@ -220,30 +218,38 @@ class BacnetClient extends EventEmitter {
|
|
|
220
218
|
|
|
221
219
|
sanitizeDeviceList() {
|
|
222
220
|
let that = this;
|
|
221
|
+
|
|
222
|
+
//1 hour in seconds
|
|
223
|
+
let timeoutThreshold = 3600;
|
|
224
|
+
|
|
225
|
+
that.renderList.forEach(function(item, index) {
|
|
226
|
+
if(((Date.now() - item.lastSeen) / 1000) > timeoutThreshold) {
|
|
227
|
+
//render item hasnt responded to whoIs for over an hour
|
|
228
|
+
|
|
229
|
+
let deviceIndex = that.deviceList.findIndex(ele => ele.deviceId == item.deviceId);
|
|
230
|
+
let device = that.deviceList[deviceIndex];
|
|
223
231
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
//device hasnt responded to whoIs for over an hour
|
|
232
|
+
let ipAddr = typeof device.getAddress() == "object" ? device.getAddress().address : device.getAddress();
|
|
233
|
+
let deviceKey = ipAddr + "-" + device.getDeviceId();
|
|
227
234
|
|
|
228
|
-
let deviceKey = (typeof device.getAddress() == "object") ? device.getAddress().address + "-" + device.getDeviceId() : device.getAddress() + "-" + device.getDeviceId();
|
|
229
235
|
delete that.networkTree[deviceKey];
|
|
230
236
|
|
|
231
|
-
if(
|
|
232
|
-
|
|
233
|
-
if(foundIndex !== -1) {
|
|
234
|
-
that.renderList.splice(foundIndex, 1);
|
|
235
|
-
}
|
|
237
|
+
if(((Date.now() - device.getLastSeen()) / 1000) > timeoutThreshold) {
|
|
238
|
+
that.deviceList.splice(deviceIndex, 1);
|
|
236
239
|
}
|
|
237
240
|
|
|
238
|
-
that.
|
|
241
|
+
that.renderList.splice(index, 1);
|
|
239
242
|
}
|
|
240
243
|
});
|
|
244
|
+
|
|
241
245
|
}
|
|
242
246
|
|
|
243
247
|
updateDeviceName(device) {
|
|
244
248
|
let that = this;
|
|
245
249
|
that._getDeviceName(device.getAddress(), device.getDeviceId()).then(function(deviceName) {
|
|
246
|
-
|
|
250
|
+
if(typeof deviceName == "string") {
|
|
251
|
+
device.setDeviceName(deviceName);
|
|
252
|
+
}
|
|
247
253
|
});
|
|
248
254
|
}
|
|
249
255
|
|
|
@@ -322,20 +328,22 @@ class BacnetClient extends EventEmitter {
|
|
|
322
328
|
let bacnetResults = {};
|
|
323
329
|
devicesToRead.forEach(function(key, index) {
|
|
324
330
|
let device = that.deviceList.find(ele => `${that.getDeviceAddress(ele)}-${ele.getDeviceId()}` == key);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
331
|
+
if(device) {
|
|
332
|
+
let deviceName = device.getDeviceName();
|
|
333
|
+
let deviceKey = (typeof device.getAddress() == "object") ? device.getAddress().address + "-" + device.getDeviceId() : device.getAddress() + "-" + device.getDeviceId();
|
|
334
|
+
let deviceObject = that.networkTree[deviceKey];
|
|
335
|
+
if(!bacnetResults[deviceName]) bacnetResults[deviceName] = {};
|
|
336
|
+
if(deviceObject) {
|
|
337
|
+
for(const pointName in readConfig.pointsToRead[key]) {
|
|
338
|
+
let bac_obj = that.getObjectType(readConfig.pointsToRead[key][pointName].objectID.type);
|
|
339
|
+
let objectId = pointName + "_" + bac_obj + '_' + readConfig.pointsToRead[key][pointName].objectID.instance;
|
|
340
|
+
let point = deviceObject[objectId];
|
|
341
|
+
bacnetResults[deviceName][pointName] = point;
|
|
342
|
+
}
|
|
335
343
|
}
|
|
336
344
|
}
|
|
337
345
|
|
|
338
|
-
if(index == devicesToRead.length - 1) that.emit('values', bacnetResults, outputType, objectPropertyType);
|
|
346
|
+
if(index == devicesToRead.length - 1 && Object.keys(readConfig.pointsToRead).length > 0) that.emit('values', bacnetResults, outputType, objectPropertyType);
|
|
339
347
|
});
|
|
340
348
|
} catch(e) {
|
|
341
349
|
that.logOut("Issue doing read, see error: ", e);
|
|
@@ -375,10 +383,7 @@ class BacnetClient extends EventEmitter {
|
|
|
375
383
|
let objectName = that._findValueById(point.values, baEnum.PropertyIdentifier.OBJECT_NAME);
|
|
376
384
|
//checks for error code json structure, returned for invalid bacnet requests
|
|
377
385
|
if(!object.value.value && toReadProperty !== -1 && objectName !== "") {
|
|
378
|
-
|
|
379
|
-
let bac_obj = that.getObjectType(currobjectId);
|
|
380
|
-
let objectId;
|
|
381
|
-
objectId = objectName;
|
|
386
|
+
let objectId = objectName;
|
|
382
387
|
|
|
383
388
|
//init json object
|
|
384
389
|
if(!values[objectId]) values[objectId] = {};
|
|
@@ -929,7 +934,7 @@ class BacnetClient extends EventEmitter {
|
|
|
929
934
|
let isMstpDevice = deviceInfo.getIsMstpDevice();
|
|
930
935
|
let manualDiscoveryMode = deviceInfo.getManualDiscoveryMode();
|
|
931
936
|
|
|
932
|
-
if(deviceObject) {
|
|
937
|
+
if(deviceObject && typeof deviceName !== "object") {
|
|
933
938
|
let children = [];
|
|
934
939
|
let pointIndex = 0;
|
|
935
940
|
|
|
@@ -982,7 +987,7 @@ class BacnetClient extends EventEmitter {
|
|
|
982
987
|
children.push({"key": `${index}-${pointIndex}`, "label": displayName, "data": displayName, "pointName": pointName, "icon": that.getPointIcon(values.meta.objectId.type), "children": pointProperties, "type": "point", "parentDevice": deviceName, "showAdded": false, "bacnetType": values.meta.objectId.type})
|
|
983
988
|
pointIndex++;
|
|
984
989
|
}
|
|
985
|
-
let foundIndex = that.renderList.findIndex(ele => ele.
|
|
990
|
+
let foundIndex = that.renderList.findIndex(ele => ele.deviceId == deviceId && ele.ipAddr == ipAddr);
|
|
986
991
|
if(foundIndex !== -1) {
|
|
987
992
|
that.renderList[foundIndex] = {"key": index, "label": deviceName, "data": deviceName, "icon": that.getDeviceIcon(isMstpDevice, manualDiscoveryMode), "children": children.sort(that.sortPoints), "type": "device", "lastSeen": deviceInfo.getLastSeen(), "showAdded": false, "ipAddr": ipAddr, "deviceId": deviceId, "isMstpDevice": isMstpDevice};
|
|
988
993
|
} else if(foundIndex == -1) {
|
|
@@ -996,7 +1001,7 @@ class BacnetClient extends EventEmitter {
|
|
|
996
1001
|
resolve({renderList: that.renderList, deviceList: that.deviceList, pointList: that.networkTree, pollFrequency: that.discover_polling_schedule});
|
|
997
1002
|
}
|
|
998
1003
|
}
|
|
999
|
-
|
|
1004
|
+
|
|
1000
1005
|
release();
|
|
1001
1006
|
});
|
|
1002
1007
|
});
|
|
@@ -1082,10 +1087,8 @@ class BacnetClient extends EventEmitter {
|
|
|
1082
1087
|
try {
|
|
1083
1088
|
pointProperty.values.forEach(function(object, objectIndex) {
|
|
1084
1089
|
//checks for error code json structure, returned for invalid bacnet requests
|
|
1085
|
-
//if(!object.value.value && !object.value[0].value.errorClass && !object.value.errorClass) {
|
|
1086
1090
|
if(object && object.value && !object.value.errorClass) {
|
|
1087
1091
|
|
|
1088
|
-
|
|
1089
1092
|
if(!values[objectId]) values[objectId] = {};
|
|
1090
1093
|
values[objectId].meta = {
|
|
1091
1094
|
objectId: pointProperty.objectId
|
package/bacnet_read.html
CHANGED