fix: correctly receive all chunks in recorder
This commit is contained in:
@@ -28,6 +28,7 @@ class RecorderClient(QObject):
|
|||||||
socket.AF_INET, socket.SOCK_STREAM)
|
socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.timer: Optional[QTimer] = None
|
self.timer: Optional[QTimer] = None
|
||||||
self.connected: bool = False
|
self.connected: bool = False
|
||||||
|
self.buffer: bytes = b""
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def start(self):
|
def start(self):
|
||||||
@@ -40,26 +41,26 @@ class RecorderClient(QObject):
|
|||||||
print("Connected to server")
|
print("Connected to server")
|
||||||
|
|
||||||
def poll_socket(self):
|
def poll_socket(self):
|
||||||
buffer: bytes = b""
|
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
while True:
|
||||||
chunk: bytes = self.socket.recv(self.DATA_CHUNK_SIZE)
|
chunk: bytes = self.socket.recv(self.DATA_CHUNK_SIZE)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
return
|
return
|
||||||
buffer += chunk
|
self.buffer += chunk
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if len(buffer) < 4:
|
if len(self.buffer) < 4:
|
||||||
break
|
break
|
||||||
msg_len: int = struct.unpack(">I", buffer[:4])[0]
|
msg_len: int = struct.unpack(">I", self.buffer[:4])[0]
|
||||||
msg_end: int = 4 + msg_len
|
msg_end: int = 4 + msg_len
|
||||||
if len(buffer) < msg_end:
|
if len(self.buffer) < msg_end:
|
||||||
break
|
break
|
||||||
|
|
||||||
message: bytes = buffer[4:msg_end]
|
message: bytes = self.buffer[4:msg_end]
|
||||||
buffer = buffer[msg_end:]
|
self.buffer = self.buffer[msg_end:]
|
||||||
self.on_message(message)
|
self.on_message(message)
|
||||||
except BlockingIOError:
|
except BlockingIOError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class Snapshot:
|
|||||||
(nbr_raycasts,), data = iter_unpack(">B", data)
|
(nbr_raycasts,), data = iter_unpack(">B", data)
|
||||||
raycast_distances, data = iter_unpack(f">{nbr_raycasts}f", data)
|
raycast_distances, data = iter_unpack(f">{nbr_raycasts}f", data)
|
||||||
|
|
||||||
(h, w), data = iter_unpack(">ii", data)
|
(h, w), data = iter_unpack(">II", data)
|
||||||
|
|
||||||
if h * w > 0:
|
if h * w > 0:
|
||||||
image = np.frombuffer(data, np.uint8).reshape(h, w, 3)
|
image = np.frombuffer(data, np.uint8).reshape(h, w, 3)
|
||||||
|
|||||||
Reference in New Issue
Block a user