@@ -653,6 +653,71 @@ class Client extends EventEmitter {
653653 } ) ;
654654 }
655655
656+ /**
657+ * The confirmedCOVNotification command is used to push notifications to other
658+ * systems that have registered with us via a subscribeCOV message.
659+ * @function bacstack.confirmedCOVNotification
660+ * @param {string } address - IP address of the target device.
661+ * @param {object } monitoredObject - The object being monitored, from subscribeCOV.
662+ * @param {number } monitoredObject.type - Object type.
663+ * @param {number } monitoredObject.instance - Object instance.
664+ * @param {number } subscribeId - Subscriber ID from subscribeCOV,
665+ * @param {number } initiatingDeviceId - Our BACnet device ID.
666+ * @param {number } lifetime - Number of seconds left until the subscription expires.
667+ * @param {array } values - values for the monitored object. See example.
668+ * @param {object= } options
669+ * @param {MaxSegmentsAccepted= } options.maxSegments - The maximimal allowed number of segments.
670+ * @param {MaxApduLengthAccepted= } options.maxApdu - The maximal allowed APDU size.
671+ * @param {number= } options.invokeId - The invoke ID of the confirmed service telegram.
672+ * @param {function } next - The callback containing an error, in case of a failure and value object in case of success.
673+ * @example
674+ * const bacnet = require('bacstack');
675+ * const client = new bacnet();
676+ *
677+ * const settings = {deviceId: 123}; // our BACnet device
678+ *
679+ * // Items saved from subscribeCOV message
680+ * const monitoredObject = {type: 1, instance: 1};
681+ * const subscriberProcessId = 123;
682+ *
683+ * client.confirmedCOVNotification(
684+ * '192.168.1.43',
685+ * monitoredObject,
686+ * subscriberProcessId,
687+ * settings.deviceId,
688+ * 30, // should be lifetime of subscription really
689+ * [
690+ * {
691+ * property: { id: bacnet.enum.PropertyIdentifier.PRESENT_VALUE },
692+ * value: [
693+ * {value: 123, type: bacnet.enum.ApplicationTags.REAL},
694+ * ],
695+ * },
696+ * ],
697+ * (err) => {
698+ * console.log('error: ', err);
699+ * }
700+ * );
701+ */
702+ confirmedCOVNotification ( address , monitoredObject , subscribeId , initiatingDeviceId , lifetime , values , options , next ) {
703+ next = next || options ;
704+ const settings = {
705+ maxSegments : options . maxSegments || baEnum . MaxSegmentsAccepted . SEGMENTS_65 ,
706+ maxApdu : options . maxApdu || baEnum . MaxApduLengthAccepted . OCTETS_1476 ,
707+ invokeId : options . invokeId || this . _getInvokeId ( )
708+ } ;
709+ const buffer = this . _getBuffer ( ) ;
710+ baNpdu . encode ( buffer , baEnum . NpduControlPriority . NORMAL_MESSAGE | baEnum . NpduControlBits . EXPECTING_REPLY , address ) ;
711+ baApdu . encodeConfirmedServiceRequest ( buffer , baEnum . PduTypes . CONFIRMED_REQUEST , baEnum . ConfirmedServiceChoice . CONFIRMED_COV_NOTIFICATION , settings . maxSegments , settings . maxApdu , settings . invokeId , 0 , 0 ) ;
712+ baServices . covNotify . encode ( buffer , subscribeId , initiatingDeviceId , monitoredObject , lifetime , values ) ;
713+ baBvlc . encode ( buffer . buffer , baEnum . BvlcResultPurpose . ORIGINAL_UNICAST_NPDU , buffer . offset ) ;
714+ this . _transport . send ( buffer . buffer , buffer . offset , address ) ;
715+ this . _addCallback ( settings . invokeId , ( err , data ) => {
716+ if ( err ) return next ( err ) ;
717+ next ( ) ;
718+ } ) ;
719+ }
720+
656721 /**
657722 * The deviceCommunicationControl command enables or disables network communication of the target device.
658723 * @function bacstack.deviceCommunicationControl
0 commit comments