def main(): global this_device, this_application # 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) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): # parse the command line arguments and initialize loggers 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), vendorName="B612", ) # make a sample application this_application = SampleApplication(this_device, args.ini.address) 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 _log.debug("running") run() _log.debug("fini")
def _init_bacnet(self): # local bacnet device ldo = LocalDeviceObject( objectName=self._config.bacnet.get('objectName'), objectIdentifier=int(self._config.bacnet.get('objectIdentifier')), maxApduLengthAccepted=int(self._config.bacnet.get('maxApduLengthAccepted')), segmentationSupported=self._config.bacnet.get('segmentationSupported'), vendorIdentifier=int(self._config.bacnet.get('vendorIdentifier')),) # Send an empty support string pss = ServicesSupported() ldo.protocolServicesSupported = pss.value # TODO: look to use domain name resolution on address info = self._config.bacnet.get('address') hostname = "" for i, c in enumerate(info): if c is '/' or c is ':': break hostname += c suffix = info[i:] # MRH: The way BACpypes binds to the interface for broadcast is tricky with containers # overload this for now if docker_test(): import fcntl hostname = socket.gethostname() netmask = socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x891b, struct.pack(b'256s', b'eth0'))[20:24]) suffix = "/" + str(sum([bin(int(x)).count('1') for x in netmask.split('.')])) + ":47808" print("host %s" % hostname) addr = socket.gethostbyname(hostname) print("bacnet stack using %s" % (addr + suffix)) self.bacnet_app = BACnet(ldo, addr + suffix)
def Init(pAddress): global this_application, this_ServerAdress this_ServerAdress = pAddress # 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 simple 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
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 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 main(): global this_application, context # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "address", help="address of server", ) parser.add_argument( "objtype", help="object type", ) parser.add_argument( "objinst", type=int, help="object instance", ) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # set the context, the collection of the above parameters context = args.address, args.objtype, args.objinst if _debug: _log.debug(" - context: %r", context) # 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 = 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 console this_console = ReadWritePropertyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global args # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an option to override the sleep time parser.add_argument( '--sleep', type=float, help="sleep before returning the value", default=SLEEP_TIME, ) # parse the command line arguments args = 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=('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 some random input objects for i in range(1, RANDOM_OBJECT_COUNT + 1): ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', i), objectName='Random-%d' % (i, ), ) _log.debug(" - ravo: %r", ravo) this_application.add_object(ravo) # make sure they are all there _log.debug(" - object list: %r", this_device.objectList) _log.debug("running") run() _log.debug("fini")
def main(): global this_application global Dispositivos args = ConfigArgumentParser(description=__doc__).parse_args() 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), ) this_application = SubscribeCOVApplication(this_device, args.ini.address) try: ficheiro = open(this_file_path + "/" + "Config.csv", "r") configs = ficheiro.read() ficheiro.close() numLinhas = 0 for linha in configs.split("\n"): valores = {} argumento = {} objectos = {} try: if numLinhas == 0: numLinhas += 1 pass else: DeviceID, IPort, ProcID, Object, ObjectID, Argument, VarName, DefaultVarValue, writeble = linha.split( ";") valores["valorActual"] = int(DefaultVarValue) valores["NomeVAR"] = VarName valores["ProcID"] = int(ProcID) valores["escrita"] = bool(int(writeble)) argumento[Argument] = valores objectos[Object + "_" + ObjectID] = argumento objectos["IPort"] = IPort if not DeviceID in Dispositivos: Dispositivos[DeviceID] = objectos else: Dispositivos[DeviceID].update(objectos) numLinhas += 1 except: pass #serve para ignorar a ultima linha que nao contem qualquer tipo de informacao util except Exception as e: with open("ErrorLog.txt", "a") as myfile: myfile.write( str(time.strftime("%d-%m-%Y %H:%M:%S")) + " Failed to open configuration file.\n") myfile.write("Error -> " + str(e) + "\n") services_supported = this_application.get_services_supported() this_device.protocolServicesSupported = services_supported.value enable_sleeping() subscribe_thread = SubscricaoDados() SMmonitor_thread = ComunicacaoSM() deferred(SMmonitor_thread.start) deferred(subscribe_thread.start) run()
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_length_accepted(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) kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None} server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def main(): # 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) # add the additional service this_application.add_capability(ReadWritePropertyMultipleServices) # 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 accumulator = AccumulatorObject( objectIdentifier=('accumulator', 1), objectName='Something1', presentValue=100, statusFlags = [0, 0, 0, 0], eventState='normal', scale=Scale(floatScale=2.3), units='btusPerPoundDryAir', ) if _debug: _log.debug(" - accumulator: %r", accumulator) # add it to the device this_application.add_object(accumulator) if _debug: _log.debug(" - object list: %r", this_device.objectList) # create a task that bumps the value by one every 10 seconds pulse_task = PulseTask(accumulator, 1, 10 * 1000) if _debug: _log.debug(" - pulse_task: %r", pulse_task) _log.debug("running") run() _log.debug("fini")
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_length_accepted(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) kwargs = {"spin":0.1, "sigterm": None, "sigusr1": None} server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def main(): global this_application # 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 simple 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 thread_list = [] # loop through the address and point lists for addr, points in point_list: # create a thread read_thread = ReadPointListThread(addr, points) if _debug: _log.debug(" - read_thread: %r", read_thread) thread_list.append(read_thread) # create a thread supervisor thread_supervisor = ThreadSupervisor(thread_list) # start it running when the core is running deferred(thread_supervisor.start) _log.debug("running") run() # dump out the results for read_thread in thread_list: for request, response in zip(read_thread.point_list, read_thread.response_values): print(request, response) _log.debug("fini")
def main(): # 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) # add the additional service this_application.add_capability(ReadWritePropertyMultipleServices) # 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 accumulator = AccumulatorObject( objectIdentifier=('accumulator', 1), objectName='Something1', presentValue=100, statusFlags=[0, 0, 0, 0], eventState='normal', scale=Scale(floatScale=2.3), units='btusPerPoundDryAir', ) if _debug: _log.debug(" - accumulator: %r", accumulator) # add it to the device this_application.add_object(accumulator) if _debug: _log.debug(" - object list: %r", this_device.objectList) # create a task that bumps the value by one every 10 seconds pulse_task = PulseTask(accumulator, 1, 10 * 1000) if _debug: _log.debug(" - pulse_task: %r", pulse_task) _log.debug("running") run() _log.debug("fini")
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 main(): # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # 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 = ReadPropertyMultipleApplication(this_device, args.ini.address) # make a random input object ravo1 = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Random1' ) _log.debug(" - ravo1: %r", ravo1) ravo2 = RandomAnalogValueObject( objectIdentifier=('analogValue', 2), objectName='Random2' ) _log.debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) _log.debug(" - object list: %r", this_device.objectList) # 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") run() _log.debug("fini")
def main(): # 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), _dcc_password="******", ) # make a sample application this_application = ReadPropertyMultipleApplication(this_device, args.ini.address) # make a random input object ravo1 = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Random1', eventMessageTexts=ArrayOf(CharacterString)(["hello"]), ) _log.debug(" - ravo1: %r", ravo1) ravo2 = RandomAnalogValueObject(objectIdentifier=('analogValue', 2), objectName='Random2') _log.debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) _log.debug(" - object list: %r", this_device.objectList) # 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") run() _log.debug("fini")
def main(): # 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 = BIPSimpleApplication(this_device, args.ini.address) # add the capability to server file content this_application.add_capability(FileServices) # 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 record access file, add to the device f1 = TestRecordFile( objectIdentifier=('file', 1), objectName='RecordAccessFile1' ) _log.debug(" - f1: %r", f1) this_application.add_object(f1) # make a stream access file, add to the device f2 = TestStreamFile( objectIdentifier=('file', 2), objectName='StreamAccessFile2' ) _log.debug(" - f2: %r", f2) this_application.add_object(f2) _log.debug("running") run() _log.debug("fini")
def main(): global vendor_id # 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=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: _log.debug(" - ravo1: %r", ravo1) ravo2 = VendorAVObject( objectIdentifier=(513, 2), objectName='Random2' ) if _debug: _log.debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) if _debug: _log.debug(" - object list: %r", this_device.objectList) if _debug: _log.debug("running") run() if _debug: _log.debug("fini")
def main(): global this_application # 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 simple application #this_application = BIPSimpleApplication(this_device, args.ini.address) this_application = BIPForeignApplication( 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 = WriteSomethingConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): # 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 = BIPSimpleApplication(this_device, args.ini.address) # add the capability to server file content this_application.add_capability(FileServices) # 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 record access file, add to the device f1 = TestRecordFile(objectIdentifier=('file', 1), objectName='RecordAccessFile1') _log.debug(" - f1: %r", f1) this_application.add_object(f1) # make a stream access file, add to the device f2 = TestStreamFile(objectIdentifier=('file', 2), objectName='StreamAccessFile2') _log.debug(" - f2: %r", f2) this_application.add_object(f2) _log.debug("running") run() _log.debug("fini")
def main(): # 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 = 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 multistate value object msvo = MultiStateValueObject( objectIdentifier=('multiStateValue', 1), objectName='My Special Object', presentValue=1, numberOfStates=3, stateText=ArrayOf(CharacterString)(['red', 'green', 'blue']), ) _log.debug(" - msvo: %r", msvo) # add it to the device this_application.add_object(msvo) _log.debug(" - object list: %r", this_device.objectList) _log.debug("running") run() _log.debug("fini")
def main(): global vendor_id # 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=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: _log.debug(" - ravo1: %r", ravo1) ravo2 = VendorAVObject(objectIdentifier=(513, 2), objectName='Random2') if _debug: _log.debug(" - ravo2: %r", ravo2) # add it to the device this_application.add_object(ravo1) this_application.add_object(ravo2) if _debug: _log.debug(" - object list: %r", this_device.objectList) if _debug: _log.debug("running") run() if _debug: _log.debug("fini")
def main(): global this_application # check the version if (sys.version_info[:2] != (2, 5)): sys.stderr.write("Python 2.5 only\n") sys.exit(1) # 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 simple 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 console this_console = ReadPropertyConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # 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 simple 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 # create a thread and read_thread = ReadPointListThread(point_list) if _debug: _log.debug(" - read_thread: %r", read_thread) # start it running when the core is running deferred(read_thread.start) _log.debug("running") run() # dump out the results for request, response in zip(point_list, read_thread.response_values): print(request, response) _log.debug("fini")
def main(): # 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 = WhoIsIAmApplication(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") run() _log.debug("fini") print("----- Who Is -----") for (src, lowlim, hilim), count in sorted(who_is_counter.items()): print("%-20s %8s %8s %4d" % (src, lowlim, hilim, count)) print("") print("----- I Am -----") for (src, devid), count in sorted(i_am_counter.items()): print("%-20s %8d %4d" % (src, devid, count)) print("")
def main(): # 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 some random input objects for i in range(1, RANDOM_OBJECT_COUNT+1): ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', i), objectName='Random-%d' % (i,), ) _log.debug(" - ravo: %r", ravo) this_application.add_object(ravo) # make sure they are all there _log.debug(" - object list: %r", this_device.objectList) _log.debug("running") run() _log.debug("fini")
def main(): # 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") # run until stopped, ^C works run() _log.debug("fini") print("----- Who Has -----") for (src, objname), count in sorted(who_has_counter.items()): print("%-20s %-30s %4d" % (src, objname, count)) print("") print("----- I Have -----") for (src, devid, objid, objname), count in sorted(i_have_counter.items()): print("%-20s %-20s %-20s %-20s %4d" % (src, devid, objid, objname, count)) print("")
def main(): # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # add an argument for interval parser.add_argument( 'interval', type=int, help='repeat rate in seconds', ) # now parse the arguments args = 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), ) # make a dog this_application = PrairieDog(args.interval, this_device, args.ini.address) 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 _log.debug("running") run() _log.debug("fini")
def main(): global this_application # 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 simple application this_application = ReadPointListApplication(point_list, 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 # fire off a request when the core has a chance deferred(this_application.next_request) _log.debug("running") run() # dump out the results for request, response in zip(point_list, this_application.response_values): print(request, response) _log.debug("fini")
def main(): global this_application # 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 simple application this_application = SubscribeCOVApplication(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 = SubscribeCOVConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def main(): global this_application # make a device object this_device = LocalDeviceObject( objectName='Energy Box', objectIdentifier=599, maxApduLengthAccepted=1024, segmentationSupported='segmentedBoth', vendorIdentifier=15, ) points = [] for i in range(10): points.append( ('analogInput', i, ['presentValue', 'objectName', 'units'])) this_application = ReadPointListApplication(points, this_device, '10.81.0.14') # 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 # fire off a request when the core has a chance deferred(this_application.do_request) _log.debug("running") # enable_sleeping() run() # dump out the results pprint.pprint(this_application.response_values) _log.debug("fini")
def main(): # parse the command line arguments # parser = ArgumentParser( # description=__doc__, # formatter_class=argparse.RawDescriptionHelpFormatter, # ) # # # add an argument for interval # parser.add_argument('addr1', type=str, # help='address of first network', # ) # # # add an argument for interval # parser.add_argument('net1', type=int, # help='network number of first network', # ) # # # add an argument for interval # parser.add_argument('addr2', type=str, # help='address of second network', # ) # # # add an argument for interval # parser.add_argument('net2', type=int, # help='network number of second network', # ) # # # now parse the arguments # args = parser.parse_args() # # if _debug: _log.debug("initialization") # if _debug: _log.debug(" - args: %r", args) # local_address = Address(args.addr1) # local_network = args.net1 # vlan_address = Address(args.addr2) # vlan_network = args.net2 local_address = Address('130.91.139.93') local_network = 0 vlan_address = Address(5) vlan_network = 9997 # create the VLAN router, bind it to the local network router = VLANRouter(local_address, local_network) # create a VLAN vlan = Network() # create a node for the router, address 1 on the VLAN 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) device_instance = vlan_network * 100 + 5 # vlan_address device_instance2 = vlan_network * 100 + 6 _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, # ) #ADDED vlan_device = \ LocalDeviceObject( objectName='laptopBehindNetwork', objectIdentifier=device_instance, maxApduLengthAccepted=1024, segmentationSupported='noSegmentation', vendorIdentifier=15, ) vlan_device2 = \ LocalDeviceObject( objectName='laptopBehindNetwork2', objectIdentifier=device_instance2, maxApduLengthAccepted=1024, segmentationSupported='noSegmentation', vendorIdentifier=15, ) #ADDED _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) vlan_app2 = VLANApplication(vlan_device2, Address(6)) vlan.add_node(vlan_app2.vlan_node) _log.debug(" - vlan_app: %r", vlan_app) #ADDED services_supported = vlan_app.get_services_supported() # let the device object know vlan_device.protocolServicesSupported = services_supported.value services_supported = vlan_app2.get_services_supported() # let the device object know vlan_device2.protocolServicesSupported = services_supported.value #ADDED # make a random value object # ravo = RandomAnalogValueObject( # objectIdentifier=('analogValue', 1), # objectName='Device%d/Random1' % (device_instance,), # ) ravo = ModbusAnalogInputObject( objectIdentifier=('analogInput', 1), objectName='Device%d/Modbus1' % (device_instance, ), ) _log.debug(" - ravo1: %r", ravo) # add it to the device vlan_app.add_object(ravo) # make a random value object ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Device%d/Random1' % (device_instance2, ), ) # add it to the device vlan_app2.add_object(ravo) _log.debug("running") print('run') run() _log.debug("fini")
def main(): global test_application # make a parser parser = ConfigArgumentParser(description=__doc__) parser.add_argument("--console", action="store_true", default=False, help="create a console", ) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object test_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 test_application = SubscribeCOVApplication(test_device, args.ini.address) # make a binary value object test_bv = BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='bv', presentValue='inactive', statusFlags=[0, 0, 0, 0], ) _log.debug(" - test_bv: %r", test_bv) # add it to the device test_application.add_object(test_bv) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=1.0, ) _log.debug(" - test_av: %r", test_av) # add it to the device test_application.add_object(test_av) _log.debug(" - object list: %r", test_device.objectList) # get the services supported services_supported = test_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know test_device.protocolServicesSupported = services_supported.value # make a console if args.console: test_console = COVConsoleCmd() _log.debug(" - test_console: %r", test_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
# 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") request = WhoIsRequest() if args.address is not None: request.pduDestination = Address(args.address) else: request.pduDestination = GlobalBroadcast() if args.range is not None: request.deviceInstanceRangeLowLimit = int(args.range[0]) request.deviceInstanceRangeHighLimit = int(args.range[1])
def main(): global this_application, device_address, object_identifier, property_list # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "address", help="device address", ) parser.add_argument( "objtype", help="object types, e.g., analogInput", ) parser.add_argument( "objinstance", type=int, help="object instance", ) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # interpret the address device_address = Address(args.address) if _debug: _log.debug(" - device_address: %r", device_address) # build an identifier object_identifier = (args.objtype, args.objinstance) if _debug: _log.debug(" - object_identifier: %r", object_identifier) # get the object class object_class = get_object_class(args.objtype) if _debug: _log.debug(" - object_class: %r", object_class) # make a queue of the properties property_list = deque(prop.identifier for prop in object_class.properties) if _debug: _log.debug(" - property_list: %r", property_list) # 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 # fire off a request when the core has a chance deferred(this_application.next_request) _log.debug("running") run() _log.debug("fini")
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, request_check_interval=100): _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_length_accepted(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) def send_cov_subscription_callback(device_address, subscriber_process_identifier, monitored_object_identifier, lifetime, point_name): """ Asynchronous cov subscription callback for gevent """ async_call.send(None, self.send_cov_subscription, device_address, subscriber_process_identifier, monitored_object_identifier, lifetime, point_name) def forward_cov_callback(point_name, apdu, result_dict): """ Asynchronous callback to forward cov values to the platform driver for gevent """ async_call.send(None, self.forward_cov, point_name, apdu, result_dict) self.bacnet_application = BACnetApplication( i_am_callback, send_cov_subscription_callback, forward_cov_callback, request_check_interval, this_device, address) # Having a recurring task makes the spin value kind of irrelevant. kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None} server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
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 = 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 # local host, special port HOST, PORT = "", int(args.port) server = ThreadedTCPServer((HOST, PORT), ThreadedHTTPRequestHandler) if _debug: _log.debug(" - server: %r", server) # Start a thread with the server -- that thread will then start a thread for each request server_thread = threading.Thread(target=server.serve_forever) if _debug: _log.debug(" - server_thread: %r", server_thread) # exit the server thread when the main thread terminates server_thread.daemon = True server_thread.start() if _debug: _log.debug("running")
def main(): device_info = { 'ip': '10.169.204.200', 'netmask': 23, 'port': 47809, 'objectName': 'FHL-DAF-DUSTMETER', 'objectIdentifier': 522020, 'vendorIdentifier': 15, 'location': 'FHL-DAF-CLEAN-ROOM', 'vendorName': 'DESY-ATLAS', 'modelName': 'DUST-METERS', 'softwareVersion': 'bacpypes_v0.16.2_py27', 'description': 'FHL-DAF clean room dustmeter server' } print device_info this_device = LocalDeviceObject( objectName=device_info['objectName'], objectIdentifier=device_info['objectIdentifier'], vendorIdentifier=device_info['vendorIdentifier']) this_device._values['location'] = CharacterString(device_info['location']) this_device._values['vendorName'] = CharacterString( device_info['vendorName']) this_device._values['modelName'] = CharacterString( device_info['modelName']) this_device._values['applicationSoftwareVersion'] = CharacterString( device_info['softwareVersion']) this_device._values['description'] = CharacterString( device_info['description']) this_addr = str(device_info['ip'] + '/' + str(device_info['netmask']) + ':' + str(device_info['port'])) print 'bacnet server will listen at', this_addr this_application = BIPSimpleApplication(this_device, this_addr) this_application.add_capability(ReadWritePropertyMultipleServices) this_device.protocolServicesSupported = this_application.get_services_supported( ).value meter_info = [ { 'name': 'dustmeter_a19', 'index': 1, 'host': 'fhlrs232_a19.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a27', 'index': 2, 'host': 'fhlrs232_a27.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a40', 'index': 3, 'host': 'fhlrs232_a40.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a43', 'index': 4, 'host': 'fhlrs232_a43.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a49', 'index': 5, 'host': 'fhlrs232_a49.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, { 'name': 'dustmeter_a56', 'index': 6, 'host': 'fhlrs232_a56.desy.de', 'description': 'dustmeter on RS232-Ethernet bridge at somewhere', }, ] meters = [] for info in meter_info: m = dustmeter.DustMeter(name=info['name'], host=info['host']) m.start() meters.append(m) objs = [] for info in meter_info: ai_obj = AnalogInputObject(objectIdentifier=('analogInput', info['index']), \ objectName=info['name']) ai_obj._values['description'] = CharacterString(info['description']) ai_obj._values['deviceType'] = CharacterString( 'Particles(>0.5um) PerCubicFoot') ai_obj._values['units'] = EngineeringUnits('noUnits') ai_obj._values['updateInterval'] = Unsigned(60) ai_obj._values['resolution'] = Real(100) this_application.add_object(ai_obj) objs.append(ai_obj) mythread = dataThread(meters, objs) mythread.start() run() mythread.stop() mythread.join() for m in meters: m.stop() m.join() print "end of join"
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, request_check_interval=100): _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_length_accepted(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) def send_cov_subscription_callback(device_address, subscriberProcessIdentifier, monitoredObjectIdentifier, lifetime, point_name): """Asynchronus cov subscription callback for gevent""" async_call.send(None, self.send_cov_subscription, device_address, subscriberProcessIdentifier, monitoredObjectIdentifier, lifetime, point_name) def forward_cov_callback(point_name, apdu, result_dict): """Asynchronus callback to forward cov values to the master driver for gevent""" async_call.send(None, self.forward_cov, point_name, apdu, result_dict) #i_am_callback('foo', 'bar', 'baz', 'foobar', 'foobaz') self.this_application = BACnet_application(i_am_callback, send_cov_subscription_callback, forward_cov_callback, request_check_interval, this_device, address) # Having a recurring task makes the spin value kind of irrelevant. kwargs = {"spin": 0.1, "sigterm": None, "sigusr1": None} server_thread = threading.Thread(target=bacpypes.core.run, kwargs=kwargs) # exit the BACnet App thread when the main thread terminates server_thread.daemon = True server_thread.start()
def main(): global test_application # make a parser parser = ConfigArgumentParser(description=__doc__) parser.add_argument( "--console", action="store_true", default=False, help="create a console", ) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object test_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 test_application = SubscribeCOVApplication(test_device, args.ini.address) # make a binary value object test_bv = BinaryValueObject( objectIdentifier=('binaryValue', 1), objectName='bv', presentValue='inactive', statusFlags=[0, 0, 0, 0], ) _log.debug(" - test_bv: %r", test_bv) # add it to the device test_application.add_object(test_bv) # make an analog value object test_av = AnalogValueObject( objectIdentifier=('analogValue', 1), objectName='av', presentValue=0.0, statusFlags=[0, 0, 0, 0], covIncrement=1.0, ) _log.debug(" - test_av: %r", test_av) # add it to the device test_application.add_object(test_av) _log.debug(" - object list: %r", test_device.objectList) # get the services supported services_supported = test_application.get_services_supported() if _debug: _log.debug(" - services_supported: %r", services_supported) # let the device object know test_device.protocolServicesSupported = services_supported.value # make a console if args.console: test_console = COVConsoleCmd() _log.debug(" - test_console: %r", test_console) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")