continuing refactoring of printouts
This commit is contained in:
parent
3c302bd4e8
commit
5896ecad07
@ -77,26 +77,6 @@ class EiveHookObject(TmTcHookBase):
|
||||
|
||||
return get_object_ids()
|
||||
|
||||
@staticmethod
|
||||
def handle_service_8_telemetry(
|
||||
object_id: bytes, action_id: int, custom_data: bytearray
|
||||
) -> DataReplyUnpacked:
|
||||
from pus_tm.service_8_hook import user_analyze_service_8_data
|
||||
|
||||
return user_analyze_service_8_data(
|
||||
object_id=object_id, action_id=action_id, custom_data=custom_data
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def handle_service_5_event(
|
||||
object_id: bytes, event_id: int, param_1: int, param_2: int
|
||||
) -> str:
|
||||
from pus_tm.event_handler import handle_event_packet
|
||||
|
||||
return handle_event_packet(
|
||||
object_id=object_id, event_id=event_id, param_1=param_1, param_2=param_2
|
||||
)
|
||||
|
||||
def get_retval_dict(self) -> RetvalDictT:
|
||||
return get_retval_dict()
|
||||
|
||||
|
@ -6,7 +6,7 @@ from typing import Union
|
||||
|
||||
from tmtccmd.config.definitions import CoreServiceList
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from tmtccmd.logging.pus import log_pus_tc
|
||||
from tmtccmd.logging.pus import log_raw_pus_tc
|
||||
from tmtccmd.tc.definitions import TcQueueT
|
||||
from tmtccmd.tc.service_5_event import pack_generic_service5_test_into
|
||||
from tmtccmd.pus.service_17_test import pack_service_17_ping_command
|
||||
@ -72,7 +72,7 @@ LOGGER = get_console_logger()
|
||||
def pre_tc_send_cb(packet: bytes, user_args: any):
|
||||
service = packet[7]
|
||||
subservice = packet[8]
|
||||
log_pus_tc(packet=packet, srv_subservice=(service, subservice))
|
||||
log_raw_pus_tc(packet=packet, srv_subservice=(service, subservice))
|
||||
|
||||
|
||||
def pack_service_queue_user(
|
||||
|
@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
from datetime import datetime
|
||||
from config.object_ids import get_object_ids
|
||||
|
||||
from tmtccmd.tm import Service5Tm
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from tmtccmd.fsfw import parse_fsfw_events_csv, EventDictT, EventInfo
|
||||
|
||||
@ -22,26 +24,33 @@ def get_event_dict() -> EventDictT:
|
||||
return __EVENT_DICT
|
||||
|
||||
|
||||
def handle_event_packet(
|
||||
object_id: bytes, event_id: int, param_1: int, param_2: int
|
||||
) -> str:
|
||||
def handle_event_packet(file_logger: logging.Logger, tm: Service5Tm) -> str:
|
||||
additional_event_info = ""
|
||||
event_dict = get_event_dict()
|
||||
info = event_dict.get(event_id)
|
||||
info = event_dict.get(tm.event_id)
|
||||
if info is None:
|
||||
LOGGER.warning(f"Event ID {event_id} has no information")
|
||||
LOGGER.warning(f"Event ID {tm.event_id} has no information")
|
||||
info = EventInfo()
|
||||
info.name = "Unknown event"
|
||||
obj_ids = get_object_ids()
|
||||
obj_id_obj = obj_ids.get(bytes(object_id))
|
||||
obj_id_obj = obj_ids.get(tm.reporter_id.as_bytes)
|
||||
if obj_id_obj is None:
|
||||
LOGGER.warning(f"Object ID 0x{object_id.hex()} has no name")
|
||||
obj_name = object_id.hex()
|
||||
LOGGER.warning(f"Object ID 0x{tm.reporter_id.as_string} has no name")
|
||||
obj_name = tm.reporter_id.as_string
|
||||
else:
|
||||
obj_name = obj_id_obj.name
|
||||
generic_event_string = f"Object {obj_name} generated Event {event_id} | {info.name}"
|
||||
generic_event_string = (
|
||||
f"Object {obj_name} generated Event {tm.event_id} | {info.name}"
|
||||
)
|
||||
if info.info != "":
|
||||
additional_event_info = (
|
||||
f" | Additional info: {info.info} | P1: {param_1} | P2: {param_2}"
|
||||
f"Additional info: {info.info} | P1: {tm.param_1} | P2: {tm.param_2}"
|
||||
)
|
||||
return generic_event_string + additional_event_info
|
||||
file_logger.info(
|
||||
f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: {generic_event_string}"
|
||||
)
|
||||
LOGGER.info(generic_event_string)
|
||||
if additional_event_info != "":
|
||||
file_logger.info(additional_event_info)
|
||||
print(additional_event_info)
|
||||
return generic_event_string + " | " + additional_event_info
|
||||
|
@ -6,64 +6,73 @@
|
||||
from tmtccmd.tm.service_8_fsfw_functional_cmd import Service8FsfwTm
|
||||
from spacepackets.ecss.tm import PusTelemetry
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from tmtccmd.logging.pus import log_pus_tm, log_unknown_packet, PacketTypes
|
||||
from tmtccmd.logging.pus import (
|
||||
log_raw_pus_tm,
|
||||
log_raw_unknown_packet,
|
||||
PacketTypes,
|
||||
create_tmtc_logger,
|
||||
)
|
||||
|
||||
from tmtccmd.pus.service_1_verification import Service1TMExtended
|
||||
from tmtccmd.pus.service_17_test import Service17TMExtended
|
||||
from tmtccmd.tm.service_3_fsfw_housekeeping import Service3FsfwTm
|
||||
from tmtccmd.tm.service_20_fsfw_parameters import Service20FsfwTm
|
||||
from tmtccmd.tm.service_5_event import Service5Tm
|
||||
from tmtccmd.tm.service_200_fsfw_mode import Service200FsfwTm
|
||||
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter, PrintFormats
|
||||
from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter
|
||||
|
||||
from config.definitions import PUS_APID
|
||||
from .event_handler import handle_event_packet
|
||||
from .verification_handler import handle_service_1_packet
|
||||
from .hk_handling import handle_hk_packet
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
|
||||
|
||||
def ccsds_tm_handler(
|
||||
apid: int, raw_tm_packet: bytes, tmtc_printer: FsfwTmTcPrinter
|
||||
) -> None:
|
||||
FSFW_PRINTER = FsfwTmTcPrinter(file_logger=create_tmtc_logger())
|
||||
|
||||
|
||||
def ccsds_tm_handler(apid: int, raw_tm_packet: bytes, _user_args: any) -> None:
|
||||
if apid == PUS_APID:
|
||||
pus_factory_hook(raw_tm_packet=raw_tm_packet, tmtc_printer=tmtc_printer)
|
||||
pus_factory_hook(raw_tm_packet=raw_tm_packet)
|
||||
|
||||
|
||||
def pus_factory_hook(raw_tm_packet: bytes, tmtc_printer: FsfwTmTcPrinter):
|
||||
def pus_factory_hook(raw_tm_packet: bytes):
|
||||
if len(raw_tm_packet) < 8:
|
||||
LOGGER.warning("Detected packet shorter than 8 bytes!")
|
||||
return
|
||||
service_type = raw_tm_packet[7]
|
||||
subservice_type = raw_tm_packet[8]
|
||||
tm_packet = None
|
||||
file_logger = FSFW_PRINTER.file_logger
|
||||
try:
|
||||
if service_type == 1:
|
||||
tm_packet = Service1TMExtended.unpack(raw_telemetry=raw_tm_packet)
|
||||
if service_type == 3:
|
||||
handle_service_1_packet(printer=FSFW_PRINTER, raw_tm=raw_tm_packet)
|
||||
elif service_type == 3:
|
||||
tm_packet = Service3FsfwTm.unpack(
|
||||
raw_telemetry=raw_tm_packet, custom_hk_handling=False
|
||||
)
|
||||
if service_type == 5:
|
||||
handle_hk_packet(hk_packet=tm_packet, packet_if=tm_packet)
|
||||
elif service_type == 5:
|
||||
tm_packet = Service5Tm.unpack(raw_telemetry=raw_tm_packet)
|
||||
if service_type == 8:
|
||||
handle_event_packet(file_logger=file_logger, tm=tm_packet)
|
||||
elif service_type == 8:
|
||||
tm_packet = Service8FsfwTm.unpack(raw_telemetry=raw_tm_packet)
|
||||
if service_type == 17:
|
||||
elif service_type == 17:
|
||||
tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet)
|
||||
if service_type == 20:
|
||||
elif service_type == 20:
|
||||
tm_packet = Service20FsfwTm.unpack(raw_telemetry=raw_tm_packet)
|
||||
if service_type == 200:
|
||||
elif service_type == 200:
|
||||
tm_packet = Service200FsfwTm.unpack(raw_telemetry=raw_tm_packet)
|
||||
if tm_packet is None:
|
||||
else:
|
||||
LOGGER.info(
|
||||
f"The service {service_type} is not implemented in Telemetry Factory"
|
||||
)
|
||||
tm_packet = PusTelemetry.unpack(raw_telemetry=raw_tm_packet)
|
||||
tm_packet.print_source_data(PrintFormats.HEX)
|
||||
LOGGER.info(f"Received packet with service {service_type}")
|
||||
log_pus_tm(packet=raw_tm_packet, srv_subservice=(service_type, subservice_type))
|
||||
# tmtc_printer.print_telemetry(
|
||||
# packet_if=tm_packet, info_if=tm_packet, print_raw_tm=False
|
||||
# )
|
||||
log_raw_pus_tm(
|
||||
packet=raw_tm_packet, srv_subservice=(service_type, subservice_type)
|
||||
)
|
||||
except ValueError:
|
||||
# TODO: Log faulty packet
|
||||
LOGGER.warning("Invalid packet format detected")
|
||||
log_unknown_packet(packet=raw_tm_packet, packet_type=PacketTypes.TM)
|
||||
log_raw_unknown_packet(packet=raw_tm_packet, packet_type=PacketTypes.TM)
|
||||
|
@ -4,11 +4,13 @@ import os
|
||||
import datetime
|
||||
|
||||
from tmtccmd.config.definitions import HkReplyUnpacked
|
||||
from tmtccmd.tm.base import PusTmInterface
|
||||
from tmtccmd.tm.service_3_fsfw_housekeeping import Service3Base
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from pus_tc.devs.bpx_batt import BpxSetIds
|
||||
from pus_tc.devs.syrlinks_hk_handler import SetIds
|
||||
from pus_tc.devs.imtq import ImtqSetIds
|
||||
from tmtccmd.pus.obj_id import ObjectId
|
||||
from config.object_ids import (
|
||||
SYRLINKS_HANDLER_ID,
|
||||
IMTQ_HANDLER_ID,
|
||||
@ -22,9 +24,22 @@ from config.object_ids import (
|
||||
LOGGER = get_console_logger()
|
||||
|
||||
|
||||
def handle_user_hk_packet(
|
||||
object_id: bytes, set_id: int, hk_data: bytearray, service3_packet: Service3Base
|
||||
) -> HkReplyUnpacked:
|
||||
def handle_hk_packet(hk_packet: Service3Base, packet_if: PusTmInterface):
|
||||
if packet_if.subservice == 25 or packet_if.subservice == 26:
|
||||
handle_regular_hk_print(
|
||||
object_id=hk_packet.object_id,
|
||||
hk_packet=hk_packet,
|
||||
hk_data=packet_if.tm_data[8:],
|
||||
)
|
||||
if packet_if.subservice == 10 or packet_if.subservice == 12:
|
||||
LOGGER.warning("HK definitions printout not implemented yet")
|
||||
|
||||
|
||||
def handle_regular_hk_print(
|
||||
object_id: ObjectId, hk_packet: Service3Base, hk_data: bytes
|
||||
):
|
||||
object_id = object_id.as_bytes
|
||||
set_id = hk_packet.set_id
|
||||
"""This function is called when a Service 3 Housekeeping packet is received."""
|
||||
if object_id == SYRLINKS_HANDLER_ID:
|
||||
if set_id == SetIds.RX_REGISTERS_DATASET:
|
||||
@ -54,7 +69,7 @@ def handle_user_hk_packet(
|
||||
|
||||
|
||||
def handle_syrlinks_rx_registers_dataset(
|
||||
hk_data: bytearray,
|
||||
hk_data: bytes,
|
||||
) -> HkReplyUnpacked:
|
||||
reply = HkReplyUnpacked()
|
||||
reply.header_list = [
|
||||
@ -91,7 +106,7 @@ def handle_syrlinks_rx_registers_dataset(
|
||||
|
||||
|
||||
def handle_syrlinks_tx_registers_dataset(
|
||||
hk_data: bytearray,
|
||||
hk_data: bytes,
|
||||
) -> HkReplyUnpacked:
|
||||
reply = HkReplyUnpacked()
|
||||
reply.header_list = ["TX Status", "TX Waveform", "TX AGC value"]
|
||||
@ -104,7 +119,7 @@ def handle_syrlinks_tx_registers_dataset(
|
||||
return reply
|
||||
|
||||
|
||||
def handle_self_test_data(hk_data: bytearray) -> HkReplyUnpacked:
|
||||
def handle_self_test_data(hk_data: bytes) -> HkReplyUnpacked:
|
||||
reply = HkReplyUnpacked()
|
||||
reply.hk_header = [
|
||||
"Init Err",
|
||||
@ -238,7 +253,7 @@ def handle_self_test_data(hk_data: bytearray) -> HkReplyUnpacked:
|
||||
return reply
|
||||
|
||||
|
||||
def handle_gps_data(hk_data: bytearray) -> HkReplyUnpacked:
|
||||
def handle_gps_data(hk_data: bytes) -> HkReplyUnpacked:
|
||||
LOGGER.info(f"Received GPS data, HK data length {len(hk_data)}")
|
||||
reply = HkReplyUnpacked()
|
||||
var_index = 0
|
||||
|
30
pus_tm/verification_handler.py
Normal file
30
pus_tm/verification_handler.py
Normal file
@ -0,0 +1,30 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import cast
|
||||
|
||||
from tmtccmd.pus.service_1_verification import Service1TMExtended
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter
|
||||
from config.retvals import get_retval_dict
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
|
||||
|
||||
def handle_service_1_packet(printer: FsfwTmTcPrinter, raw_tm: bytes):
|
||||
tm_packet = Service1TMExtended.unpack(raw_telemetry=raw_tm)
|
||||
printer.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet)
|
||||
srv1_packet = cast(Service1TMExtended, tm_packet)
|
||||
retval_dict = get_retval_dict()
|
||||
if srv1_packet.has_tc_error_code:
|
||||
retval_info = retval_dict.get(srv1_packet.error_code)
|
||||
if retval_info is None:
|
||||
LOGGER.info(
|
||||
f"No returnvalue information found for error code {srv1_packet.error_code}"
|
||||
)
|
||||
else:
|
||||
retval_string = (
|
||||
f"Error Code information for code {srv1_packet.error_code}| "
|
||||
f"Name: {retval_info.name} | Info: {retval_info.info}"
|
||||
)
|
||||
LOGGER.info(retval_string)
|
||||
printer.file_logger.info(retval_string)
|
@ -72,7 +72,7 @@ def main():
|
||||
tmtc_backend = tmtccmd.get_default_tmtc_backend(
|
||||
hook_obj=hook_obj,
|
||||
json_cfg_path=hook_obj.get_json_config_file_path(),
|
||||
tm_handler=ccsds_handler
|
||||
tm_handler=ccsds_handler,
|
||||
)
|
||||
tmtc_backend.set_pre_send_cb(callable=pre_tc_send_cb, user_args=None)
|
||||
tmtccmd.run_tmtccmd(False, tmtc_backend=tmtc_backend, run_setup=False)
|
||||
|
2
tmtccmd
2
tmtccmd
@ -1 +1 @@
|
||||
Subproject commit 092babfe1430c756f0b3b1eb55333c8771b3e2b9
|
||||
Subproject commit 36f3453c274a5cdc4505b4e8cc22cd2827b7fc16
|
Loading…
Reference in New Issue
Block a user