1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00
This commit is contained in:
Joel Bender 2018-06-20 18:47:26 -04:00
commit 207e195edc
13 changed files with 56 additions and 40 deletions

View File

@ -18,7 +18,7 @@ if _sys.platform not in _supported_platforms:
# Project Metadata
#
__version__ = '0.17.2'
__version__ = '0.17.3'
__author__ = 'Joel Bender'
__email__ = 'joel@carrickbender.com'

View File

@ -1525,7 +1525,7 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
xpdu = atype()
xpdu.decode(apdu)
except Exception, err:
ApplicationServiceAccessPoint._exception("unconfirmed request decoding error: %r", err)
ApplicationServiceAccessPoint._exception("complex ack decoding error: %r", err)
return
elif isinstance(apdu, ErrorPDU):

View File

@ -140,12 +140,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet():
self.trigger()
def wait(self, *args):
def wait(self, *args, **kwargs):
"""Wait for the completion event to be set."""
if _debug: IOCB._debug("wait(%d) %r", self.ioID, args)
if _debug: IOCB._debug("wait(%d) %r %r", self.ioID, args, kwargs)
# waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args)
return self.ioComplete.wait(*args, **kwargs)
def trigger(self):
"""Set the completion event and make the callback(s)."""

View File

@ -776,7 +776,7 @@ class NetworkServiceElement(ApplicationServiceElement):
self.response(adapter, iamrtn)
else:
if _debug: NetworkServiceElement._debug(" - forwarding request to other adapters")
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a request
whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData)
@ -806,18 +806,20 @@ class NetworkServiceElement(ApplicationServiceElement):
sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList)
# skip if this is not a router
if len(sap.adapters) > 1:
if len(sap.adapters) == 1:
if _debug: NetworkServiceElement._debug(" - not a router")
else:
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a broadcast annoucement
iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData)
iamrtn.pduDestination = LocalBroadcast()
# send it to all of the connected adapters
for xadapter in sap.adapters.values():
# skip the horse it rode in on
if (xadapter is adapter):
continue
# request this
if xadapter is not adapter:
if _debug: NetworkServiceElement._debug(" - sending on adapter: %r", xadapter)
self.request(xadapter, iamrtn)
# look for pending NPDUs for the networks

View File

@ -18,7 +18,7 @@ if _sys.platform not in _supported_platforms:
# Project Metadata
#
__version__ = '0.17.2'
__version__ = '0.17.3'
__author__ = 'Joel Bender'
__email__ = 'joel@carrickbender.com'

View File

@ -1522,7 +1522,7 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
xpdu = atype()
xpdu.decode(apdu)
except Exception as err:
ApplicationServiceAccessPoint._exception("unconfirmed request decoding error: %r", err)
ApplicationServiceAccessPoint._exception("complex ack decoding error: %r", err)
return
elif isinstance(apdu, ErrorPDU):

View File

@ -141,12 +141,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet():
self.trigger()
def wait(self, *args):
def wait(self, *args, **kwargs):
"""Wait for the completion event to be set."""
if _debug: IOCB._debug("wait(%d) %r", self.ioID, args)
if _debug: IOCB._debug("wait(%d) %r %r", self.ioID, args, kwargs)
# waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args)
return self.ioComplete.wait(*args, **kwargs)
def trigger(self):
"""Set the completion event and make the callback(s)."""

View File

@ -762,6 +762,9 @@ class NetworkServiceElement(ApplicationServiceElement):
if router_net not in sap.adapters:
if _debug: NetworkServiceElement._debug(" - path error (6)")
return
if sap.adapters[router_net] is adapter:
if _debug: NetworkServiceElement._debug(" - same network")
return
# build a response
iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData)
@ -771,7 +774,7 @@ class NetworkServiceElement(ApplicationServiceElement):
self.response(adapter, iamrtn)
else:
if _debug: NetworkServiceElement._debug(" - forwarding request to other adapters")
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a request
whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData)
@ -801,18 +804,20 @@ class NetworkServiceElement(ApplicationServiceElement):
sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList)
# skip if this is not a router
if len(sap.adapters) > 1:
if len(sap.adapters) == 1:
if _debug: NetworkServiceElement._debug(" - not a router")
else:
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a broadcast annoucement
iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData)
iamrtn.pduDestination = LocalBroadcast()
# send it to all of the connected adapters
for xadapter in sap.adapters.values():
# skip the horse it rode in on
if (xadapter is adapter):
continue
# request this
if xadapter is not adapter:
if _debug: NetworkServiceElement._debug(" - sending on adapter: %r", xadapter)
self.request(xadapter, iamrtn)
# look for pending NPDUs for the networks

View File

@ -18,7 +18,7 @@ if _sys.platform not in _supported_platforms:
# Project Metadata
#
__version__ = '0.17.2'
__version__ = '0.17.3'
__author__ = 'Joel Bender'
__email__ = 'joel@carrickbender.com'

View File

@ -1522,7 +1522,7 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
xpdu = atype()
xpdu.decode(apdu)
except Exception as err:
ApplicationServiceAccessPoint._exception("unconfirmed request decoding error: %r", err)
ApplicationServiceAccessPoint._exception("complex ack decoding error: %r", err)
return
elif isinstance(apdu, ErrorPDU):

View File

@ -141,12 +141,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet():
self.trigger()
def wait(self, *args):
def wait(self, *args, **kwargs):
"""Wait for the completion event to be set."""
if _debug: IOCB._debug("wait(%d) %r", self.ioID, args)
if _debug: IOCB._debug("wait(%d) %r %r", self.ioID, args, kwargs)
# waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args)
return self.ioComplete.wait(*args, **kwargs)
def trigger(self):
"""Set the completion event and make the callback(s)."""

View File

@ -762,6 +762,9 @@ class NetworkServiceElement(ApplicationServiceElement):
if router_net not in sap.adapters:
if _debug: NetworkServiceElement._debug(" - path error (6)")
return
if sap.adapters[router_net] is adapter:
if _debug: NetworkServiceElement._debug(" - same network")
return
# build a response
iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData)
@ -771,7 +774,7 @@ class NetworkServiceElement(ApplicationServiceElement):
self.response(adapter, iamrtn)
else:
if _debug: NetworkServiceElement._debug(" - forwarding request to other adapters")
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a request
whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData)
@ -801,18 +804,20 @@ class NetworkServiceElement(ApplicationServiceElement):
sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList)
# skip if this is not a router
if len(sap.adapters) > 1:
if len(sap.adapters) == 1:
if _debug: NetworkServiceElement._debug(" - not a router")
else:
if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a broadcast annoucement
iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData)
iamrtn.pduDestination = LocalBroadcast()
# send it to all of the connected adapters
for xadapter in sap.adapters.values():
# skip the horse it rode in on
if (xadapter is adapter):
continue
# request this
if xadapter is not adapter:
if _debug: NetworkServiceElement._debug(" - sending on adapter: %r", xadapter)
self.request(xadapter, iamrtn)
# look for pending NPDUs for the networks

View File

@ -12,7 +12,7 @@ from bacpypes.consolecmd import ConsoleCmd
from bacpypes.core import run, enable_sleeping
from bacpypes.pdu import Address
from bacpypes.npdu import InitializeRoutingTable, WhoIsRouterToNetwork
from bacpypes.npdu import InitializeRoutingTable, WhoIsRouterToNetwork, IAmRouterToNetwork
from bacpypes.app import BIPNetworkApplication
@ -41,6 +41,10 @@ class WhoIsRouterApplication(BIPNetworkApplication):
def indication(self, adapter, npdu):
if _debug: WhoIsRouterApplication._debug("indication %r %r", adapter, npdu)
if isinstance(npdu, IAmRouterToNetwork):
print("{} -> {}, {}".format(npdu.pduSource, npdu.pduDestination, npdu.iartnNetworkList))
BIPNetworkApplication.indication(self, adapter, npdu)
def response(self, adapter, npdu):