@bitpoolos/edge-bacnet 1.6.2 → 1.6.4
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 +114 -66
- package/bacnet_client.js +65 -56
- package/bacnet_gateway.html +233 -18
- package/bacnet_gateway.js +41 -8
- package/bacnet_inspector.js +88 -12
- package/bacnet_inspector_worker.js +13 -3
- package/bacnet_read.html +223 -7
- package/bacnet_read.js +13 -1
- package/common.js +17 -78
- package/inspector.html +35 -1
- package/package.json +2 -2
- package/resources/style.css +28 -1
- package/treeBuilder.js +683 -567
package/treeBuilder.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
const { queueConfigStore } = require("./common");
|
|
2
2
|
const { BacnetDevice } = require("./bacnet_device");
|
|
3
3
|
|
|
4
|
+
// Global state for smart caching - minimal memory overhead
|
|
5
|
+
let lastCacheTime = 0;
|
|
6
|
+
let lastDataHash = "";
|
|
7
|
+
let cacheInterval = 30000; // Start with 30 seconds
|
|
8
|
+
let consecutiveNoChangeCount = 0;
|
|
9
|
+
const MAX_CACHE_INTERVAL = 300000; // Max 5 minutes
|
|
10
|
+
const MIN_CACHE_INTERVAL = 20000; // Min 20 seconds
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Simple hash function for change detection
|
|
14
|
+
*/
|
|
15
|
+
function simpleHash(data) {
|
|
16
|
+
const str = JSON.stringify(data);
|
|
17
|
+
let hash = 0;
|
|
18
|
+
for (let i = 0; i < str.length; i++) {
|
|
19
|
+
const char = str.charCodeAt(i);
|
|
20
|
+
hash = (hash << 5) - hash + char;
|
|
21
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return hash.toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
4
27
|
/**
|
|
5
28
|
* The `treeBuilder` class is responsible for building and processing the network tree structure.
|
|
6
29
|
* It takes in a list of devices, a network tree object, a render list, a render list count, and an initial tree build flag.
|
|
@@ -18,608 +41,701 @@ const { BacnetDevice } = require("./bacnet_device");
|
|
|
18
41
|
* @param {boolean} initialTreeBuild - The initial tree build flag.
|
|
19
42
|
*/
|
|
20
43
|
class treeBuilder {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
constructor(deviceList, networkTree, renderList, renderListCount, initialTreeBuild) {
|
|
45
|
+
this.deviceList = deviceList;
|
|
46
|
+
this.networkTree = networkTree;
|
|
47
|
+
this.renderList = renderList;
|
|
48
|
+
this.renderListCount = renderListCount;
|
|
49
|
+
this.initialTreeBuild = initialTreeBuild;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Smart cache with change detection and adaptive timing.
|
|
54
|
+
* Only writes to file when data actually changes, with intelligent interval adjustment.
|
|
55
|
+
*
|
|
56
|
+
* @returns {void}
|
|
57
|
+
*/
|
|
58
|
+
cacheData() {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
|
|
61
|
+
// Always allow caching on initial build
|
|
62
|
+
if (this.initialTreeBuild) {
|
|
63
|
+
this.performCache();
|
|
64
|
+
return;
|
|
27
65
|
}
|
|
28
66
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @returns {void}
|
|
33
|
-
*/
|
|
34
|
-
cacheData() {
|
|
35
|
-
// Cache the current state of the network tree and other data
|
|
36
|
-
queueConfigStore({
|
|
37
|
-
renderList: this.renderList,
|
|
38
|
-
deviceList: this.deviceList,
|
|
39
|
-
pointList: this.networkTree,
|
|
40
|
-
renderListCount: this.renderListCount,
|
|
41
|
-
});
|
|
67
|
+
// Check if enough time has passed since last cache attempt
|
|
68
|
+
if (now - lastCacheTime < cacheInterval) {
|
|
69
|
+
return; // Skip this cache attempt
|
|
42
70
|
}
|
|
43
71
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (deviceObject) {
|
|
65
|
-
await this.processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index);
|
|
66
|
-
|
|
67
|
-
//delete dummy object if all conditions satisfied
|
|
68
|
-
if (deviceName !== null) {
|
|
69
|
-
if (deviceId !== null) {
|
|
70
|
-
let lastIndex = deviceName.lastIndexOf(deviceId);
|
|
71
|
-
if (lastIndex) {
|
|
72
|
-
let formattedName = deviceName.substring(0, lastIndex);
|
|
73
|
-
formattedName = `${formattedName.trim()}_Device_${deviceId}`;
|
|
74
|
-
if (
|
|
75
|
-
this.networkTree[deviceKey][formattedName] &&
|
|
76
|
-
Object.keys(this.networkTree[deviceKey][formattedName]).length > 0 &&
|
|
77
|
-
this.networkTree[deviceKey]["device"]
|
|
78
|
-
) {
|
|
79
|
-
delete this.networkTree[deviceKey]["device"];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
} else {
|
|
86
|
-
//invalid ip object, likely dumb mstp router
|
|
87
|
-
if (device.getIsDumbMstpRouter()) {
|
|
88
|
-
//update dumb mstp router name
|
|
89
|
-
await this.updateDumbMstpRouterName(deviceName, ipAddress, deviceId);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
72
|
+
// Prepare data for hashing (only essential data to minimize hash computation)
|
|
73
|
+
const cacheData = {
|
|
74
|
+
deviceList: this.deviceList,
|
|
75
|
+
pointList: this.networkTree,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Generate hash of current data
|
|
79
|
+
const currentHash = simpleHash(cacheData);
|
|
80
|
+
|
|
81
|
+
// Check if data has actually changed
|
|
82
|
+
if (currentHash === lastDataHash) {
|
|
83
|
+
// No changes detected - increase cache interval (adaptive backing off)
|
|
84
|
+
consecutiveNoChangeCount++;
|
|
85
|
+
// Exponential backoff with cap
|
|
86
|
+
if (consecutiveNoChangeCount >= 3) {
|
|
87
|
+
cacheInterval = Math.min(cacheInterval * 1.5, MAX_CACHE_INTERVAL);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
lastCacheTime = now;
|
|
91
|
+
return; // Skip caching since no changes
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
// Data has changed - perform cache and reset adaptive timing
|
|
95
|
+
lastDataHash = currentHash;
|
|
96
|
+
lastCacheTime = now;
|
|
97
|
+
consecutiveNoChangeCount = 0;
|
|
98
|
+
|
|
99
|
+
// Reset interval to be more responsive during active changes
|
|
100
|
+
cacheInterval = Math.max(cacheInterval * 0.8, MIN_CACHE_INTERVAL);
|
|
101
|
+
|
|
102
|
+
// Perform the actual cache operation
|
|
103
|
+
this.performCache();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Performs the actual cache operation
|
|
108
|
+
*/
|
|
109
|
+
performCache() {
|
|
110
|
+
// Cache only the essential data, exclude renderList as it's too large and can be rebuilt
|
|
111
|
+
queueConfigStore({
|
|
112
|
+
deviceList: this.deviceList,
|
|
113
|
+
pointList: this.networkTree,
|
|
114
|
+
// renderList: excluded to reduce file size - will be rebuilt from deviceList and networkTree
|
|
115
|
+
// renderListCount: excluded as it can be recalculated
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Process a device and its points.
|
|
121
|
+
*
|
|
122
|
+
* @param {Device} device - The device to process.
|
|
123
|
+
* @param {number} index - The index of the device.
|
|
124
|
+
* @returns {Promise<void>} - A promise that resolves when the device and its points have been processed.
|
|
125
|
+
*/
|
|
126
|
+
async processDevice(device, index) {
|
|
127
|
+
const ipAddress = this.getDeviceIpAddress(device);
|
|
128
|
+
const deviceId = device.getDeviceId();
|
|
129
|
+
const deviceName = this.computeDeviceName(device);
|
|
130
|
+
const deviceKey = `${ipAddress}-${deviceId}`;
|
|
131
|
+
const deviceObject = this.networkTree[deviceKey];
|
|
132
|
+
|
|
133
|
+
// Add the root device folder to the render list
|
|
134
|
+
if (this.initialTreeBuild) {
|
|
135
|
+
this.addRootDeviceFolder(device, deviceName, index, ipAddress, deviceId);
|
|
103
136
|
}
|
|
104
137
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// Check if the device already exists in the renderList
|
|
124
|
-
const existingDeviceIndex = this.renderList.findIndex(item => item.deviceId === deviceId && item.ipAddr === ipAddress);
|
|
125
|
-
if (existingDeviceIndex === -1) { // Device not found, add new entry
|
|
126
|
-
let isDumbMstpRouter = false;
|
|
127
|
-
if (device.getIsDumbMstpRouter() && deviceId == null) isDumbMstpRouter = true;
|
|
128
|
-
const rootFolder = {
|
|
129
|
-
key: index,
|
|
130
|
-
label: displayName,
|
|
131
|
-
data: displayName,
|
|
132
|
-
icon: this.getDeviceIcon(device),
|
|
133
|
-
children: [{ key: `${deviceId}-0`, label: 'Points', data: 'Points Folder', icon: 'pi pi-circle-fill', type: 'pointFolder', children: [] }],
|
|
134
|
-
type: 'device',
|
|
135
|
-
lastSeen: device.getLastSeen(),
|
|
136
|
-
showAdded: false,
|
|
137
|
-
ipAddr: ipAddress,
|
|
138
|
-
deviceId,
|
|
139
|
-
isMstpDevice: device.getIsMstpDevice(),
|
|
140
|
-
initialName: device.getDeviceName(),
|
|
141
|
-
isDumbMstpRouter: isDumbMstpRouter,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// Add the root folder to the render list
|
|
145
|
-
this.renderList.push(rootFolder);
|
|
138
|
+
// Check if the device object exists and the device name is valid
|
|
139
|
+
if (deviceObject) {
|
|
140
|
+
await this.processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index);
|
|
141
|
+
|
|
142
|
+
//delete dummy object if all conditions satisfied
|
|
143
|
+
if (deviceName !== null) {
|
|
144
|
+
if (deviceId !== null) {
|
|
145
|
+
let lastIndex = deviceName.lastIndexOf(deviceId);
|
|
146
|
+
if (lastIndex) {
|
|
147
|
+
let formattedName = deviceName.substring(0, lastIndex);
|
|
148
|
+
formattedName = `${formattedName.trim()}_Device_${deviceId}`;
|
|
149
|
+
if (
|
|
150
|
+
this.networkTree[deviceKey][formattedName] &&
|
|
151
|
+
Object.keys(this.networkTree[deviceKey][formattedName]).length > 0 &&
|
|
152
|
+
this.networkTree[deviceKey]["device"]
|
|
153
|
+
) {
|
|
154
|
+
delete this.networkTree[deviceKey]["device"];
|
|
146
155
|
}
|
|
156
|
+
}
|
|
147
157
|
}
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
//invalid ip object, likely dumb mstp router
|
|
161
|
+
|
|
162
|
+
if (device.getIsDumbMstpRouter()) {
|
|
163
|
+
//update dumb mstp router name
|
|
164
|
+
await this.updateDumbMstpRouterName(deviceName, ipAddress, deviceId);
|
|
165
|
+
}
|
|
148
166
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
isProtocolServicesSet: false,
|
|
178
|
-
isInitialQuery: true,
|
|
179
|
-
isDumbMstpRouter: true,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
let newBacnetDevice = new BacnetDevice(true, newDevice);
|
|
183
|
-
this.deviceList.push(newBacnetDevice);
|
|
184
|
-
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async updateDumbMstpRouterName(deviceName, ipAddress, deviceId) {
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
let listDeviceIndex = this.renderList.findIndex(
|
|
172
|
+
(item) => item.deviceId == deviceId && item.ipAddr == ipAddress && item.isDumbMstpRouter == true
|
|
173
|
+
);
|
|
174
|
+
if (listDeviceIndex !== -1) {
|
|
175
|
+
this.renderList[listDeviceIndex].label = deviceName;
|
|
176
|
+
this.renderList[listDeviceIndex].data = deviceName;
|
|
177
|
+
}
|
|
178
|
+
resolve();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Add the root device folder to the render list.
|
|
184
|
+
*
|
|
185
|
+
* @param {Object} device - The device object.
|
|
186
|
+
* @param {string} deviceName - The name of the device.
|
|
187
|
+
* @param {number} index - The index of the device.
|
|
188
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
189
|
+
* @param {string} deviceId - The ID of the device.
|
|
190
|
+
* @returns {void}
|
|
191
|
+
*/
|
|
192
|
+
addRootDeviceFolder(device, deviceName, index, ipAddress, deviceId) {
|
|
193
|
+
if (!this.renderList) {
|
|
194
|
+
this.renderList = [];
|
|
185
195
|
}
|
|
186
196
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
197
|
+
if (!device.getIsMstpDevice()) {
|
|
198
|
+
let displayName = deviceName ? deviceName : `${ipAddress} - ${deviceId}`;
|
|
199
|
+
|
|
200
|
+
// Check if the device already exists in the renderList
|
|
201
|
+
const existingDeviceIndex = this.renderList.findIndex((item) => item.deviceId === deviceId && item.ipAddr === ipAddress);
|
|
202
|
+
if (existingDeviceIndex === -1) {
|
|
203
|
+
// Device not found, add new entry
|
|
204
|
+
let isDumbMstpRouter = false;
|
|
205
|
+
if (device.getIsDumbMstpRouter() && deviceId == null) isDumbMstpRouter = true;
|
|
206
|
+
const rootFolder = {
|
|
207
|
+
key: index,
|
|
208
|
+
label: displayName,
|
|
209
|
+
data: displayName,
|
|
210
|
+
icon: this.getDeviceIcon(device),
|
|
211
|
+
children: [
|
|
212
|
+
{
|
|
213
|
+
key: `${deviceId}-0`,
|
|
214
|
+
label: "Points",
|
|
215
|
+
data: "Points Folder",
|
|
216
|
+
icon: "pi pi-circle-fill",
|
|
217
|
+
type: "pointFolder",
|
|
218
|
+
children: [],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
type: "device",
|
|
222
|
+
lastSeen: device.getLastSeen(),
|
|
223
|
+
showAdded: false,
|
|
224
|
+
ipAddr: ipAddress,
|
|
225
|
+
deviceId,
|
|
226
|
+
isMstpDevice: device.getIsMstpDevice(),
|
|
227
|
+
initialName: device.getDeviceName(),
|
|
228
|
+
isDumbMstpRouter: isDumbMstpRouter,
|
|
229
|
+
};
|
|
212
230
|
|
|
213
|
-
// Add the
|
|
214
|
-
this.
|
|
231
|
+
// Add the root folder to the render list
|
|
232
|
+
this.renderList.push(rootFolder);
|
|
233
|
+
}
|
|
215
234
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
addEmptyIpRootDevice(childDevice) {
|
|
238
|
+
const ipAddress = this.getDeviceIpAddress(childDevice);
|
|
239
|
+
|
|
240
|
+
//let deviceIndex = this.deviceList.findIndex(ele => ele.address === ipAddress && ele.deviceId === null && ele.deviceName === ipAddress && ele.displayName === ipAddress);
|
|
241
|
+
let deviceIndex = this.deviceList.findIndex((ele) => ele.address === ipAddress && ele.deviceId === null);
|
|
242
|
+
|
|
243
|
+
if (deviceIndex === -1) {
|
|
244
|
+
let newDevice = {
|
|
245
|
+
address: ipAddress,
|
|
246
|
+
isMstp: false,
|
|
247
|
+
deviceId: null,
|
|
248
|
+
maxApdu: childDevice.getMaxApdu(),
|
|
249
|
+
segmentation: childDevice.getSegmentation(),
|
|
250
|
+
vendorId: childDevice.getVendorId(),
|
|
251
|
+
lastSeen: null,
|
|
252
|
+
deviceName: ipAddress,
|
|
253
|
+
pointsList: [],
|
|
254
|
+
pointListUpdateTs: null,
|
|
255
|
+
manualDiscoveryMode: false,
|
|
256
|
+
pointListRetryCount: 0,
|
|
257
|
+
priorityQueueIsActive: false,
|
|
258
|
+
priorityQueue: [],
|
|
259
|
+
lastPriorityQueueTS: null,
|
|
260
|
+
childDevices: [childDevice.getDeviceId()],
|
|
261
|
+
parentDeviceId: null,
|
|
262
|
+
displayName: ipAddress,
|
|
263
|
+
protocolServicesSupported: [],
|
|
264
|
+
isProtocolServicesSet: false,
|
|
265
|
+
isInitialQuery: true,
|
|
266
|
+
isDumbMstpRouter: true,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
let newBacnetDevice = new BacnetDevice(true, newDevice);
|
|
270
|
+
this.deviceList.push(newBacnetDevice);
|
|
249
271
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Process the points of a device and add them to the render list.
|
|
276
|
+
*
|
|
277
|
+
* @param {Device} device - The device object.
|
|
278
|
+
* @param {Object} deviceObject - The object containing the points of the device.
|
|
279
|
+
* @param {string} deviceName - The name of the device.
|
|
280
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
281
|
+
* @param {string} deviceId - The ID of the device.
|
|
282
|
+
* @param {number} index - The index of the device.
|
|
283
|
+
* @returns {Promise<void>} - A promise that resolves when the points have been processed and added to the render list.
|
|
284
|
+
*/
|
|
285
|
+
async processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index) {
|
|
286
|
+
// Initialize the list of children points
|
|
287
|
+
let children = [];
|
|
288
|
+
|
|
289
|
+
// Process each point in the device object
|
|
290
|
+
for (const pointName in deviceObject) {
|
|
291
|
+
// Ensure processing should continue
|
|
292
|
+
this.checkInterruptFlag();
|
|
293
|
+
|
|
294
|
+
// Process the point and add it to the list of children
|
|
295
|
+
const point = deviceObject[pointName];
|
|
296
|
+
const childPoint = await this.processPoint(point, pointName, index, deviceName, device);
|
|
297
|
+
children.push(childPoint);
|
|
274
298
|
}
|
|
275
299
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
// Add the device and its children to the render list
|
|
301
|
+
this.updateRenderList(children, device, deviceName, index, ipAddress, deviceId);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Process a point and create a child point object.
|
|
306
|
+
*
|
|
307
|
+
* @param {Object} point - The point to process.
|
|
308
|
+
* @param {string} pointName - The name of the point.
|
|
309
|
+
* @param {number} index - The index of the point.
|
|
310
|
+
* @param {string} deviceName - The name of the parent device.
|
|
311
|
+
* @param {Object} device - The parent device object.
|
|
312
|
+
* @returns {Object} - The child point object.
|
|
313
|
+
*/
|
|
314
|
+
async processPoint(point, pointName, index, deviceName, device) {
|
|
315
|
+
// Get the properties and data of the point
|
|
316
|
+
const pointProperties = this.extractPointProperties(point);
|
|
317
|
+
|
|
318
|
+
// Determine the point's display name and apply formatting if necessary
|
|
319
|
+
const displayName = this.formatDisplayName(point, pointName);
|
|
320
|
+
|
|
321
|
+
// Create the child point object
|
|
322
|
+
return {
|
|
323
|
+
key: `${index}-0-${pointName}`,
|
|
324
|
+
label: displayName,
|
|
325
|
+
data: displayName,
|
|
326
|
+
pointName,
|
|
327
|
+
icon: this.getPointIcon(point),
|
|
328
|
+
children: pointProperties,
|
|
329
|
+
type: "point",
|
|
330
|
+
parentDevice: deviceName,
|
|
331
|
+
parentDeviceId: device.getDeviceId(),
|
|
332
|
+
showAdded: false,
|
|
333
|
+
bacnetType: point.meta.objectId.type,
|
|
334
|
+
bacnetInstance: point.meta.objectId.instance,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Extracts the properties of a point object.
|
|
340
|
+
*
|
|
341
|
+
* @param {Object} point - The point object to extract properties from.
|
|
342
|
+
* @returns {Array} - An array of point properties.
|
|
343
|
+
*/
|
|
344
|
+
extractPointProperties(point) {
|
|
345
|
+
const pointProperties = [];
|
|
346
|
+
|
|
347
|
+
// Add properties such as name, type, instance, and others
|
|
348
|
+
this.addPointProperty(pointProperties, "Name", point.objectName);
|
|
349
|
+
this.addPointProperty(pointProperties, "Object Type", point.meta.objectId.type);
|
|
350
|
+
this.addPointProperty(pointProperties, "Object Instance", point.meta.objectId.instance);
|
|
351
|
+
this.addPointProperty(pointProperties, "Description", point.description);
|
|
352
|
+
this.addPointProperty(pointProperties, "Units", point.units);
|
|
353
|
+
this.addPointProperty(pointProperties, "Present Value", point.presentValue);
|
|
354
|
+
this.addPointProperty(pointProperties, "System Status", point.systemStatus);
|
|
355
|
+
this.addPointProperty(pointProperties, "Modification Date", point.modificationDate);
|
|
356
|
+
this.addPointProperty(pointProperties, "Program State", point.programState);
|
|
357
|
+
this.addPointProperty(pointProperties, "Record Count", point.recordCount);
|
|
358
|
+
|
|
359
|
+
// Return the array of point properties
|
|
360
|
+
return pointProperties;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Adds a property to the list of point properties.
|
|
365
|
+
*
|
|
366
|
+
* @param {Array} properties - The list of point properties.
|
|
367
|
+
* @param {string} label - The label of the property.
|
|
368
|
+
* @param {any} value - The value of the property.
|
|
369
|
+
* @returns {void}
|
|
370
|
+
*/
|
|
371
|
+
addPointProperty(properties, label, value) {
|
|
372
|
+
if (value !== null && value !== undefined && value !== "") {
|
|
373
|
+
properties.push({
|
|
374
|
+
label: `${label}: ${value}`,
|
|
375
|
+
data: value,
|
|
376
|
+
icon: "pi pi-cog",
|
|
377
|
+
children: null,
|
|
378
|
+
});
|
|
293
379
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Formats the display name for a point.
|
|
384
|
+
*
|
|
385
|
+
* If the point has a display name, it returns the display name.
|
|
386
|
+
* Otherwise, it removes any special characters from the point name and returns it.
|
|
387
|
+
*
|
|
388
|
+
* @param {Object} point - The point object.
|
|
389
|
+
* @param {string} pointName - The name of the point.
|
|
390
|
+
* @returns {string} - The formatted display name.
|
|
391
|
+
*/
|
|
392
|
+
formatDisplayName(point, pointName) {
|
|
393
|
+
const reg = /[$#\/\\+]/gi;
|
|
394
|
+
if (point.displayName) {
|
|
395
|
+
return point.displayName;
|
|
396
|
+
}
|
|
397
|
+
return pointName.replace(reg, "");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Updates the render list with the folder structure for a device.
|
|
402
|
+
*
|
|
403
|
+
* @param {Array} children - The children of the device.
|
|
404
|
+
* @param {Object} device - The device object.
|
|
405
|
+
* @param {string} deviceName - The name of the device.
|
|
406
|
+
* @param {number} index - The index of the device.
|
|
407
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
408
|
+
* @param {string} deviceId - The ID of the device.
|
|
409
|
+
* @returns {void}
|
|
410
|
+
*/
|
|
411
|
+
updateRenderList(children, device, deviceName, index, ipAddress, deviceId) {
|
|
412
|
+
// Create the folder structure for the device
|
|
413
|
+
const folderJson = this.createFolderJson(children, device.hasChildDevices(), deviceId);
|
|
414
|
+
if (!this.renderList) {
|
|
415
|
+
this.renderList = [];
|
|
311
416
|
}
|
|
312
417
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
418
|
+
// Find the device's entry in the render list
|
|
419
|
+
let foundIndex = this.renderList.findIndex((ele) => ele.deviceId == deviceId && ele.ipAddr == ipAddress);
|
|
420
|
+
|
|
421
|
+
// If the device is not in the render list, add it as a new entry
|
|
422
|
+
const newDeviceEntry = {
|
|
423
|
+
key: index,
|
|
424
|
+
label: deviceName,
|
|
425
|
+
data: deviceName,
|
|
426
|
+
icon: this.getDeviceIcon(device),
|
|
427
|
+
children: folderJson,
|
|
428
|
+
type: "device",
|
|
429
|
+
lastSeen: device.getLastSeen(),
|
|
430
|
+
showAdded: false,
|
|
431
|
+
ipAddr: ipAddress,
|
|
432
|
+
deviceId,
|
|
433
|
+
isMstpDevice: device.getIsMstpDevice(),
|
|
434
|
+
initialName: device.getDeviceName(),
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
if (device.getIsMstpDevice()) {
|
|
438
|
+
// For child MSTP devices, find the parent device and the MSTP network folder
|
|
439
|
+
const parentDeviceId = device.getParentDeviceId();
|
|
440
|
+
const parentDeviceIndex = this.renderList.findIndex((ele) => ele.deviceId == parentDeviceId && ele.ipAddr == ipAddress);
|
|
441
|
+
const mstpNetworkNumber = device.getMstpNetworkNumber();
|
|
442
|
+
|
|
443
|
+
if (parentDeviceIndex !== -1) {
|
|
444
|
+
let parentDeviceEntry = this.renderList[parentDeviceIndex];
|
|
445
|
+
let mstpNetworkFolder = parentDeviceEntry.children.find((child) => child.label === `MSTP NET${mstpNetworkNumber}`);
|
|
446
|
+
|
|
447
|
+
// Create the MSTP network folder if it doesn't exist
|
|
448
|
+
if (!mstpNetworkFolder) {
|
|
449
|
+
mstpNetworkFolder = {
|
|
450
|
+
key: `${deviceId}-mstp-${mstpNetworkNumber}`,
|
|
451
|
+
label: `MSTP NET${mstpNetworkNumber}`,
|
|
452
|
+
data: `Devices Folder (${mstpNetworkNumber})`,
|
|
453
|
+
icon: "pi pi-database",
|
|
454
|
+
type: "mstpfolder",
|
|
455
|
+
children: [],
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
parentDeviceEntry.children.push(mstpNetworkFolder);
|
|
329
459
|
}
|
|
330
460
|
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
label: deviceName,
|
|
338
|
-
data: deviceName,
|
|
339
|
-
icon: this.getDeviceIcon(device),
|
|
340
|
-
children: folderJson,
|
|
341
|
-
type: 'device',
|
|
342
|
-
lastSeen: device.getLastSeen(),
|
|
343
|
-
showAdded: false,
|
|
344
|
-
ipAddr: ipAddress,
|
|
345
|
-
deviceId,
|
|
346
|
-
isMstpDevice: device.getIsMstpDevice(),
|
|
347
|
-
initialName: device.getDeviceName(),
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
if (device.getIsMstpDevice()) {
|
|
351
|
-
// For child MSTP devices, find the parent device and the MSTP network folder
|
|
352
|
-
const parentDeviceId = device.getParentDeviceId();
|
|
353
|
-
const parentDeviceIndex = this.renderList.findIndex(ele => ele.deviceId == parentDeviceId && ele.ipAddr == ipAddress);
|
|
354
|
-
const mstpNetworkNumber = device.getMstpNetworkNumber();
|
|
355
|
-
|
|
356
|
-
if (parentDeviceIndex !== -1) {
|
|
357
|
-
let parentDeviceEntry = this.renderList[parentDeviceIndex];
|
|
358
|
-
let mstpNetworkFolder = parentDeviceEntry.children.find(child => child.label === `MSTP NET${mstpNetworkNumber}`);
|
|
359
|
-
|
|
360
|
-
// Create the MSTP network folder if it doesn't exist
|
|
361
|
-
if (!mstpNetworkFolder) {
|
|
362
|
-
mstpNetworkFolder = {
|
|
363
|
-
key: `${deviceId}-mstp-${mstpNetworkNumber}`,
|
|
364
|
-
label: `MSTP NET${mstpNetworkNumber}`,
|
|
365
|
-
data: `Devices Folder (${mstpNetworkNumber})`,
|
|
366
|
-
icon: 'pi pi-database',
|
|
367
|
-
type: 'deviceFolder',
|
|
368
|
-
children: [],
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
parentDeviceEntry.children.push(mstpNetworkFolder);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Add or update the child MSTP device in the MSTP folder
|
|
375
|
-
const mstpDeviceIndex = mstpNetworkFolder.children.findIndex(ele => ele.deviceId == deviceId && ele.ipAddr == ipAddress);
|
|
376
|
-
if (mstpDeviceIndex === -1) {
|
|
377
|
-
mstpNetworkFolder.children.push(newDeviceEntry);
|
|
378
|
-
} else {
|
|
379
|
-
mstpNetworkFolder.children[mstpDeviceIndex] = newDeviceEntry;
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
//no parent found in render list
|
|
383
|
-
|
|
384
|
-
if (parentDeviceId !== null) {
|
|
385
|
-
let parentDeviceListIndex = this.deviceList.findIndex(ele => ele.getDeviceId == parentDeviceId);
|
|
386
|
-
|
|
387
|
-
if (parentDeviceListIndex !== -1) {
|
|
388
|
-
let parentDevice = this.deviceList[parentDeviceListIndex];
|
|
389
|
-
this.addRootDeviceFolder(parentDevice, parentDevice.getDeviceName(), parentDeviceListIndex, parentDevice.getAddress(), parentDeviceId);
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
this.addEmptyIpRootDevice(device);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
461
|
+
// Add or update the child MSTP device in the MSTP folder
|
|
462
|
+
const mstpDeviceIndex = mstpNetworkFolder.children.findIndex(
|
|
463
|
+
(ele) => ele.deviceId == deviceId && ele.ipAddr == ipAddress
|
|
464
|
+
);
|
|
465
|
+
if (mstpDeviceIndex === -1) {
|
|
466
|
+
mstpNetworkFolder.children.push(newDeviceEntry);
|
|
396
467
|
} else {
|
|
397
|
-
|
|
398
|
-
if (foundIndex === -1) {
|
|
399
|
-
this.renderList.push(newDeviceEntry);
|
|
400
|
-
} else {
|
|
401
|
-
// If the device is already in the render list, update its entry
|
|
402
|
-
this.renderList[foundIndex] = newDeviceEntry;
|
|
403
|
-
}
|
|
468
|
+
mstpNetworkFolder.children[mstpDeviceIndex] = newDeviceEntry;
|
|
404
469
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
470
|
+
} else {
|
|
471
|
+
//no parent found in render list
|
|
472
|
+
|
|
473
|
+
if (parentDeviceId !== null) {
|
|
474
|
+
let parentDeviceListIndex = this.deviceList.findIndex((ele) => ele.getDeviceId() == parentDeviceId);
|
|
475
|
+
|
|
476
|
+
if (parentDeviceListIndex !== -1) {
|
|
477
|
+
let parentDevice = this.deviceList[parentDeviceListIndex];
|
|
478
|
+
this.addRootDeviceFolder(
|
|
479
|
+
parentDevice,
|
|
480
|
+
parentDevice.getDeviceName(),
|
|
481
|
+
parentDeviceListIndex,
|
|
482
|
+
parentDevice.getAddress(),
|
|
483
|
+
parentDeviceId
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
this.addEmptyIpRootDevice(device);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
// Add the new device entry to the root of the render list
|
|
492
|
+
if (foundIndex === -1) {
|
|
493
|
+
this.renderList.push(newDeviceEntry);
|
|
494
|
+
} else {
|
|
495
|
+
// If the device is already in the render list, preserve existing MSTP folders
|
|
496
|
+
const existingDevice = this.renderList[foundIndex];
|
|
497
|
+
|
|
498
|
+
// Preserve existing MSTP folders while updating the device info
|
|
499
|
+
const existingMstpFolders = existingDevice.children.filter(
|
|
500
|
+
(child) => child.type === "mstpfolder" || (child.label && child.label.includes("MSTP"))
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
// Start with the new device structure
|
|
504
|
+
const updatedDevice = { ...newDeviceEntry };
|
|
505
|
+
|
|
506
|
+
// Add back any existing MSTP folders
|
|
507
|
+
existingMstpFolders.forEach((mstpFolder) => {
|
|
508
|
+
const existingMstpIndex = updatedDevice.children.findIndex((child) => child.label === mstpFolder.label);
|
|
509
|
+
if (existingMstpIndex === -1) {
|
|
510
|
+
// MSTP folder doesn't exist in new structure, add it
|
|
511
|
+
updatedDevice.children.push(mstpFolder);
|
|
512
|
+
} else {
|
|
513
|
+
// MSTP folder exists, keep the existing one (with all its children)
|
|
514
|
+
updatedDevice.children[existingMstpIndex] = mstpFolder;
|
|
515
|
+
}
|
|
516
|
+
});
|
|
429
517
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*
|
|
433
|
-
* @returns {Object} The finalized network tree data
|
|
434
|
-
* - renderList: The list of devices and their points
|
|
435
|
-
* - deviceList: The list of devices
|
|
436
|
-
* - pointList: The list of points in the network tree
|
|
437
|
-
* - pollFrequency: The polling schedule for discovery
|
|
438
|
-
*/
|
|
439
|
-
finalizeNetworkTreeData() {
|
|
440
|
-
this.renderList.sort(this.sortDevices);
|
|
441
|
-
|
|
442
|
-
return {
|
|
443
|
-
renderList: this.renderList,
|
|
444
|
-
deviceList: this.deviceList,
|
|
445
|
-
pointList: this.networkTree,
|
|
446
|
-
pollFrequency: this.discover_polling_schedule,
|
|
447
|
-
};
|
|
518
|
+
this.renderList[foundIndex] = updatedDevice;
|
|
519
|
+
}
|
|
448
520
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Creates a folder JSON object for the network tree.
|
|
525
|
+
*
|
|
526
|
+
* @param {Array} children - The children nodes of the folder.
|
|
527
|
+
* @param {boolean} hasChildDevices - Indicates if the device has child devices.
|
|
528
|
+
* @param {string} deviceId - The ID of the device.
|
|
529
|
+
* @returns {Array} - The folder JSON object.
|
|
530
|
+
*/
|
|
531
|
+
createFolderJson(children, hasChildDevices, deviceId) {
|
|
532
|
+
const folders = [
|
|
533
|
+
{
|
|
534
|
+
key: `${deviceId}-0`,
|
|
535
|
+
label: "Points",
|
|
536
|
+
data: "Points Folder",
|
|
537
|
+
icon: "pi pi-circle-fill",
|
|
538
|
+
type: "pointFolder",
|
|
539
|
+
children: children.sort(this.sortPoints),
|
|
540
|
+
},
|
|
541
|
+
];
|
|
542
|
+
|
|
543
|
+
return folders;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Finalize the network tree data
|
|
548
|
+
*
|
|
549
|
+
* @returns {Object} The finalized network tree data
|
|
550
|
+
* - renderList: The list of devices and their points
|
|
551
|
+
* - deviceList: The list of devices
|
|
552
|
+
* - pointList: The list of points in the network tree
|
|
553
|
+
* - pollFrequency: The polling schedule for discovery
|
|
554
|
+
*/
|
|
555
|
+
finalizeNetworkTreeData() {
|
|
556
|
+
this.renderList.sort(this.sortDevices);
|
|
557
|
+
|
|
558
|
+
return {
|
|
559
|
+
renderList: this.renderList,
|
|
560
|
+
deviceList: this.deviceList,
|
|
561
|
+
pointList: this.networkTree,
|
|
562
|
+
pollFrequency: this.discover_polling_schedule,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Checks if the buildTreeException flag is set and throws an error if it is.
|
|
568
|
+
*
|
|
569
|
+
* @throws {Error} - Throws an error with the message 'Build tree interrupted' if the buildTreeException flag is set.
|
|
570
|
+
*/
|
|
571
|
+
checkInterruptFlag() {
|
|
572
|
+
if (this.buildTreeException) {
|
|
573
|
+
throw new Error("Build tree interrupted");
|
|
459
574
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Returns the IP address of the given device.
|
|
579
|
+
*
|
|
580
|
+
* @param {object} device - The device object.
|
|
581
|
+
* @returns {string} The IP address of the device.
|
|
582
|
+
*/
|
|
583
|
+
getDeviceIpAddress(device) {
|
|
584
|
+
switch (typeof device.getAddress()) {
|
|
585
|
+
case "object":
|
|
586
|
+
return device.getAddress().address;
|
|
587
|
+
case "string":
|
|
588
|
+
return device.getAddress();
|
|
589
|
+
default:
|
|
590
|
+
return device.getAddress();
|
|
476
591
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return device.getDeviceName();
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Computes the device name based on the provided device object.
|
|
596
|
+
* If the device has a display name, it will be returned.
|
|
597
|
+
* Otherwise, the device name will be returned.
|
|
598
|
+
*
|
|
599
|
+
* @param {Object} device - The device object.
|
|
600
|
+
* @returns {string} - The computed device name.
|
|
601
|
+
*/
|
|
602
|
+
computeDeviceName(device) {
|
|
603
|
+
if (device.getDeviceName() == null && device.getDisplayName() == null) {
|
|
604
|
+
return `${this.getDeviceIpAddress(device)}-${device.getDeviceId()}`;
|
|
605
|
+
} else if (device.getDisplayName() !== null && device.getDisplayName() !== "" && device.getDisplayName() !== undefined) {
|
|
606
|
+
return device.getDisplayName();
|
|
493
607
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return a.label.localeCompare(b.label);
|
|
608
|
+
return device.getDeviceName();
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Sorts the points based on their BACnet type and label.
|
|
613
|
+
*
|
|
614
|
+
* @param {Object} a - The first point object to compare.
|
|
615
|
+
* @param {Object} b - The second point object to compare.
|
|
616
|
+
* @returns {number} - A negative number if a should be sorted before b, a positive number if b should be sorted before a, or 0 if they are equal.
|
|
617
|
+
*/
|
|
618
|
+
sortPoints(a, b) {
|
|
619
|
+
if (a.bacnetType > b.bacnetType) {
|
|
620
|
+
return 1;
|
|
621
|
+
} else if (a.bacnetType < b.bacnetType) {
|
|
622
|
+
return -1;
|
|
623
|
+
} else if (a.bacnetType == b.bacnetType) {
|
|
624
|
+
return 0;
|
|
512
625
|
}
|
|
513
626
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
627
|
+
return a.label.localeCompare(b.label);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Sorts devices based on their deviceId.
|
|
632
|
+
*
|
|
633
|
+
* @param {Object} a - The first device object to compare.
|
|
634
|
+
* @param {Object} b - The second device object to compare.
|
|
635
|
+
* @returns {number} - Returns -1 if a.deviceId is less than b.deviceId, 1 if a.deviceId is greater than b.deviceId, or 0 if they are equal.
|
|
636
|
+
*/
|
|
637
|
+
sortDevices(a, b) {
|
|
638
|
+
if (a.deviceId < b.deviceId) {
|
|
639
|
+
return -1;
|
|
640
|
+
} else if (a.deviceId > b.deviceId) {
|
|
641
|
+
return 1;
|
|
528
642
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
643
|
+
return 0; // deviceIds are equal
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Returns the icon class name for a given point based on its object type.
|
|
648
|
+
*
|
|
649
|
+
* @param {Object} values - The values object containing the point's metadata.
|
|
650
|
+
* @returns {string} - The icon class name for the point.
|
|
651
|
+
*/
|
|
652
|
+
getPointIcon(values) {
|
|
653
|
+
const objectId = values.meta.objectId.type;
|
|
654
|
+
const hasPriorityArray =
|
|
655
|
+
values.hasPriorityArray && values.hasOwnProperty("hasPriorityArray") ? values.hasPriorityArray : false;
|
|
656
|
+
|
|
657
|
+
if (hasPriorityArray) {
|
|
658
|
+
return "pi writePointIcon";
|
|
659
|
+
} else {
|
|
660
|
+
switch (objectId) {
|
|
661
|
+
case 0:
|
|
662
|
+
//AI
|
|
663
|
+
return "pi readPointIcon";
|
|
664
|
+
case 1:
|
|
665
|
+
//AO
|
|
666
|
+
return "pi readPointIcon";
|
|
667
|
+
case 2:
|
|
668
|
+
//AV
|
|
669
|
+
return "pi readPointIcon";
|
|
670
|
+
case 3:
|
|
671
|
+
//BI
|
|
672
|
+
return "pi readPointIcon";
|
|
673
|
+
case 4:
|
|
674
|
+
//BO
|
|
675
|
+
return "pi readPointIcon";
|
|
676
|
+
case 5:
|
|
677
|
+
//BV
|
|
678
|
+
return "pi readPointIcon";
|
|
679
|
+
case 8:
|
|
680
|
+
//Device
|
|
681
|
+
return "pi pi-box";
|
|
682
|
+
case 13:
|
|
683
|
+
//MI
|
|
684
|
+
return "pi readPointIcon";
|
|
685
|
+
case 14:
|
|
686
|
+
//MO
|
|
687
|
+
return "pi readPointIcon";
|
|
688
|
+
case 19:
|
|
689
|
+
//MV
|
|
690
|
+
return "pi readPointIcon";
|
|
691
|
+
case 10:
|
|
692
|
+
//File
|
|
693
|
+
return "pi pi-file";
|
|
694
|
+
case 16:
|
|
695
|
+
//Program
|
|
696
|
+
return "pi pi-database";
|
|
697
|
+
case 20:
|
|
698
|
+
//Trendlog
|
|
699
|
+
return "pi pi-chart-line";
|
|
700
|
+
case 15:
|
|
701
|
+
//Notification Class
|
|
702
|
+
return "pi pi-bell";
|
|
703
|
+
case 56:
|
|
704
|
+
return "pi pi-sitemap";
|
|
705
|
+
case 178:
|
|
706
|
+
return "pi pi-lock";
|
|
707
|
+
case 17:
|
|
708
|
+
return "pi pi-calendar";
|
|
709
|
+
case 6:
|
|
710
|
+
return "pi pi-calendar";
|
|
711
|
+
default:
|
|
712
|
+
//Return circle for all other types
|
|
713
|
+
return "pi readPointIcon";
|
|
714
|
+
}
|
|
600
715
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Returns the icon for a given device based on its properties.
|
|
720
|
+
*
|
|
721
|
+
* @param {Object} device - The device object.
|
|
722
|
+
* @returns {string} - The icon class name.
|
|
723
|
+
*/
|
|
724
|
+
getDeviceIcon(device) {
|
|
725
|
+
const isMstp = device.getIsMstpDevice();
|
|
726
|
+
const manualDiscoveryMode = device.getManualDiscoveryMode();
|
|
727
|
+
|
|
728
|
+
if (manualDiscoveryMode == true) {
|
|
729
|
+
return "pi pi-question-circle";
|
|
730
|
+
} else if (manualDiscoveryMode == false) {
|
|
731
|
+
if (isMstp == true) {
|
|
732
|
+
return "pi pi-box";
|
|
733
|
+
} else if (isMstp == false) {
|
|
621
734
|
return "pi pi-server";
|
|
735
|
+
}
|
|
622
736
|
}
|
|
737
|
+
return "pi pi-server";
|
|
738
|
+
}
|
|
623
739
|
}
|
|
624
740
|
|
|
625
|
-
module.exports = { treeBuilder };
|
|
741
|
+
module.exports = { treeBuilder };
|