Skip to content

Commit ac3c7cb

Browse files
committed
update TCP Com IF
1 parent b1a70a9 commit ac3c7cb

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ dependencies = [
3636
"Deprecated~=1.2",
3737
"pyserial~=3.5",
3838
"dle-encoder~=0.2.3",
39-
"spacepackets>=0.24.0, <=0.27",
39+
# "spacepackets>=0.24.0, <=0.27",
40+
"spacepackets @ git+https://github.com/us-irs/spacepackets-py.git@71f42112e0cea9f6c7d47e5dd34fccbf13e58242",
4041
"cfdp-py>=0.1.1, <=0.5",
4142
]
4243

src/tmtccmd/com/tcp.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from collections import deque
1313
from typing import Any, Optional, Sequence
1414

15-
from spacepackets.ccsds.spacepacket import parse_space_packets, PacketId
15+
from spacepackets.ccsds.spacepacket import (
16+
PacketId,
17+
parse_space_packets_from_deque,
18+
)
1619

1720
from tmtccmd.com import ComInterface, SendError
1821
from tmtccmd.com.tcpip_utils import EthAddr
@@ -115,7 +118,7 @@ def __connect_socket(self):
115118
finally:
116119
self.__tcp_socket.settimeout(None)
117120

118-
def close(self, args: any = None) -> None:
121+
def close(self, args: Any = None) -> None:
119122
if not self.is_open():
120123
return
121124
self.__thread_kill_signal.set()
@@ -128,7 +131,7 @@ def close(self, args: any = None) -> None:
128131
def send(self, data: bytes | bytearray):
129132
self.__tc_queue.put(data)
130133

131-
def receive(self, poll_timeout: float = 0) -> list[bytes]:
134+
def receive(self, parameters: float = 0) -> list[bytes]:
132135
self.__tm_queue_to_packet_list()
133136
tm_packet_list = self.tm_packet_list
134137
self.tm_packet_list = []
@@ -139,13 +142,23 @@ def __tm_queue_to_packet_list(self):
139142
self.__analysis_queue.append(self.__tm_queue.get())
140143
# TCP is stream based, so there might be broken packets or multiple packets in one recv
141144
# call. We parse the space packets contained in the stream here
142-
if self.com_type == TcpCommunicationType.SPACE_PACKETS:
143-
self.tm_packet_list.extend(
144-
parse_space_packets(
145-
analysis_queue=self.__analysis_queue,
146-
packet_ids=self.space_packet_ids,
147-
)
145+
if self.com_type == TcpCommunicationType.SPACE_PACKETS and self.__analysis_queue:
146+
result = parse_space_packets_from_deque(
147+
analysis_queue=self.__analysis_queue,
148+
packet_ids=self.space_packet_ids,
148149
)
150+
flattened = bytearray()
151+
for packet in result.tm_list:
152+
self.tm_packet_list.append(packet)
153+
while self.__analysis_queue:
154+
flattened.extend(self.__analysis_queue.popleft())
155+
# Might be spammy, but I consider this a configuration error, and the user
156+
# should be notified about it.
157+
for skipped_range in result.skipped_ranges:
158+
_LOGGER.warning("skipped bytes in received TCP datastream:")
159+
print(flattened[skipped_range.start : skipped_range.stop])
160+
_LOGGER.warning("list of valid packet IDs might be incomplete")
161+
self.__analysis_queue.append(flattened[result.scanned_bytes :])
149162
else:
150163
while self.__analysis_queue:
151164
self.tm_packet_list.append(self.__analysis_queue.popleft())

0 commit comments

Comments
 (0)