fsfw-example-hosted/tmtc/tmtcc.py

62 lines
2.0 KiB
Python
Raw Normal View History

2022-07-03 19:29:53 +02:00
#!/usr/bin/env python3
"""TMTC commander for FSFW Example"""
2022-07-03 21:00:28 +02:00
import sys
import time
from spacepackets.ecss import PusVerificator
2022-07-03 19:29:53 +02:00
import tmtccmd
2022-07-03 21:00:28 +02:00
from common_tmtc.common import setup_params, setup_tmtc_handlers, setup_backend
2022-07-03 19:29:53 +02:00
from config.hook import FsfwHookBase
2022-07-03 21:00:28 +02:00
from tmtccmd import get_console_logger
from tmtccmd.core import BackendRequest
from tmtccmd.logging.pus import (
RegularTmtcLogWrapper,
RawTmtcTimedLogWrapper,
TimedLogWhen,
)
from tmtccmd.pus import VerificationWrapper
2022-07-27 14:41:07 +02:00
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
2022-07-03 21:00:28 +02:00
LOGGER = get_console_logger()
2022-07-03 19:29:53 +02:00
def main():
2022-07-03 21:00:28 +02:00
setup_wrapper = setup_params(FsfwHookBase())
tmtc_logger = RegularTmtcLogWrapper()
printer = FsfwTmTcPrinter(tmtc_logger.logger)
raw_logger = RawTmtcTimedLogWrapper(when=TimedLogWhen.PER_HOUR, interval=2)
pus_verificator = PusVerificator()
verif_wrapper = VerificationWrapper(
console_logger=get_console_logger(),
file_logger=printer.file_logger,
pus_verificator=pus_verificator,
)
ccsds_handler, tc_handler = setup_tmtc_handlers(
verif_wrapper=verif_wrapper, raw_logger=raw_logger, printer=printer
)
tmtccmd.setup(setup_wrapper)
backend = setup_backend(
setup_wrapper=setup_wrapper, ccsds_handler=ccsds_handler, tc_handler=tc_handler
)
try:
while True:
state = backend.periodic_op(None)
if state.request == BackendRequest.TERMINATION_NO_ERROR:
sys.exit(0)
elif state.request == BackendRequest.DELAY_IDLE:
LOGGER.info("TMTC Client in IDLE mode")
time.sleep(3.0)
elif state.request == BackendRequest.DELAY_LISTENER:
time.sleep(0.8)
elif state.request == BackendRequest.DELAY_CUSTOM:
time.sleep(state.next_delay.total_seconds())
elif state.request == BackendRequest.CALL_NEXT:
pass
except KeyboardInterrupt:
sys.exit(0)
2022-07-03 19:29:53 +02:00
if __name__ == "__main__":
main()