示例#1
0
def create_ReadPropertyRequest(args):
    """
    Create a ReadPropertyRequest from a string
    """
    args = args.split()
    addr, obj_type, obj_inst, prop_id = args[:4]
    print(addr)

    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)

    datatype = get_datatype(obj_type, prop_id)
    if not datatype:
        raise ValueError("invalid property for object type")

    # build a request
    request = ReadPropertyRequest(
        objectIdentifier=(obj_type, obj_inst),
        propertyIdentifier=prop_id,
    )
    request.pduDestination = Address(addr)

    if len(args) == 5:
        request.propertyArrayIndex = int(args[4])

    return request
示例#2
0
    def do_read(self, args):
        """read <addr> <type> <inst> <prop> [ <indx> ]"""
        args = args.split()
        if _debug: TestConsoleCmd._debug("do_read %r", args)

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

            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)

            datatype = get_datatype(obj_type, prop_id)
            if not datatype:
                raise ValueError, "invalid property for object type"

            # build a request
            request = ReadPropertyRequest(
                objectIdentifier=(obj_type, obj_inst),
                propertyIdentifier=prop_id,
                )
            request.pduDestination = Address(addr)

            if len(args) == 5:
                request.propertyArrayIndex = int(args[4])
            if _debug: TestConsoleCmd._debug("    - request: %r", request)

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

        except Exception, e:
            TestConsoleCmd._exception("exception: %r", e)
示例#3
0
    def next_request(self):
        if _debug: PrairieDog._debug("next_request")

        # check to see if we're done
        if not self.point_queue:
            if _debug: PrairieDog._debug("    - done")

            # dump out the results
            for request, response in zip(point_list, self.response_values):
                print(request, response)

            # no longer busy
            self.is_busy = False

            return

        # get the next request
        addr, obj_type, obj_inst, prop_id = self.point_queue.popleft()

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
        )
        request.pduDestination = Address(addr)
        if _debug: PrairieDog._debug("    - request: %r", request)

        # send the request
        iocb = self.request(request)
        if _debug: PrairieDog._debug("    - iocb: %r", iocb)

        # set a callback for the response
        iocb.add_callback(self.complete_request)
示例#4
0
    def read_next_object(self, context):
        if _debug:
            ReadObjectListApplication._debug("read_next_object %r", context)

        # if there's nothing more to do, we're done
        if not context._object_list_queue:
            if _debug: ReadObjectListApplication._debug("    - all done")
            context.completed()
            return

        # pop off the next object identifier
        object_id = context._object_list_queue.popleft()
        if _debug:
            ReadObjectListApplication._debug("    - object_id: %r", object_id)

        # build a request for the object name
        request = ReadPropertyRequest(
            destination=context.device_addr,
            objectIdentifier=object_id,
            propertyIdentifier='objectName',
        )
        if _debug:
            ReadObjectListApplication._debug("    - request: %r", request)

        # make an IOCB, reference the context
        iocb = IOCB(request)
        iocb.context = context
        if _debug: ReadObjectListApplication._debug("    - iocb: %r", iocb)

        # let us know when its complete
        iocb.add_callback(self.object_name_results)

        # give it to the application
        self.request_io(iocb)
示例#5
0
 def _get_device_info(self):
     request = ReadPropertyRequest(destination=self.source,
                                   objectIdentifier=self.id,
                                   propertyIdentifier='objectName')
     iocb = IOCB(request)
     iocb.add_callback(self._got_object_name)
     self.bacnet_adapter.request_io(iocb)
示例#6
0
文件: Read.py 项目: gnmerritt/BAC0
    def build_rp_request(self, args, arr_index=None, vendor_id=0, bacoid=None):
        addr, obj_type, obj_inst, prop_id = args[:4]
        vendor_id = vendor_id
        bacoid = bacoid

        if obj_type.isdigit():
            obj_type = int(obj_type)
        elif "@obj_" in obj_type:
            obj_type = int(obj_type.split("_")[1])
        elif not get_object_class(obj_type, vendor_id=vendor_id):
            raise ValueError("Unknown object type : {}".format(obj_type))

        obj_inst = int(obj_inst)

        if prop_id.isdigit():
            prop_id = int(prop_id)
        elif "@prop_" in prop_id:
            prop_id = int(prop_id.split("_")[1])

        # datatype = get_datatype(obj_type, prop_id, vendor_id=vendor_id)

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
            propertyArrayIndex=arr_index,
        )
        request.pduDestination = Address(addr)

        if len(args) == 5:
            request.propertyArrayIndex = int(args[4])
        self._log.debug("{:<20} {!r}".format("REQUEST", request))
        return request
示例#7
0
    def read_prop_vendor(self):
        #get bacnet source pdu from point_list array. point_list has been override by next_request method
        addr = point_list[0][0]

        obj_type = self.obj
        obj_inst = self.inst
        prop_id = self.prop

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=int(prop_id),
        )
        request.pduDestination = Address(addr)

        request.propertyArrayIndex = self.idx
        #if _debug: ReadPropertyAnyConsoleCmd._debug("    - request: %r", request)

        # make an IOCB
        iocb = IOCB(request)

        #if _debug: ReadPropertyAnyConsoleCmd._debug("    - iocb: %r", iocb)

        # set a callback for the response
        iocb.add_callback(self.prop_vendor_ack)

        # give it to the application
        this_application.request_io(iocb)
示例#8
0
    def next_request(self):
        if _debug: PrairieDog._debug("next_request")

        # check to see if we're done
        if not self.point_queue:
            if _debug: PrairieDog._debug("    - done")

            # dump out the results
            for request, response in zip(point_list, self.response_values):
                print request, response

            # no longer busy
            self.is_busy = False

            return

        # get the next request
        addr, obj_type, obj_inst, prop_id = self.point_queue.popleft()

        # build a request
        self._request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
            )
        self._request.pduDestination = Address(addr)
        if _debug: PrairieDog._debug("    - request: %r", self._request)

        # forward it along
        BIPSimpleApplication.request(self, self._request)
示例#9
0
async def discover_properties(app, device_id, addr):
    objects = await app.execute_request(
        ReadPropertyRequest(objectIdentifier=('device', device_id),
                            propertyIdentifier='objectList',
                            destination=Address(addr)))
    result = {}
    for object_identifier in objects:
        _logger.info(object_identifier)
        read_access_specs = [
            ReadAccessSpecification(
                objectIdentifier=object_identifier,
                listOfPropertyReferences=[
                    PropertyReference(propertyIdentifier='presentValue'),
                    PropertyReference(propertyIdentifier='objectName'),
                    PropertyReference(propertyIdentifier='objectType'),
                    PropertyReference(propertyIdentifier='description'),
                    PropertyReference(propertyIdentifier='units'),
                ],
            ),
        ]
        result.update(await app.execute_request(
            ReadPropertyMultipleRequest(
                listOfReadAccessSpecs=read_access_specs,
                destination=Address(addr)), ))
    global properties
    properties = result
    asyncio.get_event_loop().stop()
示例#10
0
    def next_request(self):
        if _debug: ReadPointListApplication._debug("next_request")

        # check to see if we're done
        if not self.point_queue:
            if _debug: ReadPointListApplication._debug("    - done")
            stop()
            return

        # get the next request
        addr, obj_type, obj_inst, prop_id = self.point_queue.popleft()

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
        )
        request.pduDestination = Address(addr)
        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)
示例#11
0
    def do_read(self, args):
        """read <addr> <objid> <prop> [ <indx> ]"""
        args = args.split()
        if _debug: TestConsoleCmd._debug("do_read %r", args)

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

            datatype = get_datatype(obj_id[0], prop_id)
            if not datatype:
                raise ValueError, "invalid property for object type"

            # build a request
            request = ReadPropertyRequest(
                objectIdentifier=obj_id,
                propertyIdentifier=prop_id,
                )
            request.pduDestination = Address(addr)

            if len(args) == 4:
                request.propertyArrayIndex = int(args[3])
            if _debug: TestConsoleCmd._debug("    - request: %r", request)

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

        except Exception, e:
            TestConsoleCmd._exception("exception: %r", e)
示例#12
0
    def next_request(self):
        if _debug: ReadPropertyApplication._debug("next_request")
        global device_address, object_identifier, property_list

        # check to see if we're done
        if not property_list:
            if _debug: ReadPropertyApplication._debug("    - done")
            stop()
            return

        # get the next request
        self.property_identifier = property_list.popleft()
        if _debug:
            ReadPropertyApplication._debug("    - property_identifier: %r",
                                           self.property_identifier)

        # build a request
        request = ReadPropertyRequest(
            destination=device_address,
            objectIdentifier=object_identifier,
            propertyIdentifier=self.property_identifier,
        )
        if _debug: ReadPropertyApplication._debug("    - request: %r", request)

        # make an IOCB
        iocb = IOCB(request)

        # set a callback for the response
        iocb.add_callback(self.complete_request)
        if _debug: ReadPropertyApplication._debug("    - iocb: %r", iocb)

        # send the request
        this_application.request_io(iocb)
示例#13
0
 def _get_new_sensors_for_new_device(self, source, device_id):
     request = ReadPropertyRequest(destination=source,
                                   objectIdentifier=device_id,
                                   propertyIdentifier="objectList")
     iocb = IOCB(request)
     iocb.add_callback(self._got_sensors_for_device)
     self.bacnet_adapter.request_io(iocb)
示例#14
0
 def _get_value_for_prop(self, prop):
     request = ReadPropertyRequest(destination=self.device.source,
                                   objectIdentifier=self.object,
                                   propertyIdentifier=prop)
     iocb = IOCB(request)
     iocb.add_callback(self._got_prop, prop)
     self.bacnet_adapter.request_io(iocb)
示例#15
0
 def _get_prop_for_obj(self, obj_id):
     request = ReadPropertyRequest(destination=self.device.source,
                                   objectIdentifier=obj_id,
                                   propertyIdentifier='propertyList')
     iocb = IOCB(request)
     iocb.add_callback(self._got_properties_for_object, obj_id)
     self.bacnet_adapter.request_io(iocb)
    def do_read(self, args):
        """read <addr> <type> <inst> <prop> [ <indx> ]"""
        args = args.split()
        if _debug: TestConsoleCmd._debug("do_read %r", args)

        try:
            addr, objType, objInst, propId = args[:4]
            if objType.isdigit():
                objType = int(objType)
            objInst = int(objInst)

            # build a request
            request = ReadPropertyRequest(
                objectIdentifier=(objType, objInst),
                propertyIdentifier=propId,
            )
            request.pduDestination = Address(addr)
            if len(args) == 5:
                request.propertyArrayIndex = int(args[4])
            if _debug: TestConsoleCmd._debug("    - request: %r", request)

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

        except Exception, e:
            TestConsoleCmd._exception("exception: %r", e)
示例#17
0
    def test_readProperty(self):

        request = ReadPropertyRequest(objectIdentifier=("analogInput", 14),
                                      propertyIdentifier=85)
        request.apduMaxResp = 1024
        request.apduInvokeID = 101
        apdu = APDU()
        request.encode(apdu)
        pdu = PDU()
        apdu.encode(pdu)
        buf_size = 1024
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.sendto(pdu.pduData,
                 ("127.0.0.1", self.bacnet_server.server.server_port))
        data = s.recvfrom(buf_size)
        s.close()
        received_data = data[0]

        expected = ReadPropertyACK()
        expected.pduDestination = GlobalBroadcast()
        expected.apduInvokeID = 101
        expected.objectIdentifier = 14
        expected.objectName = "AI 01"
        expected.propertyIdentifier = 85
        expected.propertyValue = Any(Real(68.0))

        exp_apdu = APDU()
        expected.encode(exp_apdu)
        exp_pdu = PDU()
        exp_apdu.encode(exp_pdu)

        self.assertEqual(exp_pdu.pduData, received_data)
示例#18
0
    def read_object_list(self, device_id, device_addr):
        if _debug:
            ReadAllObjectPropertiesApplication._debug("read_object_list %r %r",
                                                      device_id, device_addr)

        # create a context to hold the results
        context = ObjectPropertyContext(device_id, device_addr)

        # build a request for the object name
        request = ReadPropertyRequest(
            destination=context.device_addr,
            objectIdentifier=context.device_id,
            propertyIdentifier='objectList',
        )
        if _debug:
            ReadAllObjectPropertiesApplication._debug("    - request: %r",
                                                      request)

        # make an IOCB, reference the context
        iocb = IOCB(request)
        iocb.context = context
        if _debug:
            ReadAllObjectPropertiesApplication._debug("    - iocb: %r", iocb)

        # let us know when its complete
        iocb.add_callback(self.object_list_results)

        # give it to the application
        self.request_io(iocb)
示例#19
0
    def build_rp_request(self, args, arr_index = None):
        addr, obj_type, obj_inst, prop_id = args[:4]

        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)

        datatype = get_datatype(obj_type, prop_id)
        if not datatype:
            raise ValueError("invalid property for object type")

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
            propertyArrayIndex=arr_index,
        )
        request.pduDestination = Address(addr)

        if len(args) == 5:
            request.propertyArrayIndex = int(args[4])
        log_debug(ReadProperty, "    - request: %r", request)

        return request              
示例#20
0
    def read(self, obj_type, obj_inst, prop_id, address):
        datatype = get_datatype(obj_type, prop_id)
        if not datatype:
            print("invalid property %s for object type %s" % (prop_id,object_type))
            return "error invalid property %s for object type %s" % (prop_id,object_type)

        # build a request
        request = ReadPropertyRequest(objectIdentifier=(obj_type, obj_inst), propertyIdentifier=prop_id)
        request.pduDestination = Address(address)

        # TODO: How do we handle an index? This is a 'parameterized get' case that uses b
        # request.propertyArrayIndex = <handle me>

        # build an IOCB, save the request
        iocb = IOCB()
        iocb.ioRequest = request

        # give it to the application to send
        _ss.bacnet_app.do_request(request, iocb)

        # wait for the response
        iocb.ioComplete.wait()

        # filter out errors and aborts
        if isinstance(iocb.ioResponse, Error) or isinstance(iocb.ioResponse, AbortPDU):
            print( "get operation failed %s %s %s" % (obj_type, obj_inst, str(iocb.ioResponse)))
            n = "error get operation failed %s %s %s" % (obj_type, obj_inst, str(iocb.ioResponse))
        else:
            n = self._value_format(prop_id,iocb.ioResponse)
            
        print("read %s %s %s %s" % (address, obj_inst, prop_id, n))

        return n
示例#21
0
    def next_request(self):

        # check to see if we're done
        if not self.point_queue:
            stop()
            return

        # get the next request
        point_id, addr, obj_type, obj_inst, prop_id, idx = self.point_queue.popleft()

        # build a request
        request = ReadPropertyRequest(
            objectIdentifier=(obj_type, obj_inst),
            propertyIdentifier=prop_id,
            propertyArrayIndex=idx
            )
        request.pduDestination = Address(addr)

        # make an IOCB
        iocb = IOCB(request)

        # set a callback for the response
        iocb.add_callback(self.complete_request)

        # send the request
        self.request_io(iocb)
示例#22
0
async def read_device_props(app, device_id, addr):
    return await app.execute_requests(
        ReadPropertyRequest(objectIdentifier=('device', device_id),
                            propertyIdentifier=property_id,
                            destination=Address(addr)) for property_id in [
                                'objectName', 'modelName', 'vendorName',
                                'serialNumber', 'objectList'
                            ])
示例#23
0
    def get_object_list(self):
        request = ReadPropertyRequest(destination=self.source,
                                      objectIdentifier=self.id,
                                      propertyIdentifier="objectList")

        iocb = IOCB(request)
        iocb.add_callback(self._got_object_list)
        self.bacnet_adapter.request_io(iocb)
示例#24
0
 def get_state_async(self, bac_app, address):
     request = ReadPropertyRequest(objectIdentifier=(self.object_type,
                                                     self.instance_number),
                                   propertyIdentifier=self.property)
     request.pduDestination = address
     iocb = IOCB(request)
     bac_app.request(iocb)
     return iocb.ioDefered
示例#25
0
    def run(self):
        if _debug: ReadPointListThread._debug("run")
        global this_application

        # loop through the points
        for obj_id, prop_id in self.point_list:
            obj_id = ObjectIdentifier(obj_id).value

            # build a request
            request = ReadPropertyRequest(
                destination=self.device_address,
                objectIdentifier=obj_id,
                propertyIdentifier=prop_id,
            )
            if _debug: ReadPointListThread._debug("    - request: %r", request)

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

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

            # wait for the response
            iocb.wait()

            if iocb.ioResponse:
                apdu = iocb.ioResponse

                # find the datatype
                datatype = get_datatype(apdu.objectIdentifier[0],
                                        apdu.propertyIdentifier)
                if _debug:
                    ReadPointListThread._debug("    - datatype: %r", datatype)
                if not datatype:
                    raise TypeError("unknown datatype")

                # special case for array parts, others are managed by cast_out
                if issubclass(datatype, Array) and (apdu.propertyArrayIndex
                                                    is not None):
                    if apdu.propertyArrayIndex == 0:
                        value = apdu.propertyValue.cast_out(Unsigned)
                    else:
                        value = apdu.propertyValue.cast_out(datatype.subtype)
                else:
                    value = apdu.propertyValue.cast_out(datatype)
                if _debug: ReadPointListThread._debug("    - value: %r", value)

                # save the value
                self.response_values.append(value)

            if iocb.ioError:
                if _debug:
                    ReadPointListThread._debug("    - error: %r", iocb.ioError)
                self.response_values.append(iocb.ioError)

        if _debug: ReadPointListThread._debug("    - fini")
示例#26
0
    def do_saverl(self, args):
        """saverl <addr> <inst>"""
        args = args.split()
        if _debug: EventNotificationConsoleCmd._debug("do_saverl %r", args)
        global saved_recipent_list

        try:
            addr, obj_inst = args
            obj_inst = int(obj_inst)

            # build a request
            request = ReadPropertyRequest(
                objectIdentifier=('notificationClass', obj_inst),
                propertyIdentifier='recipientList',
            )
            request.pduDestination = Address(addr)

            # make an IOCB
            iocb = IOCB(request)
            if _debug:
                EventNotificationConsoleCmd._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 error/reject/abort
            if iocb.ioError:
                sys.stdout.write(str(iocb.ioError) + '\n')

            # do something for success
            elif iocb.ioResponse:
                apdu = iocb.ioResponse

                # should be an ack
                if not isinstance(apdu, ReadPropertyACK):
                    if _debug:
                        EventNotificationConsoleCmd._debug("    - not an ack")
                    return

                # turn the property tag list blob into a list of destinations
                saved_recipent_list = apdu.propertyValue.cast_out(
                    ListOfDestination)

                for destination in saved_recipent_list:
                    destination.debug_contents(file=sys.stdout)

            # do something with nothing?
            else:
                if _debug:
                    EventNotificationConsoleCmd._debug(
                        "    - ioError or ioResponse expected")

        except Exception as error:
            EventNotificationConsoleCmd._exception("exception: %r", error)
示例#27
0
    def test_remote_read_2(self):
        """Remote read property, matching device."""
        if _debug: TestConfirmedRequests._debug("test_remote_read_2")

        # create a network
        tnet = TNetwork()

        # test device sends request and sees the response
        tnet.td.start_state.doc("5-1-0") \
            .send(ReadPropertyRequest(
                destination=RemoteStation(2, 4),
                objectIdentifier=('device', 4),
                propertyIdentifier='vendorIdentifier',
                )).doc("5-1-1") \
            .receive(ReadPropertyACK).doc("5-1-2") \
            .success()

        # sniffer on network 1 sees the request and the response
        tnet.sniffer1.start_state.doc("5-2-0") \
            .receive(PDU,
                pduData=xtob('01.80.00.00.02'       # who is router to network
                    )
                ).doc("5-2-1") \
            .receive(PDU,
                pduData=xtob('01.80.01.00.02'       # I am router to network
                    )
                ).doc("5-2-2") \
            .receive(PDU,
                pduData=xtob('01.24.00.02.01.04.ff'                 # request
                    '02.44.01.0c.0c.02.00.00.04.19.78'
                    )
                ).doc("5-2-3") \
            .receive(PDU,
                pduData=xtob('01.08.00.02.01.04'                    # ack
                    '30.01.0c.0c.02.00.00.04.19.78.3e.22.03.e7.3f'
                    )
                ).doc("5-2-4") \
            .timeout(3).doc("5-2-5") \
            .success()

        # network 2 sees routed request and unicast response
        tnet.sniffer2.start_state.doc('5-3-0') \
            .receive(PDU,
                pduData=xtob('01.0c.00.01.01.01'                    # request
                    '02.44.01.0c.0c.02.00.00.04.19.78'
                    )
                ).doc("5-3-1") \
            .receive(PDU,
                pduData=xtob('01.20.00.01.01.01.ff'                 # ack
                    '30.01.0c.0c.02.00.00.04.19.78.3e.22.03.e7.3f'
                    )
                ).doc("5-3-2") \
            .timeout(3).doc("5-3-3") \
            .success()

        # run the group
        tnet.run()
示例#28
0
 def read_property(self, target_address, object_type, instance_number, property_name, property_index=None):
     request = ReadPropertyRequest(
         objectIdentifier=(object_type, instance_number),
         propertyIdentifier=property_name,
         propertyArrayIndex=property_index)
     request.pduDestination = Address(target_address)
     iocb = self.iocb_class(request)
     self.bacnet_application.submit_request(iocb)
     bacnet_results = iocb.ioResult.get(10)
     return bacnet_results
示例#29
0
    def do_IAmRequest(self, apdu):
        """Do something with incoming I-Am requests."""
        if _debug: DiscoveryApplication._debug("do_IAmRequest %r", apdu)

        # check for required parameters
        if apdu.iAmDeviceIdentifier is None:
            raise MissingRequiredParameter("iAmDeviceIdentifier required")
        if apdu.maxAPDULengthAccepted is None:
            raise MissingRequiredParameter("maxAPDULengthAccepted required")
        if apdu.segmentationSupported is None:
            raise MissingRequiredParameter("segmentationSupported required")
        if apdu.vendorID is None:
            raise MissingRequiredParameter("vendorID required")

        # extract the device instance number
        device_instance = apdu.iAmDeviceIdentifier[1]
        if _debug:
            DiscoveryApplication._debug("    - device_instance: %r",
                                        device_instance)

        # extract the source address
        device_address = apdu.pduSource
        if _debug:
            DiscoveryApplication._debug("    - device_address: %r",
                                        device_address)

        # we didn't request anything yet
        if not self.who_is_request:
            return

        if (self.who_is_request.deviceInstanceRangeLowLimit is not None) and \
                (device_instance < self.who_is_request.deviceInstanceRangeLowLimit):
            pass
        elif (self.who_is_request.deviceInstanceRangeHighLimit is not None) and \
                (device_instance > self.who_is_request.deviceInstanceRangeHighLimit):
            pass
        else:
            # build a request for the object name
            request = ReadPropertyRequest(
                destination=apdu.pduSource,
                objectIdentifier=apdu.iAmDeviceIdentifier,
                propertyIdentifier='objectName',
            )

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

            # let us know when its complete
            iocb.add_callback(self.device_discovered)

            # give it to the application
            self.request_io(iocb)
示例#30
0
    def read_next_object_properties(self, context):
        if _debug:
            ReadAllObjectPropertiesApplication._debug("read_next_object %r",
                                                      context)

        # if there's nothing more to do, we're done

        if all([
                len(context.properties_dict_queue[element]) == 0
                for element in context.properties_dict_queue
        ]):
            if _debug:
                ReadAllObjectPropertiesApplication._debug("    - all done")
            context.completed()
            return

        # pop off the next object identifier
        if context.current_object_id is None or len(
                context.properties_dict_queue[context.current_object_id]) == 0:
            context.current_object_id = context._object_list_queue.popleft()
            context.property_result_dict.update({
                context.current_object_id[0] + str(context.current_object_id[1]):
                dict()
            })

        context.current_property = context.properties_dict_queue[
            context.current_object_id].popleft()

        if _debug:
            ReadAllObjectPropertiesApplication._debug(
                "    - object_id: %r", context.current_object_id)

        # build a request for the object name
        request = ReadPropertyRequest(
            destination=context.device_addr,
            objectIdentifier=context.current_object_id,
            propertyIdentifier=context.current_property[0],
        )
        if _debug:
            ReadAllObjectPropertiesApplication._debug("    - request: %r",
                                                      request)

        # make an IOCB, reference the context
        iocb = IOCB(request)
        iocb.context = context
        if _debug:
            ReadAllObjectPropertiesApplication._debug("    - iocb: %r", iocb)

        # let us know when its complete
        iocb.add_callback(self.object_properties_results)

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