1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +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:
Joel Bender 2016-01-23 21:27:37 -05:00
parent 36a2aa754a
commit 214e8b97ee
3 changed files with 43 additions and 21 deletions

View File

@ -721,11 +721,14 @@ class StreamToPacket(Client, Server):
self.downstreamBuffer = {}
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
buff = streamBuffer.get(addr, '') + pdu.pduData
if _debug: StreamToPacket._debug(" - buff: %r", buff)
# look for a packet
while 1:
@ -733,7 +736,11 @@ class StreamToPacket(Client, Server):
if packet is None:
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]
# save what didn't get sent
@ -741,10 +748,10 @@ class StreamToPacket(Client, Server):
# buffer related to the addresses
if pdu.pduSource:
for pdu in Chop(pdu.pduSource):
for pdu in chop(pdu.pduSource):
yield pdu
if pdu.pduDestination:
for pdu in Chop(pdu.pduDestination):
for pdu in chop(pdu.pduDestination):
yield pdu
def indication(self, pdu):

View File

@ -715,19 +715,27 @@ class StreamToPacket(Client, Server):
self.downstreamBuffer = {}
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
buff = streamBuffer.get(addr, '') + pdu.pduData
buff = streamBuffer.get(addr, b'') + pdu.pduData
if _debug: StreamToPacket._debug(" - buff: %r", buff)
# look for a packet
while 1:
packet = self.packetFn(buff)
if _debug: StreamToPacket._debug(" - packet: %r", packet)
if packet is None:
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]
# save what didn't get sent
@ -735,10 +743,10 @@ class StreamToPacket(Client, Server):
# buffer related to the addresses
if pdu.pduSource:
for pdu in Chop(pdu.pduSource):
for pdu in chop(pdu.pduSource):
yield pdu
if pdu.pduDestination:
for pdu in Chop(pdu.pduDestination):
for pdu in chop(pdu.pduDestination):
yield pdu
def indication(self, pdu):
@ -777,8 +785,8 @@ class StreamToPacketSAP(ApplicationServiceElement, ServiceAccessPoint):
if addPeer:
# create empty buffers associated with the peer
self.stp.upstreamBuffer[addPeer] = ''
self.stp.downstreamBuffer[addPeer] = ''
self.stp.upstreamBuffer[addPeer] = b''
self.stp.downstreamBuffer[addPeer] = b''
if delPeer:
# delete the buffer contents associated with the peer

View File

@ -715,11 +715,14 @@ class StreamToPacket(Client, Server):
self.downstreamBuffer = {}
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
buff = streamBuffer.get(addr, '') + pdu.pduData
buff = streamBuffer.get(addr, b'') + pdu.pduData
if _debug: StreamToPacket._debug(" - buff: %r", buff)
# look for a packet
while 1:
@ -727,7 +730,11 @@ class StreamToPacket(Client, Server):
if packet is None:
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]
# save what didn't get sent
@ -735,10 +742,10 @@ class StreamToPacket(Client, Server):
# buffer related to the addresses
if pdu.pduSource:
for pdu in Chop(pdu.pduSource):
for pdu in chop(pdu.pduSource):
yield pdu
if pdu.pduDestination:
for pdu in Chop(pdu.pduDestination):
for pdu in chop(pdu.pduDestination):
yield pdu
def indication(self, pdu):
@ -777,8 +784,8 @@ class StreamToPacketSAP(ApplicationServiceElement, ServiceAccessPoint):
if addPeer:
# create empty buffers associated with the peer
self.stp.upstreamBuffer[addPeer] = ''
self.stp.downstreamBuffer[addPeer] = ''
self.stp.upstreamBuffer[addPeer] = b''
self.stp.downstreamBuffer[addPeer] = b''
if delPeer:
# delete the buffer contents associated with the peer