2022-11-20 18:07:38 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Example client for the sat-rs example application"""
|
2023-02-04 13:52:39 +01:00
|
|
|
import logging
|
2022-11-20 18:07:38 +01:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
import tmtccmd
|
2024-05-09 11:41:11 +02:00
|
|
|
from spacepackets.ecss import PusVerificator
|
2022-11-20 18:07:38 +01:00
|
|
|
|
2024-05-09 11:41:11 +02:00
|
|
|
from tmtccmd import ProcedureParamsWrapper
|
2022-11-20 18:07:38 +01:00
|
|
|
from tmtccmd.core.base import BackendRequest
|
|
|
|
from tmtccmd.pus import VerificationWrapper
|
2024-05-09 11:41:11 +02:00
|
|
|
from tmtccmd.tmtc import CcsdsTmHandler
|
2022-11-20 18:07:38 +01:00
|
|
|
from tmtccmd.config import (
|
|
|
|
default_json_path,
|
|
|
|
SetupParams,
|
|
|
|
params_to_procedure_conversion,
|
|
|
|
)
|
|
|
|
from tmtccmd.config import PreArgsParsingWrapper, SetupWrapper
|
2023-02-04 13:52:39 +01:00
|
|
|
from tmtccmd.logging import add_colorlog_console_logger
|
2022-11-20 18:07:38 +01:00
|
|
|
from tmtccmd.logging.pus import (
|
|
|
|
RegularTmtcLogWrapper,
|
|
|
|
RawTmtcTimedLogWrapper,
|
|
|
|
TimedLogWhen,
|
|
|
|
)
|
2024-05-09 11:41:11 +02:00
|
|
|
from spacepackets.seqcount import PusFileSeqCountProvider
|
2022-11-20 18:07:38 +01:00
|
|
|
|
|
|
|
|
2024-05-09 11:41:11 +02:00
|
|
|
from pytmtc.config import SatrsConfigHook
|
|
|
|
from pytmtc.pus_tc import TcHandler
|
|
|
|
from pytmtc.pus_tm import PusHandler
|
2022-11-20 18:07:38 +01:00
|
|
|
|
2023-07-02 17:47:47 +02:00
|
|
|
_LOGGER = logging.getLogger()
|
2022-11-20 18:07:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-02-04 13:52:39 +01:00
|
|
|
add_colorlog_console_logger(_LOGGER)
|
2022-11-20 18:07:38 +01:00
|
|
|
tmtccmd.init_printout(False)
|
2024-05-09 11:41:11 +02:00
|
|
|
hook_obj = SatrsConfigHook(json_cfg_path=default_json_path())
|
2022-11-20 18:07:38 +01:00
|
|
|
parser_wrapper = PreArgsParsingWrapper()
|
|
|
|
parser_wrapper.create_default_parent_parser()
|
|
|
|
parser_wrapper.create_default_parser()
|
|
|
|
parser_wrapper.add_def_proc_args()
|
|
|
|
params = SetupParams()
|
2023-02-04 13:52:39 +01:00
|
|
|
post_args_wrapper = parser_wrapper.parse(hook_obj, params)
|
2022-11-20 18:07:38 +01:00
|
|
|
proc_wrapper = ProcedureParamsWrapper()
|
|
|
|
if post_args_wrapper.use_gui:
|
2023-02-04 13:52:39 +01:00
|
|
|
post_args_wrapper.set_params_without_prompts(proc_wrapper)
|
2022-11-20 18:07:38 +01:00
|
|
|
else:
|
2023-02-04 13:52:39 +01:00
|
|
|
post_args_wrapper.set_params_with_prompts(proc_wrapper)
|
2022-11-20 18:07:38 +01:00
|
|
|
setup_args = SetupWrapper(
|
|
|
|
hook_obj=hook_obj, setup_params=params, proc_param_wrapper=proc_wrapper
|
|
|
|
)
|
|
|
|
# Create console logger helper and file loggers
|
|
|
|
tmtc_logger = RegularTmtcLogWrapper()
|
2023-07-02 17:47:47 +02:00
|
|
|
file_logger = tmtc_logger.logger
|
2022-11-20 18:07:38 +01:00
|
|
|
raw_logger = RawTmtcTimedLogWrapper(when=TimedLogWhen.PER_HOUR, interval=1)
|
|
|
|
verificator = PusVerificator()
|
2023-07-02 17:47:47 +02:00
|
|
|
verification_wrapper = VerificationWrapper(verificator, _LOGGER, file_logger)
|
2022-11-20 18:07:38 +01:00
|
|
|
# Create primary TM handler and add it to the CCSDS Packet Handler
|
2023-07-02 17:47:47 +02:00
|
|
|
tm_handler = PusHandler(file_logger, verification_wrapper, raw_logger)
|
2024-04-04 15:18:53 +02:00
|
|
|
ccsds_handler = CcsdsTmHandler(generic_handler=tm_handler)
|
|
|
|
# TODO: We could add the CFDP handler for the CFDP APID at a later stage.
|
|
|
|
# ccsds_handler.add_apid_handler(tm_handler)
|
2022-11-20 18:07:38 +01:00
|
|
|
|
|
|
|
# Create TC handler
|
|
|
|
seq_count_provider = PusFileSeqCountProvider()
|
|
|
|
tc_handler = TcHandler(seq_count_provider, verification_wrapper)
|
|
|
|
tmtccmd.setup(setup_args=setup_args)
|
|
|
|
init_proc = params_to_procedure_conversion(setup_args.proc_param_wrapper)
|
|
|
|
tmtc_backend = tmtccmd.create_default_tmtc_backend(
|
|
|
|
setup_wrapper=setup_args,
|
|
|
|
tm_handler=ccsds_handler,
|
|
|
|
tc_handler=tc_handler,
|
|
|
|
init_procedure=init_proc,
|
|
|
|
)
|
|
|
|
tmtccmd.start(tmtc_backend=tmtc_backend, hook_obj=hook_obj)
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
state = tmtc_backend.periodic_op(None)
|
|
|
|
if state.request == BackendRequest.TERMINATION_NO_ERROR:
|
2024-04-22 20:29:14 +02:00
|
|
|
tmtc_backend.close_com_if()
|
2022-11-20 18:07:38 +01:00
|
|
|
sys.exit(0)
|
|
|
|
elif state.request == BackendRequest.DELAY_IDLE:
|
2023-02-04 13:52:39 +01:00
|
|
|
_LOGGER.info("TMTC Client in IDLE mode")
|
2022-11-20 18:07:38 +01:00
|
|
|
time.sleep(3.0)
|
|
|
|
elif state.request == BackendRequest.DELAY_LISTENER:
|
|
|
|
time.sleep(0.8)
|
|
|
|
elif state.request == BackendRequest.DELAY_CUSTOM:
|
2022-11-20 18:45:11 +01:00
|
|
|
if state.next_delay.total_seconds() <= 0.4:
|
|
|
|
time.sleep(state.next_delay.total_seconds())
|
|
|
|
else:
|
|
|
|
time.sleep(0.4)
|
2022-11-20 18:07:38 +01:00
|
|
|
elif state.request == BackendRequest.CALL_NEXT:
|
|
|
|
pass
|
|
|
|
except KeyboardInterrupt:
|
2024-04-22 20:29:14 +02:00
|
|
|
tmtc_backend.close_com_if()
|
2022-11-20 18:07:38 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|