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