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 build_binary(self, input_device, input_dev_point): self.input_device = input_device self.input_dev_point = input_dev_point register_object_type(BinaryValueCmdObject, vendor_id=842) bv_object = BinaryValueCmdObject( objectIdentifier=("binaryValue", BAC0_Converter.binary_value_num), objectName=self.input_dev_point, presentValue='inactive', description=CharacterString( f"imported from {self.input_device}: {self.input_dev_point} ")) BAC0_Converter.binary_value_num += 1 BAC0_Converter.binary_value_list.append(bv_object) self.device.this_application.add_object(bv_object) return bv_object
def build_analog(self, input_device, input_dev_point): global objects self.input_device = input_device self.input_dev_point = input_dev_point register_object_type(AnalogValueCmdObject, vendor_id=842) av_object = AnalogValueCmdObject( objectIdentifier=("analogValue", BAC0_Converter.analog_value_num), objectName=self.input_dev_point, presentValue=666, description=CharacterString( f"imported from {self.input_device}: {self.input_dev_point} ")) BAC0_Converter.analog_value_num += 1 BAC0_Converter.analog_value_list.append(av_object) self.device.this_application.add_object(av_object) return av_object
def create_proprietary_object(params): try: _validate_params(params) except: raise props = [ Property(v["obj_id"], v["primitive"], mutable=v["mutable"]) for k, v in params["properties"].items() ] new_class = type( params["name"], (params["bacpypes_type"],), {"objectType": params["objectType"], "properties": props}, ) register_object_type(new_class, vendor_id=params["vendor_id"])
def wrapper(*args, **kwargs): if callable(func): obj = func(*args, **kwargs) else: obj = func base_cls = obj.__class__ base_cls_name = obj.__class__.__name__ + cls.__name__ new_type = type(base_cls_name, (cls, base_cls), {}) register_object_type(new_type, vendor_id=842) instance, objectName, presentValue, description = args new_object = new_type( objectIdentifier=(base_cls.objectType, instance), objectName="{}".format(objectName), presentValue=presentValue, description=CharacterString("{}".format(description)), ) return new_object
def wrapper(*args, **kwargs): if callable(func): obj = func(*args, **kwargs) else: obj = func allowed_prop = _allowed_prop(obj) _type = allowed_prop["presentValue"] _commando = Commandable(_type) base_cls = obj.__class__ base_cls_name = obj.__class__.__name__ + "Cmd" new_type = type(base_cls_name, (_commando, base_cls), {}) new_type.__name__ = base_cls_name register_object_type(new_type, vendor_id=842) objectType, instance, objectName, presentValue, description = args new_object = new_type( objectIdentifier=(base_cls.objectType, instance), objectName="{}".format(objectName), presentValue=presentValue, description=CharacterString("{}".format(description)), ) return new_object
# Random Accumulator Object # @bacpypes_debugging class RandomAccumulatorObject(AccumulatorObject): properties = [ RandomUnsignedValueProperty('presentValue'), CurrentDateTimeProperty('valueChangeTime'), ] def __init__(self, **kwargs): if _debug: RandomAccumulatorObject._debug("__init__ %r", kwargs) AccumulatorObject.__init__(self, **kwargs) register_object_type(RandomAccumulatorObject) # # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
from misty.mstplib import MSTPSimpleApplication from bacpypes.object import register_object_type from bacpypes.local.device import ( LocalDeviceObject, ) from bacpypes.local.object import ( AnalogValueCmdObject, BinaryOutputCmdObject, DateValueCmdObject, ) # some debugging _debug = 0 _log = ModuleLogger(globals()) # register the classes register_object_type(LocalDeviceObject, vendor_id=999) register_object_type(AnalogValueCmdObject, vendor_id=999) register_object_type(BinaryOutputCmdObject, vendor_id=999) register_object_type(DateValueCmdObject, vendor_id=999) 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)
@bacpypes_debugging class VendorAVObject(AnalogValueObject): objectType = 513 properties = [ RandomValueProperty(5504), ] def __init__(self, **kwargs): if _debug: VendorAVObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) register_object_type(VendorAVObject, vendor_id=vendor_id) # # main # @bacpypes_debugging 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)
self._record_data.extend(record_data) # check to extend the file out to start_record records elif (start_record > len(self._record_data)): self._record_data.extend(['' for i in range(start_record - len(self._record_data))]) start_record = len(self._record_data) self._record_data.extend(record_data) # slice operation works for other cases else: self._record_data[start_record:start_record + record_count] = record_data # return where the 'writing' actually started return start_record register_object_type(LocalRecordAccessFileObject) # # Local Stream Access File Object Type # @bacpypes_debugging class LocalStreamAccessFileObject(FileObject): def __init__(self, **kwargs): """ Initialize a stream accessed file object. """ if _debug: LocalStreamAccessFileObject._debug("__init__ %r", kwargs, ) FileObject.__init__(self,
def main(): global args, this_application # 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( "net2", type=int, help="network number of second network", ) # add an argument for how many virtual devices parser.add_argument( "--count", type=int, help="number of virtual devices", default=1, ) # add an argument for how many virtual devices parser.add_argument( "--rpm", help="enable read property multiple", action="store_true", ) # add an argument for including the property list parser.add_argument( "--plist", help="enable property list property", action="store_true", ) # 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_network = args.net2 # create the VLAN router, bind it to the local network router = VLANRouter(local_address, local_network) # create a VLAN vlan = Network(broadcast_address=LocalBroadcast()) # create a node for the router, address 1 on the VLAN router_addr = Address(1) router_node = Node(router_addr) vlan.add_node(router_node) # bind the router stack to the vlan network through this node router.nsap.bind(router_node, vlan_network, router_addr) # send network topology deferred(router.nse.i_am_router_to_network) # add the dynamic property list if args.plist: RandomAnalogValueObject.properties.append(CurrentPropertyList()) # register it now that all its properties are defined register_object_type(RandomAnalogValueObject, vendor_id=999) # console is the first device device_number = 2 device_instance = vlan_network * 100 + device_number _log.debug(" - console device_instance: %r", device_instance) # make a vlan device object vlan_device = LocalDeviceObject( objectName="VLAN Console Node %d" % (device_instance, ), objectIdentifier=("device", device_instance), maxApduLengthAccepted=1024, segmentationSupported="noSegmentation", vendorIdentifier=15, ) _log.debug(" - vlan_device: %r", vlan_device) vlan_address = Address(device_number) _log.debug(" - vlan_address: %r", vlan_address) # make the console application, add it to the network this_application = VLANConsoleApplication(vlan_device, vlan_address) vlan.add_node(this_application.vlan_node) _log.debug(" - this_application: %r", this_application) # make a console this_console = VLANConsoleCmd() if _debug: _log.debug(" - this_console: %r", this_console) # make a random value object ravo = RandomAnalogValueObject( objectIdentifier=("analogValue", 1), objectName="Random-1-%d" % (device_instance, ), ) _log.debug(" - ravo: %r", ravo) # add it to the device this_application.add_object(ravo) # make some more devices for device_number in range(3, 3 + args.count - 1): # device identifier is assigned from the address device_instance = vlan_network * 100 + device_number _log.debug(" - device_instance: %r", device_instance) # make a vlan device object vlan_device = LocalDeviceObject( objectName="VLAN Node %d" % (device_instance, ), objectIdentifier=("device", device_instance), maxApduLengthAccepted=1024, segmentationSupported="noSegmentation", vendorIdentifier=15, ) _log.debug(" - vlan_device: %r", vlan_device) vlan_address = Address(device_number) _log.debug(" - vlan_address: %r", vlan_address) # make the application, add it to the network vlan_app = VLANApplication(vlan_device, vlan_address) vlan.add_node(vlan_app.vlan_node) _log.debug(" - vlan_app: %r", vlan_app) # make a random value object ravo = RandomAnalogValueObject( objectIdentifier=("analogValue", 1), objectName="Random-1-%d" % (device_instance, ), ) _log.debug(" - ravo: %r", ravo) # add it to the device vlan_app.add_object(ravo) # enable sleeping will help with threads enable_sleeping() _log.debug("running") run() _log.debug("fini")
def register(cls, vendor_id=5): register_object_type(cls, vendor_id=vendor_id)
# @bacpypes_debugging class RandomAnalogValueObject(AnalogValueObject): properties = [ RandomValueProperty('presentValue'), ] def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) register_object_type(RandomAnalogValueObject) # # __main__ # try: # parse the command line arguments args = ConfigArgumentParser(description=__doc__).parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject( objectName=args.ini.objectname,
# if _debug: ModbusAnalogInputObject._debug('BACnet REQUEST for (%s, %s), (%s, %s), %s= %s at %s', # self._app.localDevice._values['objectName'], # self._app.localDevice._values['objectIdentifier'][1], # self._values['objectName'], self._values['objectIdentifier'][1], # propid, value, _strftime(decimal_places=3)) if _debug: ModbusAnalogInputObject._debug( 'BACnet REQUEST for (%s, %s), (%s, %s), %s= %s at %s', self._app.localDevice.objectName, self._app.localDevice.objectIdentifier[1], self.objectName, self.objectIdentifier[1], propid, value, _strftime(decimal_places=3)) return value register_object_type(ModbusAnalogInputObject) @bacpypes_debugging class ModbusLocalDevice(LocalDeviceObject): properties = [ ReadableProperty('deviceIp', CharacterString), ReadableProperty('modbusId', Integer), ReadableProperty('modbusMapName', CharacterString), ReadableProperty('modbusMapRev', CharacterString), ReadableProperty('deviceModelName', CharacterString), ReadableProperty('modbusPort', Integer), # ReadableProperty('wordOrder', CharacterString) ReadableProperty('meterRespWordOrder', CharacterString), ]
presentValue=value, statusFlags=[0, 0, 0, 0] ) if _debug: _CharacterStringValueObject._debug("__init__ %r", kwargs) CharacterStringValueObject.__init__(self, **kwargs) def set_value(self, value: str) -> None: self.presentValue = value def set_fault(self, fault: bool) -> None: self.statusFlags[StatusFlags.bitNames["fault"]] = int(fault) register_object_type(_CharacterStringValueObject) @bacpypes_debugging class _AnalogValueObject(AnalogValueObject, Logable): def __init__(self, index: int, name: str, value: float = 0): kwargs = dict( objectIdentifier=("analogValue", index), objectName=name, presentValue=value, statusFlags=[0, 0, 0, 0], ) if _debug: _AnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs)
global args global booleanValue return booleanValue class MyAnalogValueObject(AnalogValueObject): properties = [ RealProperty('presentValue'), BooleanProperty('outOfService') ] def __init__(self, **kwargs): AnalogValueObject.__init__(self, **kwargs) register_object_type(MyAnalogValueObject) class MyAveragingObject(AveragingObject): properties = [ RealProperty('minimumValue'), RealProperty('averageValue'), RealProperty('maximumValue') ] def __init__(self, **kwargs): AveragingObject.__init__(self, **kwargs) register_object_type(MyAveragingObject)
def register_extended_object_types(): register_object_type(ExtendedAnalogInputObject, vendor_id=7) register_object_type(ExtendedAnalogValueObject, vendor_id=7)
# # Random Value Object Type # class RandomAnalogValueObject(AnalogValueObject): properties = [ RandomValueProperty('presentValue'), ] def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) bacpypes_debugging(RandomAnalogValueObject) register_object_type(RandomAnalogValueObject) # # __main__ # 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")
# Vendor Analog Value Object Type # @bacpypes_debugging class VendorAVObject(AnalogValueObject): objectType = 513 properties = [ RandomValueProperty(5504), ] def __init__(self, **kwargs): if _debug: VendorAVObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) register_object_type(VendorAVObject, vendor_id=vendor_id) # # main # @bacpypes_debugging 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)
# @bacpypes_debugging class RandomAnalogValueObject(AnalogValueObject): properties = [ RandomValueProperty('presentValue'), ] def __init__(self, **kwargs): if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs) AnalogValueObject.__init__(self, **kwargs) register_object_type(RandomAnalogValueObject) @bacpypes_debugging class ModbusValueProperty(Property): def __init__(self, identifier): if _debug: ModbusValueProperty._debug("__init__ %r", identifier) self.register_reader = None Property.__init__(self, identifier, Real, default=None, optional=True, mutable=False) def ReadProperty(self, obj, arrayIndex=None):
from bacpypes.core import run from bacpypes.basetypes import StatusFlags from bacpypes.app import BIPSimpleApplication from bacpypes.object import register_object_type from bacpypes.local.device import LocalDeviceObject from bacpypes.local.object import BinaryOutputCmdObject, BinaryValueCmdObject, AnalogOutputCmdObject, AnalogValueCmdObject # some debugging _debug = 0 _log = ModuleLogger(globals()) # register the classes register_object_type(LocalDeviceObject, vendor_id=999) @bacpypes_debugging @register_object_type(vendor_id=999) class BinaryOutputFeedbackObject(AnalogValueCmdObject): def __init__(self, *args, **kwargs): if _debug: BinaryOutputFeedbackObject._debug("__init__ %r %r", args, kwargs) super().__init__(*args, **kwargs) # listen for changes to the present value self._property_monitors["presentValue"].append(self.check_feedback) def check_feedback(self, old_value, new_value): if _debug: