def createApplication(device): global applicationCount, applications try: #Defining Device threadName = 'app_' + str(applicationCount) localDevice = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 localDevice.protocolServicesSupported = pss.value application = Application(localDevice, device.getDeviceAddress()) applications.append(application) applicationThread = BACpypeThread(threadName) applicationThread.start() applicationCount += 1 except Exception, e: print "Error: doStart()" ErrorHandler(e,device)
def setup_device(self, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): _log.info('seg_supported ' + str(seg_supported)) _log.info('max_apdu_len ' + str(max_apdu_len)) _log.info('obj_id ' + str(obj_id)) _log.info('obj_name ' + str(obj_name)) _log.info('ven_id ' + str(ven_id)) this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value self.this_application = BACnet_application(this_device, address) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def doStart(device): global this_application, this_device, applicationThread, has_started has_started = False try: #Defining Device this_device = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 this_device.protocolServicesSupported = pss.value this_application = Application(this_device, device.getDeviceAddress()) #Start BACpypes Thread applicationThread = BACpypeThread('BACPYPE-APP') applicationThread.start() has_started = True return has_started except Exception, e: ErrorHandler(e,device)
def createApplication(device): global applicationCount, applications try: #Defining Device threadName = 'app_' + str(applicationCount) localDevice = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 localDevice.protocolServicesSupported = pss.value application = Application(localDevice, device.getDeviceAddress()) applications.append(application) applicationThread = BACpypeThread(threadName) applicationThread.start() applicationCount += 1 except Exception, e: print "Error: doStart()" ErrorHandler(e, device)
def doStart(device): global this_application, this_device, applicationThread, has_started has_started = False try: # Defining Device this_device = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) pss = ServicesSupported() pss["whoIs"] = 1 pss["iAm"] = 1 pss["readProperty"] = 1 pss["writeProperty"] = 1 this_device.protocolServicesSupported = pss.value this_application = Application(this_device, device.getDeviceAddress()) # Start BACpypes Thread applicationThread = BACpypeThread("BACPYPE-APP") applicationThread.start() has_started = True return has_started except Exception, e: ErrorHandler(e, device)
def get_server_application(self): if _debug: DeviceAbstraction._debug(" - creating application") # make a device object this_device = LocalDeviceObject(objectName="Betelgeuse", objectIdentifier=args.device_id, maxApduLengthAccepted=1024, segmentationSupported="segmentedBoth", vendorIdentifier=15) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['readPropertyMultiple'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a sample application this_application = ReadPropertyMultipleApplication( this_device, args.interface) registers = self.registers[('byte', True)] #Currently we don't actually enforce read only properties. for register in registers: if _debug: DeviceAbstraction._debug( " - creating object of type: %s, %i", register.object_type, register.instance_number) klass = get_object_class(register.object_type) ravo = klass(objectIdentifier=(register.object_type, register.instance_number), objectName=register.point_name) ravo.WriteProperty("presentValue", 0, direct=True) this_application.add_object(ravo) registers = self.registers[('byte', False)] for register in registers: if _debug: DeviceAbstraction._debug( " - creating object of type: %s, %i", register.object_type, register.instance_number) klass = get_object_class(register.object_type) ravo = klass(objectIdentifier=(register.object_type, register.instance_number), objectName=register.point_name) ravo.WriteProperty("presentValue", 0, direct=True) this_application.add_object(ravo) return this_application
def setup_device(self, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): global this_application #We use a singleton device if this_application is not None: return print 'seg_supported', seg_supported print 'max_apdu_len', max_apdu_len print 'obj_id', obj_id print 'obj_name', obj_name print 'ven_id', ven_id #Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError( 'Invalid max_apdu_len: Valid options are 50, 128, 206, 480, 1024, and 1476' ) this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value this_application = BACnet_application(this_device, address) #We must use traditional python threads, otherwise the driver will # hang during startup while trying to scrape actuator values. # I think this is because the reactor hasn't started before we start trying # to use the other threads. #reactor.callInThread(bacpypes.core.run) #reactor.addSystemEventTrigger("before", "shutdown", bacpypes.core.stop) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def get_server_application(self): if _debug: DeviceAbstraction._debug(" - creating application") # make a device object this_device = LocalDeviceObject( objectName="Betelgeuse", objectIdentifier=599, maxApduLengthAccepted=1024, segmentationSupported="segmentedBoth", vendorIdentifier=15 ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['readPropertyMultiple'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a sample application this_application = ReadPropertyMultipleApplication(this_device, args.interface) registers= self.registers[('byte',True)] #Currently we don't actually enforce read only properties. for register in registers: if _debug: DeviceAbstraction._debug(" - creating object of type: %s, %i", register.object_type, register.instance_number) klass = get_object_class(register.object_type) ravo = klass(objectIdentifier=(register.object_type, register.instance_number), objectName=register.point_name) ravo.WriteProperty("presentValue", 0, direct=True) this_application.add_object(ravo) registers= self.registers[('byte',False)] for register in registers: if _debug: DeviceAbstraction._debug(" - creating object of type: %s, %i", register.object_type, register.instance_number) klass = get_object_class(register.object_type) ravo = klass(objectIdentifier=(register.object_type, register.instance_number), objectName=register.point_name) ravo.WriteProperty("presentValue", 0, direct=True) this_application.add_object(ravo) return this_application
def main(): global this_device, this_application, this_console # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) if _debug: _log.debug(" - this_device: %r", this_device) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application this_application = WhoIsIAmApplication( this_device, args.ini.address, Address(args.ini.foreignbbmd), int(args.ini.foreignttl), ) if _debug: _log.debug(" - this_application: %r", this_application) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make a console this_console = WhoIsIAmConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) _log.debug("running") run() _log.debug("finally")
def main(): if _debug: main._debug("initialization") try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: main._debug("initialization") if _debug: main._debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=vendor_id, ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make some objects ravo1 = VendorAVObject( objectIdentifier=(513, 1), objectName='Random1' ) if _debug: main._debug(" - ravo1: %r", ravo1) ravo2 = VendorAVObject( objectIdentifier=(513, 2), objectName='Random2' ) if _debug: main._debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) if _debug: main._debug(" - object list: %r", this_device.objectList) if _debug: main._debug("running") run() except Exception as error: main._exception("an error has occurred: %s", error) finally: if _debug: main._debug("finally")
def setup_device(self, async_call, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): _log.info('seg_supported ' + str(seg_supported)) _log.info('max_apdu_len ' + str(max_apdu_len)) _log.info('obj_id ' + str(obj_id)) _log.info('obj_name ' + str(obj_name)) _log.info('ven_id ' + str(ven_id)) #Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError( 'Invalid max_apdu_len: {} Valid options are 50, 128, 206, 480, 1024, and 1476' .format(max_apdu_len)) this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names. pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value def i_am_callback(address, device_id, max_apdu_len, seg_supported, vendor_id): async_call.send(None, self.i_am, address, device_id, max_apdu_len, seg_supported, vendor_id) #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz') self.this_application = BACnet_application(i_am_callback, this_device, address) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def main(): if _debug: main._debug("initialization") try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: main._debug("initialization") if _debug: main._debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=vendor_id, ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make some objects ravo1 = VendorAVObject(objectIdentifier=(513, 1), objectName='Random1') if _debug: main._debug(" - ravo1: %r", ravo1) ravo2 = VendorAVObject(objectIdentifier=(513, 2), objectName='Random2') if _debug: main._debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) if _debug: main._debug(" - object list: %r", this_device.objectList) if _debug: main._debug("running") run() except Exception as error: main._exception("an error has occurred: %s", error) finally: if _debug: main._debug("finally")
def setup_device(self, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): global this_application #We use a singleton device if this_application is not None: return print 'seg_supported', seg_supported print 'max_apdu_len', max_apdu_len print 'obj_id', obj_id print 'obj_name', obj_name print 'ven_id', ven_id #Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError('Invalid max_apdu_len: Valid options are 50, 128, 206, 480, 1024, and 1476') this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value this_application = BACnet_application(this_device, address) #We must use traditional python threads, otherwise the driver will # hang during startup while trying to scrape actuator values. # I think this is because the reactor hasn't started before we start trying # to use the other threads. #reactor.callInThread(bacpypes.core.run) #reactor.addSystemEventTrigger("before", "shutdown", bacpypes.core.stop) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def broadcast(): try: device_list = list() localaddress = list() ips = getIPs() print "found local ip as ", ips for ip in ips: str(ip) localaddress = ip + "/24" # make a device object this_device = LocalDeviceObject( objectName="BEMOSS", objectIdentifier= 599, #change if there exists a bacnet device with same identifier maxApduLengthAccepted=1024, segmentationSupported="segmentedBoth", vendorIdentifier=99, ) # Device application this_application = Application(this_device, localaddress) request = WhoIsRequest() request.pduDestination = GlobalBroadcast() def time_out(): time.sleep(5) stop() thread = threading.Thread(target=time_out) thread.start() this_application.request(request) this_application.found_address = list() this_application.found_deviceidentifier = list() run() #time.sleep(10) this_application.release = True this_application.update = False address, deviceidentifier = this_application.updator() todelete = list() for i in range(0, len(deviceidentifier)): if deviceidentifier[i] == 0: todelete.append(i) for i in todelete: del address[i], deviceidentifier[ i] #Deleting identified bacnet router Remote_address = list(set(address)) #Removing repeatition Identifier = list(set(deviceidentifier)) #Removing repeatition print "destination address list is ", Remote_address print "object instance of that address", Identifier return this_application, Remote_address, Identifier except Exception, e: _log.exception("an error has occurred: %s", e) return None
def __init__(self, template, template_directory, args): self.server_port = 0 self.dom = etree.parse(template) databus = conpot_core.get_databus() device_info_root = self.dom.xpath('//bacnet/device_info')[0] name_key = databus.get_value( device_info_root.xpath('./device_name/text()')[0]) id_key = device_info_root.xpath('./device_identifier/text()')[0] vendor_name_key = device_info_root.xpath('./vendor_name/text()')[0] vendor_identifier_key = device_info_root.xpath( './vendor_identifier/text()')[0] apdu_length_key = device_info_root.xpath( './max_apdu_length_accepted/text()')[0] segmentation_key = device_info_root.xpath( './segmentation_supported/text()')[0] # self.local_device_address = dom.xpath('./@*[name()="host" or name()="port"]') self.thisDevice = LocalDeviceObject( objectName=name_key, objectIdentifier=int(id_key), maxApduLengthAccepted=int(apdu_length_key), segmentationSupported=segmentation_key, vendorName=vendor_name_key, vendorIdentifier=int(vendor_identifier_key)) self.bacnet_app = None logger.info('Conpot Bacnet initialized using the %s template.', template)
def setup_device(self, async_call, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): _log.info('seg_supported '+str(seg_supported)) _log.info('max_apdu_len '+str(max_apdu_len)) _log.info('obj_id '+str(obj_id)) _log.info('obj_name '+str(obj_name)) _log.info('ven_id '+str(ven_id)) #Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError('Invalid max_apdu_len: {} Valid options are 50, 128, 206, 480, 1024, and 1476'.format(max_apdu_len)) this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names. pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value def i_am_callback(address, device_id, max_apdu_len, seg_supported, vendor_id): async_call.send(None, self.i_am, address, device_id, max_apdu_len, seg_supported, vendor_id) #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz') self.this_application = BACnet_application(i_am_callback, this_device, address) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def setup_device(self, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): _log.info('seg_supported ' + str(seg_supported)) _log.info('max_apdu_len ' + str(max_apdu_len)) _log.info('obj_id ' + str(obj_id)) _log.info('obj_name ' + str(obj_name)) _log.info('ven_id ' + str(ven_id)) # Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError( 'Invalid max_apdu_len: {} Valid options are 50, 128, 206, 480, 1024, and 1476' .format(max_apdu_len)) this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value self.this_application = BACnet_application(this_device, address) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True request = WhoIsRequest() request.pduDestination = GlobalBroadcast() server_thread.start()
def main(): if _debug: main._debug("initialization") global this_application try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: main._debug("initialization") if _debug: main._debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a simple application this_application = ReadPropertyApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make a console this_console = ReadWritePropertyConsoleCmd() main._debug("running") run() except Exception as error: main._exception("an error has occurred: %s", error) finally: main._debug("finally")
def addDevice(device): global this_application #Defining Device localDevice = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) this_application.add_object(localDevice)
def main( ): # USage address, obj_type, obj_inst, prop_id--- 192.168.10.67 8 123 70 value arguments = sys.argv if (len(arguments) is not 6): print "Insufficient arguments please provide exactly 5 arguments with device address as 1st argument , object property as 2nd argument, property instance as 3rd argument and " \ "property name as 4th argument and value to be written as 5th argument" return ips = getIPs() device_address = ips[0] + "/24" # make a device object this_device = LocalDeviceObject( objectName="BEMOSS-PLUS", objectIdentifier=int(599), maxApduLengthAccepted=int(1024), segmentationSupported="segmentedBoth", vendorIdentifier=int(15), ) # make a simple application this_application = SynchronousApplication(this_device, device_address) _log.debug("starting build") address = arguments[1] obj_type = int(arguments[2]) device_id = int(arguments[3]) prop_id = int(arguments[4]) #convert to PropertyIdentifier value = int(arguments[5]) result = get_iam(this_application, device_id, address) target_address = result.pduSource _log.debug('pduSource = ' + repr(result.pduSource)) _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier)) _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted)) _log.debug('segmentationSupported = ' + str(result.segmentationSupported)) _log.debug('vendorID = ' + str(result.vendorID)) device_id = result.iAmDeviceIdentifier[1] Specific_object, Specific_property = getObjectnProperty(obj_type, prop_id) if Specific_object == "" or Specific_property == "": print "Incorrect object type or property instance" return try: Result = write_bacnet(this_application, target_address, Specific_object, device_id, Specific_property, value) print Result return except Exception as e: print "Error during reading-- ", e exit(1) return
def doStart(device): global this_application, this_device, applicationThread, request_addr, has_started has_started = True applicationThread = None try: #Defining Device this_device = LocalDeviceObject( #objectName="Name", objectName=device.getObjectName(), #objectIdentifier=2450, objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), #maxApduLenghtAccepted = int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), #device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), #int(device.getVendorIdentifier()), ) #request_addr = "192.168.92.68" request_addr = device.getRequestAddress() print 'req Add: ' + request_addr pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 this_device.protocolServicesSupported = pss.value this_application = Application(this_device, device.getDeviceAddress()) print "this Addr:" + str(device.getDeviceAddress()) #Start BACpypes Thread applicationThread = BACpypeThread('BACPYPE-APP') applicationThread.start() except Exception, e: has_started = False print 'An error has occured: ' + str(e) + "\n"
def main(): if _debug: main._debug("initialization") global this_application try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: main._debug("initialization") if _debug: main._debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application this_application = ReadPropertyApplication(this_device, args.ini.address) this_console = ReadWritePropertyConsoleCmd() main._debug("running") run() except Exception, e: main._exception("an error has occurred: %s", e)
def doStart(device): global this_application, this_device, applicationThread, request_addr, has_started has_started = True try: #args = ConfigArgumentParser(description=__doc__).parse_args() #Defining Device this_device = LocalDeviceObject( objectName=device.getObjectName(), objectIdentifier=int(device.getObjectIdentifier()), maxApduLengthAccepted=int(device.getMaxApduLengthAccepted()), segmentationSupported=device.getSegmentationSupported(), vendorIdentifier=int(device.getVendorIdentifier()), ) print request_addr = device.getRequestAddress() pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 this_device.protocolServicesSupported = pss.value this_application = Application(this_device, device.getDeviceAddress()) print "this Addr:" + str(device.getDeviceAddress()) #Start BACpypes Thread applicationThread = BACpypeThread('BACPYPE-APP') applicationThread.start() except Exception: has_started = False finally: #print "Finally\n" return has_started
def __init__(self, config): if _debug: BACnetAggregator._debug("__init__ %r", config) # get local address from the config file laddr = config.get('BACpypes', 'address') # make a local device object local_device = \ LocalDeviceObject( objectName=config.get('BACpypes','objectName') , objectIdentifier=config.getint('BACpypes','objectIdentifier') , maxApduLengthAccepted=config.getint('BACpypes','maxApduLengthAccepted') , segmentationSupported=config.get('BACpypes','segmentationSupported') , vendorIdentifier=config.getint('BACpypes','vendorIdentifier') ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits local_device.protocolServicesSupported = pss.value # make a simple application BIPSimpleApplication.__init__(self, local_device, laddr) # create logger self.logger = BACnetDataLogger(self, config) self.loadKey() # keep track of requests to line up responses self._request = None # connect to local repo self.publisher = RepoSocketPublisher(12345) self.interval = 5 # in seconds
def setup_device(self, address, max_apdu_len=1024, seg_supported='segmentedBoth', obj_id=599, obj_name='sMap BACnet driver', ven_id=15): print 'seg_supported', seg_supported print 'max_apdu_len', max_apdu_len print 'obj_id', obj_id print 'obj_name', obj_name print 'ven_id', ven_id #Check to see if they gave a valid apdu length. if encode_max_apdu_response(max_apdu_len) is None: raise ValueError('Invalid max_apdu_len: Valid options are 50, 128, 206, 480, 1024, and 1476') this_device = LocalDeviceObject( objectName=obj_name, objectIdentifier=obj_id, maxApduLengthAccepted=max_apdu_len, segmentationSupported=seg_supported, vendorIdentifier=ven_id, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value self.this_application = BACnet_application(this_device, address) server_thread = threading.Thread(target=bacpypes.core.run) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def setup_device(self, address, port): this_device = LocalDeviceObject( objectName="sMap BACnet driver", objectIdentifier=599, maxApduLengthAccepted=1024, segmentationSupported="segmentedBoth", vendorIdentifier=15, ) # build a bit string that knows about the bit names and leave it empty. We respond to NOTHING. pss = ServicesSupported() # set the property value to be just the bits this_device.protocolServicesSupported = pss.value self.this_application = BACnet_application(this_device, address + ':' + str(port)) server_thread = threading.Thread(target=self.this_application.run_me) # exit the server thread when the main thread terminates server_thread.daemon = True server_thread.start()
def startApp(self): """ This function is used to define the local device, including services supported. Once the application is defined, calls the _startAppThread which will handle the thread creation """ log_debug("App initialization") try: # make a device object self.this_device = LocalDeviceObject( objectName=self.localObjName, objectIdentifier=int(self.Boid), maxApduLengthAccepted=int(self.maxAPDULengthAccepted), segmentationSupported=self.segmentationSupported, vendorIdentifier=int(self.vendorId), vendorName=self.vendorName, modelName=self.modelName, systemStatus=self.systemStatus, description='http://christiantremblay.github.io/BAC0/', firmwareRevision=''.join(sys.version.split('|')[:2]), applicationSoftwareVersion=infos.__version__, protocolVersion=1, protocolRevision=0, ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 pss['readPropertyMultiple'] = 1 # set the property value to be just the bits self.this_device.protocolServicesSupported = pss.value # make a simple application self.this_application = ScriptApplication( self.this_device, self.localIPAddr) log_debug("Starting") self._initialized = True self._startAppThread() log_debug("Running") except Exception as error: log_exception("an error has occurred: %s", error) finally: log_debug("finally")
def __init__(self, *args): ips = getIPs() device_address = ips[0] + "/24" # make a device object this_device = LocalDeviceObject( objectName="BEMOSS-PLUS", objectIdentifier=int(599), maxApduLengthAccepted=int(1024), segmentationSupported="segmentedBoth", vendorIdentifier=int(15), ) # make a simple application SynchronousApplication._debug("__init__ %r", args) BIPSimpleApplication.__init__(self, *args) self.expect_confirmation = True
# # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application
help="Lower and upper limit on device ID in results" ) arg_parser.add_argument("--timeout", type=int, metavar=('SECONDS'), help="Time, in seconds, to wait for responses. Default: %(default)s", default = 5) args = arg_parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application this_application = WhoIsIAmApplication(this_device, args.ini.address) _log.debug("running")
def main(): # parse the command line arguments arg_parser = ConfigArgumentParser(description=__doc__) arg_parser.add_argument("device_id", type=int, help="Device ID of the target device") arg_parser.add_argument( "--address", help= "Address of target device, may be needed to help route initial request to device." ) arg_parser.add_argument("--registry-out-file", type=argparse.FileType('wb'), help="Output registry to CSV file", default=sys.stdout) arg_parser.add_argument("--driver-out-file", type=argparse.FileType('wb'), help="Output driver configuration to JSON file.", default=sys.stdout) arg_parser.add_argument( "--max-range-report", nargs='?', type=float, help= 'Affects how very large numbers are reported in the "Unit Details" column of the output. ' 'Does not affect driver behavior.', default=1.0e+20) args = arg_parser.parse_args() _log.debug("initialization") _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a simple application this_application = SynchronousApplication(this_device, args.ini.address) _log.debug("starting build") result = get_iam(this_application, args.device_id, args.address) # request = WhoIsRequest() # request.pduDestination = target_address # result = this_application.make_request(request, expect_confirmation = False) # if not isinstance(result, IAmRequest): # result.debug_contents() # raise TypeError("Error making WhoIs request, try running again.") # device_type, device_instance = result.iAmDeviceIdentifier # if device_type != 'device': # raise DecodingError("invalid object type") target_address = result.pduSource device_id = result.iAmDeviceIdentifier[1] _log.debug('pduSource = ' + repr(result.pduSource)) _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier)) _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted)) _log.debug('segmentationSupported = ' + str(result.segmentationSupported)) _log.debug('vendorID = ' + str(result.vendorID)) config_file_name = basename(args.registry_out_file.name) config = { "driver_config": { "device_address": str(target_address), "device_id": device_id }, "driver_type": "bacnet", "registry_config": "config://registry_configs/{}".format(config_file_name) } json.dump(config, args.driver_out_file, indent=4) try: device_name = read_prop(this_application, target_address, "device", device_id, "objectName") _log.debug('device_name = ' + str(device_name)) except TypeError: _log.debug('device missing objectName') try: device_description = read_prop(this_application, target_address, "device", device_id, "description") _log.debug('description = ' + str(device_description)) except TypeError: _log.debug('device missing description') config_writer = DictWriter( args.registry_out_file, ('Reference Point Name', 'Volttron Point Name', 'Units', 'Unit Details', 'BACnet Object Type', 'Property', 'Writable', 'Index', 'Write Priority', 'Notes')) config_writer.writeheader() try: objectCount = read_prop(this_application, target_address, "device", device_id, "objectList", index=0) list_property = "objectList" except TypeError: objectCount = read_prop(this_application, target_address, "device", device_id, "structuredObjectList", index=0) list_property = "structuredObjectList" _log.debug('objectCount = ' + str(objectCount)) for object_index in xrange(1, objectCount + 1): _log.debug('object_device_index = ' + repr(object_index)) bac_object = read_prop(this_application, target_address, "device", device_id, list_property, index=object_index) obj_type, index = bac_object try: process_object(this_application, target_address, obj_type, index, args.max_range_report, config_writer) except: _log.debug("Unexpected error processing object: {} {}".format( obj_type, index)) _log.debug(traceback.format_exc())
def main(): # parse the command line arguments arg_parser = ConfigArgumentParser(description=__doc__) arg_parser.add_argument("device_id", type=int, help="Device ID of the target device") arg_parser.add_argument( "--address", help= "Address of target device, may be needed to help route initial request to device." ) arg_parser.add_argument("--out-file", type=argparse.FileType('wb'), help="Optional output file for configuration", default=sys.stdout) arg_parser.add_argument( "--max_range_report", nargs='?', type=float, help= 'Affects how very large numbers are reported in the "Unit Details" column of the output. ' 'Does not affect driver behavior.', default=1.0e+20) args = arg_parser.parse_args() _log.debug("initialization") _log.debug(" - args: %r", args) ips = getIPs() print "found local ip as ", ips device_address = ips[0] + "/24" # make a device object this_device = LocalDeviceObject( objectName="BEMOSS", objectIdentifier=int(599), maxApduLengthAccepted=int(1024), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a simple application this_application = SynchronousApplication(this_device, device_address) _log.debug("starting build") result = get_iam(this_application, args.device_id, args.address) target_address = result.pduSource _log.debug('pduSource = ' + repr(result.pduSource)) _log.debug('iAmDeviceIdentifier = ' + str(result.iAmDeviceIdentifier)) _log.debug('maxAPDULengthAccepted = ' + str(result.maxAPDULengthAccepted)) _log.debug('segmentationSupported = ' + str(result.segmentationSupported)) _log.debug('vendorID = ' + str(result.vendorID)) device_id = result.iAmDeviceIdentifier[1] try: device_name = read_prop(this_application, target_address, "device", device_id, "objectName") _log.debug('device_name = ' + str(device_name)) except TypeError: _log.debug('device missing objectName') try: device_description = read_prop(this_application, target_address, "device", device_id, "description") _log.debug('description = ' + str(device_description)) except TypeError: _log.debug('device missing description') config_writer = DictWriter( args.out_file, ('Reference Point Name', 'Volttron Point Name', 'Units', 'Unit Details', 'BACnet Object Type', 'Property', 'Writable', 'Index', 'Write Priority', 'Notes')) config_writer.writeheader() try: objectCount = read_prop(this_application, target_address, "device", device_id, "objectList", index=0) list_property = "objectList" except TypeError: objectCount = read_prop(this_application, target_address, "device", device_id, "structuredObjectList", index=0) list_property = "structuredObjectList" _log.debug('objectCount = ' + str(objectCount)) for object_index in xrange(1, objectCount + 1): _log.debug('object_device_index = ' + repr(object_index)) bac_object = read_prop(this_application, target_address, "device", device_id, list_property, index=object_index) obj_type, index = bac_object print object_index print print process_object(this_application, target_address, obj_type, index, args.max_range_report, config_writer)
raise RuntimeError, "configuration file not found" # get the address from the config file addr = config.get('BACpypes', 'address') # maybe use a different port if '--port' in sys.argv: i = sys.argv.index('--port') addr += ':' + sys.argv[i + 1] _log.debug(" - addr: %r", addr) # make a device object this_device = LocalDeviceObject( objectName=config.get('BACpypes', 'objectName'), objectIdentifier=config.getint('BACpypes', 'objectIdentifier'), maxApduLengthAccepted=config.getint('BACpypes', 'maxApduLengthAccepted'), segmentationSupported=config.get('BACpypes', 'segmentationSupported'), vendorIdentifier=config.getint('BACpypes', 'vendorIdentifier'), ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application
try: # parse the command line arguments args = ArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # create a VLAN vlan = Network() # create the first device vlan_device_1 = \ LocalDeviceObject( objectName="VLAN Node 1", objectIdentifier=('device', 1), maxApduLengthAccepted=1024, segmentationSupported='noSegmentation', vendorIdentifier=15, ) # create the application stack, add it to the network vlan_app_1 = VLANApplication(vlan_device_1, Address(1)) vlan.add_node(vlan_app_1.vlan_node) # create the second device vlan_device_2 = \ LocalDeviceObject( objectName="VLAN Node 2", objectIdentifier=('device', 2), maxApduLengthAccepted=1024, segmentationSupported='noSegmentation',
# # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=int(args.ini.objectidentifier), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = WhoHasIHaveApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value _log.debug("running")
is_instance = isinstance(pdu, transition_pdu) if _debug: MatchingStateMachine._debug(" - is_instance: %r", is_instance) return is_instance # # main # setUp(sys.argv[1:]) # make a device object test_device = LocalDeviceObject( objectName='test_device', objectIdentifier=100, maxApduLengthAccepted=1024, segmentationSupported='segmentedBoth', vendorIdentifier=15, ) # make a test address test_address = Address(1) # create a client state machine, trapped server, and bind them together test_application = TestApplication(test_device, test_address) print("objects: " + str(test_application.objectIdentifier)) # get the services supported services_supported = test_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported)
# __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() # if _debug: _log.debug("initialization") # if _debug: _log.debug(" - args: %r", args) str_ipAddress = "192.168.92.68" # make a device object this_device = LocalDeviceObject( objectName=str_ipAddress, #args.ini.objectname, objectIdentifier=2450, #int(args.ini.objectidentifier), maxApduLengthAccepted=1024, #int(args.ini.maxapdulengthaccepted), segmentationSupported="segmentedBoth", #args.ini.segmentationsupported, vendorIdentifier=25, #int(args.ini.vendoridentifier), ) # build a bit string that knows about the bit names pss = ServicesSupported() pss['whoIs'] = 1 pss['iAm'] = 1 pss['readProperty'] = 1 pss['writeProperty'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a simple application
MatchingStateMachine._debug(" - is_instance: %r", is_instance) return is_instance # # main # setUp(sys.argv[1:]) # make a device object test_device = LocalDeviceObject( objectName='test_device', objectIdentifier=100, maxApduLengthAccepted=1024, segmentationSupported='segmentedBoth', vendorIdentifier=15, ) # make a test address test_address = Address(1) # create a client state machine, trapped server, and bind them together test_application = TestApplication(test_device, test_address) print("objects: " + str(test_application.objectIdentifier)) # get the services supported services_supported = test_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported)
# # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=('device', int(args.ini.objectidentifier)), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a random input object ravo1 = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Random1', description='normal', ) _log.debug(" - ravo1: %r", ravo1)
# # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=('device', int(args.ini.objectidentifier)), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # get the services supported services_supported = this_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know this_device.protocolServicesSupported = services_supported.value # make a random input object
@bacpypes_debugging def tearDown(): if _debug: tearDown._debug("tearDown") # # main # setUp(sys.argv[1:]) # make a device object test_device = LocalDeviceObject( objectName='test_device', objectIdentifier=100, maxApduLengthAccepted=1024, segmentationSupported='segmentedBoth', vendorIdentifier=15, ) # make a test address test_address = Address(1) # create a client state machine, trapped server, and bind them together test_application = TestApplication(test_device, test_address) # include a application decoder test_asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation
router_node = Node(Address(1)) vlan.add_node(router_node) # bind the router stack to the vlan network through this node router.nsap.bind(router_node, vlan_network) # device identifier is assigned from the address device_instance = vlan_network * 100 + int(args.addr2) _log.debug(" - device_instance: %r", device_instance) # make a vlan device object vlan_device = \ LocalDeviceObject( objectName="VLAN Node %d" % (device_instance,), objectIdentifier=('device', device_instance), maxApduLengthAccepted=1024, segmentationSupported='noSegmentation', vendorIdentifier=15, ) _log.debug(" - vlan_device: %r", vlan_device) # make the application, add it to the network vlan_app = VLANApplication(vlan_device, vlan_address) vlan.add_node(vlan_app.vlan_node) _log.debug(" - vlan_app: %r", vlan_app) # make a random value object ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Device%d/Random1' % (device_instance, ), )
# # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname, objectIdentifier=('device', int(args.ini.objectidentifier)), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a random input object ravo1 = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Random1' ) _log.debug(" - ravo1: %r", ravo1) ravo1d = ravo1._dict_contents() print ravo1d