Skip to content

Commit

Permalink
Merge pull request #59 from robamu-org/eive
Browse files Browse the repository at this point in the history
Major tmtccmd overhaul
  • Loading branch information
robamu committed Apr 6, 2022
2 parents 5ebc16a + 1aa9de8 commit eed581e
Show file tree
Hide file tree
Showing 71 changed files with 1,065 additions and 1,439 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -11,8 +11,7 @@ build
# Python egg metadata, regenerated from source files by setuptools.
*.egg-info

/example/log
/example/tmtc_config.json
/examples/log
/src/log
/src/tests/log

Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.md
Expand Up @@ -9,13 +9,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [v1.14.0]

### Changed

- Improve core API: Changes core functions to setup and run. Requirement to user to create backend.
Makes it easier to directly configure the backend and move to a generally more pythonic API
- Refactoring and extending file logging functionalities
- Exposes functions to create a raw PUS logger and a TMTC logger
- Refactor modules to move packet printout and logging to user level
- Simplified hook object, removed 2 static PUS handlers
- Updated CCSDS Handler to make it more easily extensible by creating a new ApidHandler class
- New Pre-Send Callback which is called by backend before sending each telecommand

### Added

- Parsing functions to parse the CSV files generated by the FSFW generators.
Includes event, object ID and returnvalue files. These parsing functions
generatre dictionaries.
generate dictionaries.
- New function in Hook base to return return value dictionary
- Service 1 Failure Handler in TMTC printer

## [v1.13.1]

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -35,14 +35,14 @@ It can be run like this on Linux

```sh
cd example
./tmtc_cli.py
./tmtccli.py
```

or on Windows

```sh
cd example
py tmtc_cli.py
py tmtccli.py
```

The [SOURCE](https://git.ksat-stuttgart.de/source/tmtc) implementation of the TMTC commander
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
@@ -0,0 +1 @@
/log
3 changes: 2 additions & 1 deletion docs/api.rst
Expand Up @@ -46,4 +46,5 @@ Other Submodules
.. toctree::
:maxdepth: 4

api/tmtccmd.utility
api/tmtccmd.utility
api/tmtccmd.logging
13 changes: 13 additions & 0 deletions docs/api/tmtccmd.logging.rst
@@ -0,0 +1,13 @@
tmtccmd.logging package
=======================

Submodules
----------

tmtccmd.logging.pus
------------------------------------

.. automodule:: tmtccmd.logging.pus
:members:
:undoc-members:
:show-inheritance:
8 changes: 0 additions & 8 deletions docs/api/tmtccmd.utility.rst
Expand Up @@ -28,14 +28,6 @@ tmtccmd.utility.json\_handler module
:undoc-members:
:show-inheritance:

tmtccmd.utility.logger module
-----------------------------

.. automodule:: tmtccmd.utility.logger
:members:
:undoc-members:
:show-inheritance:

tmtccmd.utility.tmtc\_printer module
------------------------------------

Expand Down
78 changes: 53 additions & 25 deletions docs/gettingstarted.rst
Expand Up @@ -3,7 +3,7 @@ Getting Started
===============

The example provided in the ``example`` folder of the Python package is a good place to get started.
You can run the ``tmtc_cli.py`` file to test the CLI interface or the ``tmtc_gui.py`` file
You can run the ``tmtccli.py`` file to test the CLI interface or the ``tmtcgui.py`` file
to test the GUI interface. The only working communication interface for the example applications is
the ``dummy`` interface.

Expand All @@ -13,51 +13,79 @@ The example application for the CLI mode looks like this:

::

from tmtccmd.ccsds.handler import CcsdsTmHandler
from tmtccmd.runner import run_tmtc_commander, initialize_tmtc_commander, add_ccsds_handler
from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler
import tmtccmd.runner as tmtccmd
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,
)
from tmtccmd.logging import get_console_logger
from tmtccmd.tm.handler import default_ccsds_packet_handler

from config.hook_implementation import ExampleHookClass
from config.definitions import APID
from config.definitions import APID, pre_send_cb


LOGGER = get_console_logger()


def main():
hook_obj = ExampleHookClass()
initialize_tmtc_commander(hook_object=hook_obj)
tmtccmd.init_printout(False)
hook_obj = ExampleHookClass(json_cfg_path=default_json_path())
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=APID, cli_args=args)
apid_handler = ApidHandler(
cb=default_ccsds_packet_handler, queue_len=50, user_args=None
)
ccsds_handler = CcsdsTmHandler()
ccsds_handler.add_tm_handler(apid=APID, pus_tm_handler=default_ccsds_packet_handler, max_queue_len=50)
add_ccsds_handler(ccsds_handler)
run_tmtc_commander(use_gui=False)
ccsds_handler.add_tm_handler(apid=APID, handler=apid_handler)
tmtccmd.setup(setup_args=setup_args)
tmtccmd.add_ccsds_handler(ccsds_handler)
tmtc_backend = tmtccmd.get_default_tmtc_backend(
setup_args=setup_args,
tm_handler=ccsds_handler,
)
tmtc_backend.set_pre_send_cb(callable=pre_send_cb, user_args=None)
tmtccmd.run(tmtc_backend=tmtc_backend)

1. The ``ExampleHookClass`` is located inside the ``example/config`` folder and contains all
1. The ``ExampleHookClass`` is located inside the
`examples/config <https://github.com/robamu-org/tmtccmd/blob/main/examples/config/hook_implementation.py>`_ folder and contains all
important hook implementations.
#. The hook instance is passed to the :py:meth:`tmtccmd.runner.initialize_tmtc_commander` method
which takes care of internal initialization.
#. An argument parser is created and converted to also parse all CLI arguments required
by ``tmtccmd``
#. A :py:class:`tmtccmd.config.SetupArgs` class is created which contains most of the
configuration required by ``tmtcccmd``. The CLI arguments are also passed to this
class
#. An :py:class:`tmtccmd.ccsds.handler.ApidHandler` is created to handle all telemetry
for the application APID. This handler takes a user callback to handle the packets
#. After that, a generic :py:class:`tmtccmd.ccsds.handler.CcsdsTmHandler` is
created, which can be used to handle PUS packets, which are a specific type of CCSDS packets.
Here, it is assumed the so called Application Process Identifier or APID will be constant
for all PUS packets.
#. A telemetry handler is added to the CCSDS handler for handling PUS telemetry with that specific
APID.
#. The CCSDS Handler is added so it can be used by the TMTC commander core
#. Finally, the application can be started with the :py:meth:`tmtccmd.runner.run_tmtc_commander`
call.

Most of the TMTC commander configuration is done through the hook object instance. More information
about its implementation will be provided in the :ref:`hook-func-label` chapter
created and the APID handler is added to it. This allows specifying different handler for
different APIDs
#. Finally, a TMTC backend is created. A backend is required for the :py:func:`tmtccmd.runner.run`
function.
#. A pre-send callback is added to the backend. Each time a telecommand is sent, this callback
will be called

Most of the TMTC commander configuration is done through the hook object instance and the setup
object. More information about its implementation will be provided in the :ref:`hook-func-label`
chapter

CLI
===

If ``tmtc_cli.py`` is run without any command line arguments the commander core will prompt values
If ``tmtccli.py`` is run without any command line arguments the commander core will prompt values
like the service or operation code. These values are passed on to the hook functions, which
allows a developers to package different telecommand stacks for different service and op code
combinations.

GUI
===

Simply run the ``tmtc_gui.py`` application and connect to the Dummy communication interface.
Simply run the ``tmtcgui.py`` application and connect to the Dummy communication interface.
After that, you can send a ping command and see the generated replies.

.. _hook-func-label:
Expand Down
16 changes: 16 additions & 0 deletions examples/config/definitions.py
@@ -1 +1,17 @@
from spacepackets.ecss import PusTelecommand

from tmtccmd.com_if.com_interface_base import CommunicationInterface
from tmtccmd.logging import get_console_logger

APID = 0xEF
LOGGER = get_console_logger()


def pre_send_cb(
data: bytes,
com_if: CommunicationInterface,
cmd_info: PusTelecommand,
_user_args: any,
):
LOGGER.info(cmd_info)
com_if.send(data=data)
42 changes: 9 additions & 33 deletions examples/config/hook_implementation.py
@@ -1,43 +1,31 @@
import argparse
from typing import Union, Dict, Tuple
from typing import Union, Tuple

from tmtccmd.config.definitions import ServiceOpCodeDictT
from tmtccmd.config.hook import TmTcHookBase
from tmtccmd.utility.logger import get_console_logger
from tmtccmd.config.hook import TmTcHookBase, ObjectIdDictT
from tmtccmd.logging import get_console_logger
from tmtccmd.core.backend import TmTcHandler
from tmtccmd.utility.tmtc_printer import TmTcPrinter
from tmtccmd.tc.definitions import TcQueueT
from tmtccmd.com_if.com_interface_base import CommunicationInterface
from tmtccmd.tm.service_3_base import Service3Base

from config.definitions import APID
from .definitions import APID

LOGGER = get_console_logger()


class ExampleHookClass(TmTcHookBase):
def add_globals_pre_args_parsing(self, gui: bool = False):
from tmtccmd.config.globals import set_default_globals_pre_args_parsing

set_default_globals_pre_args_parsing(gui=gui, tc_apid=APID, tm_apid=APID)

def add_globals_post_args_parsing(self, args: argparse.Namespace):
from tmtccmd.config.globals import set_default_globals_post_args_parsing

set_default_globals_post_args_parsing(
args=args, json_cfg_path=self.get_json_config_file_path()
)
def __init__(self, json_cfg_path: str):
super().__init__(json_cfg_path=json_cfg_path)

def assign_communication_interface(
self, com_if_key: str, tmtc_printer: TmTcPrinter
self, com_if_key: str
) -> Union[CommunicationInterface, None]:
from tmtccmd.config.com_if import create_communication_interface_default

LOGGER.info("Communication interface assignment function was called")
return create_communication_interface_default(
com_if_key=com_if_key,
tmtc_printer=tmtc_printer,
json_cfg_path=self.get_json_config_file_path(),
json_cfg_path=self.json_cfg_path,
)

def perform_mode_operation(self, tmtc_backend: TmTcHandler, mode: int):
Expand All @@ -54,7 +42,7 @@ def pack_service_queue(
service=service, op_code=op_code, service_queue=service_queue
)

def get_object_ids(self) -> Dict[bytes, list]:
def get_object_ids(self) -> ObjectIdDictT:
from tmtccmd.config.objects import get_core_object_ids

return get_core_object_ids()
Expand All @@ -69,15 +57,3 @@ def handle_service_8_telemetry(
object_id: int, action_id: int, custom_data: bytearray
) -> Tuple[list, list]:
pass

@staticmethod
def handle_service_3_housekeeping(
object_id: int, set_id: int, hk_data: bytearray, service3_packet: Service3Base
) -> Tuple[list, list, bytearray, int]:
pass

@staticmethod
def handle_service_5_event(
object_id: bytes, event_id: int, param_1: int, param_2: int
) -> str:
pass
28 changes: 0 additions & 28 deletions examples/tmtc_cli.py

This file was deleted.

3 changes: 3 additions & 0 deletions examples/tmtc_conf.json
@@ -0,0 +1,3 @@
{
"com_if": "dummy"
}
1 change: 0 additions & 1 deletion examples/tmtc_config.json

This file was deleted.

29 changes: 0 additions & 29 deletions examples/tmtc_gui.py

This file was deleted.

0 comments on commit eed581e

Please sign in to comment.