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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # 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(): # 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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a multistate value object msvo = MultiStateValueObject( objectIdentifier=('multiStateValue', 1), objectName='My Special Object', presentValue=1, numberOfStates=3, stateText=['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 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(): # 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 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 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 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(): 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 main(): # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") _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 some objects savo = SampleAnalogValueObject( objectIdentifier=("analogValue", 1), objectName="SampleAnalogValueObject", presentValue=123.4, ) _log.debug(" - savo: %r", savo) this_application.add_object(savo) # make some objects sbvo = SampleBinaryValueObject( objectIdentifier=("binaryValue", 1), objectName="SampleBinaryValueObject", presentValue=True, ) _log.debug(" - sbvo: %r", sbvo) this_application.add_object(sbvo) # 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 = BIPSimpleApplication(this_device, args.ini.address) # make the buttons for id in DI_devs: dev = VBIdev(id) bio = DIBinaryInput( dev, objectIdentifier=(DIBinaryInput.objectType, id), objectName=dev.file, ) _log.debug(" - bio: %r", bio) this_application.add_object(bio) # make the LEDs for id in DO_devs: dev = VBOdev(id) boo = DOBinaryOutput( dev, objectIdentifier=(DOBinaryOutput.objectType, id), objectName=dev.file, ) _log.debug(" - boo: %r", boo) this_application.add_object(boo) _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=("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 the buttons for button_id, bio_id in button_list: bio = RPiBinaryInput( button_id, objectIdentifier=("binaryInput", bio_id), objectName="Button-%d" % (button_id, ), ) _log.debug(" - bio: %r", bio) this_application.add_object(bio) # make the LEDs for led_id, boo_id in led_list: boo = RPiBinaryOutput( led_id, objectIdentifier=("binaryOutput", boo_id), objectName="LED-%d" % (led_id, ), ) _log.debug(" - boo: %r", boo) this_application.add_object(boo) _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(): # 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) # make a commandable analog value object, add to the device cavo1 = CommandableAnalogValueObject(objectIdentifier=("analogValue", 1), objectName="Commandable1") if _debug: _log.debug(" - cavo1: %r", cavo1) this_application.add_object(cavo1) # get the current date today = Date().now() # make a commandable date value object, add to the device cdvo2 = CommandableDateValueObject( objectIdentifier=("dateValue", 1), objectName="Commandable2", presentValue=today.value ) if _debug: _log.debug(" - cdvo2: %r", cdvo2) this_application.add_object(cdvo2) if _debug: _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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # this_application # make a commandable binary output object, add to the device boo1 = BinaryOutputFeedbackObject( objectIdentifier=("binaryOutput", 1), objectName="boo1", presentValue="inactive", eventState="normal", statusFlags=StatusFlags(), feedbackValue="inactive", relinquishDefault="inactive", minimumOnTime=5, # let it warm up minimumOffTime=10, # let it cool off outOfService="inactive", ) if _debug: _log.debug(" - boo1: %r", boo1) this_application.add_object(boo1) if _debug: _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=('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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # add the additional service this_application.add_capability(ReadWritePropertyMultipleServices) # 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 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) # make a commandable analog value object, add to the device cavo1 = CommandableAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Commandable1', ) if _debug: _log.debug(" - cavo1: %r", cavo1) this_application.add_object(cavo1) # get the current date today = Date().now() # make a commandable date value object, add to the device cdvo2 = CommandableDateValueObject( objectIdentifier=('dateValue', 1), objectName='Commandable2', presentValue=today.value, ) if _debug: _log.debug(" - cdvo2: %r", cdvo2) this_application.add_object(cdvo2) if _debug: _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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # add the capability to server file content this_application.add_capability(FileServices) # 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=('device', int(args.ini.objectidentifier)), maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), vendorName="testVendor" ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make some random input objects for i in range(1, RANDOM_OBJECT_COUNT+1): ravo = RandomAnalogValueObject( objectIdentifier=('analogValue', i), objectName='Random-%d' % (i,), units=64 ) _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 = BIPSimpleApplication(this_device, args.ini.address) # make a commandable analog value object, add to the device avo1 = LocalAnalogValueObjectCmd( objectIdentifier=('analogValue', 1), objectName='avo1', ) if _debug: _log.debug(" - avo1: %r", avo1) this_application.add_object(avo1) # make a commandable binary output object, add to the device boo1 = LocalBinaryOutputObjectCmd( objectIdentifier=('binaryOutput', 1), objectName='boo1', presentValue='inactive', relinquishDefault='inactive', minimumOnTime=5, # let it warm up minimumOffTime=10, # let it cool off ) if _debug: _log.debug(" - boo1: %r", boo1) this_application.add_object(boo1) # get the current date today = Date().now() # make a commandable date value object, add to the device dvo1 = LocalDateValueObjectCmd( objectIdentifier=('dateValue', 1), objectName='dvo1', presentValue=today.value, ) if _debug: _log.debug(" - dvo1: %r", dvo1) this_application.add_object(dvo1) if _debug: _log.debug("running") run() _log.debug("fini")
def main(): global args parser = ConfigArgumentParser(description=__doc__) args = parser.parse_args() this_device = LocalDeviceObject(ini=args.ini) this_application = BIPSimpleApplication(this_device, args.ini.address) global realValue global booleanValue booleanValue = False realValue = int(input("Inserire un numero ")) analog = MyAnalogValueObject(objectIdentifier=('analogValue', 123), objectName='hea') averaging = MyAveragingObject(objectIdentifier=('averaging', 70), objectName='averagingTest') this_application.add_object(analog) this_application.add_object(averaging) run()
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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a commandable analog value object, add to the device avo1 = AnalogValueCmdObject(objectIdentifier=("analogValue", 1), objectName="avo1") if _debug: _log.debug(" - avo1: %r", avo1) this_application.add_object(avo1) # make a commandable binary output object, add to the device boo1 = BinaryOutputCmdObject( objectIdentifier=("binaryOutput", 1), objectName="boo1", presentValue="inactive", relinquishDefault="inactive", minimumOnTime=5, # let it warm up minimumOffTime=10, # let it cool off ) if _debug: _log.debug(" - boo1: %r", boo1) this_application.add_object(boo1) # get the current date today = Date().now() # make a commandable date value object, add to the device dvo1 = DateValueCmdObject(objectIdentifier=("dateValue", 1), objectName="dvo1", presentValue=today.value) if _debug: _log.debug(" - dvo1: %r", dvo1) this_application.add_object(dvo1) if _debug: _log.debug("running") run() _log.debug("fini")
def main(): if not path.exists("server.cfg"): logger.error("Error: File server.cfg not found.") exit(1) cparser = configparser.ConfigParser() cparser.read("server.cfg") if not "server" in cparser: logger.error("Invalid config: No server section") exit(1) required_keys = { "ip", "port", "objectname", "vendoridentifier", "location", "vendorname", "modelname", "description" } missing_keys = required_keys - set(cparser["server"].keys()) if len(missing_keys) != 0: logger.error("Missing config keys in server section: " + (" ".join(missing_keys))) exit(1) device_info = { 'ip': cparser["server"]["ip"], 'netmask': 23, 'port': cparser["server"]["port"], 'objectName': cparser["server"]["objectName"], 'objectIdentifier': 522020, 'vendorIdentifier': int(cparser["server"]["vendorIdentifier"]), 'location': cparser["server"]["location"], 'vendorName': cparser["server"]["vendorName"], 'modelName': cparser["server"]["modelName"], 'softwareVersion': "bacpypes_{}_python{}.{}.{}".format(bacpypes_version, version_info[0], version_info[1], version_info[2]), 'description': cparser["server"]["description"] } logger.info("=== INIT ===") logger.info(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'])) logger.info("bacnet server will listen at {}".format(this_addr)) this_application = BIPSimpleApplication(this_device, this_addr) this_application.add_capability(ReadWritePropertyMultipleServices) this_device.protocolServicesSupported = this_application.get_services_supported( ).value meters_active = [] ai_objs = [] idx = 1 logger.info("Initializing meters...") for key, metermodule in METERS.items(): if not key in cparser["server"]: logger.warning( "No key '{}' in config server section. Skipping".format(key)) continue metersections = cparser["server"][key].split() missing_metersections = set(metersections) - set(cparser.keys()) if len(missing_metersections) != 0: logger.error("Missing config sections for meters: " + "".join(missing_metersections)) exit(1) for metersection in metersections: info = cparser[metersection] ms = metermodule.getMeters(info) logger.info("Got {} meter(s) from {}".format( len(ms), metersection)) meters_active.extend(ms) for m in ms: m.name = "{}_{}".format(metersection, m.name) ai_obj = AnalogInputObject(objectIdentifier=("analogInput", idx), objectName=m.name) if "description" in info: ai_obj._values["description"] = CharacterString( info["description"]) if "deviceType" in info: ai_obj._values["deviceType"] = CharacterString( info["deviceType"]) ai_obj._values["units"] = EngineeringUnits("noUnits") if "updateInterval" in info: try: updateInterval = int(info["updateInterval"]) if updateInterval < 0: raise ValueError("Invalid negative value :" + info["updateInterval"]) except ValueError as e: logger.error( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["updateInterval"] = Unsigned(updateInterval) if "resolution" in info: try: resolution = float(info["resolution"]) except ValueError as e: logger.error( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["resolution"] = Real(resolution) this_application.add_object(ai_obj) ai_objs.append(ai_obj) idx += 1 fname = m.name output_csv = os.path.join(str('/var/www/html'), fname + u".csv") mode = 'a' if sys.version_info.major < 3: mode += 'b' with open(output_csv, mode) as f: header = OrderedDict([('# time', None), (m.name, None)]) writer = csv.DictWriter(f, fieldnames=header, extrasaction=u"ignore") writer.writeheader() f.close() for m in meters_active: m.start() datathread = DataThread(meters_active, ai_objs) datathread.start() bacpypesrun() datathread.stop() datathread.join() for m in meters_active: m.stop() m.join()
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) # add it to the device this_application.add_object(ravo1) _log.debug(" - object list: %r", this_device.objectList) print this_device._dict_contents() def sense_value(): ravo1d = ravo1._dict_contents().popitem() b = ravo1d[1] return b #a,b=ravo1d.split(",") run() while True: time.sleep(10) value = sense_value()
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 record access file, add to the device f1 = LocalRecordAccessFileObject( 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 = LocalStreamAccessFileObject( objectIdentifier=('file', 2), objectName='StreamAccessFile2' ) _log.debug(" - f2: %r", f2) this_application.add_object(f2) _log.debug("running") run() except Exception as error: _log.exception("an error has occurred: %s", error)
this_device.protocolServicesSupported = services_supported.value # make a random input object ravo1 = RandomAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Random1' ) _log.debug(" - ravo1: %r", ravo1) ravo1d = ravo1._dict_contents() print ravo1d 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) print this_device._dict_contents() run() except Exception, e: _log.exception("an error has occurred: %s", e) finally: _log.debug("finally")
pss['atomicReadFile'] = 1 pss['atomicWriteFile'] = 1 # set the property value to be just the bits this_device.protocolServicesSupported = pss.value # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a record access file, add to the device f1 = LocalRecordAccessFileObject( 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 = LocalStreamAccessFileObject( objectIdentifier=('file', 2), objectName='StreamAccessFile2' ) _log.debug(" - f2: %r", f2) this_application.add_object(f2) _log.debug("running") run() except Exception, e: _log.exception("an error has occurred: %s", e)
except ValueError as e: print( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["updateInterval"] = Unsigned(updateInterval) if "resolution" in info: try: resolution = float(info["resolution"]) except ValueError as e: print( "Value of updateInterval in section {}: {}".format( metersection, e)) exit(1) ai_obj._values["resolution"] = Real(resolution) this_application.add_object(ai_obj) ai_objs.append(ai_obj) idx += 1 for m in meters_active: m.start() datathread = DataThread(meters_active, ai_objs) datathread.start() bacpypesrun() datathread.stop() datathread.join()
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) # make a commandable analog value object, add to the device cavo1 = CommandableAnalogValueObject(objectIdentifier=('analogValue', 1), objectName='Commandable AV 1') if _debug: _log.debug(" - cavo1: %r", cavo1) this_application.add_object(cavo1) # make a commandable binary value object, add to the device cdvo2 = CommandableDateValueObject(objectIdentifier=('dateValue', 1), objectName='Commandable2') if _debug: _log.debug(" - cdvo2: %r", cdvo2) this_application.add_object(cdvo2) if _debug: _log.debug("running") run() except Exception as error: _log.exception("an error has occurred: %s", error) finally: if _debug: _log.debug("finally")
# 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=['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() except Exception, e: _log.exception("an error has occurred: %s", e) finally: _log.debug("finally")
] * 7), scheduleDefault=Integer(0), ) _log.debug(" - so1: %r", so1) so2 = ScheduleObject( objectIdentifier=2, objectName='Schedule 2 (real)', presentValue=Real(73.5), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(9, 0, 0, 0), value=Real(78.0)), TimeValue(time=(10, 0, 0, 0), value=Null()), ]), ] * 7), scheduleDefault=Real(72.0), ) _log.debug(" - so2: %r", so2) # add it to the device this_application.add_object(so1) this_application.add_object(so2) _log.debug(" - object list: %r", this_device.objectList) run() except Exception, e: _log.exception("an error has occurred: %s", e) finally: _log.debug("finally")
def main(): global args, test_analog_value, test_schedule # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # 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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # create a writeable analog value object test_analog_value = WritableAnalogValueObject( objectIdentifier=("analogValue", 1), objectName="Test Analog Value", presentValue=0.0, ) _log.debug(" - test_analog_value: %r", test_analog_value) this_application.add_object(test_analog_value) # print when the value changes test_analog_value._property_monitors["presentValue"].append( analog_value_changed) # # Simple daily schedule (actually a weekly schedule with every day # being identical. # test_schedule = LocalScheduleObject( objectIdentifier=("schedule", 1), objectName="Test Schedule", presentValue=Real(8.0), effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2)), weeklySchedule=ArrayOf(DailySchedule, 7)([ DailySchedule(daySchedule=[ TimeValue(time=(8, 0, 0, 0), value=Real(8.0)), TimeValue(time=(14, 0, 0, 0), value=Null()), TimeValue(time=(17, 0, 0, 0), value=Real(42.0)), ]) ] * 7), listOfObjectPropertyReferences=ListOf(DeviceObjectPropertyReference)([ DeviceObjectPropertyReference( objectIdentifier=("analogValue", 1), propertyIdentifier="presentValue", ) ]), scheduleDefault=Real(0.0), ) _log.debug(" - test_schedule: %r", test_schedule) this_application.add_object(test_schedule) TestConsoleCmd() _log.debug("running") run() _log.debug("fini")
segmentationSupported=args.ini.segmentationsupported, vendorIdentifier=int(args.ini.vendoridentifier), ) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # make a multistate value object msvo = MultiStateValueObject( objectIdentifier=('multiStateValue', 1), objectName='My Special Object', presentValue=1, numberOfStates=3, stateText=['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() except Exception, e: _log.exception("an error has occurred: %s", e) finally: _log.debug("finally")
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 main(): global args, schedule_objects # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # 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(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # # Simple daily schedule (actually a weekly schedule with every day # being identical. # so = LocalScheduleObject( objectIdentifier=('schedule', 1), objectName='Schedule 1', presentValue=Integer(8), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(8, 0, 0, 0), value=Integer(8)), TimeValue(time=(14, 0, 0, 0), value=Null()), TimeValue(time=(17, 0, 0, 0), value=Integer(42)), # TimeValue(time=(0,0,0,0), value=Null()), ]), ] * 7), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A special schedule when the Year 2000 problem was supposed to collapse # systems, the panic clears ten minutes later when it didn't. # so = LocalScheduleObject( objectIdentifier=('schedule', 2), objectName='Schedule 2', presentValue=CharacterString(""), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( date=Date("2000-01-01").value, ), ), listOfTimeValues=[ TimeValue(time=(0, 0, 0, 0), value=CharacterString("Panic!")), TimeValue(time=(0, 10, 0, 0), value=Null()), ], eventPriority=1, ), ]), scheduleDefault=CharacterString("Don't panic."), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A special schedule to celebrate Friday. # so = LocalScheduleObject( objectIdentifier=('schedule', 3), objectName='Schedule 3', presentValue=CharacterString(""), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.05"), ), ), listOfTimeValues=[ TimeValue(time=(0, 0, 0, 0), value=CharacterString("It's Friday!")), ], eventPriority=1, ), ]), scheduleDefault=CharacterString("Keep working."), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A schedule object that refers to an AnalogValueObject in the test # device. # so = LocalScheduleObject( objectIdentifier=('schedule', 4), objectName='Schedule 4', presentValue=Real(73.5), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(9, 0, 0, 0), value=Real(78.0)), TimeValue(time=(10, 0, 0, 0), value=Null()), ]), ] * 7), scheduleDefault=Real(72.0), listOfObjectPropertyReferences=SequenceOf( DeviceObjectPropertyReference)([ DeviceObjectPropertyReference( objectIdentifier=('analogValue', 1), propertyIdentifier='presentValue', ), ]), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # The beast # so = LocalScheduleObject( objectIdentifier=('schedule', 5), objectName='Schedule 5', presentValue=Integer(0), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(5, 0, 0, 0), value=Integer(5)), TimeValue(time=(6, 0, 0, 0), value=Null()), ], eventPriority=1, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(4, 0, 0, 0), value=Integer(4)), TimeValue(time=(7, 0, 0, 0), value=Null()), ], eventPriority=2, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(3, 0, 0, 0), value=Integer(3)), TimeValue(time=(8, 0, 0, 0), value=Null()), ], eventPriority=3, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(2, 0, 0, 0), value=Integer(2)), TimeValue(time=(9, 0, 0, 0), value=Null()), ], eventPriority=4, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(1, 0, 0, 0), value=Integer(1)), ], eventPriority=5, ), ]), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # list of time values for every five minutes ltv = [] for hr in range(24): for mn in range(0, 60, 5): ltv.append( TimeValue(time=(hr, mn, 0, 0), value=Integer(hr * 100 + mn))) so = LocalScheduleObject( objectIdentifier=('schedule', 6), objectName='Schedule 6', presentValue=Integer(0), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=ltv, eventPriority=1, ), ]), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # make sure they are all there _log.debug(" - object list: %r", this_device.objectList) TestConsoleCmd() _log.debug("running") run() _log.debug("fini")
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) # make a commandable analog value object, add to the device cavo1 = CommandableAnalogValueObject( objectIdentifier=('analogValue', 1), objectName='Commandable AV 1' ) if _debug: _log.debug(" - cavo1: %r", cavo1) this_application.add_object(cavo1) # make a commandable binary value object, add to the device cdvo2 = CommandableDateValueObject( objectIdentifier=('dateValue', 1), objectName='Commandable2' ) if _debug: _log.debug(" - cdvo2: %r", cdvo2) this_application.add_object(cdvo2) if _debug: _log.debug("running") run() except Exception as error: _log.exception("an error has occurred: %s", error) finally:
class BACServer(metaclass=Singleton): def __init__(self): self.__config: Union[BACnetSetting, None] = None self.__bacnet_server: Union[BACnetServerModel, None] = None self.__registry: Dict[str, Commandable] = {} self.__sync_status: bool = False self.__running: bool = False self.ldo = None self.__bacnet = None self._thread = None @property def config(self) -> Union[BACnetSetting, None]: return self.__config def status(self) -> bool: return bool(self.config and self.config.enabled and self.__bacnet and self.__sync_status) def start_bac(self, config: BACnetSetting): self.__config = config self.__bacnet_server = BACnetServerModel.create_default_server_if_does_not_exist( self.config) self.loop_forever() def loop_forever(self): while True: try: if not self.__running: self.connect(self.__bacnet_server) setting: AppSetting = current_app.config[ AppSetting.FLASK_KEY] if setting.mqtt.enabled: mqtt_client = MqttClient() while not mqtt_client.status(): logger.warning( "MQTT is not connected, waiting for MQTT connection successful..." ) time.sleep(self.config.attempt_reconnect_secs) self.sync_stack() self.__running = True else: self.sync_stack() self.__running = True time.sleep(2) except Exception as e: logger.error(e) logger.warning( "BACnet is not connected, waiting for BACnet server connection..." ) time.sleep(self.config.attempt_reconnect_secs) def stop_bacnet(self): if self.__bacnet: self.__bacnet.close_socket() bacnet_stop() def start_bacnet(self, bacnet_server): self.__bacnet_server = bacnet_server FlaskThread(target=self.connect, args=(bacnet_server, )).start() # create_bacnet_stack def restart_bacnet(self, bacnet_server): if self.__bacnet: self.stop_bacnet() self.__reset_variable() self.start_bacnet(bacnet_server) def __reset_variable(self): self.ldo = None self.__bacnet = None self._thread = None self.__running = False self.__registry = {} def sync_stack(self): for point in BACnetPointModel.query.filter_by( object_type=PointType.analogOutput): self.add_point(point, False) for point in BACnetPointModel.query.filter_by( object_type=PointType.analogValue): self.add_point(point, False) self.__sync_status = True self.__running = True def connect(self, bacnet_server): address = self._ip_address(bacnet_server) version = get_version() description = "nube-io bacnet server" self.ldo = LocalDeviceObject( objectName=bacnet_server.local_obj_name, objectIdentifier=int(bacnet_server.device_id), maxApduLengthAccepted=1024, segmentationSupported="segmentedBoth", vendorIdentifier=bacnet_server.vendor_id, firmwareRevision=CharacterString(version), modelName=CharacterString(bacnet_server.model_name), vendorName=CharacterString(bacnet_server.vendor_name), description=CharacterString(description), systemStatus=DeviceStatus(1), applicationSoftwareVersion=CharacterString(version), databaseRevision=0) self.__bacnet = BIPSimpleApplication(self.ldo, address) self.__bacnet.add_capability(ReadWritePropertyMultipleServices) self.sync_stack() FlaskThread(target=bacnet_run).start() # start bacpypes thread def add_point(self, point: BACnetPointModel, _update_point_store=True): [priority_array, present_value] = default_values(point.priority_array_write, point.relinquish_default) if point.use_next_available_address: point.address = BACnetPointModel.get_next_available_address( point.address) object_identifier = create_object_identifier(point.object_type.name, point.address) if point.object_type.name == "analogOutput": register_object_type(AnalogOutputCmdObject) p = AnalogOutputFeedbackObject( profileName=point.uuid, objectIdentifier=(point.object_type.name, point.address), objectName=point.object_name, relinquishDefault=point.relinquish_default, presentValue=present_value, priorityArray=priority_array, eventState=point.event_state.name, statusFlags=StatusFlags(), units=EngineeringUnits(point.units.name), description=point.description, outOfService=False, ) self.__bacnet.add_object(p) self.__registry[object_identifier] = p elif point.object_type.name == "analogValue": register_object_type(AnalogValueCmdObject) p = AnalogValueFeedbackObject( profileName=point.uuid, objectIdentifier=(point.object_type.name, point.address), objectName=point.object_name, relinquishDefault=point.relinquish_default, presentValue=present_value, priorityArray=priority_array, eventState=point.event_state.name, statusFlags=StatusFlags(), units=EngineeringUnits(point.units.name), description=point.description, outOfService=False, ) self.__bacnet.add_object(p) self.__registry[object_identifier] = p if _update_point_store: # make it so on start of app not to update the point store update_point_store(point.uuid, present_value) setting: AppSetting = current_app.config[AppSetting.FLASK_KEY] if setting.mqtt.enabled: priority = get_highest_priority_field(point.priority_array_write) mqtt_client = MqttClient() mqtt_client.publish_value( ('ao', object_identifier, point.object_name), present_value, priority) def remove_point(self, point): object_identifier = create_object_identifier(point.object_type.name, point.address) self.__bacnet.delete_object(self.__registry[object_identifier]) del self.__registry[object_identifier] def remove_all_points(self): object_identifiers = copy.deepcopy(list(self.__registry.keys())) for object_identifier in object_identifiers: self.__bacnet.delete_object(self.__registry[object_identifier]) del self.__registry[object_identifier] def _ip_address(self, bacnet_server): use_nic = self.config.enable_ip_by_nic_name if use_nic: ip_by_nic_name = self.config.ip_by_nic_name address = IP.get_nic_ipv4(ip_by_nic_name) return address else: ip = bacnet_server.ip port = bacnet_server.port mask = None try: ip, subnet_mask_and_port = ip.split("/") try: mask, port = subnet_mask_and_port.split(":") except ValueError: mask = subnet_mask_and_port except ValueError: ip = ip if not mask: mask = 24 if not port: port = 47808 address = "{}/{}:{}".format(ip, mask, port) return address