mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
pass the last value down into the object and assign a value when created so the current property list has something not None
This commit is contained in:
parent
cd82a06b49
commit
60acb838b4
|
@ -25,7 +25,10 @@ from bacpypes.bvllservice import BIPSimple, AnnexJCodec, UDPMultiplexer
|
|||
from bacpypes.app import Application
|
||||
from bacpypes.appservice import StateMachineAccessPoint, ApplicationServiceAccessPoint
|
||||
from bacpypes.local.device import LocalDeviceObject
|
||||
from bacpypes.service.device import WhoIsIAmServices
|
||||
from bacpypes.local.object import CurrentPropertyList
|
||||
from bacpypes.service.device import (
|
||||
WhoIsIAmServices,
|
||||
)
|
||||
from bacpypes.service.object import (
|
||||
ReadWritePropertyServices,
|
||||
ReadWritePropertyMultipleServices,
|
||||
|
@ -41,6 +44,9 @@ from bacpypes.errors import ExecutionError
|
|||
_debug = 0
|
||||
_log = ModuleLogger(globals())
|
||||
|
||||
# globals
|
||||
args = None
|
||||
|
||||
#
|
||||
# RandomValueProperty
|
||||
#
|
||||
|
@ -63,18 +69,27 @@ class RandomValueProperty(Property):
|
|||
value = random.random() * 100.0
|
||||
if _debug: RandomValueProperty._debug(" - value: %r", value)
|
||||
|
||||
# save the value that was generated
|
||||
super(RandomValueProperty, self).WriteProperty(obj, value, direct=True)
|
||||
|
||||
# now return it to the client
|
||||
return value
|
||||
|
||||
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
|
||||
if _debug: RandomValueProperty._debug("WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct)
|
||||
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
|
||||
if not direct:
|
||||
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
|
||||
if arrayIndex is not None:
|
||||
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
|
||||
|
||||
# continue along
|
||||
super(RandomValueProperty, self).WriteProperty(obj, value, direct=True)
|
||||
|
||||
#
|
||||
# Random Value Object Type
|
||||
#
|
||||
|
||||
@bacpypes_debugging
|
||||
@register_object_type(vendor_id=999)
|
||||
class RandomAnalogValueObject(AnalogValueObject):
|
||||
|
||||
properties = [
|
||||
|
@ -85,6 +100,10 @@ class RandomAnalogValueObject(AnalogValueObject):
|
|||
if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs)
|
||||
AnalogValueObject.__init__(self, **kwargs)
|
||||
|
||||
# if a value hasn't already been provided, initialize with a random one
|
||||
if 'presentValue' not in kwargs:
|
||||
self.presentValue = random.random() * 100.0
|
||||
|
||||
#
|
||||
# VLANApplication
|
||||
#
|
||||
|
@ -94,13 +113,19 @@ class VLANApplication(
|
|||
Application,
|
||||
WhoIsIAmServices,
|
||||
ReadWritePropertyServices,
|
||||
ReadWritePropertyMultipleServices,
|
||||
):
|
||||
|
||||
def __init__(self, vlan_device, vlan_address, aseID=None):
|
||||
if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID)
|
||||
global args
|
||||
|
||||
# normal initialization
|
||||
Application.__init__(self, vlan_device, vlan_address, aseID)
|
||||
|
||||
# optional read property multiple
|
||||
if args.rpm:
|
||||
self.add_capability(ReadWritePropertyMultipleServices)
|
||||
|
||||
# include a application decoder
|
||||
self.asap = ApplicationServiceAccessPoint()
|
||||
|
||||
|
@ -178,6 +203,8 @@ class VLANRouter:
|
|||
#
|
||||
|
||||
def main():
|
||||
global args
|
||||
|
||||
# parse the command line arguments
|
||||
parser = ArgumentParser(
|
||||
description=__doc__,
|
||||
|
@ -186,24 +213,36 @@ def main():
|
|||
|
||||
# add an argument for interval
|
||||
parser.add_argument('addr1', type=str,
|
||||
help='address of first network',
|
||||
)
|
||||
help='address of first network',
|
||||
)
|
||||
|
||||
# add an argument for interval
|
||||
parser.add_argument('net1', type=int,
|
||||
help='network number of first network',
|
||||
)
|
||||
help='network number of first network',
|
||||
)
|
||||
|
||||
# add an argument for interval
|
||||
parser.add_argument('net2', type=int,
|
||||
help='network number of second network',
|
||||
)
|
||||
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,
|
||||
)
|
||||
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()
|
||||
|
@ -231,6 +270,13 @@ def main():
|
|||
# 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)
|
||||
|
||||
# make some devices
|
||||
for device_number in range(2, 2 + args.count):
|
||||
# device identifier is assigned from the address
|
||||
|
|
Loading…
Reference in New Issue
Block a user