Compare commits

..

9 Commits

Author SHA1 Message Date
55624f0447 Merge branch 'cfdp-file-downlink' of https://egit.irs.uni-stuttgart.de/eive/eive-tmtc into cfdp-file-downlink
All checks were successful
EIVE/-/pipeline/pr-main This commit looks good
2023-08-17 16:44:41 +02:00
9841076699 maybe this works better 2023-08-17 16:44:34 +02:00
f1876681fd Merge branch 'main' into cfdp-file-downlink
Some checks failed
EIVE/-/pipeline/pr-main There was a failure building this commit
2023-08-17 16:44:00 +02:00
14b558b7f7 prepare file downlink
Some checks failed
EIVE/-/pipeline/head There was a failure building this commit
2023-08-17 16:42:53 +02:00
54a7c3566f added missing stuff
All checks were successful
EIVE/-/pipeline/head This commit looks good
2023-08-17 11:34:54 +02:00
011be9837e remove more unused includes
All checks were successful
EIVE/-/pipeline/head This commit looks good
2023-08-17 11:34:34 +02:00
88161ed125 more cleaning up, new cfdp module
All checks were successful
EIVE/-/pipeline/head This commit looks good
2023-08-17 11:33:42 +02:00
f02230804d Merge pull request 'mini fixes' (#232) from mini-fixes into main
All checks were successful
EIVE/-/pipeline/head This commit looks good
Reviewed-on: #232
2023-08-16 14:04:03 +02:00
8ddcc37c74 mini fixes
All checks were successful
EIVE/-/pipeline/head This commit looks good
2023-08-16 13:25:29 +02:00
8 changed files with 258 additions and 267 deletions

View File

View File

@ -0,0 +1,16 @@
from spacepackets.cfdp import ConditionCode
from tmtccmd.cfdp.mib import DefaultFaultHandlerBase
class EiveCfdpFaultHandler(DefaultFaultHandlerBase):
def notice_of_suspension_cb(self, cond: ConditionCode):
pass
def notice_of_cancellation_cb(self, cond: ConditionCode):
pass
def abandoned_cb(self, cond: ConditionCode):
pass
def ignore_cb(self, cond: ConditionCode):
pass

52
eive_tmtc/cfdp/user.py Normal file
View File

@ -0,0 +1,52 @@
import logging
from spacepackets.cfdp import ConditionCode
from tmtccmd.cfdp import CfdpUserBase, TransactionId
from tmtccmd.cfdp.user import (
TransactionFinishedParams,
MetadataRecvParams,
FileSegmentRecvdParams,
)
_LOGGER = logging.getLogger(__name__)
class EiveCfdpUser(CfdpUserBase):
def transaction_indication(self, transaction_id: TransactionId):
_LOGGER.info(f"CFDP User: Start of File {transaction_id}")
def eof_sent_indication(self, transaction_id: TransactionId):
_LOGGER.info(f"CFDP User: EOF sent for {transaction_id}")
def transaction_finished_indication(self, params: TransactionFinishedParams):
_LOGGER.info(f"CFDP User: {params.transaction_id} finished")
def metadata_recv_indication(self, params: MetadataRecvParams):
pass
def file_segment_recv_indication(self, params: FileSegmentRecvdParams):
pass
def report_indication(self, transaction_id: TransactionId, status_report: any):
pass
def suspended_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode
):
pass
def resumed_indication(self, transaction_id: TransactionId, progress: int):
pass
def fault_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode, progress: int
):
pass
def abandoned_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode, progress: int
):
pass
def eof_recv_indication(self, transaction_id: TransactionId):
pass

View File

@ -0,0 +1,161 @@
import logging
from typing import cast
from eive_tmtc.config.definitions import (
CFDP_REMOTE_ENTITY_ID,
PUS_APID,
CFDP_LOCAL_ENTITY_ID,
)
from eive_tmtc.pus_tc.procedure_packer import handle_default_procedure
from tmtcc import CfdpInCcsdsWrapper
from tmtccmd import TcHandlerBase, ProcedureWrapper
from tmtccmd.cfdp.defs import CfdpRequestType
from tmtccmd.logging import get_current_time_string
from tmtccmd.logging.pus import RawTmtcTimedLogWrapper
from tmtccmd.tc import (
DefaultPusQueueHelper,
QueueWrapper,
FeedWrapper,
TcProcedureType,
SendCbParams,
TcQueueEntryType,
)
from tmtccmd.config import (
cfdp_put_req_params_to_procedure,
cfdp_req_to_put_req_proxy_get_req,
)
from spacepackets.ecss import PusVerificator
from tmtccmd.util import FileSeqCountProvider
from spacepackets.cfdp import PduHolder, DirectiveType
_LOGGER = logging.getLogger(__name__)
class TcHandler(TcHandlerBase):
def __init__(
self,
seq_count_provider: FileSeqCountProvider,
cfdp_in_ccsds_wrapper: CfdpInCcsdsWrapper,
pus_verificator: PusVerificator,
high_level_file_logger: logging.Logger,
raw_pus_logger: RawTmtcTimedLogWrapper,
gui: bool,
):
super().__init__()
self.cfdp_handler_started = False
self.seq_count_provider = seq_count_provider
self.pus_verificator = pus_verificator
self.high_level_file_logger = high_level_file_logger
self.pus_raw_logger = raw_pus_logger
self.gui = gui
self.queue_helper = DefaultPusQueueHelper(
queue_wrapper=QueueWrapper.empty(),
default_pus_apid=PUS_APID,
seq_cnt_provider=seq_count_provider,
pus_verificator=pus_verificator,
tc_sched_timestamp_len=4,
)
self.cfdp_in_ccsds_wrapper = cfdp_in_ccsds_wrapper
def cfdp_done(self) -> bool:
if self.cfdp_handler_started:
if not self.cfdp_in_ccsds_wrapper.handler.put_request_pending():
self.cfdp_handler_started = False
return True
return False
def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
self.queue_helper.queue_wrapper = wrapper.queue_wrapper
if info.proc_type == TcProcedureType.DEFAULT:
handle_default_procedure(self, info.to_def_procedure(), self.queue_helper)
elif info.proc_type == TcProcedureType.CFDP:
self.handle_cfdp_procedure(info)
def send_cb(self, send_params: SendCbParams):
entry_helper = send_params.entry
if entry_helper.is_tc:
if entry_helper.entry_type == TcQueueEntryType.PUS_TC:
pus_tc_wrapper = entry_helper.to_pus_tc_entry()
# pus_tc_wrapper.pus_tc.apid = PUS_APID
raw_tc = pus_tc_wrapper.pus_tc.pack()
self.pus_raw_logger.log_tc(pus_tc_wrapper.pus_tc)
tc_info_string = f"Sent {pus_tc_wrapper.pus_tc}"
_LOGGER.info(tc_info_string)
self.high_level_file_logger.info(
f"{get_current_time_string(True)}: {tc_info_string}"
)
# with open("tc.bin", "wb") as of:
# of.write(raw_tc)
send_params.com_if.send(raw_tc)
elif entry_helper.entry_type == TcQueueEntryType.CCSDS_TC:
cfdp_packet_in_ccsds = entry_helper.to_space_packet_entry()
send_params.com_if.send(cfdp_packet_in_ccsds.space_packet.pack())
# TODO: Log raw CFDP packets similarly to how PUS packets are logged.
# - Log full raw format including space packet wrapper
# - Log context information: Transaction ID, and PDU type and directive
# Could re-use file logger. Should probably do that
# print(f"sending packet: [{cfdp_packet_in_ccsds.space_packet.pack()}]")
# with open(f"cfdp_packet_{self.cfdp_counter}", "wb") as of:
# of.write(cfdp_packet_in_ccsds.space_packet.pack())
# self.cfdp_counter += 1
elif entry_helper.entry_type == TcQueueEntryType.LOG:
log_entry = entry_helper.to_log_entry()
_LOGGER.info(log_entry.log_str)
self.high_level_file_logger.info(log_entry.log_str)
def handle_cfdp_procedure(self, info: ProcedureWrapper):
cfdp_procedure = info.to_cfdp_procedure()
if cfdp_procedure.cfdp_request_type == CfdpRequestType.PUT:
if (
not self.cfdp_in_ccsds_wrapper.handler.put_request_pending()
and not self.cfdp_handler_started
):
put_req_cfg_wrapper = cfdp_procedure.request_wrapper.to_put_request()
if put_req_cfg_wrapper.cfg.proxy_op:
put_req = cfdp_req_to_put_req_proxy_get_req(
put_req_cfg_wrapper.cfg,
CFDP_REMOTE_ENTITY_ID,
CFDP_LOCAL_ENTITY_ID,
)
else:
put_req = cfdp_put_req_params_to_procedure(put_req_cfg_wrapper.cfg)
_LOGGER.info(
f"CFDP: Starting file put request with parameters:\n{put_req}"
)
self.cfdp_in_ccsds_wrapper.handler.cfdp_handler.put_request(put_req)
self.cfdp_handler_started = True
for source_pair, dest_pair in self.cfdp_in_ccsds_wrapper.handler:
pdu, sp = source_pair
pdu = cast(PduHolder, pdu)
if pdu.is_file_directive:
if pdu.pdu_directive_type == DirectiveType.METADATA_PDU:
metadata = pdu.to_metadata_pdu()
self.queue_helper.add_log_cmd(
f"CFDP Source: Sending Metadata PDU for file with size "
f"{metadata.file_size}"
)
elif pdu.pdu_directive_type == DirectiveType.EOF_PDU:
self.queue_helper.add_log_cmd(
"CFDP Source: Sending EOF PDU"
)
else:
fd_pdu = pdu.to_file_data_pdu()
self.queue_helper.add_log_cmd(
f"CFDP Source: Sending File Data PDU for segment at offset "
f"{fd_pdu.offset} with length {len(fd_pdu.file_data)}"
)
self.queue_helper.add_ccsds_tc(sp)
self.cfdp_in_ccsds_wrapper.handler.confirm_source_packet_sent()
self.cfdp_in_ccsds_wrapper.handler.source_handler.state_machine()
def queue_finished_cb(self, info: ProcedureWrapper):
if info is not None:
if info.proc_type == TcQueueEntryType.PUS_TC:
def_proc = info.to_def_procedure()
_LOGGER.info(
f"Finished queue for service {def_proc.service} and op code {def_proc.op_code}"
)
elif info.proc_type == TcProcedureType.CFDP:
_LOGGER.info("Finished CFDP queue")

View File

@ -1018,7 +1018,7 @@ def handle_gps_data_processed(pw: PrintWrapper, hk_data: bytes):
inc_len_source = struct.calcsize(fmt_source) inc_len_source = struct.calcsize(fmt_source)
inc_len_scalar = struct.calcsize(fmt_scalar) inc_len_scalar = struct.calcsize(fmt_scalar)
inc_len_vec = struct.calcsize(fmt_vec) inc_len_vec = struct.calcsize(fmt_vec)
if len(hk_data) < 2 * inc_len_scalar + 2 * inc_len_vec + inc_len_source: if len(hk_data) < 3 * inc_len_scalar + 2 * inc_len_vec + inc_len_source:
pw.dlog("Received HK set too small") pw.dlog("Received HK set too small")
return return
current_idx = 0 current_idx = 0

View File

@ -72,9 +72,7 @@ def add_gps_cmds(defs: TmtcDefinitionWrapper):
) )
def pack_gps_command( # noqa: C901 def pack_gps_command(object_id: bytes, q: DefaultPusQueueHelper, op_code: str):
object_id: bytes, q: DefaultPusQueueHelper, op_code: str
): # noqa: C901
if op_code in OpCode.RESET_GNSS: if op_code in OpCode.RESET_GNSS:
# TODO: This needs to be re-implemented # TODO: This needs to be re-implemented
_LOGGER.warning("Reset pin handling needs to be re-implemented") _LOGGER.warning("Reset pin handling needs to be re-implemented")
@ -84,52 +82,34 @@ def pack_gps_command( # noqa: C901
raise ValueError("invalid interval") raise ValueError("invalid interval")
q.add_log_cmd(f"GPS: {Info.ENABLE_CORE_HK}") q.add_log_cmd(f"GPS: {Info.ENABLE_CORE_HK}")
cmds = create_enable_periodic_hk_command_with_interval( cmds = create_enable_periodic_hk_command_with_interval(
diag=False, diag=False, sid=make_sid(object_id=object_id, set_id=SetId.CORE_HK), interval_seconds=interval
sid=make_sid(object_id=object_id, set_id=SetId.CORE_HK),
interval_seconds=interval,
) )
for cmd in cmds: for cmd in cmds:
q.add_pus_tc(cmd) q.add_pus_tc(cmd)
if op_code in OpCode.DISABLE_CORE_HK: if op_code in OpCode.DISABLE_CORE_HK:
q.add_log_cmd(f"gps: {Info.DISABLE_CORE_HK}") q.add_log_cmd(f"gps: {Info.DISABLE_CORE_HK}")
q.add_pus_tc( q.add_pus_tc(create_disable_periodic_hk_command(diag=False, sid=make_sid(object_id=object_id,
create_disable_periodic_hk_command( set_id=SetId.CORE_HK)))
diag=False, sid=make_sid(object_id=object_id, set_id=SetId.CORE_HK)
)
)
if op_code in OpCode.REQ_CORE_HK: if op_code in OpCode.REQ_CORE_HK:
q.add_log_cmd(f"GPS: {Info.REQ_CORE_HK}") q.add_log_cmd(f"GPS: {Info.REQ_CORE_HK}")
q.add_pus_tc( q.add_pus_tc(create_request_one_hk_command(sid=make_sid(object_id=object_id, set_id=SetId.CORE_HK)))
create_request_one_hk_command(
sid=make_sid(object_id=object_id, set_id=SetId.CORE_HK)
)
)
if op_code in OpCode.ENABLE_SKYVIEW_HK: if op_code in OpCode.ENABLE_SKYVIEW_HK:
interval = float(input("Please specify interval in floating point seconds: ")) interval = float(input("Please specify interval in floating point seconds: "))
if interval <= 0: if interval <= 0:
raise ValueError("invalid interval") raise ValueError("invalid interval")
q.add_log_cmd(f"GPS: {Info.ENABLE_SKYVIEW_HK}") q.add_log_cmd(f"GPS: {Info.ENABLE_SKYVIEW_HK}")
cmds = create_enable_periodic_hk_command_with_interval( cmds = create_enable_periodic_hk_command_with_interval(
diag=False, diag=False, sid=make_sid(object_id=object_id, set_id=SetId.SKYVIEW_HK), interval_seconds=interval
sid=make_sid(object_id=object_id, set_id=SetId.SKYVIEW_HK),
interval_seconds=interval,
) )
for cmd in cmds: for cmd in cmds:
q.add_pus_tc(cmd) q.add_pus_tc(cmd)
if op_code in OpCode.DISABLE_SKYVIEW_HK: if op_code in OpCode.DISABLE_SKYVIEW_HK:
q.add_log_cmd(f"gps: {Info.DISABLE_SKYVIEW_HK}") q.add_log_cmd(f"gps: {Info.DISABLE_SKYVIEW_HK}")
q.add_pus_tc( q.add_pus_tc(create_disable_periodic_hk_command(diag=False, sid=make_sid(object_id=object_id,
create_disable_periodic_hk_command( set_id=SetId.SKYVIEW_HK)))
diag=False, sid=make_sid(object_id=object_id, set_id=SetId.SKYVIEW_HK)
)
)
if op_code in OpCode.REQ_SKYVIEW_HK: if op_code in OpCode.REQ_SKYVIEW_HK:
q.add_log_cmd(f"GPS: {Info.REQ_SKYVIEW_HK}") q.add_log_cmd(f"GPS: {Info.REQ_SKYVIEW_HK}")
q.add_pus_tc( q.add_pus_tc(create_request_one_hk_command(sid=make_sid(object_id=object_id, set_id=SetId.SKYVIEW_HK)))
create_request_one_hk_command(
sid=make_sid(object_id=object_id, set_id=SetId.SKYVIEW_HK)
)
)
if op_code in OpCode.ON: if op_code in OpCode.ON:
q.add_log_cmd(f"GPS: {Info.ON}") q.add_log_cmd(f"GPS: {Info.ON}")
q.add_pus_tc(create_mode_command(object_id, Mode.ON, 0)) q.add_pus_tc(create_mode_command(object_id, Mode.ON, 0))
@ -153,7 +133,7 @@ def handle_gps_data(
def handle_core_data(pw: PrintWrapper, hk_data: bytes): def handle_core_data(pw: PrintWrapper, hk_data: bytes):
if len(hk_data) < 4 * 8 + 4 + 2 + 8: if len(hk_data) < 4*8+4+2+8:
pw.dlog( pw.dlog(
f"GPS Core dataset with size {len(hk_data)} does not have expected size" f"GPS Core dataset with size {len(hk_data)} does not have expected size"
f" of {4*8+4+2+8} bytes" f" of {4*8+4+2+8} bytes"
@ -199,7 +179,7 @@ def handle_core_data(pw: PrintWrapper, hk_data: bytes):
def handle_skyview_data(pw: PrintWrapper, hk_data: bytes): def handle_skyview_data(pw: PrintWrapper, hk_data: bytes):
data_length = 8 + GpsInfo.MAX_SATELLITES * (8 + 3 * 2 + 1) data_length = 8+GpsInfo.MAX_SATELLITES*(8+3*2+1)
if len(hk_data) < data_length: if len(hk_data) < data_length:
pw.dlog( pw.dlog(
f"GPS Skyview dataset with size {len(hk_data)} does not have expected size" f"GPS Skyview dataset with size {len(hk_data)} does not have expected size"
@ -215,46 +195,24 @@ def handle_skyview_data(pw: PrintWrapper, hk_data: bytes):
inc_len_int16 = struct.calcsize(fmt_str_int16) inc_len_int16 = struct.calcsize(fmt_str_int16)
inc_len_double = struct.calcsize(fmt_str_double) inc_len_double = struct.calcsize(fmt_str_double)
inc_len_uint8 = struct.calcsize(fmt_str_uint8) inc_len_uint8 = struct.calcsize(fmt_str_uint8)
unix = struct.unpack( unix = struct.unpack(fmt_str_unix, hk_data[current_idx: current_idx + inc_len_unix])[0]
fmt_str_unix, hk_data[current_idx : current_idx + inc_len_unix]
)
current_idx += inc_len_unix current_idx += inc_len_unix
prn_id = struct.unpack( prn_id = struct.unpack(fmt_str_int16, hk_data[current_idx: current_idx + inc_len_int16])
fmt_str_int16, hk_data[current_idx : current_idx + inc_len_int16]
)
current_idx += inc_len_int16 current_idx += inc_len_int16
azimuth = struct.unpack( azimuth = struct.unpack(fmt_str_int16, hk_data[current_idx: current_idx + inc_len_int16])
fmt_str_int16, hk_data[current_idx : current_idx + inc_len_int16]
)
current_idx += inc_len_int16 current_idx += inc_len_int16
elevation = struct.unpack( elevation = struct.unpack(fmt_str_int16, hk_data[current_idx: current_idx + inc_len_int16])
fmt_str_int16, hk_data[current_idx : current_idx + inc_len_int16]
)
current_idx += inc_len_int16 current_idx += inc_len_int16
signal_to_noise = struct.unpack( signal_to_noise = struct.unpack(fmt_str_double, hk_data[current_idx: current_idx + inc_len_double])
fmt_str_double, hk_data[current_idx : current_idx + inc_len_double]
)
current_idx += inc_len_double current_idx += inc_len_double
used = struct.unpack( used = struct.unpack(fmt_str_uint8, hk_data[current_idx: current_idx + inc_len_uint8])
fmt_str_uint8, hk_data[current_idx : current_idx + inc_len_uint8]
)
current_idx += inc_len_uint8 current_idx += inc_len_uint8
pw.dlog(f"Skyview Time: {unix} unix-sec") pw.dlog(f"Skyview Time: {unix} unix-sec")
pw.dlog( pw.dlog("{:<8} {:<8} {:<8} {:<8} {:<8}".format('PRN_ID', 'AZ [°]', 'EL [°]', 'S2N [dBW]', 'USED'))
"{:<8} {:<8} {:<8} {:<8} {:<8}".format(
"PRN_ID", "AZ [°]", "EL [°]", "S2N [dBW]", "USED"
)
)
for idx in range(GpsInfo.MAX_SATELLITES): for idx in range(GpsInfo.MAX_SATELLITES):
pw.dlog( pw.dlog("{:<8} {:<8} {:<8} {:<8} {:<8}".format(prn_id[idx], azimuth[idx], elevation[idx], signal_to_noise[idx],
"{:<8} {:<8} {:<8} {:<8} {:<8}".format( used[idx]))
prn_id[idx],
azimuth[idx],
elevation[idx],
signal_to_noise[idx],
used[idx],
)
)
FsfwTmTcPrinter.get_validity_buffer( FsfwTmTcPrinter.get_validity_buffer(
validity_buffer=hk_data[current_idx:], num_vars=6 validity_buffer=hk_data[current_idx:], num_vars=6
) )

View File

@ -29,9 +29,9 @@ classifiers = [
"Topic :: Scientific/Engineering" "Topic :: Scientific/Engineering"
] ]
dependencies = [ dependencies = [
"tmtccmd ~= 5.0", # "tmtccmd ~= 5.0",
"python-dateutil ~= 2.8", "python-dateutil ~= 2.8",
# "tmtccmd @ git+https://github.com/robamu-org/tmtccmd@1b110d321ef85#egg=tmtccmd" "tmtccmd @ git+https://github.com/robamu-org/tmtccmd@cfdp-proxy-op-support"
] ]
[project.urls] [project.urls]

206
tmtcc.py
View File

@ -4,34 +4,26 @@ import sys
import time import time
import traceback import traceback
from pathlib import Path from pathlib import Path
from typing import cast
from eive_tmtc.cfdp.fault_handler import EiveCfdpFaultHandler
from eive_tmtc.cfdp.user import EiveCfdpUser
from spacepackets.ccsds import SPACE_PACKET_HEADER_SIZE from spacepackets.ccsds import SPACE_PACKET_HEADER_SIZE
from spacepackets.cfdp import ( from spacepackets.cfdp import (
ConditionCode,
ChecksumType, ChecksumType,
TransmissionMode, TransmissionMode,
PduHolder,
DirectiveType, DirectiveType,
PduFactory, PduFactory,
PduType, PduType,
) )
from eive_tmtc.pus_tc.tc_handler import TcHandler
from tmtccmd.logging import add_colorlog_console_logger from tmtccmd.logging import add_colorlog_console_logger
from tmtccmd.cfdp import CfdpUserBase, TransactionId
from tmtccmd.cfdp.defs import CfdpRequestType
from tmtccmd.cfdp.handler import CfdpInCcsdsHandler from tmtccmd.cfdp.handler import CfdpInCcsdsHandler
from tmtccmd.cfdp.mib import ( from tmtccmd.cfdp.mib import (
DefaultFaultHandlerBase,
LocalEntityCfg, LocalEntityCfg,
IndicationCfg, IndicationCfg,
RemoteEntityCfg, RemoteEntityCfg,
) )
from tmtccmd.cfdp.user import (
TransactionFinishedParams,
MetadataRecvParams,
FileSegmentRecvdParams,
)
from tmtccmd.tc.handler import SendCbParams
try: try:
import spacepackets import spacepackets
@ -54,7 +46,7 @@ except ImportError:
sys.exit(1) sys.exit(1)
from spacepackets.ecss import PusVerificator from spacepackets.ecss import PusVerificator
from tmtccmd import TcHandlerBase, BackendBase from tmtccmd import BackendBase
from tmtccmd.util import FileSeqCountProvider, PusFileSeqCountProvider from tmtccmd.util import FileSeqCountProvider, PusFileSeqCountProvider
from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter from tmtccmd.fsfw.tmtc_printer import FsfwTmTcPrinter
@ -66,15 +58,6 @@ from tmtccmd.logging.pus import (
from tmtccmd.pus import VerificationWrapper from tmtccmd.pus import VerificationWrapper
from tmtccmd.tm import SpecificApidHandlerBase, GenericApidHandlerBase, CcsdsTmHandler from tmtccmd.tm import SpecificApidHandlerBase, GenericApidHandlerBase, CcsdsTmHandler
from tmtccmd.core import BackendRequest from tmtccmd.core import BackendRequest
from tmtccmd.logging import get_current_time_string
from tmtccmd.tc import (
ProcedureWrapper,
FeedWrapper,
TcProcedureType,
TcQueueEntryType,
DefaultPusQueueHelper,
QueueWrapper,
)
from tmtccmd.config import ( from tmtccmd.config import (
default_json_path, default_json_path,
SetupWrapper, SetupWrapper,
@ -95,7 +78,6 @@ from eive_tmtc.config.definitions import (
) )
from eive_tmtc.config.hook import EiveHookObject from eive_tmtc.config.hook import EiveHookObject
from eive_tmtc.pus_tm.pus_demux import pus_factory_hook from eive_tmtc.pus_tm.pus_demux import pus_factory_hook
from eive_tmtc.pus_tc.procedure_packer import handle_default_procedure
_LOGGER = APP_LOGGER _LOGGER = APP_LOGGER
_LOG_LEVEL = logging.INFO _LOG_LEVEL = logging.INFO
@ -105,61 +87,6 @@ ROTATING_TIMED_LOGGER_INTERVAL_WHEN = TimedLogWhen.PER_MINUTE
ROTATING_TIMED_LOGGER_INTERVAL = 30 ROTATING_TIMED_LOGGER_INTERVAL = 30
class EiveCfdpFaultHandler(DefaultFaultHandlerBase):
def notice_of_suspension_cb(self, cond: ConditionCode):
pass
def notice_of_cancellation_cb(self, cond: ConditionCode):
pass
def abandoned_cb(self, cond: ConditionCode):
pass
def ignore_cb(self, cond: ConditionCode):
pass
class EiveCfdpUser(CfdpUserBase):
def transaction_indication(self, transaction_id: TransactionId):
_LOGGER.info(f"CFDP User: Start of File {transaction_id}")
def eof_sent_indication(self, transaction_id: TransactionId):
_LOGGER.info(f"CFDP User: EOF sent for {transaction_id}")
def transaction_finished_indication(self, params: TransactionFinishedParams):
_LOGGER.info(f"CFDP User: {params.transaction_id} finished")
def metadata_recv_indication(self, params: MetadataRecvParams):
pass
def file_segment_recv_indication(self, params: FileSegmentRecvdParams):
pass
def report_indication(self, transaction_id: TransactionId, status_report: any):
pass
def suspended_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode
):
pass
def resumed_indication(self, transaction_id: TransactionId, progress: int):
pass
def fault_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode, progress: int
):
pass
def abandoned_indication(
self, transaction_id: TransactionId, cond_code: ConditionCode, progress: int
):
pass
def eof_recv_indication(self, transaction_id: TransactionId):
pass
class PusHandler(SpecificApidHandlerBase): class PusHandler(SpecificApidHandlerBase):
def __init__( def __init__(
self, self,
@ -216,129 +143,6 @@ class CfdpInCcsdsWrapper(SpecificApidHandlerBase):
self.handler.pass_pdu_packet(pdu_base) self.handler.pass_pdu_packet(pdu_base)
class TcHandler(TcHandlerBase):
def __init__(
self,
seq_count_provider: FileSeqCountProvider,
cfdp_in_ccsds_wrapper: CfdpInCcsdsWrapper,
pus_verificator: PusVerificator,
high_level_file_logger: logging.Logger,
raw_pus_logger: RawTmtcTimedLogWrapper,
gui: bool,
):
super().__init__()
self.cfdp_handler_started = False
self.cfdp_dest_id = CFDP_REMOTE_ENTITY_ID
self.seq_count_provider = seq_count_provider
self.pus_verificator = pus_verificator
self.high_level_file_logger = high_level_file_logger
self.pus_raw_logger = raw_pus_logger
self.gui = gui
self.queue_helper = DefaultPusQueueHelper(
queue_wrapper=QueueWrapper.empty(),
default_pus_apid=PUS_APID,
seq_cnt_provider=seq_count_provider,
pus_verificator=pus_verificator,
tc_sched_timestamp_len=4,
)
self.cfdp_in_ccsds_wrapper = cfdp_in_ccsds_wrapper
def cfdp_done(self) -> bool:
if self.cfdp_handler_started:
if not self.cfdp_in_ccsds_wrapper.handler.put_request_pending():
self.cfdp_handler_started = False
return True
return False
def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
self.queue_helper.queue_wrapper = wrapper.queue_wrapper
if info.proc_type == TcProcedureType.DEFAULT:
handle_default_procedure(self, info.to_def_procedure(), self.queue_helper)
elif info.proc_type == TcProcedureType.CFDP:
self.handle_cfdp_procedure(info)
def send_cb(self, send_params: SendCbParams):
entry_helper = send_params.entry
if entry_helper.is_tc:
if entry_helper.entry_type == TcQueueEntryType.PUS_TC:
pus_tc_wrapper = entry_helper.to_pus_tc_entry()
# pus_tc_wrapper.pus_tc.apid = PUS_APID
raw_tc = pus_tc_wrapper.pus_tc.pack()
self.pus_raw_logger.log_tc(pus_tc_wrapper.pus_tc)
tc_info_string = f"Sent {pus_tc_wrapper.pus_tc}"
_LOGGER.info(tc_info_string)
self.high_level_file_logger.info(
f"{get_current_time_string(True)}: {tc_info_string}"
)
# with open("tc.bin", "wb") as of:
# of.write(raw_tc)
send_params.com_if.send(raw_tc)
elif entry_helper.entry_type == TcQueueEntryType.CCSDS_TC:
cfdp_packet_in_ccsds = entry_helper.to_space_packet_entry()
send_params.com_if.send(cfdp_packet_in_ccsds.space_packet.pack())
# TODO: Log raw CFDP packets similarly to how PUS packets are logged.
# - Log full raw format including space packet wrapper
# - Log context information: Transaction ID, and PDU type and directive
# Could re-use file logger. Should probably do that
# print(f"sending packet: [{cfdp_packet_in_ccsds.space_packet.pack()}]")
# with open(f"cfdp_packet_{self.cfdp_counter}", "wb") as of:
# of.write(cfdp_packet_in_ccsds.space_packet.pack())
# self.cfdp_counter += 1
elif entry_helper.entry_type == TcQueueEntryType.LOG:
log_entry = entry_helper.to_log_entry()
_LOGGER.info(log_entry.log_str)
self.high_level_file_logger.info(log_entry.log_str)
def handle_cfdp_procedure(self, info: ProcedureWrapper):
cfdp_procedure = info.to_cfdp_procedure()
if cfdp_procedure.cfdp_request_type == CfdpRequestType.PUT:
if (
not self.cfdp_in_ccsds_wrapper.handler.put_request_pending()
and not self.cfdp_handler_started
):
put_req = cfdp_procedure.request_wrapper.to_put_request()
put_req.cfg.destination_id = self.cfdp_dest_id
_LOGGER.info(
f"CFDP: Starting file put request with parameters:\n{put_req}"
)
self.cfdp_in_ccsds_wrapper.handler.cfdp_handler.put_request(put_req)
self.cfdp_handler_started = True
for source_pair, dest_pair in self.cfdp_in_ccsds_wrapper.handler:
pdu, sp = source_pair
pdu = cast(PduHolder, pdu)
if pdu.is_file_directive:
if pdu.pdu_directive_type == DirectiveType.METADATA_PDU:
metadata = pdu.to_metadata_pdu()
self.queue_helper.add_log_cmd(
f"CFDP Source: Sending Metadata PDU for file with size "
f"{metadata.file_size}"
)
elif pdu.pdu_directive_type == DirectiveType.EOF_PDU:
self.queue_helper.add_log_cmd(
"CFDP Source: Sending EOF PDU"
)
else:
fd_pdu = pdu.to_file_data_pdu()
self.queue_helper.add_log_cmd(
f"CFDP Source: Sending File Data PDU for segment at offset "
f"{fd_pdu.offset} with length {len(fd_pdu.file_data)}"
)
self.queue_helper.add_ccsds_tc(sp)
self.cfdp_in_ccsds_wrapper.handler.confirm_source_packet_sent()
self.cfdp_in_ccsds_wrapper.handler.source_handler.state_machine()
def queue_finished_cb(self, info: ProcedureWrapper):
if info is not None:
if info.proc_type == TcQueueEntryType.PUS_TC:
def_proc = info.to_def_procedure()
_LOGGER.info(
f"Finished queue for service {def_proc.service} and op code {def_proc.op_code}"
)
elif info.proc_type == TcProcedureType.CFDP:
_LOGGER.info("Finished CFDP queue")
def setup_params() -> (SetupWrapper, int): def setup_params() -> (SetupWrapper, int):
hook_obj = EiveHookObject(default_json_path()) hook_obj = EiveHookObject(default_json_path())
params = SetupParams() params = SetupParams()