Example #1
0
def read_property_multiple_g3(device, properties, timeout=3.0, no_fallback=0):
    # Some device's do not properly answer multiple properties to multiple
    # objects. This method first tries RPM, then RPM(singular) and finially RP
    # to retrieve a list of properties.
    # A readPropertyFallback attribute remembers which mode was successful and
    # that is used in subsequent reads.
    if (not (_device_table.has_key(device)) or \
        (_device_table[device].readPropertyFallback < BACNET_RPM_SINGLE_OK)):
        results = _read_property_multiple_g3(device,properties, timeout)
        if (results != None):
            if (len(results) == len(properties)): 
                _device_table[device].readPropertyFallback=1 # No fallback needed.
                return results
            elif no_fallback != 0:
                return results
            else:
                # Broken device?
                _device_table[device].readPropertyFallback=0

    results = []
    properties = copy.copy(properties)
    while properties:
        property = properties.pop(0)
        try:
            rp_result = read_property_g3(device, property)
            if (rp_result is not None): #remember this worked
                if (_device_table[device].readPropertyFallback == BACNET_RPM_UNKNOWN):
                    msglog.log('broadway', msglog.types.WARN,
                               'read_property fallback for device = ' +
                               str(device))
                    _device_table[device].readPropertyFallback = BACNET_RPM_NOT_SUPPORTED
                #convert result to RPM style
                result = sequence.ReadAccessResult()
                result.object_identifier = rp_result.object_identifier
                result.list_of_results = [
                    sequence._ReadPropertyMultipleResult(
                        property_identifier=rp_result.property_identifier,
                        property_array_index=rp_result.property_array_index,
                        property_value=rp_result.property_value)
                    ]
            else:
                # Place holder...
                result = ReadAccessResult()
        except BACnetError, e:
            # Simulate RPMs behaviour when a subset of reads fail.
            error = sequence.Error(decode=tag.decode(e.npdu.data).value)
            result = sequence.ReadAccessResult()
            result.object_identifier = data.BACnetObjectIdentifier(property[0],
                                                                   property[1])
            if len(property) > 3 and property[3] != -1:
                index = property[3]
            else:
                index = -1
            result.list_of_results = [
                sequence._ReadPropertyMultipleResult(
                    property_identifier=property[2],
                    property_array_index=index,
                    property_access_error=error)
                ]
        results.append(result)
Example #2
0
def read_property_multiple_g3(device, properties, timeout=3.0, no_fallback=0):
    # Some device's do not properly answer multiple properties to multiple
    # objects. This method first tries RPM, then RPM(singular) and finially RP
    # to retrieve a list of properties.
    # A readPropertyFallback attribute remembers which mode was successful and
    # that is used in subsequent reads.
    if not (_device_table.has_key(device)) or (_device_table[device].readPropertyFallback < BACNET_RPM_SINGLE_OK):
        results = _read_property_multiple_g3(device, properties, timeout)
        if results != None:
            if len(results) == len(properties):
                _device_table[device].readPropertyFallback = 1  # No fallback needed.
                return results
            elif no_fallback != 0:
                return results
            else:
                # Broken device?
                _device_table[device].readPropertyFallback = 0

    results = []
    properties = copy.copy(properties)
    while properties:
        property = properties.pop(0)
        try:
            rp_result = read_property_g3(device, property)
            if rp_result is not None:  # remember this worked
                if _device_table[device].readPropertyFallback == BACNET_RPM_UNKNOWN:
                    msglog.log("broadway", msglog.types.WARN, "read_property fallback for device = " + str(device))
                    _device_table[device].readPropertyFallback = BACNET_RPM_NOT_SUPPORTED
                # convert result to RPM style
                result = sequence.ReadAccessResult()
                result.object_identifier = rp_result.object_identifier
                result.list_of_results = [
                    sequence._ReadPropertyMultipleResult(
                        property_identifier=rp_result.property_identifier,
                        property_array_index=rp_result.property_array_index,
                        property_value=rp_result.property_value,
                    )
                ]
            else:
                # Place holder...
                result = ReadAccessResult()
        except BACnetError, e:
            # Simulate RPMs behaviour when a subset of reads fail.
            error = sequence.Error(decode=tag.decode(e.npdu.data).value)
            result = sequence.ReadAccessResult()
            result.object_identifier = data.BACnetObjectIdentifier(property[0], property[1])
            if len(property) > 3 and property[3] != -1:
                index = property[3]
            else:
                index = -1
            result.list_of_results = [
                sequence._ReadPropertyMultipleResult(
                    property_identifier=property[2], property_array_index=index, property_access_error=error
                )
            ]
        results.append(result)
Example #3
0
def server_read_property_multiple(device, msg):
    request = tag.decode(msg.data)
    if DEBUG:
        print "SERVER READ PROPERTY MULTIPLE request: ", request
    results = []
    # convert request into a list of read access specifications
    ss = sequence.context_read_access_specification_list(request)
    o = None
    p = None
    if DEBUG:
        print "SERVER READ PROPERTY sequence: ", ss
    # device.time_rpm.begin()
    for s in ss:
        o = device.find_bacnet_object(s.object_identifier)
        if DEBUG:
            print "SERVER READ PROPERTY object: ", o
        result = sequence.ReadAccessResult()
        result.object_identifier = s.object_identifier
        props = []
        for spec in s.list_of_specs:
            prop_result = sequence._ReadPropertyMultipleResult()
            prop_result.property_identifier = spec.property_identifier
            i = None
            if spec.property_index != OPTIONAL:
                i = spec.property_index
                prop_result.property_array_index = i
            try:
                p = o.find_property(spec.property_identifier)
                prop_result.property_value = p.as_tags(i)
            except:
                if p:
                    prop_result.property_access_error = sequence.Error(2, 25)  # operational error
                elif o:
                    prop_result.property_access_error = sequence.Error(2, 32)  # unknown property
                else:  # unkown object
                    prop_result.property_access_error = sequence.Error(1, 31)  # unknown object
                if DEBUG:
                    print "SERVER property_access_error: ", str(
                        prop_result.property_access_error
                    ), s.object_identifier.object_type, s.object_identifier.instance_number, str(
                        spec.property_identifier
                    )
            if DEBUG:
                print "SERVER READ PROPERTY property: ", p
            props.append(prop_result.encoding)
        result.list_of_results = props
        results.extend(result.encoding)
    if DEBUG:
        print "SERVER READ PROPERTY MULTIPLE request results: ", results
    answer = complex_ack_pdu(msg, results)
    # device.time_rpm.end()
    return answer
Example #4
0
def server_read_property_multiple(device, msg):
    request = tag.decode(msg.data)
    if DEBUG: print 'SERVER READ PROPERTY MULTIPLE request: ', request
    results = []
    #convert request into a list of read access specifications
    ss = sequence.context_read_access_specification_list(request)
    o = None
    p = None
    if DEBUG: print 'SERVER READ PROPERTY sequence: ', ss
    #device.time_rpm.begin()
    for s in ss:
        o = device.find_bacnet_object(s.object_identifier)
        if DEBUG: print 'SERVER READ PROPERTY object: ', o
        result = sequence.ReadAccessResult()
        result.object_identifier = s.object_identifier
        props = []
        for spec in s.list_of_specs:
            prop_result = sequence._ReadPropertyMultipleResult()
            prop_result.property_identifier = spec.property_identifier
            i = None
            if spec.property_index != OPTIONAL:
                i = spec.property_index
                prop_result.property_array_index = i
            try:
                p = o.find_property(spec.property_identifier)
                prop_result.property_value = p.as_tags(i)
            except:
                if p:
                    prop_result.property_access_error = sequence.Error(2,25) #operational error
                elif o:
                    prop_result.property_access_error = sequence.Error(2,32) #unknown property
                else: #unkown object
                    prop_result.property_access_error = sequence.Error(1,31) #unknown object
                if DEBUG: print 'SERVER property_access_error: ', str(prop_result.property_access_error), \
                      s.object_identifier.object_type,  s.object_identifier.instance_number, \
                      str(spec.property_identifier)
            if DEBUG: print 'SERVER READ PROPERTY property: ', p
            props.append(prop_result.encoding)
        result.list_of_results = props
        results.extend(result.encoding)
    if DEBUG: print 'SERVER READ PROPERTY MULTIPLE request results: ', results
    answer = complex_ack_pdu(msg, results)
    #device.time_rpm.end()
    return answer