Skip to content
Snippets Groups Projects
Commit c6cd2e42 authored by Robin Mueller's avatar Robin Mueller
Browse files

improved code

parent bc709025
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,9 @@ def set_communication_interface(tmtc_printer: TmTcPrinter) -> CommunicationInter
tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR)
else:
communication_interface = DummyComIF(tmtc_printer=tmtc_printer)
if not communication_interface.valid:
LOGGER.warning("Invalid communication interface!")
return None
return communication_interface
except (IOError, OSError):
LOGGER.error("Error setting up communication interface")
......
......@@ -24,6 +24,7 @@ class CommunicationInterface:
"""
def __init__(self, tmtc_printer: TmTcPrinter):
self.tmtc_printer = tmtc_printer
self.valid = False
@abstractmethod
def close(self) -> None:
......
......@@ -49,8 +49,10 @@ class SerialComIF(CommunicationInterface):
super().__init__(tmtc_printer)
try:
self.serial = serial.Serial(port=com_port, baudrate=baud_rate, timeout=serial_timeout)
except serial.SerialException as error:
LOGGER.exception("Serial Port could not be closed! Traceback: %s", str(error))
self.valid = True
except serial.SerialException:
LOGGER.error("Serial Port opening failure!")
self.valid = False
self.data = bytearray()
self.ser_com_type = ser_com_type
if self.ser_com_type == SerialCommunicationType.FIXED_FRAME_BASED:
......
......@@ -141,12 +141,21 @@ class TmTcHandler:
# This flag could be used later to command the TMTC Client with a front-end
self.command_received = True
self.tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True)
self.communication_interface = None
self.tm_listener = None
self.initialize_com_if_and_listener()
atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface)
def initialize_com_if_and_listener(self):
self.communication_interface = set_communication_interface(self.tmtc_printer)
if self.communication_interface is None:
LOGGER.info("No communication interface set for now")
LOGGER.info("TM listener will not be started")
return
self.tm_listener = TmListener(
com_interface=self.communication_interface, tm_timeout=g.G_TM_TIMEOUT,
tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR
)
atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface)
self.tm_listener.start()
def perform_operation(self):
......@@ -169,8 +178,7 @@ class TmTcHandler:
Command handling.
"""
if self.mode == g.ModeList.ListenerMode:
if self.tm_listener.event_reply_received:
# TODO: Test this.
if self.tm_listener.event_reply_received.is_set():
LOGGER.info("TmTcHandler: Packets received.")
self.tmtc_printer.print_telemetry_queue(self.tm_listener.retrieve_tm_packet_queue())
self.command_received = True
......@@ -206,6 +214,7 @@ class TmTcHandler:
# mode
perform_binary_upload()
self.command_received = True
self.prompt_mode()
elif self.mode == g.ModeList.UnitTest:
# Set up test suite and run it with runner. Verbosity specifies detail level
......@@ -221,6 +230,22 @@ class TmTcHandler:
logging.error("Unknown Mode, Configuration error !")
sys.exit()
def prompt_mode(self):
next_mode = input("Please enter next mode (enter h for list of modes): ")
if next_mode == 'h':
print("Mode 0: GUI mode")
print("Mode 1: Listener mode")
print("Mode 2: Single Command mode")
print("Mode 3: Service mode")
print("Mode 4: Software mode")
print("Mode 5: Binary upload mode")
print("Mode 5: Module test mode")
self.prompt_mode()
elif next_mode == 1:
self.mode = g.ModeList.ListenerMode
else:
self.mode = g.ModeList.ListenerMode
if __name__ == "__main__":
main()
......@@ -9,6 +9,7 @@ from enum import Enum
# Yeah, I did not have a better idea yet..
# Next step would be a configuration file
# Or extracting the core into a separate repository to decouple the custom code from the core code
class Developer(Enum):
Robin = 0
......
......@@ -6,7 +6,13 @@ This module will be used to upload binaries to the OBC via a communication port,
a supplied binary. The binary will be sent via the specified communication interface.
It will be possible to encode the data (for example using DLE encoding)
"""
import tkinter as tk
from tkinter import filedialog
def perform_binary_upload():
print("Test!")
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
print(file_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment