need to fix action reply handler
All checks were successful
EIVE/-/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2024-05-06 11:23:31 +02:00
parent 5da55c3c99
commit 86a68e25f7
11 changed files with 80 additions and 68 deletions

View File

@ -62,13 +62,7 @@ class CfdpHandler:
) )
def put_request(self, request: PutRequest): def put_request(self, request: PutRequest):
if not self.remote_cfg_table.get_cfg(request.destination_id): self.source_handler.put_request(request)
raise ValueError(
f"No remote CFDP config found for entity ID {request.destination_id}"
)
self.source_handler.put_request(
request, self.remote_cfg_table.get_cfg(request.destination_id) # type: ignore
)
def pull_next_source_packet(self) -> Optional[PduHolder]: def pull_next_source_packet(self) -> Optional[PduHolder]:
res = self.source_handler.state_machine() res = self.source_handler.state_machine()

View File

@ -4,7 +4,7 @@
import logging import logging
from typing import List, cast from typing import List, cast
from tmtccmd import DefaultProcedureInfo from tmtccmd import TreeCommandingProcedure
from tmtccmd.tmtc import DefaultPusQueueHelper from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.util import ObjectIdU32 from tmtccmd.util import ObjectIdU32
@ -78,7 +78,7 @@ from eive_tmtc.utility.input_helper import InputHelper
def handle_pus_procedure( def handle_pus_procedure(
info: DefaultProcedureInfo, info: TreeCommandingProcedure,
queue_helper: DefaultPusQueueHelper, queue_helper: DefaultPusQueueHelper,
): ):
cmd_path = info.cmd_path cmd_path = info.cmd_path

View File

@ -68,8 +68,8 @@ class TcHandler(TcHandlerBase):
def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper): def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
self.queue_helper.queue_wrapper = wrapper.queue_wrapper self.queue_helper.queue_wrapper = wrapper.queue_wrapper
if info.proc_type == TcProcedureType.DEFAULT: if info.proc_type == TcProcedureType.TREE_COMMANDING:
handle_pus_procedure(info.to_def_procedure(), self.queue_helper) handle_pus_procedure(info.to_tree_commanding_procedure(), self.queue_helper)
elif info.proc_type == TcProcedureType.CFDP: elif info.proc_type == TcProcedureType.CFDP:
self.handle_cfdp_procedure(info) self.handle_cfdp_procedure(info)
@ -155,7 +155,7 @@ class TcHandler(TcHandlerBase):
def queue_finished_cb(self, info: ProcedureWrapper): def queue_finished_cb(self, info: ProcedureWrapper):
if info is not None: if info is not None:
if info.proc_type == TcQueueEntryType.PUS_TC: if info.proc_type == TcQueueEntryType.PUS_TC:
def_proc = info.to_def_procedure() def_proc = info.to_tree_commanding_procedure()
_LOGGER.info(f"Finished queue for command {def_proc.cmd_path}") _LOGGER.info(f"Finished queue for command {def_proc.cmd_path}")
elif info.proc_type == TcProcedureType.CFDP: elif info.proc_type == TcProcedureType.CFDP:
_LOGGER.info("Finished CFDP queue") _LOGGER.info("Finished CFDP queue")

View File

@ -1,5 +1,7 @@
import logging import logging
import struct import struct
from spacepackets.ecss import PusTm
from eive_tmtc.config.object_ids import ( from eive_tmtc.config.object_ids import (
ACU_HANDLER_ID, ACU_HANDLER_ID,
PDU_1_HANDLER_ID, PDU_1_HANDLER_ID,
@ -34,13 +36,16 @@ def handle_action_reply(
"""Core Action reply handler """Core Action reply handler
:return: :return:
""" """
tm_packet = Service8FsfwTm.unpack( tm_packet = PusTm.unpack(raw_tm, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE)
raw_telemetry=raw_tm, time_reader=CdsShortTimestamp.empty()
)
object_id = obj_id_dict.get(tm_packet.source_object_id_as_bytes)
pw = PrintWrapper(printer.file_logger) pw = PrintWrapper(printer.file_logger)
custom_data = tm_packet.custom_data if len(tm_packet.source_data) < 8:
action_id = tm_packet.action_id _LOGGER.warn(
"invalid TM packet length for PUS 8 reply, must have at least 8 bytes"
)
return
object_id_raw = struct.unpack("!I", tm_packet.source_data[0:4])[0]
action_id = struct.unpack("!I", tm_packet.source_data[4:8])[0]
custom_data = tm_packet.source_data[8:]
generic_print_str = printer.generic_action_packet_tm_print( generic_print_str = printer.generic_action_packet_tm_print(
packet=tm_packet, obj_id=object_id packet=tm_packet, obj_id=object_id
) )

View File

@ -25,7 +25,7 @@ def handle_event_packet( # noqa C901: Complexity okay here
): # noqa C901: Complexity okay here ): # noqa C901: Complexity okay here
if PRINT_RAW_EVENTS_B64_STR: if PRINT_RAW_EVENTS_B64_STR:
print(f"PUS Event TM Base64: {base64.b64encode(raw_tm)}") print(f"PUS Event TM Base64: {base64.b64encode(raw_tm)}")
tm = Service5Tm.unpack(data=raw_tm, time_reader=CdsShortTimestamp.empty()) tm = Service5Tm.unpack(data=raw_tm, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE)
event_dict = get_event_dict() event_dict = get_event_dict()
event_def = tm.event_definition event_def = tm.event_definition
info = event_dict.get(event_def.event_id) info = event_dict.get(event_def.event_id)
@ -40,10 +40,10 @@ def handle_event_packet( # noqa C901: Complexity okay here
obj_name = event_def.reporter_id.hex(sep=",") obj_name = event_def.reporter_id.hex(sep=",")
else: else:
obj_name = obj_id_obj.name obj_name = obj_id_obj.name
assert tm.time_provider is not None timestamp = CdsShortTimestamp.unpack(tm.timestamp)
generic_event_string = ( generic_event_string = (
f"Object {obj_name} generated Event {info.name} (ID: {event_def.event_id:#04x})" f"Object {obj_name} generated Event {info.name} (ID: {event_def.event_id:#04x})"
f" at {tm.time_provider.as_date_time()}" f" at {timestamp.as_date_time()}"
) )
_LOGGER.info(generic_event_string) _LOGGER.info(generic_event_string)
pw.file_logger.info( pw.file_logger.info(

View File

@ -2,20 +2,17 @@ import uuid
import dataclasses import dataclasses
import datetime import datetime
import sqlite3 import sqlite3
from tmtccmd.pus.tm.s3_fsfw_hk import Service3FsfwTm from spacepackets.ecss.tm import CdsShortTimestamp, PusTm
@dataclasses.dataclass @dataclasses.dataclass
class HkTmInfo: class HkTmInfo:
packet_uuid: uuid.UUID packet_uuid: uuid.UUID
hk_packet: Service3FsfwTm hk_packet: PusTm
set_id: int
db_con: sqlite3.Connection db_con: sqlite3.Connection
hk_data: bytes hk_data: bytes
@property @property
def packet_datetime(self) -> datetime.datetime: def packet_datetime(self) -> datetime.datetime:
return self.hk_packet.pus_tm.time_provider.as_datetime() return CdsShortTimestamp.unpack(self.hk_packet.timestamp).as_datetime()
@property
def set_id(self) -> int:
return self.hk_packet.set_id

View File

@ -2,10 +2,14 @@
import dataclasses import dataclasses
import logging import logging
import base64 # noqa import base64
import sqlite3 import sqlite3
import struct
from typing import List, cast from typing import List, cast
from uuid import UUID from uuid import UUID
from spacepackets.ccsds.time import CdsShortTimestamp
from spacepackets.ecss import PusTm
from eive_tmtc.config.definitions import PRINT_RAW_HK_B64_STR from eive_tmtc.config.definitions import PRINT_RAW_HK_B64_STR
from eive_tmtc.pus_tm.hk import HkTmInfo from eive_tmtc.pus_tm.hk import HkTmInfo
@ -23,9 +27,6 @@ from eive_tmtc.tmtc.power.pwr_ctrl import handle_pwr_ctrl_hk_data
from eive_tmtc.tmtc.com.syrlinks_handler import handle_syrlinks_hk_data from eive_tmtc.tmtc.com.syrlinks_handler import handle_syrlinks_hk_data
from eive_tmtc.tmtc.tcs import handle_thermal_controller_hk_data from eive_tmtc.tmtc.tcs import handle_thermal_controller_hk_data
from eive_tmtc.tmtc.tcs.tmp1075 import handle_tmp_1075_hk_data from eive_tmtc.tmtc.tcs.tmp1075 import handle_tmp_1075_hk_data
from tmtccmd.pus.tm.s3_fsfw_hk import (
Service3FsfwTm,
)
from tmtccmd.pus.tm.s3_hk_base import HkContentType from tmtccmd.pus.tm.s3_hk_base import HkContentType
from tmtccmd.util.obj_id import ObjectIdU32, ObjectIdDictT from tmtccmd.util.obj_id import ObjectIdU32, ObjectIdDictT
@ -68,17 +69,20 @@ def handle_hk_packet(
hk_level: int, hk_level: int,
db_con: sqlite3.Connection, db_con: sqlite3.Connection,
): ):
tm_packet = Service3FsfwTm.unpack(raw_telemetry=raw_tm, custom_hk_handling=False) tm_packet = PusTm.unpack(raw_tm, CdsShortTimestamp.TIMESTAMP_SIZE)
named_obj_id = cast(ObjectIdU32, obj_id_dict.get(tm_packet.object_id.as_bytes)) obj_id_raw = struct.unpack("!I", tm_packet.tm_data[0:4])[0]
named_obj_id = cast(ObjectIdU32, obj_id_dict.get(obj_id_raw))
if named_obj_id is None: if named_obj_id is None:
named_obj_id = tm_packet.object_id named_obj_id = ObjectIdU32(obj_id_raw, "Unknown ID")
if tm_packet.subservice == 25 or tm_packet.subservice == 26: if tm_packet.subservice == 25 or tm_packet.subservice == 26:
set_id = struct.unpack("!I", tm_packet.tm_data[4:8])[0]
hk_data = tm_packet.tm_data[8:] hk_data = tm_packet.tm_data[8:]
if named_obj_id.as_bytes in hk_filter.object_ids: if named_obj_id.as_bytes in hk_filter.object_ids:
if PRINT_RAW_HK_B64_STR: if PRINT_RAW_HK_B64_STR:
print(f"PUS TM Base64: {base64.b64encode(raw_tm)}") print(f"PUS TM Base64: {base64.b64encode(raw_tm)}")
handle_regular_hk_print( handle_regular_hk_print(
printer=printer, printer=printer,
set_id=set_id,
packet_uuid=packet_uuid, packet_uuid=packet_uuid,
object_id=named_obj_id, object_id=named_obj_id,
hk_packet=tm_packet, hk_packet=tm_packet,
@ -89,11 +93,12 @@ def handle_hk_packet(
try: try:
if hk_level >= 1: if hk_level >= 1:
printer.generic_hk_tm_print( printer.generic_hk_tm_print(
HkContentType.HK, named_obj_id, tm_packet.set_id, hk_data HkContentType.HK, named_obj_id, set_id, hk_data
) )
if hk_level >= 1: if hk_level >= 1:
handle_regular_hk_print( handle_regular_hk_print(
printer=printer, printer=printer,
set_id=set_id,
packet_uuid=packet_uuid, packet_uuid=packet_uuid,
object_id=named_obj_id, object_id=named_obj_id,
hk_packet=tm_packet, hk_packet=tm_packet,
@ -109,7 +114,8 @@ def handle_hk_packet(
def handle_regular_hk_print( # noqa C901: Complexity okay here def handle_regular_hk_print( # noqa C901: Complexity okay here
hk_packet: Service3FsfwTm, hk_packet: PusTm,
set_id: int,
packet_uuid: UUID, packet_uuid: UUID,
hk_data: bytes, hk_data: bytes,
db: sqlite3.Connection, db: sqlite3.Connection,
@ -117,12 +123,15 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
printer: FsfwTmTcPrinter, printer: FsfwTmTcPrinter,
): ):
objb = object_id.as_bytes objb = object_id.as_bytes
set_id = hk_packet.set_id
hk_info = HkTmInfo( hk_info = HkTmInfo(
packet_uuid=packet_uuid, hk_packet=hk_packet, db_con=db, hk_data=hk_data packet_uuid=packet_uuid,
hk_packet=hk_packet,
db_con=db,
hk_data=hk_data,
set_id=set_id,
) )
assert hk_packet.pus_tm.time_provider is not None timestamp = CdsShortTimestamp.unpack(hk_packet.timestamp)
packet_dt = hk_packet.pus_tm.time_provider.as_date_time() packet_dt = timestamp.as_datetime()
pw = PrintWrapper(printer.file_logger) pw = PrintWrapper(printer.file_logger)
"""This function is called when a Service 3 Housekeeping packet is received.""" """This function is called when a Service 3 Housekeeping packet is received."""
if objb in [obj_ids.RW1_ID, obj_ids.RW2_ID, obj_ids.RW3_ID, obj_ids.RW4_ID]: if objb in [obj_ids.RW1_ID, obj_ids.RW2_ID, obj_ids.RW3_ID, obj_ids.RW4_ID]:
@ -139,7 +148,7 @@ def handle_regular_hk_print( # noqa C901: Complexity okay here
pw=pw, pw=pw,
set_id=set_id, set_id=set_id,
hk_data=hk_data, hk_data=hk_data,
packet_time=packet_dt, packet_time=timestamp.as_datetime(),
) )
elif objb == obj_ids.PCDU_HANDLER_ID: elif objb == obj_ids.PCDU_HANDLER_ID:
return handle_pcdu_hk(pw=pw, set_id=set_id, hk_data=hk_data) return handle_pcdu_hk(pw=pw, set_id=set_id, hk_data=hk_data)

View File

@ -63,15 +63,22 @@ class PusHandler(SpecificApidHandlerBase):
_LOGGER.warning("Detected packet shorter than 8 bytes!") _LOGGER.warning("Detected packet shorter than 8 bytes!")
return return
try: try:
tm_packet = PusTelemetry.unpack(packet, CdsShortTimestamp.empty()) tm_packet = PusTelemetry.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
# _LOGGER.info(f"Sequence count: {tm_packet.seq_count}") # _LOGGER.info(f"Sequence count: {tm_packet.seq_count}")
except ValueError as value_error: except ValueError as value_error:
_LOGGER.warning(f"{value_error}") _LOGGER.warning(f"{value_error}")
_LOGGER.warning("Could not generate PUS TM object from raw data") _LOGGER.warning("Could not generate PUS TM object from raw data")
_LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}") _LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}")
return return
timestamp = CdsShortTimestamp.unpack(tm_packet.timestamp)
db_con = sqlite3.connect(TM_DB_PATH) db_con = sqlite3.connect(TM_DB_PATH)
self._store_packet_in_db(db_con, packet, tm_packet, packet_uuid) self._store_packet_in_db(
db_con=db_con,
packet=packet,
tm_packet=tm_packet,
timestamp=timestamp,
packet_uuid=packet_uuid,
)
service = tm_packet.service service = tm_packet.service
dedicated_handler = True dedicated_handler = True
if service == 1: if service == 1:
@ -94,7 +101,7 @@ class PusHandler(SpecificApidHandlerBase):
) )
elif service == 17: elif service == 17:
pus17_tm = Service17Tm.unpack( pus17_tm = Service17Tm.unpack(
data=packet, time_reader=CdsShortTimestamp.empty() data=packet, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE
) )
if pus17_tm.subservice == 2: if pus17_tm.subservice == 2:
self.verif_wrapper.dlog("Received Ping Reply TM[17,2]") self.verif_wrapper.dlog("Received Ping Reply TM[17,2]")
@ -119,11 +126,11 @@ class PusHandler(SpecificApidHandlerBase):
self, self,
db_con: sqlite3.Connection, db_con: sqlite3.Connection,
packet: bytes, packet: bytes,
timestamp: CdsShortTimestamp,
tm_packet: PusTelemetry, tm_packet: PusTelemetry,
packet_uuid: uuid.UUID, packet_uuid: uuid.UUID,
): ):
cursor = db_con.cursor() cursor = db_con.cursor()
assert tm_packet.time_provider is not None
cursor.execute( cursor.execute(
""" """
CREATE TABLE IF NOT EXISTS pus_tm( CREATE TABLE IF NOT EXISTS pus_tm(
@ -139,7 +146,7 @@ class PusHandler(SpecificApidHandlerBase):
"INSERT INTO pus_tm VALUES(?, ?, ?, ?, ?, ?)", "INSERT INTO pus_tm VALUES(?, ?, ?, ?, ?, ?)",
( (
str(packet_uuid), str(packet_uuid),
tm_packet.time_provider.as_datetime(), timestamp.as_datetime(),
tm_packet.service, tm_packet.service,
tm_packet.subservice, tm_packet.subservice,
len(packet), len(packet),
@ -150,7 +157,7 @@ class PusHandler(SpecificApidHandlerBase):
def _handle_param_packet(self, raw_data: bytes, tm_packet: PusTelemetry): def _handle_param_packet(self, raw_data: bytes, tm_packet: PusTelemetry):
param_packet = Service20FsfwTm.unpack( param_packet = Service20FsfwTm.unpack(
raw_telemetry=raw_data, time_reader=CdsShortTimestamp.empty() raw_telemetry=raw_data, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE
) )
if tm_packet.subservice == ParamSubservice.TM_DUMP_REPLY: if tm_packet.subservice == ParamSubservice.TM_DUMP_REPLY:
param_wrapper = Service20ParamDumpWrapper(param_tm=param_packet) param_wrapper = Service20ParamDumpWrapper(param_tm=param_packet)

View File

@ -17,7 +17,7 @@ def handle_service_1_fsfw_packet(wrapper: VerificationWrapper, raw_tm: bytes):
) )
# Error code with length 2 is FSFW specific # Error code with length 2 is FSFW specific
tm_packet = Service1Tm.unpack( tm_packet = Service1Tm.unpack(
data=raw_tm, params=UnpackParams(CdsShortTimestamp.empty(), 1, 2) data=raw_tm, params=UnpackParams(CdsShortTimestamp.TIMESTAMP_SIZE, 1, 2)
) )
fsfw_wrapper = Service1FsfwWrapper(tm_packet) fsfw_wrapper = Service1FsfwWrapper(tm_packet)
res = wrapper.verificator.add_tm(tm_packet) res = wrapper.verificator.add_tm(tm_packet)

View File

@ -31,7 +31,7 @@ classifiers = [
dependencies = [ dependencies = [
"tmtccmd ~= 8.0.0rc1", "tmtccmd ~= 8.0.0rc1",
"cfdp-py~=0.1.0", "cfdp-py~=0.1.0",
# "tmtccmd @ git+https://github.com/robamu-org/tmtccmd@main", # "tmtccmd @ git+https://github.com/robamu-org/tmtccmd@prep_v8.0.0",
"python-dateutil ~= 2.8", "python-dateutil ~= 2.8",
] ]

View File

@ -97,8 +97,8 @@ def setup_params() -> Tuple[SetupWrapper, int]:
hk_level = int(post_arg_parsing_wrapper.args_raw.hk) hk_level = int(post_arg_parsing_wrapper.args_raw.hk)
else: else:
hk_level = 0 hk_level = 0
if params.app_params.print_tree: if params.cmd_params.print_tree:
perform_tree_printout(params.app_params, hook_obj.get_command_definitions()) perform_tree_printout(params.cmd_params, hook_obj.get_command_definitions())
sys.exit(0) sys.exit(0)
params.apid = PUS_APID params.apid = PUS_APID
if params.com_if is None: if params.com_if is None: