eive-tmtc/pus_tc/tc_packer_hook.py

256 lines
11 KiB
Python
Raw Normal View History

2021-09-13 18:06:25 +02:00
"""Hook function which packs telecommands based on service and operation code string
2020-12-17 17:50:00 +01:00
"""
2022-04-06 16:17:51 +02:00
import logging
2020-12-17 17:50:00 +01:00
import os
from collections import deque
2021-03-19 17:39:52 +01:00
from typing import Union
2022-05-23 17:50:08 +02:00
from pus_tc.devs.rtd import pack_rtd_commands
2022-04-06 16:17:51 +02:00
from spacepackets.ecss import PusTelecommand
from tmtccmd.com_if.com_interface_base import CommunicationInterface
2022-05-11 15:42:00 +02:00
from tmtccmd.config.definitions import CoreServiceList, QueueCommands
2022-04-05 00:51:52 +02:00
from tmtccmd.logging import get_console_logger
2022-04-05 17:05:11 +02:00
from tmtccmd.logging.pus import log_raw_pus_tc
from tmtccmd.tc.definitions import TcQueueT
from tmtccmd.tc.pus_5_event import pack_generic_service5_test_into
from tmtccmd.pus.pus_17_test import pack_service_17_ping_command
2022-04-06 16:19:59 +02:00
from tmtccmd.logging import get_current_time_string
2021-03-19 17:39:52 +01:00
from pus_tc.service_200_mode import pack_service200_test_into
2022-04-08 14:46:01 +02:00
from pus_tc.devs.p60dock import pack_p60dock_cmds
2022-03-04 10:44:55 +01:00
from pus_tc.devs.pdu2 import pack_pdu2_commands
2022-03-04 10:41:05 +01:00
from pus_tc.devs.pdu1 import pack_pdu1_commands
from pus_tc.devs.bpx_batt import pack_bpx_commands
2022-05-23 11:24:55 +02:00
from pus_tc.devs.acu import pack_acu_commands
from pus_tc.devs.solar_array_deployment import pack_solar_array_deployment_test_into
2022-03-04 10:44:55 +01:00
from pus_tc.devs.imtq import pack_imtq_test_into
from pus_tc.devs.tmp1075 import pack_tmp1075_test_into
2022-03-17 19:42:27 +01:00
from pus_tc.devs.ploc_mpsoc import pack_ploc_mpsoc_commands
from pus_tc.devs.ploc_supervisor import pack_ploc_supv_commands
2022-05-03 19:01:38 +02:00
from pus_tc.devs.heater import pack_heater_cmds
2022-05-05 01:21:57 +02:00
from pus_tc.devs.reaction_wheels import pack_single_rw_test_into, pack_rw_ass_cmds
2022-03-04 10:44:55 +01:00
from pus_tc.devs.rad_sensor import pack_rad_sensor_test_into
from pus_tc.devs.ploc_memory_dumper import pack_ploc_memory_dumper_cmd
2022-03-04 10:41:05 +01:00
from pus_tc.devs.ccsds_handler import pack_ccsds_handler_test
from pus_tc.system.core import pack_core_commands
2022-03-04 10:44:55 +01:00
from pus_tc.devs.star_tracker import pack_star_tracker_commands
from pus_tc.devs.syrlinks_hk_handler import pack_syrlinks_command
2022-03-04 10:41:05 +01:00
from pus_tc.devs.gps import pack_gps_command
2022-04-09 18:44:04 +02:00
from pus_tc.system.time import pack_set_current_time_ascii_command
2022-03-22 10:14:22 +01:00
from pus_tc.system.acs import pack_acs_command, pack_sus_cmds
2022-03-04 10:44:55 +01:00
from pus_tc.devs.plpcdu import pack_pl_pcdu_commands
from pus_tc.devs.str_img_helper import pack_str_img_helper_command
2022-03-22 19:29:55 +01:00
from pus_tc.system.tcs import pack_tcs_sys_commands
2022-05-18 18:39:18 +02:00
from pus_tc.system.proc import pack_proc_commands
2022-05-27 11:53:57 +02:00
from pus_tc.system.controllers import pack_cmd_ctrl_to_prompted_mode
2021-03-19 17:39:52 +01:00
from config.definitions import CustomServiceList
2022-01-18 14:03:56 +01:00
from config.object_ids import (
2022-05-23 11:24:55 +02:00
get_object_ids,
2022-01-18 14:03:56 +01:00
P60_DOCK_HANDLER,
PDU_1_HANDLER_ID,
PDU_2_HANDLER_ID,
ACU_HANDLER_ID,
TMP_1075_1_HANDLER_ID,
TMP_1075_2_HANDLER_ID,
HEATER_ID,
IMTQ_HANDLER_ID,
PLOC_MPSOC_ID,
RW1_ID,
RW2_ID,
RW3_ID,
RW4_ID,
RAD_SENSOR_ID,
PLOC_SUPV_ID,
STAR_TRACKER_ID,
PLOC_MEMORY_DUMPER_ID,
2022-05-27 11:53:57 +02:00
GPS_CONTROLLER,
2022-01-18 14:03:56 +01:00
CCSDS_HANDLER_ID,
PDEC_HANDLER_ID,
STR_IMG_HELPER_ID,
SYRLINKS_HANDLER_ID,
SOLAR_ARRAY_DEPLOYMENT_ID,
2022-05-05 01:21:57 +02:00
RW_ASSEMBLY,
2022-05-23 18:25:25 +02:00
get_object_ids,
2022-01-18 14:03:56 +01:00
)
2022-05-24 01:49:57 +02:00
import config.object_ids as oids
2020-12-17 17:50:00 +01:00
2021-06-28 19:06:09 +02:00
LOGGER = get_console_logger()
2020-12-17 17:50:00 +01:00
2022-04-06 16:17:51 +02:00
def pre_tc_send_cb(
2022-05-11 15:42:00 +02:00
queue_entry: Union[bytes, QueueCommands],
2022-04-06 16:17:51 +02:00
com_if: CommunicationInterface,
2022-05-11 15:42:00 +02:00
queue_info: Union[PusTelecommand, any],
2022-04-06 16:17:51 +02:00
file_logger: logging.Logger,
):
2022-05-11 15:42:00 +02:00
if isinstance(queue_entry, bytes) or isinstance(queue_entry, bytearray):
log_raw_pus_tc(
2022-05-16 18:35:36 +02:00
packet=queue_entry,
srv_subservice=(queue_info.service, queue_info.subservice),
2022-05-11 15:42:00 +02:00
)
tc_info_string = f"Sent {queue_info}"
LOGGER.info(tc_info_string)
file_logger.info(f"{get_current_time_string(True)}: {tc_info_string}")
com_if.send(data=queue_entry)
elif isinstance(queue_entry, QueueCommands):
if queue_entry == QueueCommands.PRINT:
file_logger.info(queue_info)
2022-04-05 15:19:46 +02:00
2022-01-18 14:03:56 +01:00
def pack_service_queue_user(
service: Union[str, int], op_code: str, service_queue: TcQueueT
):
2022-05-23 11:24:55 +02:00
obj_id_man = get_object_ids()
2021-05-17 17:42:04 +02:00
if service == CoreServiceList.SERVICE_5.value:
2021-05-17 17:48:02 +02:00
return pack_generic_service5_test_into(tc_queue=service_queue)
2021-05-17 17:42:04 +02:00
if service == CoreServiceList.SERVICE_17.value:
2022-01-18 14:03:56 +01:00
return service_queue.appendleft(
pack_service_17_ping_command(ssc=1700).pack_command_tuple()
)
if service == CoreServiceList.SERVICE_200.value:
return pack_service200_test_into(tc_queue=service_queue)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.P60DOCK.value:
2022-05-23 11:24:55 +02:00
object_id = obj_id_man.get(P60_DOCK_HANDLER)
2022-04-08 14:46:01 +02:00
return pack_p60dock_cmds(
2022-01-18 14:03:56 +01:00
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2022-05-23 17:50:08 +02:00
if service == CustomServiceList.RTD.value:
2022-05-23 18:34:28 +02:00
return pack_rtd_commands(
object_id=None, tc_queue=service_queue, op_code=op_code
)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.PDU1.value:
2022-05-23 11:24:55 +02:00
object_id = obj_id_man.get(PDU_1_HANDLER_ID)
2022-01-18 14:03:56 +01:00
return pack_pdu1_commands(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.PDU2.value:
2022-05-23 11:24:55 +02:00
object_id = obj_id_man.get(PDU_2_HANDLER_ID)
2022-01-18 14:03:56 +01:00
return pack_pdu2_commands(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.ACU.value:
2022-05-23 11:24:55 +02:00
object_id = obj_id_man.get(ACU_HANDLER_ID)
return pack_acu_commands(
2022-01-18 14:03:56 +01:00
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
if service == CustomServiceList.BPX_BATTERY.value:
return pack_bpx_commands(tc_queue=service_queue, op_code=op_code)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.TMP1075_1.value:
2021-05-17 17:42:04 +02:00
object_id = TMP_1075_1_HANDLER_ID
2022-01-18 14:03:56 +01:00
return pack_tmp1075_test_into(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.TMP1075_2.value:
2021-05-17 17:42:04 +02:00
object_id = TMP_1075_2_HANDLER_ID
2022-01-18 14:03:56 +01:00
return pack_tmp1075_test_into(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-03-19 17:39:52 +01:00
if service == CustomServiceList.HEATER.value:
2021-05-17 17:42:04 +02:00
object_id = HEATER_ID
2022-05-05 14:30:28 +02:00
return pack_heater_cmds(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-03-26 13:56:02 +01:00
if service == CustomServiceList.IMTQ.value:
2021-06-11 13:51:56 +02:00
object_id = IMTQ_HANDLER_ID
2022-01-18 14:03:56 +01:00
return pack_imtq_test_into(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2022-03-17 19:42:27 +01:00
if service == CustomServiceList.PLOC_MPSOC.value:
2021-07-09 12:57:39 +02:00
object_id = PLOC_MPSOC_ID
2022-03-22 19:29:55 +01:00
return pack_ploc_mpsoc_commands(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-06-29 09:51:54 +02:00
if service == CustomServiceList.REACTION_WHEEL_1.value:
2022-01-18 14:03:56 +01:00
return pack_single_rw_test_into(
2022-05-05 02:00:18 +02:00
object_id=RW1_ID, rw_idx=1, tc_queue=service_queue, op_code=op_code
2022-01-18 14:03:56 +01:00
)
2021-06-29 09:51:54 +02:00
if service == CustomServiceList.REACTION_WHEEL_2.value:
2022-01-18 14:03:56 +01:00
return pack_single_rw_test_into(
2022-05-05 02:00:18 +02:00
object_id=RW2_ID, rw_idx=2, tc_queue=service_queue, op_code=op_code
2022-01-18 14:03:56 +01:00
)
2021-06-29 09:51:54 +02:00
if service == CustomServiceList.REACTION_WHEEL_3.value:
2022-01-18 14:03:56 +01:00
return pack_single_rw_test_into(
2022-05-05 02:00:18 +02:00
object_id=RW3_ID, rw_idx=3, tc_queue=service_queue, op_code=op_code
2022-01-18 14:03:56 +01:00
)
2021-06-29 09:51:54 +02:00
if service == CustomServiceList.REACTION_WHEEL_4.value:
2022-01-18 14:03:56 +01:00
return pack_single_rw_test_into(
2022-05-05 02:00:18 +02:00
object_id=RW4_ID, rw_idx=4, tc_queue=service_queue, op_code=op_code
2022-01-18 14:03:56 +01:00
)
if service == CustomServiceList.RAD_SENSOR.value:
2022-05-23 18:25:25 +02:00
object_id = obj_id_man.get(RAD_SENSOR_ID)
2021-09-08 13:20:22 +02:00
return pack_rad_sensor_test_into(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-07-11 14:29:11 +02:00
if service == CustomServiceList.PLOC_SUPV.value:
object_id = PLOC_SUPV_ID
2022-03-17 19:42:27 +01:00
return pack_ploc_supv_commands(
2021-09-08 13:20:22 +02:00
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-08-16 10:03:40 +02:00
if service == CustomServiceList.STAR_TRACKER.value:
object_id = STAR_TRACKER_ID
2021-12-02 08:01:18 +01:00
return pack_star_tracker_commands(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
if service == CustomServiceList.STR_IMG_HELPER.value:
object_id = STR_IMG_HELPER_ID
return pack_str_img_helper_command(
2021-09-08 13:20:22 +02:00
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-08-03 15:28:28 +02:00
if service == CustomServiceList.CORE.value:
return pack_core_commands(tc_queue=service_queue, op_code=op_code)
2021-08-31 11:17:01 +02:00
if service == CustomServiceList.PLOC_MEMORY_DUMPER.value:
object_id = PLOC_MEMORY_DUMPER_ID
2021-09-08 13:20:22 +02:00
return pack_ploc_memory_dumper_cmd(
object_id=object_id, tc_queue=service_queue, op_code=op_code
)
2021-09-13 18:06:25 +02:00
if service == CustomServiceList.ACS.value:
return pack_acs_command(tc_queue=service_queue, op_code=op_code)
2022-05-24 01:49:57 +02:00
if service == CustomServiceList.GPS_CTRL.value:
2022-01-18 14:03:56 +01:00
return pack_gps_command(
2022-05-24 01:49:57 +02:00
object_id=oids.GPS_CONTROLLER, tc_queue=service_queue, op_code=op_code
2022-01-18 14:03:56 +01:00
)
2021-11-24 15:56:25 +01:00
if service == CustomServiceList.CCSDS_HANDLER.value:
2022-01-18 14:03:56 +01:00
return pack_ccsds_handler_test(
object_id=CCSDS_HANDLER_ID, tc_queue=service_queue, op_code=op_code
)
2021-11-24 15:56:25 +01:00
if service == CustomServiceList.PDEC_HANDLER.value:
2022-01-18 14:03:56 +01:00
return pack_ccsds_handler_test(
object_id=PDEC_HANDLER_ID, tc_queue=service_queue, op_code=op_code
)
2021-12-02 09:25:31 +01:00
if service == CustomServiceList.SYRLINKS.value:
2022-01-18 14:03:56 +01:00
return pack_syrlinks_command(
object_id=SYRLINKS_HANDLER_ID, tc_queue=service_queue, op_code=op_code
)
if service == CustomServiceList.SA_DEPLYOMENT.value:
return pack_solar_array_deployment_test_into(
object_id=SOLAR_ARRAY_DEPLOYMENT_ID, tc_queue=service_queue
)
2022-05-18 18:39:18 +02:00
if service == CustomServiceList.PROCEDURE.value:
return pack_proc_commands(tc_queue=service_queue, op_code=op_code)
2022-03-22 10:14:22 +01:00
if service == CustomServiceList.SUS_ASS.value:
return pack_sus_cmds(tc_queue=service_queue, op_code=op_code)
2022-02-25 19:25:14 +01:00
if service == CustomServiceList.PL_PCDU.value:
return pack_pl_pcdu_commands(tc_queue=service_queue, op_code=op_code)
2022-03-07 11:07:54 +01:00
if service == CustomServiceList.ACS_ASS.value:
return pack_acs_command(tc_queue=service_queue, op_code=op_code)
2022-03-22 19:29:55 +01:00
if service == CustomServiceList.TCS_ASS.value:
return pack_tcs_sys_commands(tc_queue=service_queue, op_code=op_code)
2022-04-09 18:44:04 +02:00
if service == CustomServiceList.TIME.value:
return pack_set_current_time_ascii_command(tc_queue=service_queue, ssc=0)
2022-05-10 18:34:15 +02:00
if service == CustomServiceList.RW_ASSEMBLY.value:
2022-05-05 01:21:57 +02:00
return pack_rw_ass_cmds(
tc_queue=service_queue, object_id=RW_ASSEMBLY, op_code=op_code
)
if service == CustomServiceList.CONTROLLERS.value:
return pack_controller_commands(tc_queue=service_queue, op_code=op_code)
2022-05-24 01:49:57 +02:00
LOGGER.warning(f"Invalid Service {service}")
2020-12-17 17:50:00 +01:00
def create_total_tc_queue_user() -> TcQueueT:
if not os.path.exists("log"):
os.mkdir("log")
tc_queue = deque()
2021-02-03 14:14:54 +01:00
pack_generic_service5_test_into(tc_queue)
2021-10-04 01:33:03 +02:00
tc_queue.appendleft(pack_service_17_ping_command(ssc=1700).pack_command_tuple())
2020-12-17 17:50:00 +01:00
return tc_queue