eive-tmtc/tmtcloop.py

86 lines
2.8 KiB
Python
Raw Normal View History

2022-05-17 11:04:34 +02:00
#!/usr/bin/env python3
2022-05-17 14:34:05 +02:00
"""EIVE TMTC Commander"""
2022-05-17 11:04:34 +02:00
import sys
import traceback
try:
import tmtccmd.runner as tmtccmd
from tmtccmd.config import default_json_path, SetupArgs, CoreGlobalIds
from tmtccmd.config.definitions import CoreModeList
from tmtccmd.config.args import (
create_default_args_parser,
add_default_tmtccmd_args,
parse_default_input_arguments,
)
from tmtccmd.ccsds.handler import CcsdsTmHandler, ApidHandler
from tmtccmd.logging import get_console_logger
from tmtccmd.logging.pus import create_tmtc_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.definitions import PUS_APID
from pus_tc.tc_packer_hook import pre_tc_send_cb
from pus_tm.factory_hook import ccsds_tm_handler
2022-05-17 14:34:05 +02:00
from tmtcc import tmtcc_pre_args
2022-05-17 11:04:34 +02:00
def main():
2022-05-17 14:34:05 +02:00
hook_obj = tmtcc_pre_args()
2022-05-17 11:04:34 +02:00
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=PUS_APID, cli_args=args
)
apid_handler = ApidHandler(cb=ccsds_tm_handler, queue_len=50, user_args=None)
ccsds_handler = CcsdsTmHandler()
ccsds_handler.add_tm_handler(apid=PUS_APID, handler=apid_handler)
tmtccmd.setup(setup_args=setup_args)
tmtccmd.add_ccsds_handler(ccsds_handler)
tmtc_backend = tmtccmd.create_default_tmtc_backend(
setup_args=setup_args,
tm_handler=ccsds_handler,
)
2022-05-17 14:34:05 +02:00
tmtc_file_logger = create_tmtc_logger()
2022-05-17 11:04:34 +02:00
tmtc_backend.usr_send_wrapper = (pre_tc_send_cb, tmtc_file_logger)
2022-05-17 11:33:40 +02:00
tmtc_backend.set_mode(CoreModeList.CONTINUOUS_MODE)
2022-05-17 11:04:34 +02:00
2022-05-17 11:33:40 +02:00
get_console_logger().info("Disabling console logger for continuous operation")
2022-05-17 14:34:05 +02:00
get_console_logger().disabled = True
2022-05-17 11:04:34 +02:00
tmtccmd.init_and_start_daemons(tmtc_backend=tmtc_backend)
tmtccmd.performOperation(tmtc_backend=tmtc_backend)
2022-05-17 14:34:05 +02:00
# remove cmdline args so that we can reuse code
2022-05-17 11:04:34 +02:00
sys.argv = sys.argv[:1]
while True:
args = parse_default_input_arguments(arg_parser, hook_obj)
setup_args = SetupArgs(
hook_obj=hook_obj, use_gui=False, apid=PUS_APID, cli_args=args
)
tmtccmd.setup(setup_args=setup_args)
2022-05-17 11:33:40 +02:00
tmtc_backend.set_mode(CoreModeList.CONTINUOUS_MODE)
2022-05-17 11:04:34 +02:00
tmtccmd.performOperation(tmtc_backend=tmtc_backend)
if __name__ == "__main__":
main()