clean up python code a bit #18

Merged
muellerr merged 3 commits from some-python-client-cleanup into main 2024-04-24 20:41:03 +02:00
12 changed files with 184 additions and 15 deletions
Showing only changes of commit 879a50f79e - Show all commits

View File

@ -55,7 +55,20 @@ Commanding of the `ops-sat-rs` application is possible by different means.
### Using the `pyclient` and `pyserver` applications ### Using the `pyclient` and `pyserver` applications
You can find both commanding application inside the `pytmtc` folder. 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` 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 as a background application first, for example by simply running `pyserver.py` inside a

133
pytmtc/.gitignore vendored
View File

@ -8,3 +8,136 @@ __pycache__
/seqcnt.txt /seqcnt.txt
/.tmtc-history.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

View File

@ -1,7 +1,7 @@
import struct import struct
from serde import Model, fields 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): class CameraParameters(Model):

View File

@ -10,8 +10,8 @@ from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.pus.s11_tc_sched import create_time_tagged_cmd from tmtccmd.pus.s11_tc_sched import create_time_tagged_cmd
from tmtccmd.pus.s200_fsfw_mode import Subservice as ModeSubservice from tmtccmd.pus.s200_fsfw_mode import Subservice as ModeSubservice
from camera_params import CameraParameters from opssat_tmtc.camera_params import CameraParameters
from common import ( from opssat_tmtc.common import (
EXPERIMENT_APID, EXPERIMENT_APID,
UniqueId, UniqueId,
make_action_cmd_header, make_action_cmd_header,

View File

View File

@ -1,7 +1,7 @@
from tmtccmd.config import OpCodeEntry, TmtcDefinitionWrapper, CoreServiceList from tmtccmd.config import OpCodeEntry, TmtcDefinitionWrapper, CoreServiceList
from tmtccmd.config.globals import get_default_tmtc_defs from tmtccmd.config.globals import get_default_tmtc_defs
from common import HkOpCodes from opssat_tmtc.common import HkOpCodes
def tc_definitions() -> TmtcDefinitionWrapper: def tc_definitions() -> TmtcDefinitionWrapper:
@ -41,6 +41,5 @@ def tc_definitions() -> TmtcDefinitionWrapper:
name=CoreServiceList.SERVICE_8, name=CoreServiceList.SERVICE_8,
info="PUS Service 8 Action", info="PUS Service 8 Action",
op_code_entry=srv_8, op_code_entry=srv_8,
) )
return defs return defs

View File

@ -46,9 +46,8 @@ from tmtccmd.tmtc import (
from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider
from tmtccmd.util.obj_id import ObjectIdDictT from tmtccmd.util.obj_id import ObjectIdDictT
from opssat_tmtc.pus_tc import create_cmd_definition_tree, pack_pus_telecommands
import pus_tc from opssat_tmtc.common import EXPERIMENT_APID, EventU32
from common import EXPERIMENT_APID, EventU32
_LOGGER = logging.getLogger() _LOGGER = logging.getLogger()
@ -76,7 +75,7 @@ class SatRsConfigHook(HookBase):
def get_command_definitions(self) -> CmdTreeNode: def get_command_definitions(self) -> CmdTreeNode:
"""This function should return the root node of the command definition tree.""" """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]: def get_cmd_history(self) -> Optional[History]:
"""Optionlly return a history class for the past command paths which will be used """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: if info.proc_type == TcProcedureType.TREE_COMMANDING:
def_proc = info.to_tree_commanding_procedure() def_proc = info.to_tree_commanding_procedure()
assert def_proc.cmd_path is not None 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(): def main():

26
pytmtc/pyproject.toml Normal file
View File

@ -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"]

View File

@ -1,3 +1,2 @@
tmtccmd == 8.0.0rc2 .
serde == 0.9.0
# -e git+https://github.com/robamu-org/tmtccmd@97e5e51101a08b21472b3ddecc2063359f7e307a#egg=tmtccmd # -e git+https://github.com/robamu-org/tmtccmd@97e5e51101a08b21472b3ddecc2063359f7e307a#egg=tmtccmd

View File

@ -1,6 +1,6 @@
import struct import struct
from camera_params import CameraParameters from opssat_tmtc.camera_params import CameraParameters
from common import make_unique_id, EXPERIMENT_APID from opssat_tmtc.common import make_unique_id, EXPERIMENT_APID
def test_serde_serialization(): def test_serde_serialization():