Beispiel #1
0
def write_property(device, object, instance, property, arrayidx, priority, value, btype):
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 15
    objectIdentifier = tag.Context(0, data.BACnetObjectIdentifier(object, instance))
    propertyIdentifier = tag.Context(1, data.encode_enumerated(property))
    propertyArrayIndex = None  # @fixme Support arrayidx
    propertyValue = tag.Construct(3)
    if priority:
        priorityTag = tag.Context(4, data.encode_enumerated(priority))

    if btype == 0:
        propertyValue.value.append(tag.Null())
    elif btype == 1:
        propertyValue.value.append(tag.Boolean(int(value)))
    elif btype == 2:
        propertyValue.value.append(tag.UnsignedInteger(int(value)))
    elif btype == 3:
        propertyValue.value.append(tag.SignedInteger(int(value)))
    elif btype == 4:
        propertyValue.value.append(tag.Real(float(value)))
    elif btype == 5:
        propertyValue.value.append(tag.Double(float(value)))
    elif btype == 6:
        propertyValue.value.append(tag.OctetString(value))
    elif btype == 7:
        if type(value) == types.StringValue or type(value) == array.ArrayType:
            propertyValue.value.append(tag.CharacterString(data.ANSI_String(value)))
        else:
            propertyValue.value.append(tag.CharacterString(value))
    elif btype == 8:
        propertyValue.value.append(tag.BitString(value))
    elif btype == 9:
        propertyValue.value.append(tag.Enumerated(int(value)))
    elif btype == 10:
        propertyValue.value.append(tag.Date(value))
    elif btype == 11:
        propertyValue.value.append(tag.Time(value))
    elif btype == 12:
        propertyValue.value.append(tag.BACnetObjectIdentifier(value))
    else:
        raise EInvalidValue("btype", btype)

    if propertyArrayIndex is None:
        rp.data = objectIdentifier.encoding + propertyIdentifier.encoding + propertyValue.encoding
    else:
        rp.data = (
            objectIdentifier.encoding
            + propertyIdentifier.encoding
            + propertyArrayIndex.encoding
            + propertyValue.encoding
        )

    if priority:  # optional priority tag
        rp.data = rp.data + priorityTag.encoding

    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    return r
Beispiel #2
0
def read_property_multiple_real2(device, properties):
    results = []

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 14

    rp.data = array.array("c")
    for prop in properties:
        object = prop[0]
        instance = prop[1]
        property = prop[2]
        objID = tag.Context(0, data.BACnetObjectIdentifier(object, instance))
        if len(prop) < 4 or prop[3] == -1:
            propID = tag.Construct(1, [tag.Context(0, data.encode_enumerated(property))])
        else:
            arrayidx = prop[3]
            propID = tag.Construct(
                1,
                [
                    tag.Context(0, data.encode_enumerated(property)),
                    tag.Context(1, data.encode_unsigned_integer(arrayidx)),
                ],
            )
        rp.data.fromstring(objID.encoding)
        rp.data.fromstring(propID.encoding)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    responses = tag.decode(r.data)
    for response in responses.value:
        # Now if we felt like it, we could extract the BACnetIdentifierObject from
        # the response data, at response.number 0.  But we won't because
        # we don't need it at the moment.
        if response.number == 1:
            # Property id/value list.
            for p in response.value:
                #  Again, if we felt like it, we could extract the property
                #  ID from tag.number 2.  But we won't because we don't use
                #  it.  If we wrote code to match the request to response,
                #  we would need it.
                if p.number == 4:
                    # Property value list
                    p_value = p.value[0].value
                    if p_value is None:
                        pass
                    p_bacnet_value_type = p.value[0].number
                    results.append((p_value, p_bacnet_value_type))
                elif p.number == 3:
                    # Property value list
                    p_value = p.value[0].value
                    p_bacnet_value_type = p.value[0].number
                    results.append((p_value, p_bacnet_value_type))
                elif p.number == 5:
                    # error code
                    results.append((None, None))
    return results
Beispiel #3
0
def read_property_multiple_real2(device, properties):
    results = []

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 14

    rp.data = array.array('c')
    for prop in properties:
        object = prop[0]
        instance = prop[1]
        property = prop[2]
        objID = tag.Context(0,data.BACnetObjectIdentifier(object,instance))
        if len(prop) < 4 or prop[3] == -1:
            propID =  tag.Construct(
                1,[tag.Context(0,data.encode_enumerated(property))]
                )
        else:
            arrayidx = prop[3]
            propID = tag.Construct(
                1,[tag.Context(0, data.encode_enumerated(property)),
                   tag.Context(1, data.encode_unsigned_integer(arrayidx))]
                )
        rp.data.fromstring(objID.encoding)
        rp.data.fromstring(propID.encoding)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    responses = tag.decode(r.data)
    for response in responses.value:
        # Now if we felt like it, we could extract the BACnetIdentifierObject from
        # the response data, at response.number 0.  But we won't because
        # we don't need it at the moment.
        if response.number == 1:
            # Property id/value list.
            for p in response.value:
                #  Again, if we felt like it, we could extract the property
                #  ID from tag.number 2.  But we won't because we don't use
                #  it.  If we wrote code to match the request to response, 
                #  we would need it.
                if p.number == 4:
                    # Property value list
                    p_value = p.value[0].value
                    if p_value is None:
                        pass
                    p_bacnet_value_type = p.value[0].number
                    results.append((p_value, p_bacnet_value_type))
                elif p.number == 3:
                    # Property value list
                    p_value = p.value[0].value
                    p_bacnet_value_type = p.value[0].number
                    results.append((p_value, p_bacnet_value_type))
                elif p.number == 5:
                    # error code
                    results.append((None, None))
    return results
Beispiel #4
0
def _read_property_multiple_g3(device, properties, timeout=3.0, **keywords):
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 14

    rp.data = array.array("c")
    for prop in properties:
        object = prop[0]
        instance = prop[1]
        property = prop[2]
        objID = tag.Context(0, data.BACnetObjectIdentifier(object, instance))

        if isinstance(property, types.TupleType):
            tags = []
            for pid in property:  # loop through list of properties
                if isinstance(pid, types.TupleType):  # may have index
                    if len(pid) > 1:  # index
                        tags.append(tag.Context(0, data.encode_enumerated(pid[0])))
                        tags.append(tag.Context(1, data.encode_unsigned_integer(pid[1])))
                        continue
                    pid = pid[0]  # doen't need to be tuple
                tags.append(tag.Context(0, data.encode_enumerated(pid)))
            propID = tag.Construct(1, tags)  # frame it in contruct tags
        else:
            if len(prop) < 4 or prop[3] == -1:
                propID = tag.Construct(1, [tag.Context(0, data.encode_enumerated(property))])
            else:
                arrayidx = prop[3]
                propID = tag.Construct(
                    1,
                    [
                        tag.Context(0, data.encode_enumerated(property)),
                        tag.Context(1, data.encode_unsigned_integer(arrayidx)),
                    ],
                )
        rp.data.fromstring(objID.encoding)
        rp.data.fromstring(propID.encoding)
    # return rp
    if DEBUG:
        for c in rp.data:
            print hex(ord(c)), "  ",
        print ""
    if keywords.has_key("callback"):
        keywords["callback"].callback(_read_property_multiple_callback)
        network.send_request(device, rp, timeout, **keywords)
        return keywords["callback"]  # used as flag
    request_id = network.send_request(device, rp, timeout)
    r = recv_response(request_id, timeout)
    responses = tag.decode(r.data)
    return sequence.context_read_access_result_list(responses)
Beispiel #5
0
def _read_property_multiple_g3(device, properties, timeout=3.0, **keywords):
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 14

    rp.data = array.array('c')
    for prop in properties:
        object = prop[0]
        instance = prop[1]
        property = prop[2]
        objID = tag.Context(0,data.BACnetObjectIdentifier(object,instance))

        if isinstance(property, types.TupleType):
            tags = []
            for pid in property: #loop through list of properties
                if isinstance(pid, types.TupleType): #may have index
                    if len(pid) > 1: #index
                        tags.append(tag.Context(0, data.encode_enumerated(pid[0])))
                        tags.append(tag.Context(1, data.encode_unsigned_integer(pid[1])))
                        continue
                    pid = pid[0] #doen't need to be tuple
                tags.append(tag.Context(0,data.encode_enumerated(pid)))
            propID = tag.Construct(1,tags) #frame it in contruct tags
        else:
            if len(prop) < 4 or prop[3] == -1:
                propID =  tag.Construct(
                    1,[tag.Context(0,data.encode_enumerated(property))]
                    )
            else:
                arrayidx = prop[3]
                propID = tag.Construct(
                    1,[tag.Context(0, data.encode_enumerated(property)),
                       tag.Context(1, data.encode_unsigned_integer(arrayidx))]
                    )
        rp.data.fromstring(objID.encoding)
        rp.data.fromstring(propID.encoding)
    #return rp
    if DEBUG:
        for c in rp.data:
            print hex(ord(c)),'  ',
        print ''
    if keywords.has_key('callback'):
        keywords['callback'].callback(_read_property_multiple_callback)
        network.send_request(device, rp, timeout, **keywords)
        return keywords['callback'] #used as flag
    request_id = network.send_request(device, rp, timeout)
    r = recv_response(request_id, timeout)
    responses = tag.decode(r.data)
    return sequence.context_read_access_result_list(responses)
Beispiel #6
0
def read_property_g3(device, prop, timeout=3.0, **keywords):
    object = prop[0]
    instance = prop[1]
    property = prop[2]
    arrayidx = None
    if len(prop) > 3:
        arrayidx = prop[3]

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 12

    objID = tag.Context(0, data.BACnetObjectIdentifier(object, instance))
    propID = tag.Context(1, data.encode_enumerated(property))
    rp.data = objID.encoding + propID.encoding
    if arrayidx is not None and arrayidx != -1:
        rp.data = rp.data + tag.Context(2, data.encode_unsigned_integer(arrayidx)).encoding
    if keywords.has_key("callback"):
        keywords["callback"].callback(_read_property_callback)
        request_id = network.send_request(device, rp, timeout, **keywords)
        return keywords["callback"]
    else:  # block until answer else let tsm handle callback
        request_id = network.send_request(device, rp, timeout)
        r = recv_response(request_id, timeout)
        response = tag.decode(r.data)
        return sequence.ReadPropertyACK(decode=response.value)
Beispiel #7
0
def read_property_g3(device, prop, timeout=3.0, **keywords):
    object = prop[0]
    instance = prop[1]
    property = prop[2]
    arrayidx = None
    if len(prop) > 3 :
        arrayidx = prop[3]

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 12

    objID =   tag.Context(0,data.BACnetObjectIdentifier(object,instance))
    propID =  tag.Context(1,data.encode_enumerated(property))
    rp.data = objID.encoding + propID.encoding
    if arrayidx is not None and arrayidx != -1:
        rp.data = rp.data + \
                  tag.Context(2,data.encode_unsigned_integer(arrayidx)).\
                  encoding
    if keywords.has_key('callback'):
        keywords['callback'].callback(_read_property_callback)
        request_id = network.send_request(device, rp, timeout, **keywords)
        return keywords['callback']
    else: #block until answer else let tsm handle callback
        request_id = network.send_request(device, rp, timeout)
        r = recv_response(request_id, timeout)
        response = tag.decode(r.data)
        return sequence.ReadPropertyACK(decode=response.value)
Beispiel #8
0
def write_property(device, object, instance, property, arrayidx, priority,
                   value, btype):
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 15
    objectIdentifier = tag.Context(0,data.BACnetObjectIdentifier(object,instance))
    propertyIdentifier = tag.Context(1,data.encode_enumerated(property))
    propertyArrayIndex = None # @fixme Support arrayidx
    propertyValue = tag.Construct(3)
    if (priority):
        priorityTag = tag.Context(4,data.encode_enumerated(priority))
    
    if btype == 0:    propertyValue.value.append(tag.Null())
    elif btype == 1:  propertyValue.value.append(tag.Boolean(int(value)))
    elif btype == 2:  propertyValue.value.append(tag.UnsignedInteger(int(value)))
    elif btype == 3:  propertyValue.value.append(tag.SignedInteger(int(value)))
    elif btype == 4:  propertyValue.value.append(tag.Real(float(value)))
    elif btype == 5:  propertyValue.value.append(tag.Double(float(value)))
    elif btype == 6:  propertyValue.value.append(tag.OctetString(value))
    elif btype == 7:
        if type(value) == types.StringValue or type(value) == array.ArrayType:
            propertyValue.value.append(tag.CharacterString(data.ANSI_String(value)))
        else:
            propertyValue.value.append(tag.CharacterString(value))
    elif btype == 8:  propertyValue.value.append(tag.BitString(value))
    elif btype == 9:  propertyValue.value.append(tag.Enumerated(int(value)))
    elif btype == 10: propertyValue.value.append(tag.Date(value))
    elif btype == 11: propertyValue.value.append(tag.Time(value))
    elif btype == 12: propertyValue.value.append(tag.BACnetObjectIdentifier(value))
    else: raise EInvalidValue("btype", btype)

    if propertyArrayIndex is None:
        rp.data = objectIdentifier.encoding + propertyIdentifier.encoding + \
                  propertyValue.encoding
    else:
        rp.data = objectIdentifier.encoding + propertyIdentifier.encoding + \
                  propertyArrayIndex.encoding + propertyValue.encoding

    if (priority):  #optional priority tag
        rp.data = rp.data + priorityTag.encoding
        
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    return r
Beispiel #9
0
def read_property(device, prop):
    object = prop[0]
    instance = prop[1]
    property = prop[2]
    arrayidx = None
    if len(prop) > 3:
        arrayidx = prop[3]

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 12

    objID = tag.Context(0, data.BACnetObjectIdentifier(object, instance))
    propID = tag.Context(1, data.encode_enumerated(property))
    rp.data = objID.encoding + propID.encoding
    if arrayidx is not None and arrayidx != -1:
        rp.data = rp.data + tag.Context(2, data.encode_unsigned_integer(arrayidx)).encoding
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    response = tag.decode(r.data)
    return response
Beispiel #10
0
def read_property(device, prop):
    object = prop[0]
    instance = prop[1]
    property = prop[2]
    arrayidx = None
    if len(prop) > 3 :
        arrayidx = prop[3]

    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 12

    objID =   tag.Context(0,data.BACnetObjectIdentifier(object,instance))
    propID =  tag.Context(1,data.encode_enumerated(property))
    rp.data = objID.encoding + propID.encoding
    if arrayidx is not None and arrayidx != -1:
        rp.data = rp.data + \
                  tag.Context(2,data.encode_unsigned_integer(arrayidx)).\
                  encoding
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    response = tag.decode(r.data)
    return response