Example #1
0
def i_am(device, network):
    global _module_lock
    if debug: print 'send i am'
    boid = device.object_identifier()
    ss = device.segmentation_supported()
    s = sequence.BACnetIAm(boid, device.max_apdu_len, ss, device.vendor_id)
    if debug: print s.encoding
    # Broadcast a I AM device request.
    wi = NPDU()
    wi.version = 1
    wi.pdu_type = BACNET_UNCONFIRMED_SERVICE_REQUEST_PDU
    wi.choice = I_AM_CHOICE
    wi.data = tag.encode(s.encoding)
    wi.dspec = 1
    wi.dlen = 0
    wi.dnet = 0xffff

    #ADDED TO SUPPORT VIRTUAL ROUTER or Devices on other networks
    if not _is_master_server(device, network):
        wi.sspec = 1
        wi.slen = 6  #see above
        wi.snet = device.network
        wi.sadr = utils.bytes_as_string_of_hex_values(device.instance_number,
                                                      wi.slen)

    wi.hop_count = 255
    _send(network, Addr(), wi)
    # no longer need this since when server device is created it is added to device table
    # _network.add_server_to_device_table(device) #copy client since it won't see this
    if debug: print 'sent I am to: %s' % (str(network), )
Example #2
0
def i_am(device, network):
    global _module_lock
    if debug: print 'send i am'
    boid = device.object_identifier()
    ss = device.segmentation_supported()
    s = sequence.BACnetIAm(boid, 
          device.max_apdu_len, 
          ss, 
          device.vendor_id)
    if debug: print s.encoding
    # Broadcast a I AM device request.
    wi = NPDU()
    wi.version = 1
    wi.pdu_type = BACNET_UNCONFIRMED_SERVICE_REQUEST_PDU
    wi.choice = I_AM_CHOICE
    wi.data = tag.encode(s.encoding) 
    wi.dspec = 1
    wi.dlen = 0
    wi.dnet = 0xffff
    
    #ADDED TO SUPPORT VIRTUAL ROUTER or Devices on other networks    
    if not _is_master_server(device, network):
        wi.sspec = 1
        wi.slen = 6 #see above
        wi.snet = device.network
        wi.sadr = utils.bytes_as_string_of_hex_values(device.instance_number, wi.slen)
    
    wi.hop_count = 255
    _send(network, Addr(), wi)
    # no longer need this since when server device is created it is added to device table
    # _network.add_server_to_device_table(device) #copy client since it won't see this
    if debug: print 'sent I am to: %s' % (str(network),)
Example #3
0
def write_property_multiple_g3(device, prop_vals, no_fall_back=0):
    obj_ids = {}
    for pv in prop_vals:
        prop_tuple = pv[0]
        prop_val = pv[1]        
        object = prop_tuple[0]
        instance = prop_tuple[1]
        k = (object, instance) # use tuple as key into object map
        if not obj_ids.has_key(k): # if necy, add a map entry for the given object ID
            was = sequence.WriteAccessSpecification()
            was.list_of_properties = [] # populated on this pass, and poss'ly subsequent passes
            was.object_identifier = data.BACnetObjectIdentifier(object, instance)
            obj_ids[k] = was
        property_id = prop_tuple[2]
        property_array_index = None # default
        priority = None             # default
        # If valid index and/or priority is/are available, add it/them to extended tuple:
        if len(prop_tuple) > 3 and prop_tuple[3] != -1:
            property_array_index = prop_tuple[3]
            if len(prop_tuple) > 4:
                priority = prop_tuple[4]
        # Create and init a new BACnetPropertyValue instance (using given value), and add
        # that new instance to the corresponding object map entry:
        kw = {'property_identifier':property_id,\
              'value':prop_val,\
              'property_array_index':property_array_index}
        if not property_array_index is None:
            kw['property_array_index'] = property_array_index
        if not priority is None:
            kw['priority'] = priority
        obj_ids[k].list_of_properties.append(sequence.BACnetPropertyValue(*(),**kw))
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 16
    for obj_v in obj_ids.values():
        obj_v_enc = obj_v.encoding
        t = tag.encode(obj_v_enc)
        rp.data.fromstring(t)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    
    # @fixme Decode the BACnet-SimpleACK-PDU? and/or handle error rtns by defaulting to
    # write_prop_mults on each "obj_v" above, and then to indiv write_props on elems of
    # obj_v.list_of_properties...
    return r
Example #4
0
def write_property_multiple_g3(device, prop_vals, no_fall_back=0):
    obj_ids = {}
    for pv in prop_vals:
        prop_tuple = pv[0]
        prop_val = pv[1]
        object = prop_tuple[0]
        instance = prop_tuple[1]
        k = (object, instance)  # use tuple as key into object map
        if not obj_ids.has_key(k):  # if necy, add a map entry for the given object ID
            was = sequence.WriteAccessSpecification()
            was.list_of_properties = []  # populated on this pass, and poss'ly subsequent passes
            was.object_identifier = data.BACnetObjectIdentifier(object, instance)
            obj_ids[k] = was
        property_id = prop_tuple[2]
        property_array_index = None  # default
        priority = None  # default
        # If valid index and/or priority is/are available, add it/them to extended tuple:
        if len(prop_tuple) > 3 and prop_tuple[3] != -1:
            property_array_index = prop_tuple[3]
            if len(prop_tuple) > 4:
                priority = prop_tuple[4]
        # Create and init a new BACnetPropertyValue instance (using given value), and add
        # that new instance to the corresponding object map entry:
        kw = {"property_identifier": property_id, "value": prop_val, "property_array_index": property_array_index}
        if not property_array_index is None:
            kw["property_array_index"] = property_array_index
        if not priority is None:
            kw["priority"] = priority
        obj_ids[k].list_of_properties.append(sequence.BACnetPropertyValue(*(), **kw))
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 16
    for obj_v in obj_ids.values():
        obj_v_enc = obj_v.encoding
        t = tag.encode(obj_v_enc)
        rp.data.fromstring(t)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)

    # @fixme Decode the BACnet-SimpleACK-PDU? and/or handle error rtns by defaulting to
    # write_prop_mults on each "obj_v" above, and then to indiv write_props on elems of
    # obj_v.list_of_properties...
    return r
Example #5
0
def write_property_g3(device, prop_tuple, value_tag_list, priority=None):
    object = prop_tuple[0]
    instance = prop_tuple[1]
    property = prop_tuple[2]

    wpr = sequence.WritePropertyRequest()
    wpr.object_identifier = data.BACnetObjectIdentifier(object, instance)
    wpr.property_identifier = property
    if len(prop_tuple) > 3 and prop_tuple[3] != -1:
        wpr.property_array_index = prop_tuple[3]
    wpr.property_value = value_tag_list
    if priority is not None:
        wpr.priority = priority
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 15
    rp.data = tag.encode(wpr.encoding)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    return r
Example #6
0
def write_property_g3(device, prop_tuple, value_tag_list, priority=None):
    object = prop_tuple[0]
    instance = prop_tuple[1]
    property = prop_tuple[2]

    wpr = sequence.WritePropertyRequest()
    wpr.object_identifier = data.BACnetObjectIdentifier(object, instance)
    wpr.property_identifier = property
    if len(prop_tuple) > 3 and prop_tuple[3] != -1:
        wpr.property_array_index = prop_tuple[3]
    wpr.property_value = value_tag_list
    if priority is not None:
        wpr.priority = priority
    rp = APDU()
    rp.pdu_type = BACNET_CONFIRMED_SERVICE_REQUEST_PDU
    rp.choice = 15
    rp.data = tag.encode(wpr.encoding)
    request_id = network.send_request(device, rp)
    r = recv_response(request_id)
    return r