From 879a50f79e18b0aa275e57754f7e7cc1a9730221 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Apr 2024 20:35:59 +0200 Subject: [PATCH] pytmtc is a package now --- README.md | 15 +- pytmtc/.gitignore | 133 ++++++++++++++++++ pytmtc/{pus_tm.py => opssat_tmtc/__init__.py} | 0 pytmtc/{ => opssat_tmtc}/camera_params.py | 2 +- pytmtc/{ => opssat_tmtc}/common.py | 0 pytmtc/{ => opssat_tmtc}/pus_tc.py | 4 +- pytmtc/opssat_tmtc/pus_tm.py | 0 pytmtc/{ => opssat_tmtc}/tc_definitions.py | 3 +- pytmtc/pyclient.py | 9 +- pytmtc/pyproject.toml | 26 ++++ pytmtc/requirements.txt | 3 +- pytmtc/{ => tests}/test_serde.py | 4 +- 12 files changed, 184 insertions(+), 15 deletions(-) rename pytmtc/{pus_tm.py => opssat_tmtc/__init__.py} (100%) rename pytmtc/{ => opssat_tmtc}/camera_params.py (81%) rename pytmtc/{ => opssat_tmtc}/common.py (100%) rename pytmtc/{ => opssat_tmtc}/pus_tc.py (98%) create mode 100644 pytmtc/opssat_tmtc/pus_tm.py rename pytmtc/{ => opssat_tmtc}/tc_definitions.py (97%) create mode 100644 pytmtc/pyproject.toml rename pytmtc/{ => tests}/test_serde.py (84%) diff --git a/README.md b/README.md index 492f072..695a444 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,20 @@ Commanding of the `ops-sat-rs` application is possible by different means. ### Using the `pyclient` and `pyserver` applications You can find both commanding application inside the `pytmtc` folder. -You can also find a `requirements.txt` file there to install all required Python dependencies. +It is recommended to set up a virtual environment first, for example by running the following +code inside the `pytmtc` folder: + +```sh +python3 -m venv venv +source venv/bin/activate +``` + +After that, you can install all requirements for both the client and server application +interactively using + +```sh +pip install -e . +``` If you want to command the satellite using the OPS-SAT infrastrucute, start the `pyserver.py` as a background application first, for example by simply running `pyserver.py` inside a diff --git a/pytmtc/.gitignore b/pytmtc/.gitignore index 53b730f..008bdd0 100644 --- a/pytmtc/.gitignore +++ b/pytmtc/.gitignore @@ -8,3 +8,136 @@ __pycache__ /seqcnt.txt /.tmtc-history.txt + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# PyCharm +.idea diff --git a/pytmtc/pus_tm.py b/pytmtc/opssat_tmtc/__init__.py similarity index 100% rename from pytmtc/pus_tm.py rename to pytmtc/opssat_tmtc/__init__.py diff --git a/pytmtc/camera_params.py b/pytmtc/opssat_tmtc/camera_params.py similarity index 81% rename from pytmtc/camera_params.py rename to pytmtc/opssat_tmtc/camera_params.py index aab22b3..34ee2c4 100644 --- a/pytmtc/camera_params.py +++ b/pytmtc/opssat_tmtc/camera_params.py @@ -1,7 +1,7 @@ import struct from serde import Model, fields -from common import EXPERIMENT_APID, UniqueId, make_unique_id +from opssat_tmtc.common import EXPERIMENT_APID, UniqueId, make_unique_id class CameraParameters(Model): diff --git a/pytmtc/common.py b/pytmtc/opssat_tmtc/common.py similarity index 100% rename from pytmtc/common.py rename to pytmtc/opssat_tmtc/common.py diff --git a/pytmtc/pus_tc.py b/pytmtc/opssat_tmtc/pus_tc.py similarity index 98% rename from pytmtc/pus_tc.py rename to pytmtc/opssat_tmtc/pus_tc.py index 104ca74..49bbc71 100644 --- a/pytmtc/pus_tc.py +++ b/pytmtc/opssat_tmtc/pus_tc.py @@ -10,8 +10,8 @@ from tmtccmd.tmtc import DefaultPusQueueHelper from tmtccmd.pus.s11_tc_sched import create_time_tagged_cmd from tmtccmd.pus.s200_fsfw_mode import Subservice as ModeSubservice -from camera_params import CameraParameters -from common import ( +from opssat_tmtc.camera_params import CameraParameters +from opssat_tmtc.common import ( EXPERIMENT_APID, UniqueId, make_action_cmd_header, diff --git a/pytmtc/opssat_tmtc/pus_tm.py b/pytmtc/opssat_tmtc/pus_tm.py new file mode 100644 index 0000000..e69de29 diff --git a/pytmtc/tc_definitions.py b/pytmtc/opssat_tmtc/tc_definitions.py similarity index 97% rename from pytmtc/tc_definitions.py rename to pytmtc/opssat_tmtc/tc_definitions.py index acd2741..435e3e6 100644 --- a/pytmtc/tc_definitions.py +++ b/pytmtc/opssat_tmtc/tc_definitions.py @@ -1,7 +1,7 @@ from tmtccmd.config import OpCodeEntry, TmtcDefinitionWrapper, CoreServiceList from tmtccmd.config.globals import get_default_tmtc_defs -from common import HkOpCodes +from opssat_tmtc.common import HkOpCodes def tc_definitions() -> TmtcDefinitionWrapper: @@ -41,6 +41,5 @@ def tc_definitions() -> TmtcDefinitionWrapper: name=CoreServiceList.SERVICE_8, info="PUS Service 8 Action", op_code_entry=srv_8, - ) return defs diff --git a/pytmtc/pyclient.py b/pytmtc/pyclient.py index 6185390..e21a655 100755 --- a/pytmtc/pyclient.py +++ b/pytmtc/pyclient.py @@ -46,9 +46,8 @@ from tmtccmd.tmtc import ( from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider from tmtccmd.util.obj_id import ObjectIdDictT - -import pus_tc -from common import EXPERIMENT_APID, EventU32 +from opssat_tmtc.pus_tc import create_cmd_definition_tree, pack_pus_telecommands +from opssat_tmtc.common import EXPERIMENT_APID, EventU32 _LOGGER = logging.getLogger() @@ -76,7 +75,7 @@ class SatRsConfigHook(HookBase): def get_command_definitions(self) -> CmdTreeNode: """This function should return the root node of the command definition tree.""" - return pus_tc.create_cmd_definition_tree() + return create_cmd_definition_tree() def get_cmd_history(self) -> Optional[History]: """Optionlly return a history class for the past command paths which will be used @@ -217,7 +216,7 @@ class TcHandler(TcHandlerBase): if info.proc_type == TcProcedureType.TREE_COMMANDING: def_proc = info.to_tree_commanding_procedure() assert def_proc.cmd_path is not None - pus_tc.pack_pus_telecommands(q, def_proc.cmd_path) + pack_pus_telecommands(q, def_proc.cmd_path) def main(): diff --git a/pytmtc/pyproject.toml b/pytmtc/pyproject.toml new file mode 100644 index 0000000..81460b4 --- /dev/null +++ b/pytmtc/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "opssat-tmtc" +description = "Python TMTC client for OPS-SAT" +readme = "README.md" +version = "0.1.0" +requires-python = ">=3.8" +authors = [ + {name = "Robin Mueller", email = "robin.mueller.m@gmail.com"}, + {name = "Linus Köster", email = "st167799@stud.uni-stuttgart.de"} +] +dependencies = [ + "tmtccmd==8.0.0rc.2", + "serde==0.9.0" +] + +[tool.setuptools.packages] +find = {} + +[tool.ruff.lint] +ignore = ["E501"] +[tool.ruff.lint.extend-per-file-ignores] +"__init__.py" = ["F401"] diff --git a/pytmtc/requirements.txt b/pytmtc/requirements.txt index 1e072a2..3629228 100644 --- a/pytmtc/requirements.txt +++ b/pytmtc/requirements.txt @@ -1,3 +1,2 @@ -tmtccmd == 8.0.0rc2 -serde == 0.9.0 +. # -e git+https://github.com/robamu-org/tmtccmd@97e5e51101a08b21472b3ddecc2063359f7e307a#egg=tmtccmd diff --git a/pytmtc/test_serde.py b/pytmtc/tests/test_serde.py similarity index 84% rename from pytmtc/test_serde.py rename to pytmtc/tests/test_serde.py index 35b7c07..010f979 100644 --- a/pytmtc/test_serde.py +++ b/pytmtc/tests/test_serde.py @@ -1,6 +1,6 @@ import struct -from camera_params import CameraParameters -from common import make_unique_id, EXPERIMENT_APID +from opssat_tmtc.camera_params import CameraParameters +from opssat_tmtc.common import make_unique_id, EXPERIMENT_APID def test_serde_serialization():