From 1464b32e2dcc7f9fe4e0f1633a80d63e30b0296b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 16 May 2022 18:35:36 +0200 Subject: [PATCH 1/4] started new daemonic tmtc app --- config/definitions.py | 1 + config/hook_implementations.py | 3 +- deamon.py | 55 ++++++++++++++++++++++++++++++++++ pus_tc/tc_packer_hook.py | 4 ++- tmtccmd | 2 +- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 deamon.py diff --git a/config/definitions.py b/config/definitions.py index d6a75f9..53a8970 100644 --- a/config/definitions.py +++ b/config/definitions.py @@ -8,6 +8,7 @@ import enum PUS_APID = 0x65 +SPACE_PACKET_IDS = (0x08 << 8 | PUS_APID,) class CustomServiceList(enum.Enum): diff --git a/config/hook_implementations.py b/config/hook_implementations.py index bbc88ea..8c843ca 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -1,5 +1,6 @@ from typing import Union +from config.definitions import SPACE_PACKET_IDS from tmtccmd.config.definitions import ( ServiceOpCodeDictT, ) @@ -33,7 +34,7 @@ class EiveHookObject(TmTcHookBase): return create_communication_interface_default( com_if_key=com_if_key, json_cfg_path=self.json_cfg_path, - space_packet_ids=(0x0865,), + space_packet_ids=SPACE_PACKET_IDS, ) def perform_mode_operation(self, tmtc_backend: TmTcHandler, mode: int): diff --git a/deamon.py b/deamon.py new file mode 100644 index 0000000..99b42ea --- /dev/null +++ b/deamon.py @@ -0,0 +1,55 @@ +import sys +import traceback + +try: + import tmtccmd.runner as tmtccmd + from tmtccmd.config import default_json_path, SetupArgs + from tmtccmd.config.args import ( + create_default_args_parser, + add_default_tmtccmd_args, + parse_default_input_arguments, + ) + from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler + from tmtccmd.logging import init_console_logger + from tmtccmd.logging.pus import create_tmtc_logger +except ImportError as error: + run_tmtc_commander = None + initialize_tmtc_commander = None + tb = traceback.format_exc() + print(tb) + print("Python tmtccmd submodule could not be imported") + sys.exit(1) + +try: + import spacepackets +except ImportError as error: + print(error) + print("Python spacepackets module could not be imported") + print( + 'Install with "cd spacepackets && python3 -m pip intall -e ." for interative installation' + ) + sys.exit(1) + +from config.version import __version__ +from config.definitions import SPACE_PACKET_IDS +from tmtccmd.sendreceive.tm_listener import TmListener +from tmtccmd.com_if.tcpip_utilities import determine_tcpip_address +from tmtccmd.com_if.tcpip_tcp_com_if import TcpIpTcpComIF, TcpCommunicationType + + +def main(): + print(f"-- eive tmtc version {__version__} --") + print(f"-- spacepackets version {spacepackets.__version__} --") + com_if = TcpIpTcpComIF( + com_if_key="tcp", + com_type=TcpCommunicationType.SPACE_PACKETS, + space_packet_ids=SPACE_PACKET_IDS, + tm_polling_freqency=0.5, + max_recv_size=1500, + target_address=("localhost", 1536), + ) + tm_listener = TmListener(com_if=com_if, tm_timeout=2.0, tc_timeout_factor=2.0) + + +if __name__ == "__main__": + main() diff --git a/pus_tc/tc_packer_hook.py b/pus_tc/tc_packer_hook.py index e999f59..15f9ed2 100644 --- a/pus_tc/tc_packer_hook.py +++ b/pus_tc/tc_packer_hook.py @@ -83,7 +83,8 @@ def pre_tc_send_cb( ): if isinstance(queue_entry, bytes) or isinstance(queue_entry, bytearray): log_raw_pus_tc( - packet=queue_entry, srv_subservice=(queue_info.service, queue_info.subservice) + packet=queue_entry, + srv_subservice=(queue_info.service, queue_info.subservice), ) tc_info_string = f"Sent {queue_info}" LOGGER.info(tc_info_string) @@ -93,6 +94,7 @@ def pre_tc_send_cb( if queue_entry == QueueCommands.PRINT: file_logger.info(queue_info) + def pack_service_queue_user( service: Union[str, int], op_code: str, service_queue: TcQueueT ): diff --git a/tmtccmd b/tmtccmd index d503c8b..f3b6150 160000 --- a/tmtccmd +++ b/tmtccmd @@ -1 +1 @@ -Subproject commit d503c8b8a95d107f482880a8ba692fdd8d46adbc +Subproject commit f3b6150d9c4ebf5d01b07f3642a36744580c12ef -- 2.43.0 From 4b7529d5b74ad2b6dfa01243266c3adeb583afa6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 17 May 2022 11:13:32 +0200 Subject: [PATCH 2/4] simplified cli and gui app --- config/__init__.py | 6 ++++ config/hook_implementations.py | 6 +--- config/version.py | 6 ---- deamon.py | 5 ++- pus_tc/cmd_definitions.py | 5 ++- pus_tc/service_200_mode.py | 1 - pus_tm/hk_handling.py | 3 +- tmtcc.py | 63 ++++++++++++++++++++++++++++++++++ tmtccli.py | 60 +++----------------------------- tmtccmd | 2 +- tmtcgui.py | 39 +++------------------ 11 files changed, 86 insertions(+), 110 deletions(-) delete mode 100644 config/version.py create mode 100644 tmtcc.py diff --git a/config/__init__.py b/config/__init__.py index e69de29..56db5af 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -0,0 +1,6 @@ +SW_NAME = "eive" +VERSION_MAJOR = 1 +VERSION_MINOR = 9 +VERSION_SUBMINOR = 0 + +__version__ = "1.9.0" diff --git a/config/hook_implementations.py b/config/hook_implementations.py index 8c843ca..bf6a715 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -20,11 +20,7 @@ class EiveHookObject(TmTcHookBase): super().__init__(json_cfg_path=json_cfg_path) def get_service_op_code_dictionary(self) -> ServiceOpCodeDictT: - from tmtccmd.config.globals import get_default_service_op_code_dict - - service_op_code_dict = get_default_service_op_code_dict() - get_eive_service_op_code_dict(service_op_code_dict=service_op_code_dict) - return service_op_code_dict + return get_eive_service_op_code_dict() def assign_communication_interface( self, com_if_key: str diff --git a/config/version.py b/config/version.py deleted file mode 100644 index 56db5af..0000000 --- a/config/version.py +++ /dev/null @@ -1,6 +0,0 @@ -SW_NAME = "eive" -VERSION_MAJOR = 1 -VERSION_MINOR = 9 -VERSION_SUBMINOR = 0 - -__version__ = "1.9.0" diff --git a/deamon.py b/deamon.py index 99b42ea..e4bd331 100644 --- a/deamon.py +++ b/deamon.py @@ -30,10 +30,9 @@ except ImportError as error: ) sys.exit(1) -from config.version import __version__ +from config import __version__ from config.definitions import SPACE_PACKET_IDS from tmtccmd.sendreceive.tm_listener import TmListener -from tmtccmd.com_if.tcpip_utilities import determine_tcpip_address from tmtccmd.com_if.tcpip_tcp_com_if import TcpIpTcpComIF, TcpCommunicationType @@ -48,7 +47,7 @@ def main(): max_recv_size=1500, target_address=("localhost", 1536), ) - tm_listener = TmListener(com_if=com_if, tm_timeout=2.0, tc_timeout_factor=2.0) + tm_listener = TmListener(com_if=com_if, seq_timeout=2.0) if __name__ == "__main__": diff --git a/pus_tc/cmd_definitions.py b/pus_tc/cmd_definitions.py index 3db7e9d..08c6041 100644 --- a/pus_tc/cmd_definitions.py +++ b/pus_tc/cmd_definitions.py @@ -12,7 +12,9 @@ from pus_tc.devs.reaction_wheels import add_rw_cmds from pus_tc.devs.bpx_batt import BpxOpCodes -def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): +def get_eive_service_op_code_dict() -> ServiceOpCodeDictT: + from tmtccmd.config.globals import get_default_service_op_code_dict + service_op_code_dict = get_default_service_op_code_dict() add_bpx_cmd_definitions(cmd_dict=service_op_code_dict) add_core_controller_definitions(cmd_dict=service_op_code_dict) add_pl_pcdu_cmds(cmd_dict=service_op_code_dict) @@ -31,6 +33,7 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): add_pdec_cmds(cmd_dict=service_op_code_dict) add_heater_cmds(cmd_dict=service_op_code_dict) add_tmp_sens_cmds(cmd_dict=service_op_code_dict) + return service_op_code_dict def add_tmp_sens_cmds(cmd_dict: ServiceOpCodeDictT): diff --git a/pus_tc/service_200_mode.py b/pus_tc/service_200_mode.py index 345012f..1f046e7 100644 --- a/pus_tc/service_200_mode.py +++ b/pus_tc/service_200_mode.py @@ -38,5 +38,4 @@ def pack_service200_test_into(tc_queue: TcQueueT) -> TcQueueT: mode_data = pack_mode_data(obj_id, Modes.OFF, 0) command = PusTelecommand(service=200, subservice=1, ssc=2030, app_data=mode_data) tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.EXPORT_LOG, "log/tmtc_log_service200.txt")) return tc_queue diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index 4dd3d25..399ec5c 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -3,7 +3,6 @@ import struct import os import datetime -from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter from tmtccmd.config.definitions import HkReplyUnpacked from tmtccmd.tm.pus_3_fsfw_hk import ( Service3Base, @@ -19,7 +18,7 @@ from tmtccmd.utility.obj_id import ObjectId, ObjectIdDictT import config.object_ids as obj_ids from pus_tm.devs.reaction_wheels import handle_rw_hk_data -from pus_tm.defs import PrintWrapper, FsfwTmTcPrinter, log_to_both +from pus_tm.defs import FsfwTmTcPrinter, log_to_both LOGGER = get_console_logger() diff --git a/tmtcc.py b/tmtcc.py new file mode 100644 index 0000000..0dc37b3 --- /dev/null +++ b/tmtcc.py @@ -0,0 +1,63 @@ +import argparse +import sys +import traceback +from typing import Optional + +try: + import spacepackets +except ImportError as error: + print(error) + print("Python spacepackets module could not be imported") + print( + 'Install with "cd spacepackets && python3 -m pip intall -e ." for interative installation' + ) + sys.exit(1) + +try: + import tmtccmd.runner as tmtccmd + from tmtccmd.logging.pus import create_tmtc_logger + from tmtccmd.ccsds.handler import ApidHandler, CcsdsTmHandler + from tmtccmd.config import SetupArgs, default_json_path + from tmtccmd.config.args import ( + create_default_args_parser, + add_default_tmtccmd_args, + parse_default_input_arguments, + ) +except ImportError as error: + run_tmtc_commander = None + initialize_tmtc_commander = None + tb = traceback.format_exc() + print(tb) + print("Python tmtccmd submodule could not be imported") + sys.exit(1) + +from config import __version__ +from config.definitions import PUS_APID +from config.hook_implementations import EiveHookObject +from pus_tm.factory_hook import ccsds_tm_handler +from pus_tc.tc_packer_hook import pre_tc_send_cb + + +def tmtcc_pre_args() -> EiveHookObject: + print(f"-- eive tmtc v{__version__} --") + print(f"-- spacepackets v{spacepackets.__version__} --") + tmtccmd.init_printout(False) + return EiveHookObject(json_cfg_path=default_json_path()) + + +def tmtcc_post_args(hook_obj: EiveHookObject, use_gui: bool, args: Optional[argparse.Namespace]): + setup_args = SetupArgs( + hook_obj=hook_obj, use_gui=use_gui, apid=PUS_APID, cli_args=args + ) + tmtc_file_logger = create_tmtc_logger() + apid_handler = ApidHandler(cb=ccsds_tm_handler, queue_len=50, user_args=None) + ccsds_handler = CcsdsTmHandler() + ccsds_handler.add_tm_handler(apid=PUS_APID, handler=apid_handler) + tmtccmd.setup(setup_args=setup_args) + tmtccmd.add_ccsds_handler(ccsds_handler) + tmtc_backend = tmtccmd.create_default_tmtc_backend( + setup_args=setup_args, + tm_handler=ccsds_handler, + ) + tmtc_backend.usr_send_wrapper = (pre_tc_send_cb, tmtc_file_logger) + tmtccmd.run(tmtc_backend=tmtc_backend) diff --git a/tmtccli.py b/tmtccli.py index c80e4ac..4db046c 100755 --- a/tmtccli.py +++ b/tmtccli.py @@ -26,68 +26,16 @@ limitations under the License. @author R. Mueller """ -import sys -import traceback - -try: - import tmtccmd.runner as tmtccmd - from tmtccmd.config import default_json_path, SetupArgs - from tmtccmd.config.args import ( - create_default_args_parser, - add_default_tmtccmd_args, - parse_default_input_arguments, - ) - from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler - from tmtccmd.logging import init_console_logger - from tmtccmd.logging.pus import create_tmtc_logger -except ImportError as error: - run_tmtc_commander = None - initialize_tmtc_commander = None - tb = traceback.format_exc() - print(tb) - print("Python tmtccmd submodule could not be imported") - sys.exit(1) - -try: - import spacepackets -except ImportError as error: - print(error) - print("Python spacepackets module could not be imported") - print( - 'Install with "cd spacepackets && python3 -m pip intall -e ." for interative installation' - ) - sys.exit(1) - -from config.hook_implementations import EiveHookObject -from config.version import __version__ -from config.definitions import PUS_APID -from pus_tc.tc_packer_hook import pre_tc_send_cb -from pus_tm.factory_hook import ccsds_tm_handler +from tmtcc import tmtcc_post_args, tmtcc_pre_args, create_default_args_parser, \ + add_default_tmtccmd_args, parse_default_input_arguments def main(): - print(f"-- eive tmtc version {__version__} --") - print(f"-- spacepackets version {spacepackets.__version__} --") - tmtccmd.init_printout(False) - tmtc_file_logger = create_tmtc_logger() - hook_obj = EiveHookObject(json_cfg_path=default_json_path()) + hook_obj = tmtcc_pre_args() arg_parser = create_default_args_parser() add_default_tmtccmd_args(arg_parser) args = parse_default_input_arguments(arg_parser, hook_obj) - setup_args = SetupArgs( - hook_obj=hook_obj, use_gui=False, apid=PUS_APID, cli_args=args - ) - apid_handler = ApidHandler(cb=ccsds_tm_handler, queue_len=50, user_args=None) - ccsds_handler = CcsdsTmHandler() - ccsds_handler.add_tm_handler(apid=PUS_APID, handler=apid_handler) - tmtccmd.setup(setup_args=setup_args) - tmtccmd.add_ccsds_handler(ccsds_handler) - tmtc_backend = tmtccmd.create_default_tmtc_backend( - setup_args=setup_args, - tm_handler=ccsds_handler, - ) - tmtc_backend.usr_send_wrapper = (pre_tc_send_cb, tmtc_file_logger) - tmtccmd.run(tmtc_backend=tmtc_backend) + tmtcc_post_args(hook_obj=hook_obj, use_gui=False, args=args) if __name__ == "__main__": diff --git a/tmtccmd b/tmtccmd index f3b6150..b08fed4 160000 --- a/tmtccmd +++ b/tmtccmd @@ -1 +1 @@ -Subproject commit f3b6150d9c4ebf5d01b07f3642a36744580c12ef +Subproject commit b08fed474541d2295548e0c3dd8590987f6d3ec1 diff --git a/tmtcgui.py b/tmtcgui.py index 16759bc..2ac20d3 100755 --- a/tmtcgui.py +++ b/tmtcgui.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 """ @brief TMTC Commander entry point for command line mode. @details @@ -26,43 +26,12 @@ limitations under the License. @author R. Mueller """ -import sys - -from config.hook_implementations import EiveHookObject -from config.version import __version__ -from config.definitions import PUS_APID -from pus_tm.factory_hook import ccsds_tm_handler - -try: - from tmtccmd.runner import ( - init_tmtccmd, - run_tmtccmd, - add_ccsds_handler, - ) - from tmtccmd.ccsds.handler import CcsdsTmHandler - import spacepackets -except ImportError as error: - run_tmtc_commander = None - initialize_tmtc_commander = None - print(error) - print("Python tmtccmd submodule could not be imported") - print( - 'Install with "cd tmtccmd && python3 -m pip install -e ." for interactive installation' - ) - sys.exit(0) +from tmtcc import tmtcc_post_args, tmtcc_pre_args def main(): - hook_obj = EiveHookObject() - print(f"-- eive tmtc version {__version__}") - print(f"-- spacepackets version {spacepackets.__version__} --") - init_tmtccmd(hook_object=hook_obj) - ccsds_handler = CcsdsTmHandler() - ccsds_handler.add_tm_handler( - apid=PUS_APID, pus_tm_handler=ccsds_tm_handler, max_queue_len=50 - ) - add_ccsds_handler(ccsds_handler) - run_tmtccmd(use_gui=True) + hook_obj = tmtcc_pre_args() + tmtcc_post_args(hook_obj=hook_obj, use_gui=True, args=None) if __name__ == "__main__": -- 2.43.0 From 1cd6f2a6511c824067ae856d41beb995ebc5e239 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 17 May 2022 11:18:20 +0200 Subject: [PATCH 3/4] delete the daemon --- deamon.py | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 deamon.py diff --git a/deamon.py b/deamon.py deleted file mode 100644 index e4bd331..0000000 --- a/deamon.py +++ /dev/null @@ -1,54 +0,0 @@ -import sys -import traceback - -try: - import tmtccmd.runner as tmtccmd - from tmtccmd.config import default_json_path, SetupArgs - from tmtccmd.config.args import ( - create_default_args_parser, - add_default_tmtccmd_args, - parse_default_input_arguments, - ) - from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler - from tmtccmd.logging import init_console_logger - from tmtccmd.logging.pus import create_tmtc_logger -except ImportError as error: - run_tmtc_commander = None - initialize_tmtc_commander = None - tb = traceback.format_exc() - print(tb) - print("Python tmtccmd submodule could not be imported") - sys.exit(1) - -try: - import spacepackets -except ImportError as error: - print(error) - print("Python spacepackets module could not be imported") - print( - 'Install with "cd spacepackets && python3 -m pip intall -e ." for interative installation' - ) - sys.exit(1) - -from config import __version__ -from config.definitions import SPACE_PACKET_IDS -from tmtccmd.sendreceive.tm_listener import TmListener -from tmtccmd.com_if.tcpip_tcp_com_if import TcpIpTcpComIF, TcpCommunicationType - - -def main(): - print(f"-- eive tmtc version {__version__} --") - print(f"-- spacepackets version {spacepackets.__version__} --") - com_if = TcpIpTcpComIF( - com_if_key="tcp", - com_type=TcpCommunicationType.SPACE_PACKETS, - space_packet_ids=SPACE_PACKET_IDS, - tm_polling_freqency=0.5, - max_recv_size=1500, - target_address=("localhost", 1536), - ) - tm_listener = TmListener(com_if=com_if, seq_timeout=2.0) - - -if __name__ == "__main__": - main() -- 2.43.0 From b1f96d8a9df3ec65447e5d8518a353e5c6fe8717 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 17 May 2022 11:40:52 +0200 Subject: [PATCH 4/4] reduce comment block --- tmtccli.py | 28 +--------------------------- tmtcgui.py | 28 +--------------------------- 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/tmtccli.py b/tmtccli.py index 4db046c..3541bd4 100755 --- a/tmtccli.py +++ b/tmtccli.py @@ -1,31 +1,5 @@ #!/usr/bin/env python3 -""" -@brief TMTC Commander entry point for command line mode. -@details -This client was developed by KSat for the SOURCE project to test the on-board software but -has evolved into a more generic tool for satellite developers to perform TMTC (Telemetry and Telecommand) -handling and testing via different communication interfaces. Currently, only the PUS standard is -implemented as a packet standard. - -Run this file with the -h flag to display options. - -@license -Copyright 2020 KSat e.V. Stuttgart - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -@author R. Mueller -""" +"""TMTC commander for EIVE""" from tmtcc import tmtcc_post_args, tmtcc_pre_args, create_default_args_parser, \ add_default_tmtccmd_args, parse_default_input_arguments diff --git a/tmtcgui.py b/tmtcgui.py index 2ac20d3..6c8a1fd 100755 --- a/tmtcgui.py +++ b/tmtcgui.py @@ -1,31 +1,5 @@ #!/usr/bin/env python3 -""" -@brief TMTC Commander entry point for command line mode. -@details -This client was developed by KSat for the SOURCE project to test the on-board software but -has evolved into a more generic tool for satellite developers to perform TMTC (Telemetry and Telecommand) -handling and testing via different communication interfaces. Currently, only the PUS standard is -implemented as a packet standard. - -Run this file with the -h flag to display options. - -@license -Copyright 2020 KSat e.V. Stuttgart - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -@author R. Mueller -""" +"""TMTC commander for EIVE""" from tmtcc import tmtcc_post_args, tmtcc_pre_args -- 2.43.0