예제 #1
0
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        if _debug:
            COVTestClientServices._debug(
                "do_ConfirmedCOVNotificationRequest %r", apdu)

        # the test device needs to set these
        assert hasattr(self, 'test_ack')
        assert hasattr(self, 'test_reject')
        assert hasattr(self, 'test_abort')

        if self.test_ack:
            # success
            response = SimpleAckPDU(context=apdu)
            if _debug:
                COVTestClientServices._debug("    - simple_ack: %r", response)

        elif self.test_reject:
            # reject
            response = RejectPDU(reason=self.test_reject, context=apdu)
            if _debug:
                COVTestClientServices._debug("    - reject: %r", response)

        elif self.test_abort:
            # abort
            response = AbortPDU(reason=self.test_abort, context=apdu)
            if _debug:
                COVTestClientServices._debug("    - abort: %r", response)

        # return the result
        self.response(response)
예제 #2
0
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        if _debug:
            SubscribeCOVApplication._debug(
                "do_ConfirmedCOVNotificationRequest %r", apdu)
        global rsvp

        print("{} changed\n    {}".format(
            apdu.monitoredObjectIdentifier,
            ",\n    ".join("{} = {}".format(
                element.propertyIdentifier,
                str(element.value),
            ) for element in apdu.listOfValues),
        ))

        if rsvp[0]:
            # success
            response = SimpleAckPDU(context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - simple_ack: %r",
                                               response)

        elif rsvp[1]:
            # reject
            response = RejectPDU(reason=rsvp[1], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - reject: %r", response)

        elif rsvp[2]:
            # abort
            response = AbortPDU(reason=rsvp[2], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - abort: %r", response)

        # return the result
        self.response(response)
예제 #3
0
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        if _debug:
            SubscribeCOVApplication._debug(
                "do_ConfirmedCOVNotificationRequest %r", apdu)
        global rsvp

        if rsvp[0]:
            # success
            response = SimpleAckPDU(context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - simple_ack: %r",
                                               response)

        elif rsvp[1]:
            # reject
            response = RejectPDU(reason=rsvp[1], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - reject: %r", response)

        elif rsvp[2]:
            # abort
            response = AbortPDU(reason=rsvp[2], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - abort: %r", response)

        # return the result
        self.response(response)
예제 #4
0
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        # look up the process identifier
        context = self.subscription_contexts.get(apdu.subscriberProcessIdentifier, None)
        if not context or apdu.pduSource != context.address:
            self._log.warning(
                "Unsollicited COV Notification received from {} ({}). Have you restarted the application recently ?".format(
                    apdu.pduSource, apdu
                )
            )
            # this is turned into cancel_cov request and sent back to the client

        else:
            # now tell the context object
            elements = context.cov_notification(apdu)

            # success
            response = SimpleAckPDU(context=apdu)

            # send a confirmation
            self.response(response)
            self._log.debug("Confirmed COV Notification: {}".format(elements))
            self.subscription_contexts["context_callback"](elements)

            # execute callback
            if context.callback is not None:
                context.callback(elements=elements)
예제 #5
0
 def do_UnconfirmedCOVNotificationRequest(self, apdu):
     global rsvp
     for element in apdu.listOfValues:
         datatype = get_datatype(apdu.monitoredObjectIdentifier[0],
                                 element.propertyIdentifier)
         if not datatype:
             pass
         if issubclass(datatype, Array) and (element.propertyArrayIndex
                                             is not None):
             if element.propertyArrayIndex == 0:
                 value = element.value.cast_out(Unsigned)
             else:
                 value = element.value.cast_out(datatype.subtype)
         else:
             value = element.value.cast_out(datatype)
         deviceid = str(apdu.initiatingDeviceIdentifier[1])
         objecto = str(apdu.monitoredObjectIdentifier[0]) + "_" + str(
             apdu.monitoredObjectIdentifier[1])
         argumento = str(element.propertyIdentifier)
         if argumento in Dispositivos[deviceid][objecto]:
             Dispositivos[deviceid][objecto][argumento][
                 "valorActual"] = round(float(value), 1)
         else:
             pass
     if rsvp[0]:
         response = SimpleAckPDU(context=apdu)
     elif rsvp[1]:
         response = RejectPDU(reason=rsvp[1], context=apdu)
     elif rsvp[2]:
         response = AbortPDU(reason=rsvp[2], context=apdu)
     self.response(response)
예제 #6
0
    def do_ConfirmedEventNotificationRequest(self, apdu):
        if _debug:
            EventNotificationApplication._debug(
                "do_ConfirmedEventNotificationRequest %r", apdu)

        # dump the APDU contents
        apdu.debug_contents(file=sys.stdout)

        # double check the process identifier
        if apdu.processIdentifier != os.getpid():
            print("note: not for this process")

        # success
        self.response(SimpleAckPDU(context=apdu))
예제 #7
0
    def do_SubscribeCOVRequest(self, apdu):
        if _debug: COVApplicationMixin._debug("do_SubscribeCOVRequest %r", apdu)

        # extract the pieces
        client_addr = apdu.pduSource
        proc_id = apdu.subscriberProcessIdentifier
        obj_id = apdu.monitoredObjectIdentifier
        confirmed = apdu.issueConfirmedNotifications
        lifetime = apdu.lifetime

        # request is to cancel the subscription
        cancel_subscription = (confirmed is None) and (lifetime is None)

        # find the object
        obj = self.get_object_id(obj_id)
        if not obj:
            if _debug: COVConsoleCmd._debug("    - object not found")
            self.response(Error(errorClass='object', errorCode='unknownObject', context=apdu))
            return

        # can a match be found?
        cov = obj._cov_subscriptions.find(client_addr, proc_id, obj_id)
        if _debug: COVConsoleCmd._debug("    - cov: %r", cov)

        # if a match was found, update the subscription
        if cov:
            if cancel_subscription:
                if _debug: COVConsoleCmd._debug("    - cancel the subscription")
                cov.cancel_subscription()
            else:
                if _debug: COVConsoleCmd._debug("    - renew the subscription")
                cov.renew_subscription(lifetime)
        else:
            if cancel_subscription:
                if _debug: COVConsoleCmd._debug("    - cancel a subscription that doesn't exist")
            else:
                if _debug: COVConsoleCmd._debug("    - create a subscription")

                cov = Subscription(obj, client_addr, proc_id, obj_id, confirmed, lifetime)
                if _debug: COVConsoleCmd._debug("    - cov: %r", cov)

        # success
        response = SimpleAckPDU(context=apdu)

        # return the result
        self.response(response)
예제 #8
0
파일: COVClient.py 프로젝트: zoopp/bacpypes
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        if _debug:
            SubscribeCOVApplication._debug(
                "do_ConfirmedCOVNotificationRequest %r", apdu)
        global rsvp

        print("{} changed\n".format(apdu.monitoredObjectIdentifier))
        for element in apdu.listOfValues:
            element_value = element.value.tagList
            if _debug:
                SubscribeCOVApplication._debug("    - propertyIdentifier: %r",
                                               element.propertyIdentifier)
                SubscribeCOVApplication._debug("    - value tag list: %r",
                                               element_value)

            if len(element_value) == 1:
                element_value = element_value[0].app_to_object().value

            print("    {} is {}".format(element.propertyIdentifier,
                                        str(element_value)))

        if rsvp[0]:
            # success
            response = SimpleAckPDU(context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - simple_ack: %r",
                                               response)

        elif rsvp[1]:
            # reject
            response = RejectPDU(reason=rsvp[1], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - reject: %r", response)

        elif rsvp[2]:
            # abort
            response = AbortPDU(reason=rsvp[2], context=apdu)
            if _debug:
                SubscribeCOVApplication._debug("    - abort: %r", response)

        # return the result
        self.response(response)
예제 #9
0
    def do_ConfirmedCOVNotificationRequest(self, apdu):
        if _debug: SubscribeCOVApplication._debug("do_ConfirmedCOVNotificationRequest %r", apdu)

        # look up the process identifier
        context = subscription_contexts.get(apdu.subscriberProcessIdentifier, None)
        if not context or apdu.pduSource != context.address:
            if _debug: SubscribeCOVApplication._debug("    - no context")

            # this is turned into an ErrorPDU and sent back to the client
            raise ExecutionError('services', 'unknownSubscription')

        # now tell the context object
        context.cov_notification(apdu)

        # success
        response = SimpleAckPDU(context=apdu)
        if _debug: SubscribeCOVApplication._debug("    - simple_ack: %r", response)

        # return the result
        self.response(response)