1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

sandbox application up to current API

This commit is contained in:
Joel Bender 2018-08-08 10:09:12 -04:00
parent e8f5fa7460
commit 7814351b2d

View File

@ -14,13 +14,14 @@ from bacpypes.consolecmd import ConsoleCmd
from bacpypes.core import run from bacpypes.core import run
from bacpypes.comm import bind from bacpypes.comm import bind
from bacpypes.pdu import Address, GlobalBroadcast from bacpypes.pdu import Address, LocalBroadcast, GlobalBroadcast
from bacpypes.vlan import Network, Node from bacpypes.vlan import Network, Node
from bacpypes.app import LocalDeviceObject, Application from bacpypes.app import Application
from bacpypes.appservice import StateMachineAccessPoint, ApplicationServiceAccessPoint from bacpypes.appservice import StateMachineAccessPoint, ApplicationServiceAccessPoint
from bacpypes.netservice import NetworkServiceAccessPoint, NetworkServiceElement from bacpypes.netservice import NetworkServiceAccessPoint, NetworkServiceElement
from bacpypes.local.device import LocalDeviceObject
from bacpypes.apdu import WhoIsRequest, IAmRequest, ReadPropertyRequest, WritePropertyRequest from bacpypes.apdu import WhoIsRequest, IAmRequest, ReadPropertyRequest, WritePropertyRequest
@ -28,6 +29,10 @@ from bacpypes.primitivedata import Null, Atomic, Integer, Unsigned, Real
from bacpypes.constructeddata import Array, Any from bacpypes.constructeddata import Array, Any
from bacpypes.object import get_object_class, get_datatype from bacpypes.object import get_object_class, get_datatype
# basic services
from bacpypes.service.device import WhoIsIAmServices
from bacpypes.service.object import ReadWritePropertyServices
# some debugging # some debugging
_debug = 0 _debug = 0
_log = ModuleLogger(globals()) _log = ModuleLogger(globals())
@ -41,7 +46,7 @@ vlan_app_2 = None
# #
@bacpypes_debugging @bacpypes_debugging
class VLANApplication(Application): class VLANApplication(Application, WhoIsIAmServices, ReadWritePropertyServices):
def __init__(self, vlan_device, vlan_address, aseID=None): def __init__(self, vlan_device, vlan_address, aseID=None):
if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID) if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID)
@ -141,33 +146,27 @@ class TestConsoleCmd(ConsoleCmd):
TestConsoleCmd._exception("exception: %r", e) TestConsoleCmd._exception("exception: %r", e)
def do_read(self, args): def do_read(self, args):
"""read <addr> <type> <inst> <prop> [ <indx> ]""" """read <addr> <objid> <prop> [ <indx> ]"""
args = args.split() args = args.split()
if _debug: TestConsoleCmd._debug("do_read %r", args) if _debug: TestConsoleCmd._debug("do_read %r", args)
try: try:
addr, obj_type, obj_inst, prop_id = args[:4] addr, obj_id, prop_id = args[:3]
obj_id = ObjectIdentifier(obj_id).value
if obj_type.isdigit(): datatype = get_datatype(obj_id[0], prop_id)
obj_type = int(obj_type)
elif not get_object_class(obj_type):
raise ValueError, "unknown object type"
obj_inst = int(obj_inst)
datatype = get_datatype(obj_type, prop_id)
if not datatype: if not datatype:
raise ValueError, "invalid property for object type" raise ValueError, "invalid property for object type"
# build a request # build a request
request = ReadPropertyRequest( request = ReadPropertyRequest(
objectIdentifier=(obj_type, obj_inst), objectIdentifier=obj_id,
propertyIdentifier=prop_id, propertyIdentifier=prop_id,
) )
request.pduDestination = Address(addr) request.pduDestination = Address(addr)
if len(args) == 5: if len(args) == 4:
request.propertyArrayIndex = int(args[4]) request.propertyArrayIndex = int(args[3])
if _debug: TestConsoleCmd._debug(" - request: %r", request) if _debug: TestConsoleCmd._debug(" - request: %r", request)
# give it to the application # give it to the application
@ -177,30 +176,28 @@ class TestConsoleCmd(ConsoleCmd):
TestConsoleCmd._exception("exception: %r", e) TestConsoleCmd._exception("exception: %r", e)
def do_write(self, args): def do_write(self, args):
"""write <addr> <type> <inst> <prop> <value> [ <indx> ] [ <priority> ]""" """write <addr> <objid> <prop> <value> [ <indx> ] [ <priority> ]"""
args = args.split() args = args.split()
if _debug: TestConsoleCmd._debug("do_write %r", args) if _debug: TestConsoleCmd._debug("do_write %r", args)
try: try:
addr, obj_type, obj_inst, prop_id = args[:4] addr, obj_id, prop_id = args[:3]
if obj_type.isdigit(): obj_id = ObjectIdentifier(obj_id).value
obj_type = int(obj_type)
obj_inst = int(obj_inst)
value = args[4] value = args[4]
indx = None indx = None
if len(args) >= 6: if len(args) >= 5:
if args[5] != "-": if args[4] != "-":
indx = int(args[5]) indx = int(args[4])
if _debug: TestConsoleCmd._debug(" - indx: %r", indx) if _debug: TestConsoleCmd._debug(" - indx: %r", indx)
priority = None priority = None
if len(args) >= 7: if len(args) >= 6:
priority = int(args[6]) priority = int(args[5])
if _debug: TestConsoleCmd._debug(" - priority: %r", priority) if _debug: TestConsoleCmd._debug(" - priority: %r", priority)
# get the datatype # get the datatype
datatype = get_datatype(obj_type, prop_id) datatype = get_datatype(obj_id[0], prop_id)
if _debug: TestConsoleCmd._debug(" - datatype: %r", datatype) if _debug: TestConsoleCmd._debug(" - datatype: %r", datatype)
# change atomic values into something encodeable, null is a special case # change atomic values into something encodeable, null is a special case
@ -227,7 +224,7 @@ class TestConsoleCmd(ConsoleCmd):
# build a request # build a request
request = WritePropertyRequest( request = WritePropertyRequest(
objectIdentifier=(obj_type, obj_inst), objectIdentifier=obj_id,
propertyIdentifier=prop_id propertyIdentifier=prop_id
) )
request.pduDestination = Address(addr) request.pduDestination = Address(addr)
@ -269,7 +266,7 @@ try:
if _debug: _log.debug(" - args: %r", args) if _debug: _log.debug(" - args: %r", args)
# create a VLAN # create a VLAN
vlan = Network() vlan = Network(broadcast_address=LocalBroadcast())
# create the first device # create the first device
vlan_device_1 = \ vlan_device_1 = \