Skip to content

Commit

Permalink
pytmtc as regular package now
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed May 9, 2024
1 parent 4a8db6b commit 783388a
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 62 deletions.
5 changes: 3 additions & 2 deletions satrs-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ It is recommended to use a virtual environment to do this. To set up one in the
you can use `python3 -m venv venv` on Unix systems or `py -m venv venv` on Windows systems.
After doing this, you can check the [venv tutorial](https://docs.python.org/3/tutorial/venv.html)
on how to activate the environment and then use the following command to install the required
dependency:
dependency interactively:

```sh
pip install -r requirements.txt
pip install -e .
```

Alternatively, if you would like to use the GUI functionality provided by `tmtccmd`, you can also
install it manually with

```sh
pip install -e .
pip install tmtccmd[gui]
```

Expand Down
134 changes: 134 additions & 0 deletions satrs-example/pytmtc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/tmtc_conf.json
__pycache__

/venv
Expand All @@ -7,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
8 changes: 4 additions & 4 deletions satrs-example/pytmtc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
from tmtccmd.util.obj_id import ObjectIdDictT


import pus_tc
from common import Apid, EventU32
from pytmtc.pus_tc import pack_pus_telecommands, create_cmd_definition_tree
from pytmtc.common import Apid, EventU32

_LOGGER = logging.getLogger()

Expand Down Expand Up @@ -76,7 +76,7 @@ def get_communication_interface(self, com_if_key: str) -> Optional[ComInterface]

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
Expand Down Expand Up @@ -213,7 +213,7 @@ def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
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():
Expand Down
27 changes: 27 additions & 0 deletions satrs-example/pytmtc/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pytmtc"
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"},
]
dependencies = [
"tmtccmd~=8.0",
"pydantic~=2.7"
]

[tool.setuptools.packages]
find = {}

[tool.ruff]
extend-exclude = ["archive"]
[tool.ruff.lint]
ignore = ["E501"]
[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["F401"]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,11 @@
from tmtccmd.pus.s11_tc_sched import create_time_tagged_cmd
from tmtccmd.pus.s200_fsfw_mode import Subservice as ModeSubservice

from common import AcsId, Apid
from pytmtc.common import AcsId, Apid

_LOGGER = logging.getLogger(__name__)


def create_set_mode_cmd(
apid: int, unique_id: int, mode: int, submode: int
) -> PusTelecommand:
app_data = bytearray()
app_data.extend(struct.pack("!I", unique_id))
app_data.extend(struct.pack("!I", mode))
app_data.extend(struct.pack("!H", submode))
return PusTelecommand(
service=200,
subservice=ModeSubservice.TC_MODE_COMMAND,
apid=apid,
app_data=app_data,
)


def create_cmd_definition_tree() -> CmdTreeNode:

root_node = CmdTreeNode.root_node()
Expand Down Expand Up @@ -77,6 +62,21 @@ def create_cmd_definition_tree() -> CmdTreeNode:
return root_node


def create_set_mode_cmd(
apid: int, unique_id: int, mode: int, submode: int
) -> PusTelecommand:
app_data = bytearray()
app_data.extend(struct.pack("!I", unique_id))
app_data.extend(struct.pack("!I", mode))
app_data.extend(struct.pack("!H", submode))
return PusTelecommand(
service=200,
subservice=ModeSubservice.TC_MODE_COMMAND,
apid=apid,
app_data=app_data,
)


def pack_pus_telecommands(q: DefaultPusQueueHelper, cmd_path: str):
# It should always be at least the root path "/", so we split of the empty portion left of it.
cmd_path_list = cmd_path.split("/")[1:]
Expand Down
Empty file.
3 changes: 1 addition & 2 deletions satrs-example/pytmtc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
tmtccmd == 8.0.0rc2
# -e git+https://github.com/robamu-org/tmtccmd@97e5e51101a08b21472b3ddecc2063359f7e307a#egg=tmtccmd
.
38 changes: 0 additions & 38 deletions satrs-example/pytmtc/tc_definitions.py

This file was deleted.

0 comments on commit 783388a

Please sign in to comment.