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 # Project Metadata
# #
__version__ = '0.17.2' __version__ = '0.17.3'
__author__ = 'Joel Bender' __author__ = 'Joel Bender'
__email__ = 'joel@carrickbender.com' __email__ = 'joel@carrickbender.com'

View File

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

View File

@ -140,12 +140,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet(): if self.ioComplete.isSet():
self.trigger() self.trigger()
def wait(self, *args): def wait(self, *args, **kwargs):
"""Wait for the completion event to be set.""" """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 # waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args) return self.ioComplete.wait(*args, **kwargs)
def trigger(self): def trigger(self):
"""Set the completion event and make the callback(s).""" """Set the completion event and make the callback(s)."""

View File

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

View File

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

View File

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

View File

@ -141,12 +141,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet(): if self.ioComplete.isSet():
self.trigger() self.trigger()
def wait(self, *args): def wait(self, *args, **kwargs):
"""Wait for the completion event to be set.""" """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 # waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args) return self.ioComplete.wait(*args, **kwargs)
def trigger(self): def trigger(self):
"""Set the completion event and make the callback(s).""" """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 router_net not in sap.adapters:
if _debug: NetworkServiceElement._debug(" - path error (6)") if _debug: NetworkServiceElement._debug(" - path error (6)")
return return
if sap.adapters[router_net] is adapter:
if _debug: NetworkServiceElement._debug(" - same network")
return
# build a response # build a response
iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData) iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData)
@ -771,7 +774,7 @@ class NetworkServiceElement(ApplicationServiceElement):
self.response(adapter, iamrtn) self.response(adapter, iamrtn)
else: else:
if _debug: NetworkServiceElement._debug(" - forwarding request to other adapters") if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a request # build a request
whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData) whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData)
@ -801,19 +804,21 @@ class NetworkServiceElement(ApplicationServiceElement):
sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList) sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList)
# skip if this is not a router # 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 # build a broadcast annoucement
iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData) iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData)
iamrtn.pduDestination = LocalBroadcast() iamrtn.pduDestination = LocalBroadcast()
# send it to all of the connected adapters # send it to all of the connected adapters
for xadapter in sap.adapters.values(): for xadapter in sap.adapters.values():
# skip the horse it rode in on if xadapter is not adapter:
if (xadapter is adapter): if _debug: NetworkServiceElement._debug(" - sending on adapter: %r", xadapter)
continue self.request(xadapter, iamrtn)
# request this
self.request(xadapter, iamrtn)
# look for pending NPDUs for the networks # look for pending NPDUs for the networks
for dnet in npdu.iartnNetworkList: for dnet in npdu.iartnNetworkList:

View File

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

View File

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

View File

@ -141,12 +141,12 @@ class IOCB(DebugContents):
if self.ioComplete.isSet(): if self.ioComplete.isSet():
self.trigger() self.trigger()
def wait(self, *args): def wait(self, *args, **kwargs):
"""Wait for the completion event to be set.""" """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 # waiting from a non-daemon thread could be trouble
self.ioComplete.wait(*args) return self.ioComplete.wait(*args, **kwargs)
def trigger(self): def trigger(self):
"""Set the completion event and make the callback(s).""" """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 router_net not in sap.adapters:
if _debug: NetworkServiceElement._debug(" - path error (6)") if _debug: NetworkServiceElement._debug(" - path error (6)")
return return
if sap.adapters[router_net] is adapter:
if _debug: NetworkServiceElement._debug(" - same network")
return
# build a response # build a response
iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData) iamrtn = IAmRouterToNetwork([dnet], user_data=npdu.pduUserData)
@ -771,7 +774,7 @@ class NetworkServiceElement(ApplicationServiceElement):
self.response(adapter, iamrtn) self.response(adapter, iamrtn)
else: else:
if _debug: NetworkServiceElement._debug(" - forwarding request to other adapters") if _debug: NetworkServiceElement._debug(" - forwarding to other adapters")
# build a request # build a request
whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData) whoisrtn = WhoIsRouterToNetwork(dnet, user_data=npdu.pduUserData)
@ -801,19 +804,21 @@ class NetworkServiceElement(ApplicationServiceElement):
sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList) sap.add_router_references(adapter.adapterNet, npdu.pduSource, npdu.iartnNetworkList)
# skip if this is not a router # 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 # build a broadcast annoucement
iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData) iamrtn = IAmRouterToNetwork(npdu.iartnNetworkList, user_data=npdu.pduUserData)
iamrtn.pduDestination = LocalBroadcast() iamrtn.pduDestination = LocalBroadcast()
# send it to all of the connected adapters # send it to all of the connected adapters
for xadapter in sap.adapters.values(): for xadapter in sap.adapters.values():
# skip the horse it rode in on if xadapter is not adapter:
if (xadapter is adapter): if _debug: NetworkServiceElement._debug(" - sending on adapter: %r", xadapter)
continue self.request(xadapter, iamrtn)
# request this
self.request(xadapter, iamrtn)
# look for pending NPDUs for the networks # look for pending NPDUs for the networks
for dnet in npdu.iartnNetworkList: for dnet in npdu.iartnNetworkList:

View File

@ -12,7 +12,7 @@ from bacpypes.consolecmd import ConsoleCmd
from bacpypes.core import run, enable_sleeping from bacpypes.core import run, enable_sleeping
from bacpypes.pdu import Address from bacpypes.pdu import Address
from bacpypes.npdu import InitializeRoutingTable, WhoIsRouterToNetwork from bacpypes.npdu import InitializeRoutingTable, WhoIsRouterToNetwork, IAmRouterToNetwork
from bacpypes.app import BIPNetworkApplication from bacpypes.app import BIPNetworkApplication
@ -41,6 +41,10 @@ class WhoIsRouterApplication(BIPNetworkApplication):
def indication(self, adapter, npdu): def indication(self, adapter, npdu):
if _debug: WhoIsRouterApplication._debug("indication %r %r", 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) BIPNetworkApplication.indication(self, adapter, npdu)
def response(self, adapter, npdu): def response(self, adapter, npdu):