mirror of
https://github.com/JoelBender/bacpypes
synced 2025-10-05 22:18:16 +08:00
update tcp contents from strings to bytes, add some debugging to find the problem, changed internal 'Chop' function to 'chop'
This commit is contained in:
parent
36a2aa754a
commit
214e8b97ee
|
@ -721,11 +721,14 @@ class StreamToPacket(Client, Server):
|
||||||
self.downstreamBuffer = {}
|
self.downstreamBuffer = {}
|
||||||
|
|
||||||
def packetize(self, pdu, streamBuffer):
|
def packetize(self, pdu, streamBuffer):
|
||||||
if _debug: StreamToPacket._debug("packetize %r", pdu)
|
if _debug: StreamToPacket._debug("packetize %r ...", pdu)
|
||||||
|
|
||||||
|
def chop(addr):
|
||||||
|
if _debug: StreamToPacket._debug("chop %r", addr)
|
||||||
|
|
||||||
def Chop(addr):
|
|
||||||
# get the current downstream buffer
|
# get the current downstream buffer
|
||||||
buff = streamBuffer.get(addr, '') + pdu.pduData
|
buff = streamBuffer.get(addr, '') + pdu.pduData
|
||||||
|
if _debug: StreamToPacket._debug(" - buff: %r", buff)
|
||||||
|
|
||||||
# look for a packet
|
# look for a packet
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -733,7 +736,11 @@ class StreamToPacket(Client, Server):
|
||||||
if packet is None:
|
if packet is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
yield PDU(packet[0], source=pdu.pduSource, destination=pdu.pduDestination)
|
yield PDU(packet[0],
|
||||||
|
source=pdu.pduSource,
|
||||||
|
destination=pdu.pduDestination,
|
||||||
|
user_data=pdu.pduUserData,
|
||||||
|
)
|
||||||
buff = packet[1]
|
buff = packet[1]
|
||||||
|
|
||||||
# save what didn't get sent
|
# save what didn't get sent
|
||||||
|
@ -741,10 +748,10 @@ class StreamToPacket(Client, Server):
|
||||||
|
|
||||||
# buffer related to the addresses
|
# buffer related to the addresses
|
||||||
if pdu.pduSource:
|
if pdu.pduSource:
|
||||||
for pdu in Chop(pdu.pduSource):
|
for pdu in chop(pdu.pduSource):
|
||||||
yield pdu
|
yield pdu
|
||||||
if pdu.pduDestination:
|
if pdu.pduDestination:
|
||||||
for pdu in Chop(pdu.pduDestination):
|
for pdu in chop(pdu.pduDestination):
|
||||||
yield pdu
|
yield pdu
|
||||||
|
|
||||||
def indication(self, pdu):
|
def indication(self, pdu):
|
||||||
|
|
|
@ -715,19 +715,27 @@ class StreamToPacket(Client, Server):
|
||||||
self.downstreamBuffer = {}
|
self.downstreamBuffer = {}
|
||||||
|
|
||||||
def packetize(self, pdu, streamBuffer):
|
def packetize(self, pdu, streamBuffer):
|
||||||
if _debug: StreamToPacket._debug("packetize %r", pdu)
|
if _debug: StreamToPacket._debug("packetize %r ...", pdu)
|
||||||
|
|
||||||
|
def chop(addr):
|
||||||
|
if _debug: StreamToPacket._debug("chop %r", addr)
|
||||||
|
|
||||||
def Chop(addr):
|
|
||||||
# get the current downstream buffer
|
# get the current downstream buffer
|
||||||
buff = streamBuffer.get(addr, '') + pdu.pduData
|
buff = streamBuffer.get(addr, b'') + pdu.pduData
|
||||||
|
if _debug: StreamToPacket._debug(" - buff: %r", buff)
|
||||||
|
|
||||||
# look for a packet
|
# look for a packet
|
||||||
while 1:
|
while 1:
|
||||||
packet = self.packetFn(buff)
|
packet = self.packetFn(buff)
|
||||||
|
if _debug: StreamToPacket._debug(" - packet: %r", packet)
|
||||||
if packet is None:
|
if packet is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
yield PDU(packet[0], source=pdu.pduSource, destination=pdu.pduDestination)
|
yield PDU(packet[0],
|
||||||
|
source=pdu.pduSource,
|
||||||
|
destination=pdu.pduDestination,
|
||||||
|
user_data=pdu.pduUserData,
|
||||||
|
)
|
||||||
buff = packet[1]
|
buff = packet[1]
|
||||||
|
|
||||||
# save what didn't get sent
|
# save what didn't get sent
|
||||||
|
@ -735,10 +743,10 @@ class StreamToPacket(Client, Server):
|
||||||
|
|
||||||
# buffer related to the addresses
|
# buffer related to the addresses
|
||||||
if pdu.pduSource:
|
if pdu.pduSource:
|
||||||
for pdu in Chop(pdu.pduSource):
|
for pdu in chop(pdu.pduSource):
|
||||||
yield pdu
|
yield pdu
|
||||||
if pdu.pduDestination:
|
if pdu.pduDestination:
|
||||||
for pdu in Chop(pdu.pduDestination):
|
for pdu in chop(pdu.pduDestination):
|
||||||
yield pdu
|
yield pdu
|
||||||
|
|
||||||
def indication(self, pdu):
|
def indication(self, pdu):
|
||||||
|
@ -777,8 +785,8 @@ class StreamToPacketSAP(ApplicationServiceElement, ServiceAccessPoint):
|
||||||
|
|
||||||
if addPeer:
|
if addPeer:
|
||||||
# create empty buffers associated with the peer
|
# create empty buffers associated with the peer
|
||||||
self.stp.upstreamBuffer[addPeer] = ''
|
self.stp.upstreamBuffer[addPeer] = b''
|
||||||
self.stp.downstreamBuffer[addPeer] = ''
|
self.stp.downstreamBuffer[addPeer] = b''
|
||||||
|
|
||||||
if delPeer:
|
if delPeer:
|
||||||
# delete the buffer contents associated with the peer
|
# delete the buffer contents associated with the peer
|
||||||
|
|
|
@ -715,11 +715,14 @@ class StreamToPacket(Client, Server):
|
||||||
self.downstreamBuffer = {}
|
self.downstreamBuffer = {}
|
||||||
|
|
||||||
def packetize(self, pdu, streamBuffer):
|
def packetize(self, pdu, streamBuffer):
|
||||||
if _debug: StreamToPacket._debug("packetize %r", pdu)
|
if _debug: StreamToPacket._debug("packetize %r ...", pdu)
|
||||||
|
|
||||||
|
def chop(addr):
|
||||||
|
if _debug: StreamToPacket._debug("chop %r", addr)
|
||||||
|
|
||||||
def Chop(addr):
|
|
||||||
# get the current downstream buffer
|
# get the current downstream buffer
|
||||||
buff = streamBuffer.get(addr, '') + pdu.pduData
|
buff = streamBuffer.get(addr, b'') + pdu.pduData
|
||||||
|
if _debug: StreamToPacket._debug(" - buff: %r", buff)
|
||||||
|
|
||||||
# look for a packet
|
# look for a packet
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -727,7 +730,11 @@ class StreamToPacket(Client, Server):
|
||||||
if packet is None:
|
if packet is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
yield PDU(packet[0], source=pdu.pduSource, destination=pdu.pduDestination)
|
yield PDU(packet[0],
|
||||||
|
source=pdu.pduSource,
|
||||||
|
destination=pdu.pduDestination,
|
||||||
|
user_data=pdu.pduUserData,
|
||||||
|
)
|
||||||
buff = packet[1]
|
buff = packet[1]
|
||||||
|
|
||||||
# save what didn't get sent
|
# save what didn't get sent
|
||||||
|
@ -735,10 +742,10 @@ class StreamToPacket(Client, Server):
|
||||||
|
|
||||||
# buffer related to the addresses
|
# buffer related to the addresses
|
||||||
if pdu.pduSource:
|
if pdu.pduSource:
|
||||||
for pdu in Chop(pdu.pduSource):
|
for pdu in chop(pdu.pduSource):
|
||||||
yield pdu
|
yield pdu
|
||||||
if pdu.pduDestination:
|
if pdu.pduDestination:
|
||||||
for pdu in Chop(pdu.pduDestination):
|
for pdu in chop(pdu.pduDestination):
|
||||||
yield pdu
|
yield pdu
|
||||||
|
|
||||||
def indication(self, pdu):
|
def indication(self, pdu):
|
||||||
|
@ -777,8 +784,8 @@ class StreamToPacketSAP(ApplicationServiceElement, ServiceAccessPoint):
|
||||||
|
|
||||||
if addPeer:
|
if addPeer:
|
||||||
# create empty buffers associated with the peer
|
# create empty buffers associated with the peer
|
||||||
self.stp.upstreamBuffer[addPeer] = ''
|
self.stp.upstreamBuffer[addPeer] = b''
|
||||||
self.stp.downstreamBuffer[addPeer] = ''
|
self.stp.downstreamBuffer[addPeer] = b''
|
||||||
|
|
||||||
if delPeer:
|
if delPeer:
|
||||||
# delete the buffer contents associated with the peer
|
# delete the buffer contents associated with the peer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user