Skip to content

Commit

Permalink
update TCP Com IF
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Feb 3, 2025
1 parent b1a70a9 commit ac3c7cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ dependencies = [
"Deprecated~=1.2",
"pyserial~=3.5",
"dle-encoder~=0.2.3",
"spacepackets>=0.24.0, <=0.27",
# "spacepackets>=0.24.0, <=0.27",
"spacepackets @ git+/~https://github.com/us-irs/spacepackets-py.git@71f42112e0cea9f6c7d47e5dd34fccbf13e58242",
"cfdp-py>=0.1.1, <=0.5",
]

Expand Down
31 changes: 22 additions & 9 deletions src/tmtccmd/com/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from collections import deque
from typing import Any, Optional, Sequence

from spacepackets.ccsds.spacepacket import parse_space_packets, PacketId
from spacepackets.ccsds.spacepacket import (
PacketId,
parse_space_packets_from_deque,
)

from tmtccmd.com import ComInterface, SendError
from tmtccmd.com.tcpip_utils import EthAddr
Expand Down Expand Up @@ -115,7 +118,7 @@ def __connect_socket(self):
finally:
self.__tcp_socket.settimeout(None)

def close(self, args: any = None) -> None:
def close(self, args: Any = None) -> None:
if not self.is_open():
return
self.__thread_kill_signal.set()
Expand All @@ -128,7 +131,7 @@ def close(self, args: any = None) -> None:
def send(self, data: bytes | bytearray):
self.__tc_queue.put(data)

def receive(self, poll_timeout: float = 0) -> list[bytes]:
def receive(self, parameters: float = 0) -> list[bytes]:
self.__tm_queue_to_packet_list()
tm_packet_list = self.tm_packet_list
self.tm_packet_list = []
Expand All @@ -139,13 +142,23 @@ def __tm_queue_to_packet_list(self):
self.__analysis_queue.append(self.__tm_queue.get())
# TCP is stream based, so there might be broken packets or multiple packets in one recv
# call. We parse the space packets contained in the stream here
if self.com_type == TcpCommunicationType.SPACE_PACKETS:
self.tm_packet_list.extend(
parse_space_packets(
analysis_queue=self.__analysis_queue,
packet_ids=self.space_packet_ids,
)
if self.com_type == TcpCommunicationType.SPACE_PACKETS and self.__analysis_queue:
result = parse_space_packets_from_deque(
analysis_queue=self.__analysis_queue,
packet_ids=self.space_packet_ids,
)
flattened = bytearray()
for packet in result.tm_list:
self.tm_packet_list.append(packet)
while self.__analysis_queue:
flattened.extend(self.__analysis_queue.popleft())
# Might be spammy, but I consider this a configuration error, and the user
# should be notified about it.
for skipped_range in result.skipped_ranges:
_LOGGER.warning("skipped bytes in received TCP datastream:")
print(flattened[skipped_range.start : skipped_range.stop])
_LOGGER.warning("list of valid packet IDs might be incomplete")

Check warning on line 160 in src/tmtccmd/com/tcp.py

View check run for this annotation

Codecov / codecov/patch

src/tmtccmd/com/tcp.py#L158-L160

Added lines #L158 - L160 were not covered by tests
self.__analysis_queue.append(flattened[result.scanned_bytes :])
else:
while self.__analysis_queue:
self.tm_packet_list.append(self.__analysis_queue.popleft())
Expand Down

0 comments on commit ac3c7cb

Please sign in to comment.