예제 #1
0
파일: agent.py 프로젝트: Kisensum/volttron
    def send_cov_subscription(self, address, subscriberProcessIdentifier,
                              monitoredObjectIdentifier, lifetime, point_name):
        """

        :param address: address of the device to which the subscription
        request will be sent
        :param subscriberProcessIdentifier: arbitrarily set value for
        tracking cov subscriptions
        :param monitoredObjectIdentifier: (object_type, instance_number) from
        the subscription context
        :param lifetime: lifetime in seconds for the device to maintain the
        subscription
        :param point_name:point name for which we would like to establish the
        subscription
        :return:
        """
        subscribe_cov_request = SubscribeCOVRequest(
            subscriberProcessIdentifier=subscriberProcessIdentifier,
            monitoredObjectIdentifier=monitoredObjectIdentifier,
            issueConfirmedNotifications=True,
            lifetime=lifetime
        )

        subscribe_cov_request.pduDestination = address
        iocb = self.iocb_class(subscribe_cov_request)
        self.this_application.submit_request(iocb)
        _log.debug("COV subscription sent to device at {} for {}"
                   .format(address, point_name))
예제 #2
0
    def do_request(self):
        if _debug:
            ReadPointListApplication._debug('do_request')

        request = SubscribeCOVRequest(subscriberProcessIdentifier=1234,
                                      monitoredObjectIdentifier=('analogInput',
                                                                 0),
                                      issueConfirmedNotifications=False,
                                      lifetime=100)
        request.pduDestination = Address('192.168.2.70')
        if _debug:
            ReadPointListApplication._debug('    - request: %r', request)
        # make an IOCB
        iocb = IOCB(request)
        # set a callback for the response
        # iocb.add_callback(self.complete_request)
        if _debug:
            ReadPointListApplication._debug("    - iocb: %r", iocb)
        # send the request
        this_application.request_io(iocb)
        iocb.wait()
        # do something for success
        if iocb.ioResponse:
            if _debug:
                ReadPointListApplication._debug("    - response: %r",
                                                iocb.ioResponse)

        # do something for error/reject/abort
        if iocb.ioError:
            if _debug:
                ReadPointListApplication._debug("    - error: %r",
                                                iocb.ioError)
예제 #3
0
    def send_cov_subscription(self, address, subscriber_process_identifier,
                              monitored_object_identifier, lifetime,
                              point_name):
        """
        Send request to remote BACnet device to create subscription for COV on a point.
        :param address: address of the device to which the subscription
        request will be sent
        :param subscriber_process_identifier: arbitrarily set value for
        tracking cov subscriptions
        :param monitored_object_identifier: (object_type, instance_number) from
        the subscription context
        :param lifetime: lifetime in seconds for the device to maintain the
        subscription
        :param point_name:point name for which we would like to establish the
        subscription
        :return:
        """
        subscribe_cov_request = SubscribeCOVRequest(
            subscriberProcessIdentifier=subscriber_process_identifier,
            monitoredObjectIdentifier=monitored_object_identifier,
            issueConfirmedNotifications=True,
            lifetime=lifetime)

        subscribe_cov_request.pduDestination = address
        iocb = self.iocb_class(subscribe_cov_request)
        self.bacnet_application.submit_request(iocb)
        _log.debug("COV subscription sent to device at {} for {}".format(
            address, point_name))
예제 #4
0
 def create_COV_subscription(self,
                             target_address,
                             point_name,
                             object_type,
                             instance_number,
                             lifetime=None):
     # TODO check that the device supports cov
     subscription = None
     for sub in self.this_application.sub_cov_contexts:
         check_sub = self.this_application.sub_cov_contexts[sub]
         if check_sub.point_name == point_name and \
                 check_sub.monitoredObjectIdentifier == (object_type, instance_number):
             subscription = check_sub
     if not subscription:
         subscription = SubscriptionContext(
             target_address, point_name, object_type, instance_number,
             self.this_application.cov_sub_process_ID, lifetime)
         self.this_application.sub_cov_contexts[
             self.this_application.cov_sub_process_ID] = subscription
         self.this_application.cov_sub_process_ID += 1
     cov_request = SubscribeCOVRequest(
         subscriberProcessIdentifier=subscription.
         subscriberProcessIdentifier,
         monitoredObjectIdentifier=subscription.monitoredObjectIdentifier,
         issueConfirmedNotifications=True,
         lifetime=subscription.lifetime)
     cov_request.pduDestination = Address(subscription.address)
     iocb = self.iocb_class(cov_request)
     self.this_application.submit_request(iocb)
     _log.debug("COV subscription sent to device {} for {}".format(
         target_address, point_name))
예제 #5
0
    def send_subscription(self,
                          addr,
                          proc_id,
                          objid,
                          confirmed=None,
                          lifetime=None):
        if _debug: logger.debug("send_subscription")

        # build a request
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=proc_id,
            monitoredObjectIdentifier=objid,
        )
        request.pduDestination = Address(addr)

        # optional parameters
        if confirmed is not None:
            request.issueConfirmedNotifications = confirmed
        if lifetime is not None:
            request.lifetime = lifetime

        self._request = request

        # make an IOCB
        iocb = IOCB(request)
        if _debug: logger.debug("    - iocb: %r", iocb)

        # callback when it is acknowledged
        #iocb.add_callback(self.subscription_acknowledged)

        # give it to the application
        self.request_io(iocb)
예제 #6
0
    def send_subscription(self, context):
        if _debug: SubscribeCOVApplication._debug("send_subscription %r", context)

        # build a request
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=context.subscriberProcessIdentifier,
            monitoredObjectIdentifier=context.monitoredObjectIdentifier,
            )
        request.pduDestination = context.address

        # optional parameters
        if context.issueConfirmedNotifications is not None:
            request.issueConfirmedNotifications = context.issueConfirmedNotifications
        if context.lifetime is not None:
            request.lifetime = context.lifetime

        # make an IOCB
        iocb = IOCB(request)
        if _debug: SubscribeCOVApplication._debug("    - iocb: %r", iocb)

        # callback when it is acknowledged
        iocb.add_callback(self.subscription_acknowledged)

        # give it to the application
        this_application.request_io(iocb)
예제 #7
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug: SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r", issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug: SubscribeCOVConsoleCmd._debug("    - lifetime: %r", lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
                )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug: SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # give it to the application
            this_application.request(request)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
예제 #8
0
파일: cov.py 프로젝트: snuids/BAC0
    def _build_cov_request(self, context):
        request = SubscribeCOVRequest(
            subscriberProcessIdentifier=context.subscriberProcessIdentifier,
            monitoredObjectIdentifier=context.monitoredObjectIdentifier,
        )
        request.pduDestination = context.address

        # optional parameters
        if context.issueConfirmedNotifications is not None:
            request.issueConfirmedNotifications = context.issueConfirmedNotifications
        if context.lifetime is not None:
            request.lifetime = context.lifetime

        return request
예제 #9
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
            )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - response: %r",
                                                  iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - error: %r",
                                                  iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
예제 #10
0
파일: COVClient.py 프로젝트: zoopp/bacpypes
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_id [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug:
            SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_id = args[:3]
            obj_id = ObjectIdentifier(obj_id).value

            proc_id = int(proc_id)

            if len(args) >= 4:
                issue_confirmed = args[3]
                if issue_confirmed == "-":
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == "true"
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 5:
                lifetime = args[4]
                if lifetime == "-":
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(subscriberProcessIdentifier=proc_id,
                                          monitoredObjectIdentifier=obj_id)
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug:
                SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            deferred(this_application.request_io, iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - response: %r",
                                                  iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - error: %r",
                                                  iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
예제 #11
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r",
                                                  issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug:
                    SubscribeCOVConsoleCmd._debug("    - lifetime: %r",
                                                  lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
            )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug:
                SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # give it to the application
            this_application.request(request)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)
예제 #12
0
    def run(self):
        while True:
            self.inicio = time.time()
            for ids in Dispositivos:
                for obj in Dispositivos[ids]:
                    addr = Dispositivos[ids]["IPort"]
                    if not obj == "IPort":
                        for args in Dispositivos[ids][obj]:
                            RETRY = 0
                            DONE = False
                            if self.ProcessID > 3000: self.ProcessID = 0
                            while RETRY < SubRetrys and DONE == False:
                                try:
                                    #proc_id = Dispositivos[ids][obj][args]["ProcID"]
                                    proc_id = self.ProcessID
                                    lifetime = (int(TimeToRefreshSubs) + 30)
                                    obj_type, obj_inst = obj.split("_")
                                    issue_confirmed = True
                                    if obj_type.isdigit():
                                        obj_type = int(obj_type)
                                    elif not get_object_class(obj_type):
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                " Error trying to subscribe unknown object type.\n"
                                            )
                                    obj_inst = int(obj_inst)
                                    request = SubscribeCOVRequest(
                                        subscriberProcessIdentifier=proc_id,
                                        monitoredObjectIdentifier=(obj_type,
                                                                   obj_inst),
                                    )
                                    request.pduDestination = Address(addr)
                                    if issue_confirmed is not None:
                                        request.issueConfirmedNotifications = issue_confirmed
                                    if lifetime is not None:
                                        request.lifetime = lifetime
                                    iocb = IOCB(request)
                                    this_application.request_io(iocb)
                                    #print "Trying to subscribe to", ids, addr, obj_type, obj_inst
                                    iocb.wait(TimeToWaitForSub)
                                    state = iocb.ioState
                                    '''
									IDLE = 0        # has not been submitted
									PENDING = 1     # queued, waiting for processing
									ACTIVE = 2      # being processed
									COMPLETED = 3   # finished
									ABORTED = 4 	# finished in a bad way
									'''
                                    if state == 0:
                                        time.sleep(TimeBetweenSubs)
                                        #print "ZZzzzzZZZzzzzZZZzzzzZZZ"
                                    elif state == 1:
                                        #print "Esta na queue, vai limpar e tentar de novo..."
                                        this_application.queue_by_address.clear(
                                        )
                                        time.sleep(TimeBetweenSubs)
                                    elif state == 2:
                                        #print "Esta em processamento..."
                                        self.ProcessID += 1
                                        DONE = True
                                    elif state == 3:
                                        #print "YEIII"
                                        self.ProcessID += 1
                                        DONE = True
                                    elif state == 4:
                                        time.sleep(TimeBetweenSubs)
                                        #print "ABORTTTTTTTT, ja deu merdinha"
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                "ABORTTTTTTTT")
                                    else:
                                        time.sleep(TimeBetweenSubs)
                                        #print "WATTTT YYYY!!!! NUNCA VISTO"
                                        with open("ErrorLog.txt",
                                                  "a") as myfile:
                                            myfile.write(
                                                str(
                                                    time.strftime(
                                                        "%d-%m-%Y %H:%M:%S")) +
                                                "WATTTT YYYY!!!! NUNCA VISTO")
                                except Exception as e:
                                    with open("ErrorLog.txt", "a") as myfile:
                                        myfile.write(
                                            str(
                                                time.strftime(
                                                    "%d-%m-%Y %H:%M:%S")) +
                                            " Error while trying to subscribe, proc_id:"
                                            + str(proc_id) + " Addr:" +
                                            str(addr) + "\n")
                                        myfile.write("Error -> " + str(e) +
                                                     "\n")
                                RETRY += 1
            self.fim = time.time()
            #print "Levou:", self.fim - self.inicio
            #print "Refresh Default:", TimeToRefreshSubs
            #print "Refresh Fixed:" , TimeToRefreshSubs - TimeBetweenSubs - round(self.fim - self.inicio, 1)
            #print Dispositivos
            time.sleep(
                abs(TimeToRefreshSubs - TimeBetweenSubs -
                    round(self.fim - self.inicio, 1)))
예제 #13
0
    def do_subscribe(self, args):
        """subscribe addr proc_id obj_type obj_inst [ confirmed ] [ lifetime ]

        Generate a SubscribeCOVRequest and wait for the response.
        """
        args = args.split()
        if _debug: SubscribeCOVConsoleCmd._debug("do_subscribe %r", args)

        try:
            addr, proc_id, obj_type, obj_inst = args[:4]

            proc_id = int(proc_id)

            if obj_type.isdigit():
                obj_type = int(obj_type)
            elif not get_object_class(obj_type):
                raise ValueError("unknown object type")
            obj_inst = int(obj_inst)

            if len(args) >= 5:
                issue_confirmed = args[4]
                if issue_confirmed == '-':
                    issue_confirmed = None
                else:
                    issue_confirmed = issue_confirmed.lower() == 'true'
                if _debug: SubscribeCOVConsoleCmd._debug("    - issue_confirmed: %r", issue_confirmed)
            else:
                issue_confirmed = None

            if len(args) >= 6:
                lifetime = args[5]
                if lifetime == '-':
                    lifetime = None
                else:
                    lifetime = int(lifetime)
                if _debug: SubscribeCOVConsoleCmd._debug("    - lifetime: %r", lifetime)
            else:
                lifetime = None

            # build a request
            request = SubscribeCOVRequest(
                subscriberProcessIdentifier=proc_id,
                monitoredObjectIdentifier=(obj_type, obj_inst),
                )
            request.pduDestination = Address(addr)

            # optional parameters
            if issue_confirmed is not None:
                request.issueConfirmedNotifications = issue_confirmed
            if lifetime is not None:
                request.lifetime = lifetime

            if _debug: SubscribeCOVConsoleCmd._debug("    - request: %r", request)

            # make an IOCB
            iocb = IOCB(request)
            if _debug: SubscribeCOVConsoleCmd._debug("    - iocb: %r", iocb)

            # give it to the application
            this_application.request_io(iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                if _debug: SubscribeCOVConsoleCmd._debug("    - response: %r", iocb.ioResponse)

            # do something for error/reject/abort
            if iocb.ioError:
                if _debug: SubscribeCOVConsoleCmd._debug("    - error: %r", iocb.ioError)

        except Exception as e:
            SubscribeCOVConsoleCmd._exception("exception: %r", e)