Commit 63f3bec2 authored by Robin Mueller's avatar Robin Mueller
Browse files

made core more responsive

parent 06778c3a
......@@ -84,7 +84,7 @@ class EthernetComIF(CommunicationInterface):
return True, packet_list
return False, []
def receive_telemetry(self, parameters: any = 0) -> list:
def receive_telemetry(self, parameters: any = 0) -> PusTmListT:
packet_list = []
if self.udp_socket is None:
return packet_list
......
......@@ -4,7 +4,7 @@ import struct
from tmtc_core.pus_tc.tmtcc_pus_tc_base import PusTelecommand
class Subservice(enum.Enum):
class Srv3Subservice(enum.Enum):
ENABLE_PERIODIC_HK_GEN = 5,
DISABLE_PERIODIC_HK_GEN = 6,
ENABLE_PERIODIC_DIAGNOSTICS_GEN = 7,
......
......@@ -159,7 +159,6 @@ class CommandSenderReceiver:
return queue_entry_is_telecommand
if queue_entry_first == QueueCommands.WAIT:
wait_time = queue_entry_second
self._tm_timeout = self._tm_timeout + wait_time
self._wait_period = wait_time
......
......@@ -82,6 +82,10 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver):
self._tm_listener.clear_reply_event()
self.print_tm_queue(self._tm_listener.retrieve_tm_packet_queue())
self._tm_listener.clear_tm_packet_queue()
# This makes reply reception more responsive
elif self._tm_listener.tm_packets_available():
self.print_tm_queue(self._tm_listener.retrieve_tm_packet_queue())
self._tm_listener.clear_tm_packet_queue()
def __check_next_tc_send(self):
if self.wait_period_ongoing():
......
......@@ -100,13 +100,24 @@ class TmListener:
else:
return False
def tm_packets_available(self):
if self.lock_listener.acquire(True, timeout=1):
if self.__tm_packet_queue:
self.lock_listener.release()
return True
self.lock_listener.release()
else:
LOGGER.warning("TmListener: Blocked on lock acquisition for longer than 1 second!")
return False
def retrieve_tm_packet_queue(self) -> PusTmQueueT:
# We make sure that the queue is not manipulated while it is being copied.
if self.lock_listener.acquire(True, timeout=1):
tm_queue_copy = self.__tm_packet_queue.copy()
self.lock_listener.release()
else:
tm_queue_copy = self.__tm_packet_queue.copy()
LOGGER.critical("TmListener: Blocked on lock acquisition for longer than 1 second!")
self.lock_listener.release()
LOGGER.warning("TmListener: Blocked on lock acquisition for longer than 1 second!")
return tm_queue_copy
def clear_tm_packet_queue(self):
......@@ -162,12 +173,14 @@ class TmListener:
"""
packet_list = self.com_interface.receive_telemetry()
if len(packet_list) > 0:
if self.lock_listener.acquire(True, timeout=1):
self.__event_reply_received.set()
self.__event_reply_received.set()
# deque is thread-safe for append and pops from opposite sides but I am not sure copy
# is so we still use a lock here.
if self.lock_listener.acquire(blocking=True, timeout=1.0):
self.__tm_packet_queue.appendleft(packet_list)
self.lock_listener.release()
else:
LOGGER.error("TmListener: Blocked on lock acquisition!")
self.lock_listener.release()
LOGGER.warning("TmListener: Blocked on lock acquisition for longer than 1 second!")
else:
time.sleep(0.4)
......@@ -196,17 +209,19 @@ class TmListener:
"""
start_time = time.time()
elapsed_time = 0
# LOGGER.info("TmListener: Listening for " + str(self.__tm_timeout) + " seconds")
# LOGGER.info(f"TmListener: Listening for {self.__tm_timeout} seconds")
while elapsed_time < self.__tm_timeout:
packets_available = self.com_interface.data_available(0.2)
if packets_available > 0:
tm_list = self.com_interface.receive_telemetry()
# deque should be thread-safe to appends and pops from opposite sides, but
# I am not sure about the copy operation.
if self.lock_listener.acquire(True, timeout=1):
tm_list = self.com_interface.receive_telemetry()
self.__tm_packet_queue.appendleft(tm_list)
self.lock_listener.release()
else:
LOGGER.critical("TmListener: Blocked on lock acquisition for "
"longer than 1 second!")
self.lock_listener.release()
LOGGER.warning("TmListener: Blocked on lock acquisition for longer "
"than 1 second!")
elapsed_time = time.time() - start_time
time.sleep(0.05)
# the timeout value can be set by special TC queue entries if wiretapping_packet handling
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment