Skip to content

Commit

Permalink
feat(client): add confirmedCOVNotification() for pushing changes to s…
Browse files Browse the repository at this point in the history
…ubscribers
  • Loading branch information
adam-nielsen committed Feb 12, 2019
1 parent 20ddd16 commit 577558f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ following services are already supported at this point in time:
| Create Object | yes¹ | yes¹ |
| Delete Object | yes¹ | yes¹ |
| Subscribe COV | yes¹ | yes¹ |
| Confirmed COV Notification | yes¹ | yes¹ |
| Subscribe Property | yes¹ | yes¹ |
| Atomic Read File | yes¹ | yes¹ |
| Atomic Write File | yes¹ | yes¹ |
Expand Down
65 changes: 65 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,71 @@ class Client extends EventEmitter {
});
}

/**
* The confirmedCOVNotification command is used to push notifications to other
* systems that have registered with us via a subscribeCOV message.
* @function bacstack.confirmedCOVNotification
* @param {string} address - IP address of the target device.
* @param {object} monitoredObject - The object being monitored, from subscribeCOV.
* @param {number} monitoredObject.type - Object type.
* @param {number} monitoredObject.instance - Object instance.
* @param {number} subscribeId - Subscriber ID from subscribeCOV,
* @param {number} initiatingDeviceId - Our BACnet device ID.
* @param {number} lifetime - Number of seconds left until the subscription expires.
* @param {array} values - values for the monitored object. See example.
* @param {object=} options
* @param {MaxSegmentsAccepted=} options.maxSegments - The maximimal allowed number of segments.
* @param {MaxApduLengthAccepted=} options.maxApdu - The maximal allowed APDU size.
* @param {number=} options.invokeId - The invoke ID of the confirmed service telegram.
* @param {function} next - The callback containing an error, in case of a failure and value object in case of success.
* @example
* const bacnet = require('bacstack');
* const client = new bacnet();
*
* const settings = {deviceId: 123}; // our BACnet device
*
* // Items saved from subscribeCOV message
* const monitoredObject = {type: 1, instance: 1};
* const subscriberProcessId = 123;
*
* client.confirmedCOVNotification(
* '192.168.1.43',
* monitoredObject,
* subscriberProcessId,
* settings.deviceId,
* 30, // should be lifetime of subscription really
* [
* {
* property: { id: bacnet.enum.PropertyIdentifier.PRESENT_VALUE },
* value: [
* {value: 123, type: bacnet.enum.ApplicationTags.REAL},
* ],
* },
* ],
* (err) => {
* console.log('error: ', err);
* }
* );
*/
confirmedCOVNotification(address, monitoredObject, subscribeId, initiatingDeviceId, lifetime, values, options, next) {
next = next || options;
const settings = {
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
invokeId: options.invokeId || this._getInvokeId()
};
const buffer = this._getBuffer();
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE | baEnum.NpduControlBits.EXPECTING_REPLY, address);
baApdu.encodeConfirmedServiceRequest(buffer, baEnum.PduTypes.CONFIRMED_REQUEST, baEnum.ConfirmedServiceChoice.CONFIRMED_COV_NOTIFICATION, settings.maxSegments, settings.maxApdu, settings.invokeId, 0, 0);
baServices.covNotify.encode(buffer, subscribeId, initiatingDeviceId, monitoredObject, lifetime, values);
baBvlc.encode(buffer.buffer, baEnum.BvlcResultPurpose.ORIGINAL_UNICAST_NPDU, buffer.offset);
this._transport.send(buffer.buffer, buffer.offset, address);
this._addCallback(settings.invokeId, (err, data) => {
if (err) return next(err);
next();
});
}

/**
* The deviceCommunicationControl command enables or disables network communication of the target device.
* @function bacstack.deviceCommunicationControl
Expand Down

0 comments on commit 577558f

Please sign in to comment.