eive-tmtc/tmtccli.py

83 lines
2.8 KiB
Python
Executable File

#!/usr/bin/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
"""
import sys
import traceback
try:
import tmtccmd.runner as tmtccmd
from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler
from tmtccmd.logging import init_console_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
def main():
print(f"-- eive tmtc version {__version__} --")
print(f"-- spacepackets version {spacepackets.__version__} --")
hook_obj = EiveHookObject()
tmtccmd.init_tmtccmd(hook_object=hook_obj)
ccsds_handler = CcsdsTmHandler()
init_console_logger()
pus_handler = ApidHandler(cb=ccsds_tm_handler, queue_len=50, user_args=None)
ccsds_handler.add_tm_handler(apid=PUS_APID, handler=pus_handler)
tmtccmd.add_ccsds_handler(ccsds_handler)
tmtccmd.setup_tmtccmd(use_gui=False, reduced_printout=False)
tmtc_backend = tmtccmd.get_default_tmtc_backend(
hook_obj=hook_obj,
json_cfg_path=hook_obj.get_json_config_file_path(),
tm_handler=ccsds_handler,
)
tmtc_backend.set_pre_send_cb(callable=pre_tc_send_cb, user_args=None)
tmtccmd.run_tmtccmd(False, tmtc_backend=tmtc_backend, run_setup=False)
if __name__ == "__main__":
main()