mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
sync the new code across python versions
This commit is contained in:
parent
8d93e3d39c
commit
c3266b8a43
|
@ -11,7 +11,7 @@ from .debugging import ModuleLogger, DebugContents, bacpypes_debugging
|
|||
from .comm import Client, ServiceAccessPoint, ApplicationServiceElement
|
||||
from .task import OneShotTask
|
||||
|
||||
from .pdu import Address, LocalStation, RemoteStation
|
||||
from .pdu import Address
|
||||
from .apdu import AbortPDU, AbortReason, ComplexAckPDU, \
|
||||
ConfirmedRequestPDU, Error, ErrorPDU, RejectPDU, SegmentAckPDU, \
|
||||
SimpleAckPDU, UnconfirmedRequestPDU, apdu_types, \
|
||||
|
@ -1083,6 +1083,9 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
self.segmentTimeout = 1500
|
||||
self.maxSegmentsAccepted = 8
|
||||
|
||||
# device communication control
|
||||
self.dccEnableDisable = 'enable'
|
||||
|
||||
# local device object provides these
|
||||
if localDevice:
|
||||
self.retryCount = localDevice.numberOfApduRetries
|
||||
|
@ -1121,6 +1124,22 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
"""Packets coming up the stack are APDU's."""
|
||||
if _debug: StateMachineAccessPoint._debug("confirmation %r", pdu)
|
||||
|
||||
# check device communication control
|
||||
if self.dccEnableDisable == 'enable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications enabled")
|
||||
elif self.dccEnableDisable == 'disable':
|
||||
if (pdu.apduType == 0) and (pdu.apduService == 17):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with DCC request")
|
||||
elif (pdu.apduType == 0) and (pdu.apduService == 20):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with reinitialize device")
|
||||
elif (pdu.apduType == 1) and (pdu.apduService == 8):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with Who-Is")
|
||||
else:
|
||||
if _debug: StateMachineAccessPoint._debug(" - not a Who-Is, dropped")
|
||||
return
|
||||
elif self.dccEnableDisable == 'disableInitiation':
|
||||
if _debug: StateMachineAccessPoint._debug(" - initiation disabled")
|
||||
|
||||
# make a more focused interpretation
|
||||
atype = apdu_types.get(pdu.apduType)
|
||||
if not atype:
|
||||
|
@ -1219,6 +1238,23 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
a new transaction as a client."""
|
||||
if _debug: StateMachineAccessPoint._debug("sap_indication %r", apdu)
|
||||
|
||||
# check device communication control
|
||||
if self.dccEnableDisable == 'enable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications enabled")
|
||||
|
||||
elif self.dccEnableDisable == 'disable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications disabled")
|
||||
return
|
||||
|
||||
elif self.dccEnableDisable == 'disableInitiation':
|
||||
if _debug: StateMachineAccessPoint._debug(" - initiation disabled")
|
||||
|
||||
if (apdu.apduType == 1) and (apdu.apduService == 0):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with I-Am")
|
||||
else:
|
||||
if _debug: StateMachineAccessPoint._debug(" - not an I-Am")
|
||||
return
|
||||
|
||||
if isinstance(apdu, UnconfirmedRequestPDU):
|
||||
# deliver to the device
|
||||
self.request(apdu)
|
||||
|
@ -1408,8 +1444,8 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
|
|||
# copy the one that was assigned on its way down the stack
|
||||
if isinstance(apdu, ConfirmedRequestPDU) and apdu.apduInvokeID is None:
|
||||
if _debug: ApplicationServiceAccessPoint._debug(" - pass invoke ID upstream %r", xpdu.apduInvokeID)
|
||||
|
||||
apdu.apduInvokeID = xpdu.apduInvokeID
|
||||
|
||||
def confirmation(self, apdu):
|
||||
if _debug: ApplicationServiceAccessPoint._debug("confirmation %r", apdu)
|
||||
|
||||
|
@ -1438,7 +1474,7 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
|
|||
try:
|
||||
xpdu = atype()
|
||||
xpdu.decode(apdu)
|
||||
except Exception, err:
|
||||
except Exception,err:
|
||||
ApplicationServiceAccessPoint._exception("error PDU decoding error: %r", err)
|
||||
xpdu = Error(errorClass=0, errorCode=0)
|
||||
|
||||
|
@ -1487,3 +1523,4 @@ class ApplicationServiceAccessPoint(ApplicationServiceElement, ServiceAccessPoin
|
|||
self.response(xpdu)
|
||||
|
||||
bacpypes_debugging(ApplicationServiceAccessPoint)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from .debugging import ModuleLogger, DebugContents, bacpypes_debugging
|
|||
from .comm import Client, ServiceAccessPoint, ApplicationServiceElement
|
||||
from .task import OneShotTask
|
||||
|
||||
from .pdu import Address, LocalStation, RemoteStation
|
||||
from .pdu import Address
|
||||
from .apdu import AbortPDU, AbortReason, ComplexAckPDU, \
|
||||
ConfirmedRequestPDU, Error, ErrorPDU, RejectPDU, SegmentAckPDU, \
|
||||
SimpleAckPDU, UnconfirmedRequestPDU, apdu_types, \
|
||||
|
@ -1081,6 +1081,9 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
self.segmentTimeout = 1500
|
||||
self.maxSegmentsAccepted = 8
|
||||
|
||||
# device communication control
|
||||
self.dccEnableDisable = 'enable'
|
||||
|
||||
# local device object provides these
|
||||
if localDevice:
|
||||
self.retryCount = localDevice.numberOfApduRetries
|
||||
|
@ -1118,13 +1121,22 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
def confirmation(self, pdu):
|
||||
"""Packets coming up the stack are APDU's."""
|
||||
if _debug: StateMachineAccessPoint._debug("confirmation %r", pdu)
|
||||
if pdu.apduService != 17:
|
||||
if _debug: StateMachineAccessPoint._debug("DeviceCommunicationRequest")
|
||||
if getattr(self._localDevice, "_dcc_disable_all", None):
|
||||
raise RuntimeError("All communications disabled")
|
||||
if getattr(self._localDevice, "_dcc_disable", None):
|
||||
if pdu.apduService != 8:
|
||||
raise RuntimeError("All communications disabled except indication for Who-IS.")
|
||||
|
||||
# check device communication control
|
||||
if self.dccEnableDisable == 'enable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications enabled")
|
||||
elif self.dccEnableDisable == 'disable':
|
||||
if (pdu.apduType == 0) and (pdu.apduService == 17):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with DCC request")
|
||||
elif (pdu.apduType == 0) and (pdu.apduService == 20):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with reinitialize device")
|
||||
elif (pdu.apduType == 1) and (pdu.apduService == 8):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with Who-Is")
|
||||
else:
|
||||
if _debug: StateMachineAccessPoint._debug(" - not a Who-Is, dropped")
|
||||
return
|
||||
elif self.dccEnableDisable == 'disableInitiation':
|
||||
if _debug: StateMachineAccessPoint._debug(" - initiation disabled")
|
||||
|
||||
# make a more focused interpretation
|
||||
atype = apdu_types.get(pdu.apduType)
|
||||
|
@ -1224,12 +1236,22 @@ class StateMachineAccessPoint(Client, ServiceAccessPoint):
|
|||
a new transaction as a client."""
|
||||
if _debug: StateMachineAccessPoint._debug("sap_indication %r", apdu)
|
||||
|
||||
if apdu.apduService != 17:
|
||||
if getattr(self._localDevice, "_dcc_disable_all", None):
|
||||
raise RuntimeError("All communications disabled.")
|
||||
if getattr(self._localDevice, "_dcc_disable", None):
|
||||
if apdu.apduService != 0:
|
||||
raise RuntimeError("All communications disabled except indication for Who-IS.")
|
||||
# check device communication control
|
||||
if self.dccEnableDisable == 'enable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications enabled")
|
||||
|
||||
elif self.dccEnableDisable == 'disable':
|
||||
if _debug: StateMachineAccessPoint._debug(" - communications disabled")
|
||||
return
|
||||
|
||||
elif self.dccEnableDisable == 'disableInitiation':
|
||||
if _debug: StateMachineAccessPoint._debug(" - initiation disabled")
|
||||
|
||||
if (apdu.apduType == 1) and (apdu.apduService == 0):
|
||||
if _debug: StateMachineAccessPoint._debug(" - continue with I-Am")
|
||||
else:
|
||||
if _debug: StateMachineAccessPoint._debug(" - not an I-Am")
|
||||
return
|
||||
|
||||
if isinstance(apdu, UnconfirmedRequestPDU):
|
||||
# deliver to the device
|
||||
|
|
Loading…
Reference in New Issue
Block a user