@bitpoolos/edge-bacnet 1.4.6 → 1.5.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 +22 -0
- package/bacnet_client.js +146 -95
- package/bacnet_device.js +18 -3
- package/bacnet_gateway.html +141 -7
- package/bacnet_gateway.js +4 -5
- package/bacnet_read.html +34 -19
- package/common.js +41 -1
- package/package.json +1 -1
- package/resources/node-bacstack-ts/dist/lib/client.js +161 -82
- package/resources/node-bacstack-ts/dist/lib/transport.js +57 -25
- package/resources/style.css +1 -6
|
@@ -42,8 +42,11 @@ class Client extends events_1.EventEmitter {
|
|
|
42
42
|
this._segmentStore = [];
|
|
43
43
|
options = options || {};
|
|
44
44
|
|
|
45
|
+
this.portRangeMatrix = options.portRangeMatrix;
|
|
46
|
+
|
|
45
47
|
this._settings = {
|
|
46
48
|
port: options.port || 47808,
|
|
49
|
+
portRangeMatrix: this.portRangeMatrix || [47808],
|
|
47
50
|
interface: options.interface,
|
|
48
51
|
transport: options.transport,
|
|
49
52
|
broadcastAddress: options.broadcastAddress || '255.255.255.255',
|
|
@@ -53,7 +56,8 @@ class Client extends events_1.EventEmitter {
|
|
|
53
56
|
this._transport = this._settings.transport || new transport_1.Transport({
|
|
54
57
|
port: this._settings.port,
|
|
55
58
|
interface: this._settings.interface,
|
|
56
|
-
broadcastAddress: this._settings.broadcastAddress
|
|
59
|
+
broadcastAddress: this._settings.broadcastAddress,
|
|
60
|
+
portRangeMatrix: this._settings.portRangeMatrix
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
// Setup code
|
|
@@ -104,15 +108,15 @@ class Client extends events_1.EventEmitter {
|
|
|
104
108
|
_processAbort(invokeId, reason) {
|
|
105
109
|
this._invokeCallback(invokeId, new Error('BacnetAbort - Reason:' + reason));
|
|
106
110
|
}
|
|
107
|
-
_segmentAckResponse(receiver, negative, server, originalInvokeId, sequencenumber, actualWindowSize) {
|
|
111
|
+
_segmentAckResponse(receiver, port, negative, server, originalInvokeId, sequencenumber, actualWindowSize) {
|
|
108
112
|
const buffer = this._getBuffer();
|
|
109
113
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, receiver, null, DEFAULT_HOP_COUNT, baEnum.NetworkLayerMessageType.WHO_IS_ROUTER_TO_NETWORK, 0);
|
|
110
114
|
baApdu.encodeSegmentAck(buffer, baEnum.PduTypes.SEGMENT_ACK | (negative ? baEnum.PduSegAckBits.NEGATIVE_ACK : 0) | (server ? baEnum.PduSegAckBits.SERVER : 0), originalInvokeId, sequencenumber, actualWindowSize);
|
|
111
115
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
112
116
|
var sendAddress = typeof (receiver) != 'string' ? receiver.ip : receiver;
|
|
113
|
-
this.sendBvlc(sendAddress, buffer);
|
|
117
|
+
this.sendBvlc(sendAddress, port, buffer);
|
|
114
118
|
}
|
|
115
|
-
_performDefaultSegmentHandling(sender, adr, type, service, invokeId, maxSegments, maxApdu, sequencenumber, first, moreFollows, buffer, offset, length) {
|
|
119
|
+
_performDefaultSegmentHandling(sender, adr, type, service, invokeId, maxSegments, maxApdu, sequencenumber, first, moreFollows, buffer, offset, length, port) {
|
|
116
120
|
if (first) {
|
|
117
121
|
this._segmentStore = [];
|
|
118
122
|
type &= ~baEnum.PduConReqBits.SEGMENTED_MESSAGE;
|
|
@@ -138,7 +142,7 @@ class Client extends events_1.EventEmitter {
|
|
|
138
142
|
const apduBuffer = Buffer.concat(this._segmentStore);
|
|
139
143
|
this._segmentStore = [];
|
|
140
144
|
type &= ~baEnum.PduConReqBits.SEGMENTED_MESSAGE;
|
|
141
|
-
this._handlePdu(adr, type, apduBuffer, 0, apduBuffer.length);
|
|
145
|
+
this._handlePdu(adr, type, apduBuffer, 0, apduBuffer.length, port);
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
148
|
_handleSequenceTimeout(invokeId) {
|
|
@@ -148,13 +152,13 @@ class Client extends events_1.EventEmitter {
|
|
|
148
152
|
this._sequenceTimeout = setTimeout(() => { this._lastSequenceNumber = 0 }, this._settings.apduTimeout);
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
_processSegment(receiver, type, service, invokeId, maxSegments, maxApdu, server, sequencenumber, proposedWindowNumber, buffer, offset, length) {
|
|
155
|
+
_processSegment(receiver, type, service, invokeId, maxSegments, maxApdu, server, sequencenumber, proposedWindowNumber, buffer, offset, length, port) {
|
|
152
156
|
let first = false;
|
|
153
157
|
if (sequencenumber === 0 && this._lastSequenceNumber === 0) {
|
|
154
158
|
first = true;
|
|
155
159
|
} else {
|
|
156
160
|
if (sequencenumber !== this._lastSequenceNumber + 1) {
|
|
157
|
-
return this._segmentAckResponse(receiver, true, server, invokeId, this._lastSequenceNumber, proposedWindowNumber);
|
|
161
|
+
return this._segmentAckResponse(receiver, port, true, server, invokeId, this._lastSequenceNumber, proposedWindowNumber);
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
this._lastSequenceNumber = sequencenumber;
|
|
@@ -164,9 +168,9 @@ class Client extends events_1.EventEmitter {
|
|
|
164
168
|
this._lastSequenceNumber = 0;
|
|
165
169
|
}
|
|
166
170
|
if ((sequencenumber % proposedWindowNumber) === 0 || !moreFollows) {
|
|
167
|
-
this._segmentAckResponse(receiver, false, server, invokeId, sequencenumber, proposedWindowNumber);
|
|
171
|
+
this._segmentAckResponse(receiver, port, false, server, invokeId, sequencenumber, proposedWindowNumber);
|
|
168
172
|
}
|
|
169
|
-
this._performDefaultSegmentHandling(this, receiver, type, service, invokeId, maxSegments, maxApdu, sequencenumber, first, moreFollows, buffer, offset, length);
|
|
173
|
+
this._performDefaultSegmentHandling(this, receiver, type, service, invokeId, maxSegments, maxApdu, sequencenumber, first, moreFollows, buffer, offset, length, port);
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
_processConfirmedServiceRequest(address, type, service, maxSegments, maxApdu, invokeId, buffer, offset, length, srcAddress, destAddress) {
|
|
@@ -267,7 +271,7 @@ class Client extends events_1.EventEmitter {
|
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
|
|
270
|
-
_processUnconfirmedServiceRequest(address, type, service, buffer, offset, length, addressObject) {
|
|
274
|
+
_processUnconfirmedServiceRequest(address, type, service, buffer, offset, length, addressObject, port) {
|
|
271
275
|
let result;
|
|
272
276
|
debug('Handle this._processUnconfirmedServiceRequest');
|
|
273
277
|
if (service === baEnum.UnconfirmedServiceChoice.I_AM) {
|
|
@@ -291,9 +295,10 @@ class Client extends events_1.EventEmitter {
|
|
|
291
295
|
* console.log('address: ', device.address, ' - deviceId: ', device.deviceId, ' - maxApdu: ', device.maxApdu, ' - segmentation: ', device.segmentation, ' - vendorId: ', device.vendorId);
|
|
292
296
|
* });
|
|
293
297
|
*/
|
|
298
|
+
|
|
294
299
|
var net = typeof (addressObject) == 'object' ? addressObject.net : undefined;
|
|
295
300
|
var adr = typeof (addressObject) == 'object' ? addressObject.adr : undefined;
|
|
296
|
-
this.emit('iAm', { address: address, deviceId: result.deviceId, maxApdu: result.maxApdu, segmentation: result.segmentation, vendorId: result.vendorId, 'net': net, 'adr': adr });
|
|
301
|
+
this.emit('iAm', { address: address, port: port, deviceId: result.deviceId, maxApdu: result.maxApdu, segmentation: result.segmentation, vendorId: result.vendorId, 'net': net, 'adr': adr });
|
|
297
302
|
} else if (service === baEnum.UnconfirmedServiceChoice.WHO_IS) {
|
|
298
303
|
result = baServices.whoIs.decode(buffer, offset, length);
|
|
299
304
|
if (!result) return debug('Received invalid WhoIs message');
|
|
@@ -377,13 +382,13 @@ class Client extends events_1.EventEmitter {
|
|
|
377
382
|
}
|
|
378
383
|
}
|
|
379
384
|
|
|
380
|
-
_handlePdu(address, type, buffer, offset, length, addressObject, destAddressObject) {
|
|
385
|
+
_handlePdu(address, type, buffer, offset, length, addressObject, destAddressObject, port) {
|
|
381
386
|
let result;
|
|
382
387
|
// Handle different PDU types
|
|
383
388
|
switch (type & baEnum.PDU_TYPE_MASK) {
|
|
384
389
|
case baEnum.PduTypes.UNCONFIRMED_REQUEST:
|
|
385
390
|
result = baApdu.decodeUnconfirmedServiceRequest(buffer, offset);
|
|
386
|
-
this._processUnconfirmedServiceRequest(address, result.type, result.service, buffer, offset + result.len, length - result.len, addressObject);
|
|
391
|
+
this._processUnconfirmedServiceRequest(address, result.type, result.service, buffer, offset + result.len, length - result.len, addressObject, port);
|
|
387
392
|
break;
|
|
388
393
|
case baEnum.PduTypes.SIMPLE_ACK:
|
|
389
394
|
result = baApdu.decodeSimpleAck(buffer, offset);
|
|
@@ -396,7 +401,7 @@ class Client extends events_1.EventEmitter {
|
|
|
396
401
|
if ((type & baEnum.PduConReqBits.SEGMENTED_MESSAGE) === 0) {
|
|
397
402
|
this._invokeCallback(result.invokeId, null, { result: result, buffer: buffer, offset: offset + result.len, length: length - result.len });
|
|
398
403
|
} else {
|
|
399
|
-
this._processSegment(addressObject, result.type, result.service, result.invokeId, baEnum.MaxSegmentsAccepted.SEGMENTS_0, baEnum.MaxApduLengthAccepted.OCTETS_50, false, result.sequencenumber, result.proposedWindowNumber, buffer, offset + result.len, length - result.len);
|
|
404
|
+
this._processSegment(addressObject, result.type, result.service, result.invokeId, baEnum.MaxSegmentsAccepted.SEGMENTS_0, baEnum.MaxApduLengthAccepted.OCTETS_50, false, result.sequencenumber, result.proposedWindowNumber, buffer, offset + result.len, length - result.len, port);
|
|
400
405
|
}
|
|
401
406
|
break;
|
|
402
407
|
case baEnum.PduTypes.SEGMENT_ACK:
|
|
@@ -418,7 +423,7 @@ class Client extends events_1.EventEmitter {
|
|
|
418
423
|
if ((type & baEnum.PduConReqBits.SEGMENTED_MESSAGE) === 0) {
|
|
419
424
|
this._processConfirmedServiceRequest(address, result.type, result.service, result.maxSegments, result.maxApdu, result.invokeId, buffer, offset + result.len, length - result.len, addressObject, destAddressObject);
|
|
420
425
|
} else {
|
|
421
|
-
this._processSegment(address, result.type, result.service, result.invokeId, result.maxSegments, result.maxApdu, true, result.sequencenumber, result.proposedWindowNumber, buffer, offset + result.len, length - result.len);
|
|
426
|
+
this._processSegment(address, result.type, result.service, result.invokeId, result.maxSegments, result.maxApdu, true, result.sequencenumber, result.proposedWindowNumber, buffer, offset + result.len, length - result.len, port);
|
|
422
427
|
}
|
|
423
428
|
break;
|
|
424
429
|
default:
|
|
@@ -426,7 +431,7 @@ class Client extends events_1.EventEmitter {
|
|
|
426
431
|
break;
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
|
-
_handleNpdu(buffer, offset, msgLength, remoteAddress) {
|
|
434
|
+
_handleNpdu(buffer, offset, msgLength, remoteAddress, port) {
|
|
430
435
|
// Check data length
|
|
431
436
|
if (msgLength <= 0) return debug('No NPDU data -> Drop package');
|
|
432
437
|
// Parse baNpdu header
|
|
@@ -455,9 +460,9 @@ class Client extends events_1.EventEmitter {
|
|
|
455
460
|
msgLength -= result.len;
|
|
456
461
|
if (msgLength <= 0) return debug('No APDU data -> Drop package');
|
|
457
462
|
const apduType = baApdu.getDecodedType(buffer, offset);
|
|
458
|
-
this._handlePdu(remoteAddress, apduType, buffer, offset, msgLength, addressObject, destAddress);
|
|
463
|
+
this._handlePdu(remoteAddress, apduType, buffer, offset, msgLength, addressObject, destAddress, port);
|
|
459
464
|
}
|
|
460
|
-
_receiveData(buffer, remoteAddress) {
|
|
465
|
+
_receiveData(buffer, remoteAddress, port) {
|
|
461
466
|
// Check data length
|
|
462
467
|
if (buffer.length < baEnum.BVLC_HEADER_LENGTH)
|
|
463
468
|
return debug('Received invalid data -> Drop package');
|
|
@@ -467,7 +472,7 @@ class Client extends events_1.EventEmitter {
|
|
|
467
472
|
return debug('Received invalid BVLC header -> Drop package');
|
|
468
473
|
// Check BVLC function
|
|
469
474
|
if (result.func === baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU || result.func === baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU || result.func === baEnum.BvlcResultPurpose.FORWARDED_NPDU) {
|
|
470
|
-
this._handleNpdu(buffer, result.len, buffer.length - result.len, remoteAddress);
|
|
475
|
+
this._handleNpdu(buffer, result.len, buffer.length - result.len, remoteAddress, port);
|
|
471
476
|
}
|
|
472
477
|
else {
|
|
473
478
|
debug('Received unknown BVLC function -> Drop package');
|
|
@@ -542,7 +547,7 @@ class Client extends events_1.EventEmitter {
|
|
|
542
547
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, receiver, null, DEFAULT_HOP_COUNT, baEnum.NetworkLayerMessageType.WHO_IS_ROUTER_TO_NETWORK, 0);
|
|
543
548
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.WHO_IS);
|
|
544
549
|
baServices.whoIs.encode(buffer, settings.lowLimit, settings.highLimit);
|
|
545
|
-
this.sendBvlc(receiver, buffer);
|
|
550
|
+
this.sendBvlc(receiver, this._settings.portRangeMatrix, buffer);
|
|
546
551
|
}
|
|
547
552
|
/**
|
|
548
553
|
* The timeSync command sets the time of a target device.
|
|
@@ -555,14 +560,17 @@ class Client extends events_1.EventEmitter {
|
|
|
555
560
|
*
|
|
556
561
|
* client.timeSync('192.168.1.43', new Date());
|
|
557
562
|
*/
|
|
558
|
-
timeSync(
|
|
563
|
+
timeSync(addressObject, dateTime) {
|
|
564
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
565
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
566
|
+
|
|
559
567
|
const buffer = this._getBuffer();
|
|
560
568
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, address);
|
|
561
569
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.TIME_SYNCHRONIZATION);
|
|
562
570
|
baServices.timeSync.encode(buffer, dateTime);
|
|
563
571
|
const npduType = (address !== this._transport.getBroadcastAddress()) ? baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU : baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU;
|
|
564
572
|
//baBvlc.encode(buffer.buffer, npduType, buffer.offset);
|
|
565
|
-
this.sendBvlc(address, buffer);
|
|
573
|
+
this.sendBvlc(address, port, buffer);
|
|
566
574
|
}
|
|
567
575
|
/**
|
|
568
576
|
* The timeSyncUTC command sets the UTC time of a target device.
|
|
@@ -575,14 +583,16 @@ class Client extends events_1.EventEmitter {
|
|
|
575
583
|
*
|
|
576
584
|
* client.timeSyncUTC('192.168.1.43', new Date());
|
|
577
585
|
*/
|
|
578
|
-
timeSyncUTC(
|
|
586
|
+
timeSyncUTC(addressObject, dateTime) {
|
|
587
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
588
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
579
589
|
const buffer = this._getBuffer();
|
|
580
590
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, address);
|
|
581
591
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.UTC_TIME_SYNCHRONIZATION);
|
|
582
592
|
baServices.timeSync.encode(buffer, dateTime);
|
|
583
593
|
const npduType = (address !== this._transport.getBroadcastAddress()) ? baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU : baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU;
|
|
584
594
|
//baBvlc.encode(buffer.buffer, npduType, buffer.offset);
|
|
585
|
-
this.sendBvlc(address, buffer);
|
|
595
|
+
this.sendBvlc(address, port, buffer);
|
|
586
596
|
}
|
|
587
597
|
/**
|
|
588
598
|
* The readProperty command reads a single property of an object from a device.
|
|
@@ -606,8 +616,12 @@ class Client extends events_1.EventEmitter {
|
|
|
606
616
|
* console.log('value: ', value);
|
|
607
617
|
* });
|
|
608
618
|
*/
|
|
609
|
-
readProperty(
|
|
619
|
+
readProperty(addressObject, objectId, propertyId, options, next) {
|
|
610
620
|
next = next || options;
|
|
621
|
+
|
|
622
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
623
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
624
|
+
|
|
611
625
|
const settings = {
|
|
612
626
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
613
627
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -620,7 +634,7 @@ class Client extends events_1.EventEmitter {
|
|
|
620
634
|
baApdu.encodeConfirmedServiceRequest(buffer, type, baEnum.ConfirmedServiceChoice.READ_PROPERTY, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
621
635
|
baServices.readProperty.encode(buffer, objectId.type, objectId.instance, propertyId, settings.arrayIndex);
|
|
622
636
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
623
|
-
this.sendBvlc(address, buffer);
|
|
637
|
+
this.sendBvlc(address, port, buffer);
|
|
624
638
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
625
639
|
try {
|
|
626
640
|
if (err)
|
|
@@ -662,8 +676,12 @@ class Client extends events_1.EventEmitter {
|
|
|
662
676
|
* console.log('error: ', err);
|
|
663
677
|
* });
|
|
664
678
|
*/
|
|
665
|
-
writeProperty(
|
|
679
|
+
writeProperty(addressObject, objectId, propertyId, values, options, next) {
|
|
666
680
|
next = next || options;
|
|
681
|
+
|
|
682
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
683
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
684
|
+
|
|
667
685
|
const settings = {
|
|
668
686
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
669
687
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -676,7 +694,7 @@ class Client extends events_1.EventEmitter {
|
|
|
676
694
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.WRITE_PROPERTY, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
677
695
|
baServices.writeProperty.encode(buffer, objectId.type, objectId.instance, propertyId, settings.arrayIndex, settings.priority, values);
|
|
678
696
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
679
|
-
this.sendBvlc(address, buffer);
|
|
697
|
+
this.sendBvlc(address, port, buffer);
|
|
680
698
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
681
699
|
}
|
|
682
700
|
/**
|
|
@@ -705,8 +723,12 @@ class Client extends events_1.EventEmitter {
|
|
|
705
723
|
* console.log('value: ', value);
|
|
706
724
|
* });
|
|
707
725
|
*/
|
|
708
|
-
readPropertyMultiple(
|
|
726
|
+
readPropertyMultiple(addressObject, propertiesArray, options, next) {
|
|
709
727
|
next = next || options;
|
|
728
|
+
|
|
729
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
730
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
731
|
+
|
|
710
732
|
const settings = {
|
|
711
733
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
712
734
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -718,7 +740,7 @@ class Client extends events_1.EventEmitter {
|
|
|
718
740
|
baApdu.encodeConfirmedServiceRequest(buffer, type, baEnum.ConfirmedServiceChoice.READ_PROPERTY_MULTIPLE, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
719
741
|
baServices.readPropertyMultiple.encode(buffer, propertiesArray);
|
|
720
742
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
721
|
-
this.sendBvlc(address, buffer);
|
|
743
|
+
this.sendBvlc(address, port, buffer);
|
|
722
744
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
723
745
|
try {
|
|
724
746
|
if (err)
|
|
@@ -766,8 +788,12 @@ class Client extends events_1.EventEmitter {
|
|
|
766
788
|
* console.log('error: ', err);
|
|
767
789
|
* });
|
|
768
790
|
*/
|
|
769
|
-
writePropertyMultiple(
|
|
791
|
+
writePropertyMultiple(addressObject, values, options, next) {
|
|
770
792
|
next = next || options;
|
|
793
|
+
|
|
794
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
795
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
796
|
+
|
|
771
797
|
const settings = {
|
|
772
798
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
773
799
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -778,7 +804,7 @@ class Client extends events_1.EventEmitter {
|
|
|
778
804
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.WRITE_PROPERTY_MULTIPLE, settings.maxSegments, settings.maxApdu, settings.invokeId);
|
|
779
805
|
baServices.writePropertyMultiple.encodeObject(buffer, values);
|
|
780
806
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
781
|
-
this.sendBvlc(address, buffer);
|
|
807
|
+
this.sendBvlc(address, port, buffer);
|
|
782
808
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
783
809
|
}
|
|
784
810
|
/**
|
|
@@ -801,8 +827,10 @@ class Client extends events_1.EventEmitter {
|
|
|
801
827
|
* console.log('error: ', err);
|
|
802
828
|
* });
|
|
803
829
|
*/
|
|
804
|
-
deviceCommunicationControl(
|
|
830
|
+
deviceCommunicationControl(addressObject, timeDuration, enableDisable, options, next) {
|
|
805
831
|
next = next || options;
|
|
832
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
833
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
806
834
|
const settings = {
|
|
807
835
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
808
836
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -814,7 +842,7 @@ class Client extends events_1.EventEmitter {
|
|
|
814
842
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.DEVICE_COMMUNICATION_CONTROL, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
815
843
|
baServices.deviceCommunicationControl.encode(buffer, timeDuration, enableDisable, settings.password);
|
|
816
844
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
817
|
-
this.sendBvlc(address, buffer);
|
|
845
|
+
this.sendBvlc(address, port, buffer);
|
|
818
846
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
819
847
|
}
|
|
820
848
|
/**
|
|
@@ -836,8 +864,10 @@ class Client extends events_1.EventEmitter {
|
|
|
836
864
|
* console.log('error: ', err);
|
|
837
865
|
* });
|
|
838
866
|
*/
|
|
839
|
-
reinitializeDevice(
|
|
867
|
+
reinitializeDevice(addressObject, state, options, next) {
|
|
840
868
|
next = next || options;
|
|
869
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
870
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
841
871
|
const settings = {
|
|
842
872
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
843
873
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -849,7 +879,7 @@ class Client extends events_1.EventEmitter {
|
|
|
849
879
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.REINITIALIZE_DEVICE, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
850
880
|
baServices.reinitializeDevice.encode(buffer, state, settings.password);
|
|
851
881
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
852
|
-
this.sendBvlc(address, buffer);
|
|
882
|
+
this.sendBvlc(address, port, buffer);
|
|
853
883
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
854
884
|
}
|
|
855
885
|
/**
|
|
@@ -874,8 +904,10 @@ class Client extends events_1.EventEmitter {
|
|
|
874
904
|
* console.log('value: ', value);
|
|
875
905
|
* });
|
|
876
906
|
*/
|
|
877
|
-
writeFile(
|
|
907
|
+
writeFile(addressObject, objectId, position, fileBuffer, options, next) {
|
|
878
908
|
next = next || options;
|
|
909
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
910
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
879
911
|
const settings = {
|
|
880
912
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
881
913
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -886,7 +918,7 @@ class Client extends events_1.EventEmitter {
|
|
|
886
918
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.ATOMIC_WRITE_FILE, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
887
919
|
baServices.atomicWriteFile.encode(buffer, false, objectId, position, fileBuffer);
|
|
888
920
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
889
|
-
this.sendBvlc(address, buffer);
|
|
921
|
+
this.sendBvlc(address, port, buffer);
|
|
890
922
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
891
923
|
if (err)
|
|
892
924
|
return next(err);
|
|
@@ -918,8 +950,10 @@ class Client extends events_1.EventEmitter {
|
|
|
918
950
|
* console.log('value: ', value);
|
|
919
951
|
* });
|
|
920
952
|
*/
|
|
921
|
-
readFile(
|
|
953
|
+
readFile(addressObject, objectId, position, count, options, next) {
|
|
922
954
|
next = next || options;
|
|
955
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
956
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
923
957
|
const settings = {
|
|
924
958
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
925
959
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -930,7 +964,7 @@ class Client extends events_1.EventEmitter {
|
|
|
930
964
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.ATOMIC_READ_FILE, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
931
965
|
baServices.atomicReadFile.encode(buffer, true, objectId, position, count);
|
|
932
966
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
933
|
-
this.sendBvlc(address, buffer);
|
|
967
|
+
this.sendBvlc(address, port, buffer);
|
|
934
968
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
935
969
|
if (err)
|
|
936
970
|
return next(err);
|
|
@@ -962,8 +996,10 @@ class Client extends events_1.EventEmitter {
|
|
|
962
996
|
* console.log('value: ', value);
|
|
963
997
|
* });
|
|
964
998
|
*/
|
|
965
|
-
readRange(
|
|
999
|
+
readRange(addressObject, objectId, idxBegin, quantity, options, next) {
|
|
966
1000
|
next = next || options;
|
|
1001
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1002
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
967
1003
|
const settings = {
|
|
968
1004
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
969
1005
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -974,7 +1010,7 @@ class Client extends events_1.EventEmitter {
|
|
|
974
1010
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.READ_RANGE, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
975
1011
|
baServices.readRange.encode(buffer, objectId, baEnum.PropertyIdentifier.LOG_BUFFER, baEnum.ASN1_ARRAY_ALL, baEnum.ReadRangeType.BY_POSITION, idxBegin, new Date(), quantity);
|
|
976
1012
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
977
|
-
this.sendBvlc(address, buffer);
|
|
1013
|
+
this.sendBvlc(address, port, buffer);
|
|
978
1014
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
979
1015
|
if (err)
|
|
980
1016
|
return next(err);
|
|
@@ -1008,8 +1044,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1008
1044
|
* console.log('error: ', err);
|
|
1009
1045
|
* });
|
|
1010
1046
|
*/
|
|
1011
|
-
subscribeCOV(
|
|
1047
|
+
subscribeCOV(addressObject, objectId, subscribeId, cancel, issueConfirmedNotifications, lifetime, options, next) {
|
|
1012
1048
|
next = next || options;
|
|
1049
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1050
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1013
1051
|
const settings = {
|
|
1014
1052
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1015
1053
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1020,7 +1058,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1020
1058
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.SUBSCRIBE_COV, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1021
1059
|
baServices.subscribeCov.encode(buffer, subscribeId, objectId, cancel, issueConfirmedNotifications, lifetime);
|
|
1022
1060
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1023
|
-
this.sendBvlc(address, buffer);
|
|
1061
|
+
this.sendBvlc(address, port, buffer);
|
|
1024
1062
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1025
1063
|
}
|
|
1026
1064
|
/**
|
|
@@ -1049,8 +1087,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1049
1087
|
* console.log('error: ', err);
|
|
1050
1088
|
* });
|
|
1051
1089
|
*/
|
|
1052
|
-
subscribeProperty(
|
|
1090
|
+
subscribeProperty(addressObject, objectId, monitoredProperty, subscribeId, cancel, issueConfirmedNotifications, options, next) {
|
|
1053
1091
|
next = next || options;
|
|
1092
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1093
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1054
1094
|
const settings = {
|
|
1055
1095
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1056
1096
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1061,11 +1101,13 @@ class Client extends events_1.EventEmitter {
|
|
|
1061
1101
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.SUBSCRIBE_COV_PROPERTY, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1062
1102
|
baServices.subscribeProperty.encode(buffer, subscribeId, objectId, cancel, issueConfirmedNotifications, 0, monitoredProperty, false, 0x0f);
|
|
1063
1103
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1064
|
-
this.sendBvlc(address, buffer);
|
|
1104
|
+
this.sendBvlc(address, port, buffer);
|
|
1065
1105
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1066
1106
|
}
|
|
1067
|
-
createObject(
|
|
1107
|
+
createObject(addressObject, objectId, values, options, next) {
|
|
1068
1108
|
next = next || options;
|
|
1109
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1110
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1069
1111
|
const settings = {
|
|
1070
1112
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1071
1113
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1076,7 +1118,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1076
1118
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.CREATE_OBJECT, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1077
1119
|
baServices.createObject.encode(buffer, objectId, values);
|
|
1078
1120
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1079
|
-
this.sendBvlc(address, buffer);
|
|
1121
|
+
this.sendBvlc(address, port, buffer);
|
|
1080
1122
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1081
1123
|
}
|
|
1082
1124
|
/**
|
|
@@ -1099,8 +1141,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1099
1141
|
* console.log('error: ', err);
|
|
1100
1142
|
* });
|
|
1101
1143
|
*/
|
|
1102
|
-
deleteObject(
|
|
1144
|
+
deleteObject(addressObject, objectId, options, next) {
|
|
1103
1145
|
next = next || options;
|
|
1146
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1147
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1104
1148
|
const settings = {
|
|
1105
1149
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1106
1150
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1111,11 +1155,13 @@ class Client extends events_1.EventEmitter {
|
|
|
1111
1155
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.DELETE_OBJECT, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1112
1156
|
baServices.deleteObject.encode(buffer, objectId);
|
|
1113
1157
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1114
|
-
this.sendBvlc(address, buffer);
|
|
1158
|
+
this.sendBvlc(address, port, buffer);
|
|
1115
1159
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1116
1160
|
}
|
|
1117
|
-
removeListElement(
|
|
1161
|
+
removeListElement(addressObject, objectId, reference, values, options, next) {
|
|
1118
1162
|
next = next || options;
|
|
1163
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1164
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1119
1165
|
const settings = {
|
|
1120
1166
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1121
1167
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1126,11 +1172,13 @@ class Client extends events_1.EventEmitter {
|
|
|
1126
1172
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.REMOVE_LIST_ELEMENT, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1127
1173
|
baServices.addListElement.encode(buffer, objectId, reference.id, reference.index, values);
|
|
1128
1174
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1129
|
-
this.sendBvlc(address, buffer);
|
|
1175
|
+
this.sendBvlc(address, port, buffer);
|
|
1130
1176
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1131
1177
|
}
|
|
1132
|
-
addListElement(
|
|
1178
|
+
addListElement(addressObject, objectId, reference, values, options, next) {
|
|
1133
1179
|
next = next || options;
|
|
1180
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1181
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1134
1182
|
const settings = {
|
|
1135
1183
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1136
1184
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1141,7 +1189,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1141
1189
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.ADD_LIST_ELEMENT, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1142
1190
|
baServices.addListElement.encode(buffer, objectId, reference.id, reference.index, values);
|
|
1143
1191
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1144
|
-
this.sendBvlc(address, buffer);
|
|
1192
|
+
this.sendBvlc(address, port, buffer);
|
|
1145
1193
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1146
1194
|
}
|
|
1147
1195
|
/**
|
|
@@ -1161,8 +1209,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1161
1209
|
* console.log('value: ', value);
|
|
1162
1210
|
* });
|
|
1163
1211
|
*/
|
|
1164
|
-
getAlarmSummary(
|
|
1212
|
+
getAlarmSummary(addressObject, options, next) {
|
|
1165
1213
|
next = next || options;
|
|
1214
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1215
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1166
1216
|
const settings = {
|
|
1167
1217
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1168
1218
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1172,7 +1222,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1172
1222
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE | baEnum.NpduControlBits.EXPECTING_REPLY, address);
|
|
1173
1223
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.GET_ALARM_SUMMARY, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1174
1224
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1175
|
-
this.sendBvlc(address, buffer);
|
|
1225
|
+
this.sendBvlc(address, port, buffer);
|
|
1176
1226
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
1177
1227
|
if (err)
|
|
1178
1228
|
return next(err);
|
|
@@ -1202,8 +1252,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1202
1252
|
* console.log('value: ', value);
|
|
1203
1253
|
* });
|
|
1204
1254
|
*/
|
|
1205
|
-
getEventInformation(
|
|
1255
|
+
getEventInformation(addressObject, objectId, options, next) {
|
|
1206
1256
|
next = next || options;
|
|
1257
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1258
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1207
1259
|
const settings = {
|
|
1208
1260
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1209
1261
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1214,7 +1266,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1214
1266
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.GET_EVENT_INFORMATION, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1215
1267
|
baAsn1.encodeContextObjectId(buffer, 0, objectId.type, objectId.instance);
|
|
1216
1268
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1217
|
-
this.sendBvlc(address, buffer);
|
|
1269
|
+
this.sendBvlc(address, port, buffer);
|
|
1218
1270
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
1219
1271
|
if (err)
|
|
1220
1272
|
return next(err);
|
|
@@ -1224,8 +1276,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1224
1276
|
next(null, result);
|
|
1225
1277
|
});
|
|
1226
1278
|
}
|
|
1227
|
-
acknowledgeAlarm(
|
|
1279
|
+
acknowledgeAlarm(addressObject, objectId, eventState, ackText, evTimeStamp, ackTimeStamp, options, next) {
|
|
1228
1280
|
next = next || options;
|
|
1281
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1282
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1229
1283
|
const settings = {
|
|
1230
1284
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1231
1285
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1236,7 +1290,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1236
1290
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.ACKNOWLEDGE_ALARM, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1237
1291
|
baServices.alarmAcknowledge.encode(buffer, 57, objectId, eventState, ackText, evTimeStamp, ackTimeStamp);
|
|
1238
1292
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1239
|
-
this.sendBvlc(address, buffer);
|
|
1293
|
+
this.sendBvlc(address, port, buffer);
|
|
1240
1294
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1241
1295
|
}
|
|
1242
1296
|
/**
|
|
@@ -1259,8 +1313,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1259
1313
|
* console.log('error: ', err);
|
|
1260
1314
|
* });
|
|
1261
1315
|
*/
|
|
1262
|
-
confirmedPrivateTransfer(
|
|
1316
|
+
confirmedPrivateTransfer(addressObject, vendorId, serviceNumber, data, options, next) {
|
|
1263
1317
|
next = next || options;
|
|
1318
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1319
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1264
1320
|
const settings = {
|
|
1265
1321
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1266
1322
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1271,7 +1327,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1271
1327
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.CONFIRMED_PRIVATE_TRANSFER, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1272
1328
|
baServices.privateTransfer.encode(buffer, vendorId, serviceNumber, data);
|
|
1273
1329
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1274
|
-
this.sendBvlc(address, buffer);
|
|
1330
|
+
this.sendBvlc(address, port, buffer);
|
|
1275
1331
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1276
1332
|
}
|
|
1277
1333
|
/**
|
|
@@ -1287,13 +1343,15 @@ class Client extends events_1.EventEmitter {
|
|
|
1287
1343
|
*
|
|
1288
1344
|
* client.unconfirmedPrivateTransfer('192.168.1.43', 0, 7, [0x00, 0xaa, 0xfa, 0xb1, 0x00]);
|
|
1289
1345
|
*/
|
|
1290
|
-
unconfirmedPrivateTransfer(
|
|
1346
|
+
unconfirmedPrivateTransfer(addressObject, vendorId, serviceNumber, data) {
|
|
1291
1347
|
const buffer = this._getBuffer();
|
|
1348
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1349
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1292
1350
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, address);
|
|
1293
1351
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.UNCONFIRMED_PRIVATE_TRANSFER);
|
|
1294
1352
|
baServices.privateTransfer.encode(buffer, vendorId, serviceNumber, data);
|
|
1295
1353
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1296
|
-
this.sendBvlc(address, buffer);
|
|
1354
|
+
this.sendBvlc(address, port, buffer);
|
|
1297
1355
|
}
|
|
1298
1356
|
/**
|
|
1299
1357
|
* DEPRECATED The getEnrollmentSummary command returns a list of event-initiating objects on the target device.
|
|
@@ -1320,8 +1378,10 @@ class Client extends events_1.EventEmitter {
|
|
|
1320
1378
|
* console.log('value: ', value);
|
|
1321
1379
|
* });
|
|
1322
1380
|
*/
|
|
1323
|
-
getEnrollmentSummary(
|
|
1381
|
+
getEnrollmentSummary(addressObject, acknowledgmentFilter, options, next) {
|
|
1324
1382
|
next = next || options;
|
|
1383
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1384
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1325
1385
|
const settings = {
|
|
1326
1386
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1327
1387
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1332,7 +1392,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1332
1392
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.GET_ENROLLMENT_SUMMARY, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1333
1393
|
baServices.getEnrollmentSummary.encode(buffer, acknowledgmentFilter, options.enrollmentFilter, options.eventStateFilter, options.eventTypeFilter, options.priorityFilter, options.notificationClassFilter);
|
|
1334
1394
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1335
|
-
this.sendBvlc(address, buffer);
|
|
1395
|
+
this.sendBvlc(address, port, buffer);
|
|
1336
1396
|
this._addCallback(settings.invokeId, (err, data) => {
|
|
1337
1397
|
if (err)
|
|
1338
1398
|
return next(err);
|
|
@@ -1342,16 +1402,20 @@ class Client extends events_1.EventEmitter {
|
|
|
1342
1402
|
next(null, result);
|
|
1343
1403
|
});
|
|
1344
1404
|
}
|
|
1345
|
-
unconfirmedEventNotification(
|
|
1405
|
+
unconfirmedEventNotification(addressObject, eventNotification) {
|
|
1406
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1407
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1346
1408
|
const buffer = this._getBuffer();
|
|
1347
1409
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, address);
|
|
1348
1410
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.UNCONFIRMED_EVENT_NOTIFICATION);
|
|
1349
1411
|
baServices.eventNotifyData.encode(buffer, eventNotification);
|
|
1350
1412
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1351
|
-
this.sendBvlc(address, buffer);
|
|
1413
|
+
this.sendBvlc(address, port, buffer);
|
|
1352
1414
|
}
|
|
1353
|
-
confirmedEventNotification(
|
|
1415
|
+
confirmedEventNotification(addressObject, eventNotification, options, next) {
|
|
1354
1416
|
next = next || options;
|
|
1417
|
+
let address = addressObject.address ? addressObject.address : addressObject;
|
|
1418
|
+
let port = addressObject.port ? addressObject.port : this._settings.port;
|
|
1355
1419
|
const settings = {
|
|
1356
1420
|
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
|
|
1357
1421
|
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
|
|
@@ -1362,7 +1426,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1362
1426
|
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.CONFIRMED_EVENT_NOTIFICATION, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
|
|
1363
1427
|
baServices.eventNotifyData.encode(buffer, eventNotification);
|
|
1364
1428
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1365
|
-
this.sendBvlc(address, buffer);
|
|
1429
|
+
this.sendBvlc(address, port, buffer);
|
|
1366
1430
|
this._addCallback(settings.invokeId, (err) => next(err));
|
|
1367
1431
|
}
|
|
1368
1432
|
// Public Device Functions
|
|
@@ -1372,7 +1436,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1372
1436
|
baApdu.encodeComplexAck(buffer, baEnum.PduTypes.COMPLEX_ACK, baEnum.ConfirmedServiceChoice.READ_PROPERTY, invokeId);
|
|
1373
1437
|
baServices.readProperty.encodeAcknowledge(buffer, objectId, property.id, property.index, value);
|
|
1374
1438
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1375
|
-
this.sendBvlc(receiver, buffer);
|
|
1439
|
+
this.sendBvlc(receiver, this._settings.port, buffer);
|
|
1376
1440
|
}
|
|
1377
1441
|
readPropertyMultipleResponse(receiver, invokeId, values) {
|
|
1378
1442
|
const buffer = this._getBuffer();
|
|
@@ -1380,7 +1444,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1380
1444
|
baApdu.encodeComplexAck(buffer, baEnum.PduTypes.COMPLEX_ACK, baEnum.ConfirmedServiceChoice.READ_PROPERTY_MULTIPLE, invokeId);
|
|
1381
1445
|
baServices.readPropertyMultiple.encodeAcknowledge(buffer, values);
|
|
1382
1446
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1383
|
-
this.sendBvlc(receiver, buffer);
|
|
1447
|
+
this.sendBvlc(receiver, this._settings.port, buffer);
|
|
1384
1448
|
}
|
|
1385
1449
|
iAmResponse(deviceId, segmentation, vendorId) {
|
|
1386
1450
|
const buffer = this._getBuffer();
|
|
@@ -1388,7 +1452,7 @@ class Client extends events_1.EventEmitter {
|
|
|
1388
1452
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.I_AM);
|
|
1389
1453
|
baServices.iAmBroadcast.encode(buffer, deviceId, this._transport.getMaxPayload(), segmentation, vendorId);
|
|
1390
1454
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU, buffer.offset);
|
|
1391
|
-
this._transport.send(buffer.buffer, buffer.offset, this._transport.getBroadcastAddress());
|
|
1455
|
+
this._transport.send(buffer.buffer, buffer.offset, this._transport.getBroadcastAddress(), this._settings.port);
|
|
1392
1456
|
}
|
|
1393
1457
|
iHaveResponse(deviceId, objectId, objectName) {
|
|
1394
1458
|
const buffer = this._getBuffer();
|
|
@@ -1396,14 +1460,14 @@ class Client extends events_1.EventEmitter {
|
|
|
1396
1460
|
baApdu.encodeUnconfirmedServiceRequest(buffer, baEnum.PduTypes.UNCONFIRMED_REQUEST, baEnum.UnconfirmedServiceChoice.I_HAVE);
|
|
1397
1461
|
baServices.iHaveBroadcast.encode(buffer, deviceId, objectId, objectName);
|
|
1398
1462
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU, buffer.offset);
|
|
1399
|
-
this._transport.send(buffer.buffer, buffer.offset, this._transport.getBroadcastAddress());
|
|
1463
|
+
this._transport.send(buffer.buffer, buffer.offset, this._transport.getBroadcastAddress(), this._settings.port);
|
|
1400
1464
|
}
|
|
1401
1465
|
simpleAckResponse(receiver, service, invokeId) {
|
|
1402
1466
|
const buffer = this._getBuffer();
|
|
1403
1467
|
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE, receiver);
|
|
1404
1468
|
baApdu.encodeSimpleAck(buffer, baEnum.PduTypes.SIMPLE_ACK, service, invokeId);
|
|
1405
1469
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1406
|
-
this.sendBvlc(receiver, buffer);
|
|
1470
|
+
this.sendBvlc(receiver, this._settings.port, buffer);
|
|
1407
1471
|
}
|
|
1408
1472
|
errorResponse(receiver, service, invokeId, errorClass, errorCode) {
|
|
1409
1473
|
const buffer = this._getBuffer();
|
|
@@ -1411,14 +1475,15 @@ class Client extends events_1.EventEmitter {
|
|
|
1411
1475
|
baApdu.encodeError(buffer, baEnum.PduTypes.ERROR, service, invokeId);
|
|
1412
1476
|
baServices.error.encode(buffer, errorClass, errorCode);
|
|
1413
1477
|
//baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
|
|
1414
|
-
this.sendBvlc(receiver, buffer);
|
|
1478
|
+
this.sendBvlc(receiver, this._settings.port, buffer);
|
|
1415
1479
|
}
|
|
1416
1480
|
/**
|
|
1417
1481
|
*
|
|
1418
1482
|
* @param receiver
|
|
1419
1483
|
* @param buffer
|
|
1420
1484
|
*/
|
|
1421
|
-
sendBvlc(receiver, buffer) {
|
|
1485
|
+
sendBvlc(receiver, port, buffer) {
|
|
1486
|
+
let that = this;
|
|
1422
1487
|
if (typeof receiver === 'string') {
|
|
1423
1488
|
receiver = {
|
|
1424
1489
|
address: receiver
|
|
@@ -1434,11 +1499,25 @@ class Client extends events_1.EventEmitter {
|
|
|
1434
1499
|
// No address, broadcast
|
|
1435
1500
|
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_BROADCAST_NPDU, buffer.offset);
|
|
1436
1501
|
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
(
|
|
1441
|
-
|
|
1502
|
+
|
|
1503
|
+
//check if port is array, send on all specified ports if true
|
|
1504
|
+
if (Array.isArray(port) && port.length > 0) {
|
|
1505
|
+
port.forEach(function (p) {
|
|
1506
|
+
that._transport.send(
|
|
1507
|
+
buffer.buffer,
|
|
1508
|
+
buffer.offset,
|
|
1509
|
+
(receiver && receiver.address) || null,
|
|
1510
|
+
p
|
|
1511
|
+
);
|
|
1512
|
+
});
|
|
1513
|
+
} else {
|
|
1514
|
+
this._transport.send(
|
|
1515
|
+
buffer.buffer,
|
|
1516
|
+
buffer.offset,
|
|
1517
|
+
(receiver && receiver.address) || null,
|
|
1518
|
+
port
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1442
1521
|
}
|
|
1443
1522
|
/**
|
|
1444
1523
|
* Unloads the current BACstack instance and closes the underlying UDP socket.
|