@bitpoolos/edge-bacnet 1.5.1 → 1.5.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/CHANGELOG.md +5 -0
- package/bacnet_client.js +102 -46
- package/bacnet_gateway.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/bacnet_client.js
CHANGED
|
@@ -365,6 +365,20 @@ class BacnetClient extends EventEmitter {
|
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
forceUpdateDevices(deviceArray) {
|
|
369
|
+
let that = this;
|
|
370
|
+
try {
|
|
371
|
+
deviceArray.forEach(async function (deviceId) {
|
|
372
|
+
let device = that.deviceList.find((ele) => ele.getDeviceId() === deviceId);
|
|
373
|
+
if (device) {
|
|
374
|
+
await that.buildJsonObject(device);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
} catch (e) {
|
|
378
|
+
that.logOut("forceUpdateDevices error: ", e);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
368
382
|
async updatePointsForDevice(deviceObject) {
|
|
369
383
|
try {
|
|
370
384
|
let device = this.deviceList.find((ele) => ele.getDeviceId() === deviceObject.deviceId);
|
|
@@ -396,6 +410,7 @@ class BacnetClient extends EventEmitter {
|
|
|
396
410
|
await this.getDevicePointListWithoutObjectList(device);
|
|
397
411
|
await this.buildJsonObject(device);
|
|
398
412
|
} catch (e) {
|
|
413
|
+
await this.buildJsonObject(device);
|
|
399
414
|
this.logOut(`Update points list error 4: ${this.getDeviceAddress(device)}`, e);
|
|
400
415
|
}
|
|
401
416
|
}
|
|
@@ -495,11 +510,11 @@ class BacnetClient extends EventEmitter {
|
|
|
495
510
|
});
|
|
496
511
|
}
|
|
497
512
|
|
|
498
|
-
//test re write
|
|
499
513
|
async queryDevices() {
|
|
500
514
|
let that = this;
|
|
501
515
|
try {
|
|
502
516
|
that.pollInProgress = true;
|
|
517
|
+
|
|
503
518
|
let index = 0;
|
|
504
519
|
await query(index);
|
|
505
520
|
|
|
@@ -519,6 +534,7 @@ class BacnetClient extends EventEmitter {
|
|
|
519
534
|
}
|
|
520
535
|
}
|
|
521
536
|
try {
|
|
537
|
+
|
|
522
538
|
await that.updateDeviceName(device);
|
|
523
539
|
|
|
524
540
|
if (device.getSegmentation() !== 3) {
|
|
@@ -743,6 +759,7 @@ class BacnetClient extends EventEmitter {
|
|
|
743
759
|
|
|
744
760
|
// Process the batch when the request array is full or the last point is reached
|
|
745
761
|
if (requestArray.length === maxObjectCount || i === pointNames.length - 1) {
|
|
762
|
+
|
|
746
763
|
if (device.getProtocolServiceSupport("ReadPropertyMultiple") == true) {
|
|
747
764
|
await that.processBatch(device, requestArray, deviceName, bacnetResults, that, roundDecimal);
|
|
748
765
|
} else {
|
|
@@ -757,6 +774,7 @@ class BacnetClient extends EventEmitter {
|
|
|
757
774
|
// Check if all points for the device have been processed
|
|
758
775
|
if (processedPoints >= totalPoints) {
|
|
759
776
|
pendingRequests++;
|
|
777
|
+
|
|
760
778
|
// Emit the `values` event for the current device
|
|
761
779
|
that.emit(
|
|
762
780
|
"values",
|
|
@@ -851,22 +869,30 @@ class BacnetClient extends EventEmitter {
|
|
|
851
869
|
for (const request of requestArray) {
|
|
852
870
|
const { objectId, pointRef, pointName } = request;
|
|
853
871
|
try {
|
|
872
|
+
|
|
873
|
+
|
|
854
874
|
const result = await that.updatePoint(device, pointRef);
|
|
855
|
-
const val = result.values[0].value;
|
|
856
875
|
|
|
857
|
-
|
|
858
|
-
pointRef.presentValue = roundDecimalPlaces(val, roundDecimal);
|
|
859
|
-
} else {
|
|
860
|
-
pointRef.presentValue = val;
|
|
861
|
-
}
|
|
876
|
+
//const result = await that.updatePointWithRetry(device, pointRef, 1);
|
|
862
877
|
|
|
863
|
-
pointRef.meta["device"] = deviceMetaInfo;
|
|
864
|
-
pointRef.timestamp = Date.now();
|
|
865
|
-
pointRef.status = "online";
|
|
866
|
-
pointRef.error = "none";
|
|
867
878
|
|
|
868
|
-
|
|
869
|
-
|
|
879
|
+
if (result.objectId.type == objectId.type && result.objectId.instance == objectId.instance) {
|
|
880
|
+
const val = result.values[0].value;
|
|
881
|
+
|
|
882
|
+
if (isNumber(val)) {
|
|
883
|
+
pointRef.presentValue = roundDecimalPlaces(val, roundDecimal);
|
|
884
|
+
} else {
|
|
885
|
+
pointRef.presentValue = val;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
pointRef.meta["device"] = deviceMetaInfo;
|
|
889
|
+
pointRef.timestamp = Date.now();
|
|
890
|
+
pointRef.status = "online";
|
|
891
|
+
pointRef.error = "none";
|
|
892
|
+
|
|
893
|
+
// Store the point data in results
|
|
894
|
+
bacnetResults[deviceName][pointName] = pointRef;
|
|
895
|
+
}
|
|
870
896
|
} catch (err) {
|
|
871
897
|
that.logOut(`Error updating point ${pointName}:`, err);
|
|
872
898
|
|
|
@@ -882,6 +908,12 @@ class BacnetClient extends EventEmitter {
|
|
|
882
908
|
updateManyPoints(device, points) {
|
|
883
909
|
let that = this;
|
|
884
910
|
return new Promise((resolve, reject) => {
|
|
911
|
+
|
|
912
|
+
// let readOptions = {
|
|
913
|
+
// maxSegments: device.getMaxSe,
|
|
914
|
+
// maxApdu: that.readPropertyMultipleOptions.maxApdu,
|
|
915
|
+
// };
|
|
916
|
+
|
|
885
917
|
that
|
|
886
918
|
._readObjectWithRequestArray(device, points, that.readPropertyMultipleOptions)
|
|
887
919
|
.then(function (results) {
|
|
@@ -893,6 +925,22 @@ class BacnetClient extends EventEmitter {
|
|
|
893
925
|
});
|
|
894
926
|
}
|
|
895
927
|
|
|
928
|
+
updatePointWithRetry(device, point, retryCount = 1) {
|
|
929
|
+
let that = this;
|
|
930
|
+
const tryUpdate = (retriesLeft) => {
|
|
931
|
+
return that.updatePoint(device, point).catch((err) => {
|
|
932
|
+
if (retriesLeft > 0) {
|
|
933
|
+
that.logOut(`Retrying updatePoint... Attempts left: ${retriesLeft}`);
|
|
934
|
+
return tryUpdate(retriesLeft - 1);
|
|
935
|
+
}
|
|
936
|
+
// If no retries are left, reject with the original error
|
|
937
|
+
return Promise.reject(err);
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
return tryUpdate(retryCount);
|
|
942
|
+
}
|
|
943
|
+
|
|
896
944
|
updatePoint(device, point) {
|
|
897
945
|
let that = this;
|
|
898
946
|
let addressObject = {
|
|
@@ -1780,32 +1828,36 @@ class BacnetClient extends EventEmitter {
|
|
|
1780
1828
|
|
|
1781
1829
|
switch (object.id) {
|
|
1782
1830
|
case baEnum.PropertyIdentifier.PRESENT_VALUE:
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
if (
|
|
1787
|
-
values[objectId].presentValue = false;
|
|
1788
|
-
} else if (object.value[0].value == 1) {
|
|
1789
|
-
values[objectId].presentValue = true;
|
|
1790
|
-
}
|
|
1791
|
-
} else if (objectType == 40) {
|
|
1792
|
-
//character string
|
|
1793
|
-
values[objectId].presentValue = object.value[0].value;
|
|
1794
|
-
} else if (objectType == 13 || objectType == 14 || objectType == 19) {
|
|
1795
|
-
//check for MSV MSI MSO - for enum state text
|
|
1796
|
-
if (values[objectId].stateTextArray && values[objectId].stateTextArray.length > 0) {
|
|
1831
|
+
try {
|
|
1832
|
+
if (object.value[0] && object.value[0].value !== "undefined" && object.value[0].value !== null) {
|
|
1833
|
+
//check for binary object type
|
|
1834
|
+
if (objectType == 3 || objectType == 4 || objectType == 5) {
|
|
1797
1835
|
if (object.value[0].value == 0) {
|
|
1798
|
-
values[objectId].presentValue =
|
|
1799
|
-
} else if (object.value[0].value
|
|
1800
|
-
values[objectId].presentValue =
|
|
1801
|
-
|
|
1836
|
+
values[objectId].presentValue = false;
|
|
1837
|
+
} else if (object.value[0].value == 1) {
|
|
1838
|
+
values[objectId].presentValue = true;
|
|
1839
|
+
}
|
|
1840
|
+
} else if (objectType == 40) {
|
|
1841
|
+
//character string
|
|
1842
|
+
values[objectId].presentValue = object.value[0].value;
|
|
1843
|
+
} else if (objectType == 13 || objectType == 14 || objectType == 19) {
|
|
1844
|
+
//check for MSV MSI MSO - for enum state text
|
|
1845
|
+
if (values[objectId].stateTextArray && values[objectId].stateTextArray.length > 0) {
|
|
1846
|
+
if (object.value[0].value == 0) {
|
|
1847
|
+
values[objectId].presentValue = values[objectId].stateTextArray[object.value[0].value].value;
|
|
1848
|
+
} else if (object.value[0].value !== 0) {
|
|
1849
|
+
values[objectId].presentValue =
|
|
1850
|
+
values[objectId].stateTextArray[object.value[0].value - 1].value;
|
|
1851
|
+
}
|
|
1802
1852
|
}
|
|
1853
|
+
} else if (objectType !== 8) {
|
|
1854
|
+
values[objectId].presentValue = roundDecimalPlaces(object.value[0].value, 2);
|
|
1803
1855
|
}
|
|
1804
|
-
} else if (objectType !== 8) {
|
|
1805
|
-
values[objectId].presentValue = roundDecimalPlaces(object.value[0].value, 2);
|
|
1806
1856
|
}
|
|
1857
|
+
values[objectId].meta.arrayIndex = object.index;
|
|
1858
|
+
} catch (e) {
|
|
1859
|
+
that.logOut("buildResponse PRESENT_VALUE error: ", e);
|
|
1807
1860
|
}
|
|
1808
|
-
values[objectId].meta.arrayIndex = object.index;
|
|
1809
1861
|
break;
|
|
1810
1862
|
case baEnum.PropertyIdentifier.DESCRIPTION:
|
|
1811
1863
|
if (object.value[0]) values[objectId].description = object.value[0].value;
|
|
@@ -1853,20 +1905,24 @@ class BacnetClient extends EventEmitter {
|
|
|
1853
1905
|
}
|
|
1854
1906
|
break;
|
|
1855
1907
|
case baEnum.PropertyIdentifier.STATE_TEXT:
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1908
|
+
try {
|
|
1909
|
+
if (object.value) {
|
|
1910
|
+
values[objectId].stateTextArray = object.value;
|
|
1911
|
+
if (
|
|
1912
|
+
typeof values[objectId].presentValue == "number" &&
|
|
1913
|
+
values[objectId].presentValue !== null &&
|
|
1914
|
+
values[objectId].presentValue !== undefined
|
|
1915
|
+
) {
|
|
1916
|
+
const tempIndex = values[objectId].presentValue;
|
|
1917
|
+
if (tempIndex == 0) {
|
|
1918
|
+
values[objectId].presentValue = values[objectId].stateTextArray[tempIndex].value;
|
|
1919
|
+
} else if (tempIndex !== 0) {
|
|
1920
|
+
values[objectId].presentValue = values[objectId].stateTextArray[tempIndex - 1].value;
|
|
1921
|
+
}
|
|
1868
1922
|
}
|
|
1869
1923
|
}
|
|
1924
|
+
} catch (e) {
|
|
1925
|
+
that.logOut("buildResponse STATE_TEXT error: ", e);
|
|
1870
1926
|
}
|
|
1871
1927
|
break;
|
|
1872
1928
|
case baEnum.PropertyIdentifier.VENDOR_NAME:
|
package/bacnet_gateway.js
CHANGED
|
@@ -240,6 +240,8 @@ module.exports = function (RED) {
|
|
|
240
240
|
}).catch(function (error) {
|
|
241
241
|
logOut("Error in applyDisplayNames: ", error);
|
|
242
242
|
});
|
|
243
|
+
} else if (msg.forceUpdateDevices == true) {
|
|
244
|
+
node.bacnetClient.forceUpdateDevices(msg.deviceIdArray);
|
|
243
245
|
}
|
|
244
246
|
});
|
|
245
247
|
|