@bitpoolos/edge-bacnet 1.2.8 → 1.3.0
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 +76 -0
- package/README.md +20 -2
- package/bacnet_client.js +592 -760
- package/bacnet_device.js +122 -60
- package/bacnet_gateway.html +91 -75
- package/bacnet_gateway.js +161 -46
- package/bacnet_read.html +1025 -596
- package/bacnet_read.js +68 -84
- package/bacnet_server.js +187 -186
- package/bacnet_write.html +268 -24
- package/common.js +22 -4
- package/package.json +2 -2
- package/resources/bitArray.js +167 -0
- package/resources/node-bacstack-ts/dist/lib/asn1.js +16 -5
- package/resources/node-bacstack-ts/dist/lib/client.js +5 -6
- package/resources/style.css +321 -0
- package/treeBuilder.js +533 -0
package/treeBuilder.js
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
const { Store_Config } = require("./common");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `treeBuilder` class is responsible for building and processing the network tree structure.
|
|
5
|
+
* It takes in a list of devices, a network tree object, a render list, a render list count, and an initial tree build flag.
|
|
6
|
+
* The class provides methods for caching data, processing a device and its points, adding the root device folder to the render list,
|
|
7
|
+
* processing points for a device, processing an individual point, extracting point properties, formatting display name for a point,
|
|
8
|
+
* updating the render list, creating the folder JSON structure for a device, finalizing the network tree data, checking the interrupt flag,
|
|
9
|
+
* getting the device IP address, computing the device name, sorting points, sorting devices, getting the point icon, and getting the device icon.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @name treeBuilder
|
|
13
|
+
* @param {Array} deviceList - The list of devices.
|
|
14
|
+
* @param {Object} networkTree - The network tree object.
|
|
15
|
+
* @param {Array} renderList - The render list.
|
|
16
|
+
* @param {number} renderListCount - The render list count.
|
|
17
|
+
* @param {boolean} initialTreeBuild - The initial tree build flag.
|
|
18
|
+
*/
|
|
19
|
+
class treeBuilder {
|
|
20
|
+
constructor(deviceList, networkTree, renderList, renderListCount, initialTreeBuild) {
|
|
21
|
+
this.deviceList = deviceList;
|
|
22
|
+
this.networkTree = networkTree;
|
|
23
|
+
this.renderList = renderList;
|
|
24
|
+
this.renderListCount = renderListCount;
|
|
25
|
+
this.initialTreeBuild = initialTreeBuild;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cache the current state of the network tree and other data.
|
|
30
|
+
*
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
cacheData() {
|
|
34
|
+
// Cache the current state of the network tree and other data
|
|
35
|
+
Store_Config(JSON.stringify({
|
|
36
|
+
renderList: this.renderList,
|
|
37
|
+
deviceList: this.deviceList,
|
|
38
|
+
pointList: this.networkTree,
|
|
39
|
+
renderListCount: this.renderListCount,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Process a device and its points.
|
|
45
|
+
*
|
|
46
|
+
* @param {Device} device - The device to process.
|
|
47
|
+
* @param {number} index - The index of the device.
|
|
48
|
+
* @returns {Promise<void>} - A promise that resolves when the device and its points have been processed.
|
|
49
|
+
*/
|
|
50
|
+
async processDevice(device, index) {
|
|
51
|
+
const ipAddress = this.getDeviceIpAddress(device);
|
|
52
|
+
const deviceId = device.getDeviceId();
|
|
53
|
+
const deviceName = this.computeDeviceName(device);
|
|
54
|
+
const deviceKey = `${ipAddress}-${deviceId}`;
|
|
55
|
+
const deviceObject = this.networkTree[deviceKey];
|
|
56
|
+
|
|
57
|
+
// Add the root device folder to the render list
|
|
58
|
+
if (this.initialTreeBuild) {
|
|
59
|
+
this.addRootDeviceFolder(device, deviceName, index, ipAddress, deviceId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Check if the device object exists and the device name is valid
|
|
63
|
+
if (deviceObject && typeof deviceName !== 'object') {
|
|
64
|
+
await this.processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Add the root device folder to the render list.
|
|
70
|
+
*
|
|
71
|
+
* @param {Object} device - The device object.
|
|
72
|
+
* @param {string} deviceName - The name of the device.
|
|
73
|
+
* @param {number} index - The index of the device.
|
|
74
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
75
|
+
* @param {string} deviceId - The ID of the device.
|
|
76
|
+
* @returns {void}
|
|
77
|
+
*/
|
|
78
|
+
addRootDeviceFolder(device, deviceName, index, ipAddress, deviceId) {
|
|
79
|
+
if (!this.renderList) {
|
|
80
|
+
this.renderList = [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!device.getIsMstpDevice()) {
|
|
84
|
+
let displayName = deviceName ? deviceName : `${ipAddress} - ${deviceId}`;
|
|
85
|
+
|
|
86
|
+
// Check if the device already exists in the renderList
|
|
87
|
+
const existingDeviceIndex = this.renderList.findIndex(item => item.deviceId === deviceId && item.ipAddr === ipAddress);
|
|
88
|
+
|
|
89
|
+
if (existingDeviceIndex === -1) { // Device not found, add new entry
|
|
90
|
+
const rootFolder = {
|
|
91
|
+
key: index,
|
|
92
|
+
label: displayName,
|
|
93
|
+
data: displayName,
|
|
94
|
+
icon: this.getDeviceIcon(device),
|
|
95
|
+
children: [{ key: `${deviceId}-0`, label: 'Points', data: 'Points Folder', icon: 'pi pi-circle-fill', type: 'pointFolder', children: [] }],
|
|
96
|
+
type: 'device',
|
|
97
|
+
lastSeen: device.getLastSeen(),
|
|
98
|
+
showAdded: false,
|
|
99
|
+
ipAddr: ipAddress,
|
|
100
|
+
deviceId,
|
|
101
|
+
isMstpDevice: device.getIsMstpDevice(),
|
|
102
|
+
initialName: device.getDeviceName(),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Add the root folder to the render list
|
|
106
|
+
this.renderList.push(rootFolder);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Process the points of a device and add them to the render list.
|
|
113
|
+
*
|
|
114
|
+
* @param {Device} device - The device object.
|
|
115
|
+
* @param {Object} deviceObject - The object containing the points of the device.
|
|
116
|
+
* @param {string} deviceName - The name of the device.
|
|
117
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
118
|
+
* @param {string} deviceId - The ID of the device.
|
|
119
|
+
* @param {number} index - The index of the device.
|
|
120
|
+
* @returns {Promise<void>} - A promise that resolves when the points have been processed and added to the render list.
|
|
121
|
+
*/
|
|
122
|
+
async processDevicePoints(device, deviceObject, deviceName, ipAddress, deviceId, index) {
|
|
123
|
+
// Initialize the list of children points
|
|
124
|
+
const children = [];
|
|
125
|
+
|
|
126
|
+
// Process each point in the device object
|
|
127
|
+
for (const pointName in deviceObject) {
|
|
128
|
+
// Ensure processing should continue
|
|
129
|
+
this.checkInterruptFlag();
|
|
130
|
+
|
|
131
|
+
// Process the point and add it to the list of children
|
|
132
|
+
const point = deviceObject[pointName];
|
|
133
|
+
const childPoint = await this.processPoint(point, pointName, index, deviceName, device);
|
|
134
|
+
children.push(childPoint);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Add the device and its children to the render list
|
|
138
|
+
this.updateRenderList(children, device, deviceName, index, ipAddress, deviceId);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Process a point and create a child point object.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} point - The point to process.
|
|
145
|
+
* @param {string} pointName - The name of the point.
|
|
146
|
+
* @param {number} index - The index of the point.
|
|
147
|
+
* @param {string} deviceName - The name of the parent device.
|
|
148
|
+
* @param {Object} device - The parent device object.
|
|
149
|
+
* @returns {Object} - The child point object.
|
|
150
|
+
*/
|
|
151
|
+
async processPoint(point, pointName, index, deviceName, device) {
|
|
152
|
+
// Get the properties and data of the point
|
|
153
|
+
const pointProperties = this.extractPointProperties(point);
|
|
154
|
+
|
|
155
|
+
// Determine the point's display name and apply formatting if necessary
|
|
156
|
+
const displayName = this.formatDisplayName(point, pointName);
|
|
157
|
+
|
|
158
|
+
// Create the child point object
|
|
159
|
+
return {
|
|
160
|
+
key: `${index}-0-${pointName}`,
|
|
161
|
+
label: displayName,
|
|
162
|
+
data: displayName,
|
|
163
|
+
pointName,
|
|
164
|
+
icon: this.getPointIcon(point),
|
|
165
|
+
children: pointProperties,
|
|
166
|
+
type: 'point',
|
|
167
|
+
parentDevice: deviceName,
|
|
168
|
+
showAdded: false,
|
|
169
|
+
bacnetType: point.meta.objectId.type,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Extracts the properties of a point object.
|
|
175
|
+
*
|
|
176
|
+
* @param {Object} point - The point object to extract properties from.
|
|
177
|
+
* @returns {Array} - An array of point properties.
|
|
178
|
+
*/
|
|
179
|
+
extractPointProperties(point) {
|
|
180
|
+
const pointProperties = [];
|
|
181
|
+
|
|
182
|
+
// Add properties such as name, type, instance, and others
|
|
183
|
+
this.addPointProperty(pointProperties, 'Name', point.objectName);
|
|
184
|
+
this.addPointProperty(pointProperties, 'Object Type', point.meta.objectId.type);
|
|
185
|
+
this.addPointProperty(pointProperties, 'Object Instance', point.meta.objectId.instance);
|
|
186
|
+
this.addPointProperty(pointProperties, 'Description', point.description);
|
|
187
|
+
this.addPointProperty(pointProperties, 'Units', point.units);
|
|
188
|
+
this.addPointProperty(pointProperties, 'Present Value', point.presentValue);
|
|
189
|
+
this.addPointProperty(pointProperties, 'System Status', point.systemStatus);
|
|
190
|
+
this.addPointProperty(pointProperties, 'Modification Date', point.modificationDate);
|
|
191
|
+
this.addPointProperty(pointProperties, 'Program State', point.programState);
|
|
192
|
+
this.addPointProperty(pointProperties, 'Record Count', point.recordCount);
|
|
193
|
+
this.addPointProperty(pointProperties, 'Vendor Name', point.vendorName);
|
|
194
|
+
|
|
195
|
+
// Return the array of point properties
|
|
196
|
+
return pointProperties;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Adds a property to the list of point properties.
|
|
201
|
+
*
|
|
202
|
+
* @param {Array} properties - The list of point properties.
|
|
203
|
+
* @param {string} label - The label of the property.
|
|
204
|
+
* @param {any} value - The value of the property.
|
|
205
|
+
* @returns {void}
|
|
206
|
+
*/
|
|
207
|
+
addPointProperty(properties, label, value) {
|
|
208
|
+
if (value !== null && value !== undefined && value !== '') {
|
|
209
|
+
properties.push({
|
|
210
|
+
label: `${label}: ${value}`,
|
|
211
|
+
data: value,
|
|
212
|
+
icon: 'pi pi-cog',
|
|
213
|
+
children: null,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Formats the display name for a point.
|
|
220
|
+
*
|
|
221
|
+
* If the point has a display name, it returns the display name.
|
|
222
|
+
* Otherwise, it removes any special characters from the point name and returns it.
|
|
223
|
+
*
|
|
224
|
+
* @param {Object} point - The point object.
|
|
225
|
+
* @param {string} pointName - The name of the point.
|
|
226
|
+
* @returns {string} - The formatted display name.
|
|
227
|
+
*/
|
|
228
|
+
formatDisplayName(point, pointName) {
|
|
229
|
+
const reg = /[$#\/\\+]/gi;
|
|
230
|
+
if (point.displayName) {
|
|
231
|
+
return point.displayName;
|
|
232
|
+
}
|
|
233
|
+
return pointName.replace(reg, '');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Updates the render list with the folder structure for a device.
|
|
238
|
+
*
|
|
239
|
+
* @param {Array} children - The children of the device.
|
|
240
|
+
* @param {Object} device - The device object.
|
|
241
|
+
* @param {string} deviceName - The name of the device.
|
|
242
|
+
* @param {number} index - The index of the device.
|
|
243
|
+
* @param {string} ipAddress - The IP address of the device.
|
|
244
|
+
* @param {string} deviceId - The ID of the device.
|
|
245
|
+
* @returns {void}
|
|
246
|
+
*/
|
|
247
|
+
updateRenderList(children, device, deviceName, index, ipAddress, deviceId) {
|
|
248
|
+
// Create the folder structure for the device
|
|
249
|
+
const folderJson = this.createFolderJson(children, device.hasChildDevices(), deviceId);
|
|
250
|
+
|
|
251
|
+
if (!this.renderList) {
|
|
252
|
+
this.renderList = [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Find the device's entry in the render list
|
|
256
|
+
let foundIndex = this.renderList.findIndex(ele => ele.deviceId == deviceId && ele.ipAddr == ipAddress);
|
|
257
|
+
|
|
258
|
+
// If the device is not in the render list, add it as a new entry
|
|
259
|
+
const newDeviceEntry = {
|
|
260
|
+
key: index,
|
|
261
|
+
label: deviceName,
|
|
262
|
+
data: deviceName,
|
|
263
|
+
icon: this.getDeviceIcon(device),
|
|
264
|
+
children: folderJson,
|
|
265
|
+
type: 'device',
|
|
266
|
+
lastSeen: device.getLastSeen(),
|
|
267
|
+
showAdded: false,
|
|
268
|
+
ipAddr: ipAddress,
|
|
269
|
+
deviceId,
|
|
270
|
+
isMstpDevice: device.getIsMstpDevice(),
|
|
271
|
+
initialName: device.getDeviceName(),
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (device.getIsMstpDevice()) {
|
|
275
|
+
// For child MSTP devices, find the parent device and the MSTP network folder
|
|
276
|
+
const parentDeviceId = device.getParentDeviceId();
|
|
277
|
+
const parentDeviceIndex = this.renderList.findIndex(ele => ele.deviceId == parentDeviceId && ele.ipAddr == ipAddress);
|
|
278
|
+
const mstpNetworkNumber = device.getMstpNetworkNumber();
|
|
279
|
+
|
|
280
|
+
if (parentDeviceIndex !== -1) {
|
|
281
|
+
let parentDeviceEntry = this.renderList[parentDeviceIndex];
|
|
282
|
+
let mstpNetworkFolder = parentDeviceEntry.children.find(child => child.label === `MSTP NET${mstpNetworkNumber}`);
|
|
283
|
+
|
|
284
|
+
// Create the MSTP network folder if it doesn't exist
|
|
285
|
+
if (!mstpNetworkFolder) {
|
|
286
|
+
mstpNetworkFolder = {
|
|
287
|
+
key: `${deviceId}-mstp-${mstpNetworkNumber}`,
|
|
288
|
+
label: `MSTP NET${mstpNetworkNumber}`,
|
|
289
|
+
data: `Devices Folder (${mstpNetworkNumber})`,
|
|
290
|
+
icon: 'pi pi-database',
|
|
291
|
+
type: 'deviceFolder',
|
|
292
|
+
children: [],
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
parentDeviceEntry.children.push(mstpNetworkFolder);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Add or update the child MSTP device in the MSTP folder
|
|
299
|
+
const mstpDeviceIndex = mstpNetworkFolder.children.findIndex(ele => ele.deviceId == deviceId && ele.ipAddr == ipAddress);
|
|
300
|
+
if (mstpDeviceIndex === -1) {
|
|
301
|
+
mstpNetworkFolder.children.push(newDeviceEntry);
|
|
302
|
+
} else {
|
|
303
|
+
mstpNetworkFolder.children[mstpDeviceIndex] = newDeviceEntry;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
// Add the new device entry to the root of the render list
|
|
308
|
+
if (foundIndex === -1) {
|
|
309
|
+
this.renderList.push(newDeviceEntry);
|
|
310
|
+
} else {
|
|
311
|
+
// If the device is already in the render list, update its entry
|
|
312
|
+
this.renderList[foundIndex] = newDeviceEntry;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Creates a folder JSON object for the network tree.
|
|
319
|
+
*
|
|
320
|
+
* @param {Array} children - The children nodes of the folder.
|
|
321
|
+
* @param {boolean} hasChildDevices - Indicates if the device has child devices.
|
|
322
|
+
* @param {string} deviceId - The ID of the device.
|
|
323
|
+
* @returns {Array} - The folder JSON object.
|
|
324
|
+
*/
|
|
325
|
+
createFolderJson(children, hasChildDevices, deviceId) {
|
|
326
|
+
const folders = [
|
|
327
|
+
{
|
|
328
|
+
key: `${deviceId}-0`,
|
|
329
|
+
label: 'Points',
|
|
330
|
+
data: 'Points Folder',
|
|
331
|
+
icon: 'pi pi-circle-fill',
|
|
332
|
+
type: 'pointFolder',
|
|
333
|
+
children: children.sort(this.sortPoints),
|
|
334
|
+
}
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
return folders;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Finalize the network tree data
|
|
342
|
+
*
|
|
343
|
+
* @returns {Object} The finalized network tree data
|
|
344
|
+
* - renderList: The list of devices and their points
|
|
345
|
+
* - deviceList: The list of devices
|
|
346
|
+
* - pointList: The list of points in the network tree
|
|
347
|
+
* - pollFrequency: The polling schedule for discovery
|
|
348
|
+
*/
|
|
349
|
+
finalizeNetworkTreeData() {
|
|
350
|
+
this.renderList.sort(this.sortDevices);
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
renderList: this.renderList,
|
|
354
|
+
deviceList: this.deviceList,
|
|
355
|
+
pointList: this.networkTree,
|
|
356
|
+
pollFrequency: this.discover_polling_schedule,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Checks if the buildTreeException flag is set and throws an error if it is.
|
|
362
|
+
*
|
|
363
|
+
* @throws {Error} - Throws an error with the message 'Build tree interrupted' if the buildTreeException flag is set.
|
|
364
|
+
*/
|
|
365
|
+
checkInterruptFlag() {
|
|
366
|
+
if (this.buildTreeException) {
|
|
367
|
+
throw new Error('Build tree interrupted');
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Returns the IP address of the given device.
|
|
373
|
+
*
|
|
374
|
+
* @param {object} device - The device object.
|
|
375
|
+
* @returns {string} The IP address of the device.
|
|
376
|
+
*/
|
|
377
|
+
getDeviceIpAddress(device) {
|
|
378
|
+
switch (typeof device.getAddress()) {
|
|
379
|
+
case "object":
|
|
380
|
+
return device.getAddress().address;
|
|
381
|
+
case "string":
|
|
382
|
+
return device.getAddress();
|
|
383
|
+
default:
|
|
384
|
+
return device.getAddress();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Computes the device name based on the provided device object.
|
|
390
|
+
* If the device has a display name, it will be returned.
|
|
391
|
+
* Otherwise, the device name will be returned.
|
|
392
|
+
*
|
|
393
|
+
* @param {Object} device - The device object.
|
|
394
|
+
* @returns {string} - The computed device name.
|
|
395
|
+
*/
|
|
396
|
+
computeDeviceName(device) {
|
|
397
|
+
if (device.getDisplayName() !== null && device.getDisplayName() !== "" && device.getDisplayName() !== undefined) {
|
|
398
|
+
return device.getDisplayName();
|
|
399
|
+
}
|
|
400
|
+
return device.getDeviceName();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Sorts the points based on their BACnet type and label.
|
|
405
|
+
*
|
|
406
|
+
* @param {Object} a - The first point object to compare.
|
|
407
|
+
* @param {Object} b - The second point object to compare.
|
|
408
|
+
* @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.
|
|
409
|
+
*/
|
|
410
|
+
sortPoints(a, b) {
|
|
411
|
+
if (a.bacnetType > b.bacnetType) {
|
|
412
|
+
return 1;
|
|
413
|
+
} else if (a.bacnetType < b.bacnetType) {
|
|
414
|
+
return -1;
|
|
415
|
+
} else if (a.bacnetType == b.bacnetType) {
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return a.label.localeCompare(b.label);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Sorts devices based on their deviceId.
|
|
424
|
+
*
|
|
425
|
+
* @param {Object} a - The first device object to compare.
|
|
426
|
+
* @param {Object} b - The second device object to compare.
|
|
427
|
+
* @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.
|
|
428
|
+
*/
|
|
429
|
+
sortDevices(a, b) {
|
|
430
|
+
if (a.deviceId < b.deviceId) {
|
|
431
|
+
return -1;
|
|
432
|
+
} else if (a.deviceId > b.deviceId) {
|
|
433
|
+
return 1;
|
|
434
|
+
}
|
|
435
|
+
return 0; // deviceIds are equal
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Returns the icon class name for a given point based on its object type.
|
|
440
|
+
*
|
|
441
|
+
* @param {Object} values - The values object containing the point's metadata.
|
|
442
|
+
* @returns {string} - The icon class name for the point.
|
|
443
|
+
*/
|
|
444
|
+
getPointIcon(values) {
|
|
445
|
+
const objectId = values.meta.objectId.type;
|
|
446
|
+
const hasPriorityArray =
|
|
447
|
+
values.hasPriorityArray && values.hasOwnProperty("hasPriorityArray") ? values.hasPriorityArray : false;
|
|
448
|
+
|
|
449
|
+
if (hasPriorityArray) {
|
|
450
|
+
return "pi writePointIcon";
|
|
451
|
+
} else {
|
|
452
|
+
switch (objectId) {
|
|
453
|
+
case 0:
|
|
454
|
+
//AI
|
|
455
|
+
return "pi readPointIcon";
|
|
456
|
+
case 1:
|
|
457
|
+
//AO
|
|
458
|
+
return "pi readPointIcon";
|
|
459
|
+
case 2:
|
|
460
|
+
//AV
|
|
461
|
+
return "pi readPointIcon";
|
|
462
|
+
case 3:
|
|
463
|
+
//BI
|
|
464
|
+
return "pi readPointIcon";
|
|
465
|
+
case 4:
|
|
466
|
+
//BO
|
|
467
|
+
return "pi readPointIcon";
|
|
468
|
+
case 5:
|
|
469
|
+
//BV
|
|
470
|
+
return "pi readPointIcon";
|
|
471
|
+
case 8:
|
|
472
|
+
//Device
|
|
473
|
+
return "pi pi-box";
|
|
474
|
+
case 13:
|
|
475
|
+
//MI
|
|
476
|
+
return "pi readPointIcon";
|
|
477
|
+
case 14:
|
|
478
|
+
//MO
|
|
479
|
+
return "pi readPointIcon";
|
|
480
|
+
case 19:
|
|
481
|
+
//MV
|
|
482
|
+
return "pi readPointIcon";
|
|
483
|
+
case 10:
|
|
484
|
+
//File
|
|
485
|
+
return "pi pi-file";
|
|
486
|
+
case 16:
|
|
487
|
+
//Program
|
|
488
|
+
return "pi pi-database";
|
|
489
|
+
case 20:
|
|
490
|
+
//Trendlog
|
|
491
|
+
return "pi pi-chart-line";
|
|
492
|
+
case 15:
|
|
493
|
+
//Notification Class
|
|
494
|
+
return "pi pi-bell";
|
|
495
|
+
case 56:
|
|
496
|
+
return "pi pi-sitemap";
|
|
497
|
+
case 178:
|
|
498
|
+
return "pi pi-lock";
|
|
499
|
+
case 17:
|
|
500
|
+
return "pi pi-calendar";
|
|
501
|
+
case 6:
|
|
502
|
+
return "pi pi-calendar";
|
|
503
|
+
default:
|
|
504
|
+
//Return circle for all other types
|
|
505
|
+
return "pi readPointIcon";
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Returns the icon for a given device based on its properties.
|
|
512
|
+
*
|
|
513
|
+
* @param {Object} device - The device object.
|
|
514
|
+
* @returns {string} - The icon class name.
|
|
515
|
+
*/
|
|
516
|
+
getDeviceIcon(device) {
|
|
517
|
+
const isMstp = device.getIsMstpDevice();
|
|
518
|
+
const manualDiscoveryMode = device.getManualDiscoveryMode();
|
|
519
|
+
|
|
520
|
+
if (manualDiscoveryMode == true) {
|
|
521
|
+
return "pi pi-question-circle";
|
|
522
|
+
} else if (manualDiscoveryMode == false) {
|
|
523
|
+
if (isMstp == true) {
|
|
524
|
+
return "pi pi-box";
|
|
525
|
+
} else if (isMstp == false) {
|
|
526
|
+
return "pi pi-server";
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return "pi pi-server";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
module.exports = { treeBuilder };
|