From db033edd2374b465911b8df2c9a4878c2f61bbda Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jul 2022 11:52:47 +0200 Subject: [PATCH 01/10] move dependencies int deps folder --- .gitmodules | 4 ++-- spacepackets => deps/spacepackets | 0 tmtccmd => deps/tmtccmd | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename spacepackets => deps/spacepackets (100%) rename tmtccmd => deps/tmtccmd (100%) diff --git a/.gitmodules b/.gitmodules index 477ffc1..8cb1486 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ [submodule "tmtccmd"] - path = tmtccmd + path = deps/tmtccmd url = https://github.com/robamu-org/tmtccmd.git [submodule "spacepackets"] - path = spacepackets + path = deps/spacepackets url = https://github.com/robamu-org/py-spacepackets.git diff --git a/spacepackets b/deps/spacepackets similarity index 100% rename from spacepackets rename to deps/spacepackets diff --git a/tmtccmd b/deps/tmtccmd similarity index 100% rename from tmtccmd rename to deps/tmtccmd From fd5b9468107bb20e63055faee8ee802c911d2e0c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jul 2022 11:55:10 +0200 Subject: [PATCH 02/10] bump dependencies --- deps/spacepackets | 2 +- deps/tmtccmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/spacepackets b/deps/spacepackets index 7fdf07f..5317f4c 160000 --- a/deps/spacepackets +++ b/deps/spacepackets @@ -1 +1 @@ -Subproject commit 7fdf07f2a1a93bcad0bdda32acd48b2a600cd861 +Subproject commit 5317f4c384321b5b5d8832f51c530fa91d3b2ae5 diff --git a/deps/tmtccmd b/deps/tmtccmd index 4de1bb0..82962b9 160000 --- a/deps/tmtccmd +++ b/deps/tmtccmd @@ -1 +1 @@ -Subproject commit 4de1bb09c97b30fa64260c9f470537d23456c810 +Subproject commit 82962b95ebda8fc5200fe999319abb3bdb7fcd90 From 27edcbd71d3d085de84121a49996fb1064253be5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jul 2022 15:22:53 +0200 Subject: [PATCH 03/10] starting changing code to new API --- ....run.xml => Python tests in tests.run.xml} | 7 +- .run/Unittests_in_spacepackets.run.xml | 18 - config/hook_implementations.py | 2 +- deps/tmtccmd | 2 +- gomspace/gomspace_common.py | 19 +- pus_tc/devs/acu.py | 197 ++++--- pus_tc/devs/bpx_batt.py | 42 +- pus_tc/devs/heater.py | 35 +- pus_tc/devs/imtq.py | 293 ++++------ pus_tc/devs/p60dock.py | 323 +++++------ pus_tc/devs/pdec_handler.py | 26 +- pus_tc/devs/pdu1.py | 394 ++++++------- pus_tc/devs/pdu2.py | 438 +++++++-------- pus_tc/devs/ploc_mpsoc.py | 225 ++++---- pus_tc/devs/ploc_supervisor.py | 516 ++++++++---------- pus_tc/devs/rad_sensor.py | 42 +- pus_tc/devs/reaction_wheels.py | 54 +- pus_tc/devs/rtd.py | 37 +- pus_tc/devs/tmp1075.py | 53 +- ...{tc_packer_hook.py => procedure_packer.py} | 121 ++-- pus_tc/service_200_mode.py | 28 +- pus_tc/system/proc.py | 41 +- pus_tm/action_reply_handler.py | 10 +- pus_tm/devs/mgms.py | 12 +- pus_tm/devs/pcdu.py | 6 +- pus_tm/event_handler.py | 4 +- pus_tm/factory_hook.py | 115 ++-- pus_tm/system/tcs.py | 39 +- pus_tm/tm_tcp_server.py | 5 +- pus_tm/verification_handler.py | 39 +- tmtcc.py | 58 +- tmtccli.py | 1 - tmtcgui.py | 5 +- tmtcloop.py | 2 +- 34 files changed, 1472 insertions(+), 1737 deletions(-) rename .run/{Unittests_in_tmtccmd.run.xml => Python tests in tests.run.xml} (65%) delete mode 100644 .run/Unittests_in_spacepackets.run.xml rename pus_tc/{tc_packer_hook.py => procedure_packer.py} (80%) diff --git a/.run/Unittests_in_tmtccmd.run.xml b/.run/Python tests in tests.run.xml similarity index 65% rename from .run/Unittests_in_tmtccmd.run.xml rename to .run/Python tests in tests.run.xml index 5cdbb08..0d3e786 100644 --- a/.run/Unittests_in_tmtccmd.run.xml +++ b/.run/Python tests in tests.run.xml @@ -1,17 +1,16 @@ - + diff --git a/.run/Unittests_in_spacepackets.run.xml b/.run/Unittests_in_spacepackets.run.xml deleted file mode 100644 index bf17647..0000000 --- a/.run/Unittests_in_spacepackets.run.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - \ No newline at end of file diff --git a/config/hook_implementations.py b/config/hook_implementations.py index bf6a715..26f4560 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -39,7 +39,7 @@ class EiveHookObject(TmTcHookBase): custom_mode_operation(mode=mode, tmtc_backend=tmtc_backend) def pack_service_queue(self, service: int, op_code: str, service_queue: TcQueueT): - from pus_tc.tc_packer_hook import pack_service_queue_user + from pus_tc.procedure_packer import pack_service_queue_user pack_service_queue_user( service=service, op_code=op_code, service_queue=service_queue diff --git a/deps/tmtccmd b/deps/tmtccmd index 82962b9..e5d12ca 160000 --- a/deps/tmtccmd +++ b/deps/tmtccmd @@ -1 +1 @@ -Subproject commit 82962b95ebda8fc5200fe999319abb3bdb7fcd90 +Subproject commit e5d12ca4c0da06338e575701972aaf4180b49635 diff --git a/gomspace/gomspace_common.py b/gomspace/gomspace_common.py index 4e6ad5a..7a59471 100644 --- a/gomspace/gomspace_common.py +++ b/gomspace/gomspace_common.py @@ -8,6 +8,7 @@ """ import enum import struct +from typing import Union from tmtccmd.tc.pus_8_funccmd import generate_action_command from tmtccmd.tc.definitions import PusTelecommand @@ -74,7 +75,10 @@ class Channel: def pack_get_param_command( - object_id: bytes, table_id: int, memory_address: bytearray, parameter_size: int + object_id: bytes, + table_id: int, + memory_address: Union[int, bytes], + parameter_size: int, ) -> PusTelecommand: """Function to generate a command to retrieve parameters like the temperature from a gomspace device. @param object_id: The object id of the gomspace device handler. @@ -83,9 +87,12 @@ def pack_get_param_command( @param parameter_size: Size of the value to read. E.g. temperature is uint16_t and thus parameter_size is 2 @return: The command as bytearray. """ - app_data = struct.pack('!B', table_id) - app_data += struct.pack('!H', memory_address) - app_data += struct.pack('!B', parameter_size) + app_data = struct.pack("!B", table_id) + if isinstance(memory_address, int): + app_data += struct.pack("!H", memory_address) + else: + app_data += memory_address + app_data += struct.pack("!B", parameter_size) return generate_action_command( object_id=object_id, action_id=GomspaceDeviceActionIds.PARAM_GET, @@ -95,7 +102,7 @@ def pack_get_param_command( def pack_set_param_command( object_id: bytes, - memory_address: bytearray, + memory_address: bytes, parameter_size: int, parameter: int, ssc: int = 0, @@ -116,7 +123,7 @@ def pack_set_param_command( if parameter_size == 1: app_data.append(parameter) elif parameter_size == 2: - app_data += struct.pack('!H', parameter) + app_data += struct.pack("!H", parameter) elif parameter_size == 4: byte_one = 0xFF000000 & parameter >> 24 byte_two = 0xFF0000 & parameter >> 16 diff --git a/pus_tc/devs/acu.py b/pus_tc/devs/acu.py index a7df0f7..55163cc 100644 --- a/pus_tc/devs/acu.py +++ b/pus_tc/devs/acu.py @@ -6,9 +6,8 @@ import struct from config.definitions import CustomServiceList -from tmtccmd.config import add_op_code_entry, add_service_op_code_entry -from tmtccmd.tc.packer import TcQueueT -from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( make_sid, generate_one_diag_command, @@ -84,53 +83,48 @@ def add_acu_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_acu_commands( - object_id: ObjectId, tc_queue: TcQueueT, op_code: str -) -> TcQueueT: - tc_queue.appendleft((QueueCommands.PRINT, "Handling ACU command")) +def pack_acu_commands(object_id: ObjectId, q: QueueHelper, op_code: str) -> TcQueueT: + q.add_log_cmd("Handling ACU command") if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Print channel stats")) - command = generate_action_command( - object_id=object_id.as_bytes, - action_id=gs.GomspaceDeviceActionIds.PRINT_SWITCH_V_I, + q.add_log_cmd("ACU: Print channel stats") + q.add_pus_tc( + generate_action_command( + object_id=object_id.as_bytes, + action_id=gs.GomspaceDeviceActionIds.PRINT_SWITCH_V_I, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE: - tc_queue.appendleft( - (QueueCommands.PRINT, f"PDU1: {GsInfo.REQUEST_CORE_HK_ONCE}") - ) + q.add_log_cmd(f"PDU1: {GsInfo.REQUEST_CORE_HK_ONCE}") hk_sid = make_sid(object_id=object_id.as_bytes, set_id=gs.SetIds.ACU_CORE) - command = generate_one_diag_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_diag_command(sid=hk_sid)) if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE: - tc_queue.appendleft( - (QueueCommands.PRINT, f"PDU1: {GsInfo.REQUEST_AUX_HK_ONCE}") - ) + q.add_log_cmd(f"PDU1: {GsInfo.REQUEST_AUX_HK_ONCE}") hk_sid = make_sid(object_id=object_id.as_bytes, set_id=gs.SetIds.ACU_AUX) - command = generate_one_hk_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) if op_code in GomspaceOpCodes.GET_PARAM: - tc_queue.appendleft( - (QueueCommands.PRINT, f"PDU1: {GsInfo.GET_PARAMETER}") - ) + q.add_log_cmd(f"PDU1: {GsInfo.GET_PARAMETER}") table_id = int(input("Specify table ID: ")) memory_address = int(input("Specify memory address: 0x"), 16) parameter_size = int(input("Specify parameter size: ")) - command = gs.pack_get_param_command(object_id.as_bytes, table_id, memory_address, parameter_size) - tc_queue.appendleft(command.pack_command_tuple()) - if op_code in GomspaceOpCodes.SET_PARAM: - tc_queue.appendleft( - (QueueCommands.PRINT, f"PDU1: {GsInfo.SET_PARAMETER}") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, table_id, memory_address, parameter_size + ) ) + if op_code in GomspaceOpCodes.SET_PARAM: + q.add_log_cmd(f"PDU1: {GsInfo.SET_PARAMETER}") memory_address = int(input("Specify memory address: 0x"), 16) - memory_address = struct.pack('!H', memory_address) + memory_address = struct.pack("!H", memory_address) parameter_size = int(input("Specify parameter size: ")) parameter = int(input("Specify parameter: ")) - command = gs.pack_set_param_command(object_id.as_bytes, memory_address, parameter_size, parameter) - tc_queue.appendleft(command.pack_command_tuple()) - pack_test_cmds(object_id=object_id, tc_queue=tc_queue) + q.add_pus_tc( + gs.pack_set_param_command( + object_id.as_bytes, memory_address, parameter_size, parameter + ) + ) + pack_test_cmds(object_id=object_id, q=q) - return tc_queue + return q class ACUTestProcedure: @@ -156,91 +150,84 @@ class ACUTestProcedure: off = False -def pack_test_cmds(object_id: ObjectId, tc_queue: TcQueueT): +def pack_test_cmds(object_id: ObjectId, q: QueueHelper): if ACUTestProcedure.all or ACUTestProcedure.reboot: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reboot")) - command = gs.pack_reboot_command(object_id) - # command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("ACU: Reboot") + q.add_pus_tc(gs.pack_reboot_command(object_id)) if ACUTestProcedure.all or ACUTestProcedure.read_gnd_wdt: - tc_queue.appendleft( - (QueueCommands.PRINT, "ACU: Reading ground watchdog timer value") + q.add_log_cmd("ACU: Reading ground watchdog timer value") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.hk, + ACUHkTable.wdt_gnd_left.parameter_address, + ACUHkTable.wdt_gnd_left.parameter_size, + ) ) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.hk, - ACUHkTable.wdt_gnd_left.parameter_address, - ACUHkTable.wdt_gnd_left.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.gnd_wdt_reset: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Testing ground watchdog reset")) - command = gs.pack_gnd_wdt_reset_command(object_id) - # command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("ACU: Testing ground watchdog reset") + q.add_pus_tc(gs.pack_gnd_wdt_reset_command(object_id)) if ACUTestProcedure.all or ACUTestProcedure.ping: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Ping Test")) + q.add_log_cmd("ACU: Ping Test") ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - command = gs.pack_ping_command(object_id, ping_data) - # command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(gs.pack_ping_command(object_id, ping_data)) if ACUTestProcedure.all or ACUTestProcedure.read_temperature3: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading temperature 3")) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.hk, - ACUHkTable.temperature3.parameter_address, - ACUHkTable.temperature3.parameter_size, + q.add_log_cmd("ACU: Reading temperature 3") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.hk, + ACUHkTable.temperature3.parameter_address, + ACUHkTable.temperature3.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.read_vboost: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vboost value")) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.config, - ACUConfigTable.vboost.parameter_address, - ACUConfigTable.vboost.parameter_size, + q.add_log_cmd("ACU: Reading vboost value") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.config, + ACUConfigTable.vboost.parameter_address, + ACUConfigTable.vboost.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_hi: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vbat_max_hi")) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.config, - ACUConfigTable.vbat_max_hi.parameter_address, - ACUConfigTable.vbat_max_hi.parameter_size, + q.add_log_cmd("ACU: Reading vbat_max_hi") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.config, + ACUConfigTable.vbat_max_hi.parameter_address, + ACUConfigTable.vbat_max_hi.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_lo: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vbat_max_lo")) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.config, - ACUConfigTable.vbat_max_lo.parameter_address, - ACUConfigTable.vbat_max_lo.parameter_size, + q.add_log_cmd("ACU: Reading vbat_max_lo") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.config, + ACUConfigTable.vbat_max_lo.parameter_address, + ACUConfigTable.vbat_max_lo.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.read_ov_mode: - tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading ov_mode")) - command = gs.pack_get_param_command( - object_id.as_bytes, - gs.TableIds.config, - ACUConfigTable.ov_mode.parameter_address, - ACUConfigTable.ov_mode.parameter_size, + q.add_log_cmd("ACU: Reading ov_mode") + q.add_pus_tc( + gs.pack_get_param_command( + object_id.as_bytes, + gs.TableIds.config, + ACUConfigTable.ov_mode.parameter_address, + ACUConfigTable.ov_mode.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if ACUTestProcedure.all or ACUTestProcedure.off: - tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning off ACU")) - command = gs.pack_set_param_command( - ACU_HANDLER_ID, - P60DockConfigTable.out_en_0.parameter_address, - P60DockConfigTable.out_en_0.parameter_size, - gs.Channel.off, + q.add_log_cmd("P60 Dock: Turning off ACU") + q.add_pus_tc( + gs.pack_set_param_command( + ACU_HANDLER_ID, + P60DockConfigTable.out_en_0.parameter_address, + P60DockConfigTable.out_en_0.parameter_size, + gs.Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) diff --git a/pus_tc/devs/bpx_batt.py b/pus_tc/devs/bpx_batt.py index 3073327..dffbfca 100644 --- a/pus_tc/devs/bpx_batt.py +++ b/pus_tc/devs/bpx_batt.py @@ -1,5 +1,5 @@ -from tmtccmd.tc.definitions import TcQueueT, QueueCommands from config.object_ids import BPX_HANDLER_ID +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_8_funccmd import generate_action_command from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid @@ -24,33 +24,33 @@ class BpxOpCodes: REBOOT = ["4", "reboot"] -def pack_bpx_commands(tc_queue: TcQueueT, op_code: str): +def pack_bpx_commands(q: QueueHelper, op_code: str): if op_code in BpxOpCodes.HK: - tc_queue.appendleft((QueueCommands.PRINT, "Requesting BPX battery HK set")) + q.add_log_cmd("Requesting BPX battery HK set") sid = make_sid(object_id=BPX_HANDLER_ID, set_id=BpxSetIds.GET_HK_SET) - cmd = generate_one_hk_command(sid=sid, ssc=0) - tc_queue.appendleft(cmd.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=sid)) if op_code in BpxOpCodes.RST_BOOT_CNT: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counters")) - cmd = generate_action_command( - object_id=BPX_HANDLER_ID, action_id=BpxActionIds.RESET_COUNTERS + q.add_log_cmd("Resetting reboot counters") + q.add_pus_tc( + generate_action_command( + object_id=BPX_HANDLER_ID, action_id=BpxActionIds.RESET_COUNTERS + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in BpxOpCodes.REQUEST_CFG: - tc_queue.appendleft((QueueCommands.PRINT, "Requesting configuration struct")) - cmd = generate_action_command( - object_id=BPX_HANDLER_ID, action_id=BpxActionIds.GET_CFG + q.add_log_cmd("Requesting configuration struct") + q.add_pus_tc( + generate_action_command( + object_id=BPX_HANDLER_ID, action_id=BpxActionIds.GET_CFG + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in BpxOpCodes.REQUEST_CFG_HK: - tc_queue.appendleft((QueueCommands.PRINT, "Requesting configuration struct HK")) + q.add_log_cmd("Requesting configuration struct HK") sid = make_sid(object_id=BPX_HANDLER_ID, set_id=BpxSetIds.GET_CFG_SET) - cmd = generate_one_hk_command(sid=sid, ssc=0) - tc_queue.appendleft(cmd.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=sid)) if op_code in BpxOpCodes.REBOOT: - tc_queue.appendleft((QueueCommands.PRINT, "Rebooting BPX battery")) - cmd = generate_action_command( - object_id=BPX_HANDLER_ID, action_id=BpxActionIds.REBOOT + q.add_log_cmd("Rebooting BPX battery") + q.add_pus_tc( + generate_action_command( + object_id=BPX_HANDLER_ID, action_id=BpxActionIds.REBOOT + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) - pass diff --git a/pus_tc/devs/heater.py b/pus_tc/devs/heater.py index 4dc9ef5..664cc13 100644 --- a/pus_tc/devs/heater.py +++ b/pus_tc/devs/heater.py @@ -7,16 +7,14 @@ import enum from config.definitions import CustomServiceList from config.object_ids import get_object_ids +from tmtccmd.tc import QueueHelper from tmtccmd.utility.obj_id import ObjectId -from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT from tmtccmd.tc.pus_201_fsfw_health import ( pack_set_health_cmd_data, FsfwHealth, Subservices, ) from tmtccmd.tc.pus_8_funccmd import generate_action_command -from tmtccmd.config.globals import add_service_op_code_entry, add_op_code_entry -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand @@ -82,9 +80,9 @@ def add_heater_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_heater_cmds(object_id: bytearray, op_code: str, tc_queue: TcQueueT): +def pack_heater_cmds(object_id: bytearray, op_code: str, q: QueueHelper): if op_code in OpCodes.HEATER_CMD: - tc_queue.appendleft((QueueCommands.PRINT, "Heater Switching")) + q.add_log_cmd("Heater Switching") heater_number = prompt_heater() while True: action = input("Turn switch on or off? (0 - off, 1 - on): ") @@ -101,14 +99,13 @@ def pack_heater_cmds(object_id: bytearray, op_code: str, tc_queue: TcQueueT): else: act_str = "off" debug_string = f"Switching heater {heater_number} {act_str}" - tc_queue.appendleft((QueueCommands.PRINT, debug_string)) - command = pack_switch_heater_command(object_id, heater_number, action) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd(debug_string) + q.add_pus_tc(pack_switch_heater_command(object_id, heater_number, action)) if op_code in OpCodes.HEATER_EXT_CTRL: heater_number = prompt_heater() obj_id = heater_idx_to_obj(heater_number) health_cmd( - tc_queue=tc_queue, + q=q, object_id=obj_id, health=FsfwHealth.EXTERNAL_CTRL, health_str="External Control", @@ -118,7 +115,7 @@ def pack_heater_cmds(object_id: bytearray, op_code: str, tc_queue: TcQueueT): heater_number = prompt_heater() obj_id = heater_idx_to_obj(heater_number) health_cmd( - tc_queue=tc_queue, + q=q, object_id=obj_id, health=FsfwHealth.FAULTY, health_str="Faulty", @@ -128,7 +125,7 @@ def pack_heater_cmds(object_id: bytearray, op_code: str, tc_queue: TcQueueT): heater_number = prompt_heater() obj_id = heater_idx_to_obj(heater_number) health_cmd( - tc_queue=tc_queue, + q=q, object_id=obj_id, health=FsfwHealth.HEALTHY, health_str="Healthy", @@ -188,23 +185,19 @@ def prompt_heater() -> int: def health_cmd( - tc_queue: TcQueueT, + q: QueueHelper, heater_idx: int, object_id: ObjectId, health: FsfwHealth, health_str: str, ): - tc_queue.appendleft( - ( - QueueCommands.PRINT, - f"Setting Heater {heater_idx} {object_id} to {health_str}", + q.add_log_cmd(f"Setting Heater {heater_idx} {object_id} to {health_str}") + app_data = pack_set_health_cmd_data(object_id=object_id.as_bytes, health=health) + q.add_pus_tc( + PusTelecommand( + service=201, subservice=Subservices.TC_SET_HEALTH, app_data=app_data ) ) - app_data = pack_set_health_cmd_data(object_id=object_id.as_bytes, health=health) - cmd = PusTelecommand( - service=201, subservice=Subservices.TC_SET_HEALTH, app_data=app_data - ) - tc_queue.appendleft(cmd.pack_command_tuple()) def pack_switch_heater_command( diff --git a/pus_tc/devs/imtq.py b/pus_tc/devs/imtq.py index ea31b5d..7105185 100644 --- a/pus_tc/devs/imtq.py +++ b/pus_tc/devs/imtq.py @@ -7,16 +7,15 @@ """ import struct -from tmtccmd.config.definitions import QueueCommands - -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( make_sid, generate_one_diag_command, generate_one_hk_command, ) from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes +from tmtccmd.utility import ObjectId class ImtqSetIds: @@ -40,233 +39,149 @@ class ImtqActionIds: perform_negative_y_test = bytearray([0x0, 0x0, 0x0, 0x0A]) perform_positive_z_test = bytearray([0x0, 0x0, 0x0, 0x0B]) perform_negative_z_test = bytearray([0x0, 0x0, 0x0, 0x0C]) - # Initiates the reading of the last performed self test. After sending this command the results can be downlinked - # via the housekeeping service by using the appropriate set ids listed above. + # Initiates the reading of the last performed self test. After sending this command the results + # can be downlinked via the housekeeping service by using the appropriate set ids listed above. read_self_test_results = bytearray([0x0, 0x0, 0x0, 0x0D]) -def pack_imtq_test_into( - object_id: bytearray, tc_queue: TcQueueT, op_code: str -) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing ISIS IMTQ handler with object id: 0x" + object_id.hex(), - ) +def pack_imtq_test_into(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd( + f"Testing ISIS IMTQ handler with object id: {object_id.as_hex_string}" ) if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Set mode off")) - command = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=9, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Set mode off") + command = pack_mode_data(object_id.as_bytes, Modes.OFF, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "1": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Set mode on")) - command = pack_mode_data(object_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Set mode on") + command = pack_mode_data(object_id.as_bytes, Modes.ON, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "2": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Mode Normal")) - command = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Mode Normal") + command = pack_mode_data(object_id.as_bytes, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "3": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform positive x self test")) - command = object_id + ImtqActionIds.perform_positive_x_test - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform positive x self test") + command = object_id.as_bytes + ImtqActionIds.perform_positive_x_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of positive x self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Initiate reading of positive x self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with positive x self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.POSITIVE_X_TEST) - command = generate_one_hk_command(sid, 24) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Request dataset with positive x self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_X_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "4": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform negative x self test")) - command = object_id + ImtqActionIds.perform_negative_x_test - command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of negative x self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with negative x self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.NEGATIVE_X_TEST) - command = generate_one_hk_command(sid, 27) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform negative x self test") + command = object_id.as_bytes + ImtqActionIds.perform_negative_x_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + q.add_log_cmd("IMTQ: Initiate reading of negative x self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + q.add_log_cmd("IMTQ: Request dataset with negative x self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_X_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "5": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform positive y self test")) - command = object_id + ImtqActionIds.perform_positive_y_test - command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform positive y self test") + command = object_id.as_bytes + ImtqActionIds.perform_positive_y_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + q.add_log_cmd("IMTQ: Initiate reading of positive y self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of positive y self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=29, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with positive y self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.POSITIVE_Y_TEST) - command = generate_one_hk_command(sid, 30) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Request dataset with positive y self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_Y_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "6": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform negative y self test")) - command = object_id + ImtqActionIds.perform_negative_y_test - command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform negative y self test") + command = object_id.as_bytes + ImtqActionIds.perform_negative_y_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of negative y self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Initiate reading of negative y self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with negative y self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.NEGATIVE_Y_TEST) - command = generate_one_hk_command(sid, 33) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Request dataset with negative y self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_Y_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "7": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform positive z self test")) - command = object_id + ImtqActionIds.perform_positive_z_test - command = PusTelecommand(service=8, subservice=128, ssc=34, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform positive z self test") + command = object_id.as_bytes + ImtqActionIds.perform_positive_z_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of positive z self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=35, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Initiate reading of positive z self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with positive z self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.POSITIVE_Y_TEST) - command = generate_one_hk_command(sid, 36) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Request dataset with positive z self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.POSITIVE_Y_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "8": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Perform negative z self test")) - command = object_id + ImtqActionIds.perform_negative_z_test - command = PusTelecommand(service=8, subservice=128, ssc=35, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Initiate reading of negative z self test results", - ) - ) - command = object_id + ImtqActionIds.read_self_test_results - command = PusTelecommand(service=8, subservice=128, ssc=36, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "IMTQ: Request dataset with negative z self test results", - ) - ) - sid = make_sid(object_id, ImtqSetIds.NEGATIVE_Z_TEST) - command = generate_one_hk_command(sid, 37) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Perform negative z self test") + command = object_id.as_bytes + ImtqActionIds.perform_negative_z_test + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + q.add_log_cmd("IMTQ: Initiate reading of negative z self test results") + command = object_id.as_bytes + ImtqActionIds.read_self_test_results + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + q.add_log_cmd("IMTQ: Request dataset with negative z self test results") + sid = make_sid(object_id.as_bytes, ImtqSetIds.NEGATIVE_Z_TEST) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "9": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Commanding dipole")) + q.add_log_cmd("IMTQ: Commanding dipole") x_dipole = 0 y_dipole = 0 z_dipole = 0 duration = 0 # ms - command = pack_dipole_command(object_id, x_dipole, y_dipole, z_dipole, duration) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc( + pack_dipole_command( + object_id.as_bytes, x_dipole, y_dipole, z_dipole, duration + ) + ) if op_code == "10": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Get commanded dipole")) - command = object_id + ImtqActionIds.get_commanded_dipole - command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("IMTQ: Get commanded dipole") + command = object_id.as_bytes + ImtqActionIds.get_commanded_dipole + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "11": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Get engineering hk set")) - command = generate_one_diag_command( - sid=make_sid(object_id=object_id, set_id=ImtqSetIds.ENG_HK_SET), ssc=0 + q.add_log_cmd("IMTQ: Get engineering hk set") + q.add_pus_tc( + generate_one_diag_command( + sid=make_sid(object_id=object_id.as_bytes, set_id=ImtqSetIds.ENG_HK_SET) + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == "12": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Get calibrated MTM hk set")) - command = generate_one_diag_command( - sid=make_sid(object_id=object_id, set_id=ImtqSetIds.CAL_MTM_SET), ssc=0 + q.add_log_cmd("IMTQ: Get calibrated MTM hk set") + q.add_pus_tc( + generate_one_diag_command( + sid=make_sid( + object_id=object_id.as_bytes, set_id=ImtqSetIds.CAL_MTM_SET + ) + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == "13": - tc_queue.appendleft((QueueCommands.PRINT, "IMTQ: Get raw MTM hk set")) - command = generate_one_diag_command( - sid=make_sid(object_id=object_id, set_id=ImtqSetIds.RAW_MTM_SET), ssc=0 + q.add_log_cmd("IMTQ: Get raw MTM hk set") + q.add_pus_tc( + generate_one_diag_command( + sid=make_sid( + object_id=object_id.as_bytes, set_id=ImtqSetIds.RAW_MTM_SET + ) + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - - return tc_queue def pack_dipole_command( - object_id: bytearray, x_dipole: int, y_dipole: int, z_dipole: int, duration: int + object_id: bytes, x_dipole: int, y_dipole: int, z_dipole: int, duration: int ) -> PusTelecommand: """This function packs the command causing the ISIS IMTQ to generate a dipole. @param object_id The object id of the IMTQ handler. @@ -279,9 +194,9 @@ def pack_dipole_command( """ action_id = ImtqActionIds.start_actuation_dipole command = object_id + action_id - command += struct.pack('!h', x_dipole) - command += struct.pack('!h', y_dipole) - command += struct.pack('!h', z_dipole) - command += struct.pack('!h', duration) - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) + command += struct.pack("!h", x_dipole) + command += struct.pack("!h", y_dipole) + command += struct.pack("!h", z_dipole) + command += struct.pack("!h", duration) + command = PusTelecommand(service=8, subservice=128, app_data=command) return command diff --git a/pus_tc/devs/p60dock.py b/pus_tc/devs/p60dock.py index c0f395a..31e671a 100644 --- a/pus_tc/devs/p60dock.py +++ b/pus_tc/devs/p60dock.py @@ -7,6 +7,8 @@ """ from tmtccmd.config.definitions import QueueCommands from tmtccmd.tc.packer import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, make_sid, @@ -87,240 +89,193 @@ class P60DockHkTable: wdt_gnd_left = TableEntry(bytearray([0x00, 0xA8]), TableEntry.uint32_size) -def pack_p60dock_cmds(object_id: ObjectId, tc_queue: TcQueueT, op_code: str): +def pack_p60dock_cmds(object_id: ObjectId, q: QueueHelper, op_code: str): objb = object_id.as_bytes if op_code in P60OpCodes.STACK_3V3_ON: - tc_queue.appendleft((QueueCommands.PRINT, Info.STACK_3V3_ON)) - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_9.parameter_address, - P60DockConfigTable.out_en_9.parameter_size, - Channel.on, + q.add_log_cmd(Info.STACK_3V3_ON) + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_9.parameter_address, + P60DockConfigTable.out_en_9.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in P60OpCodes.STACK_3V3_OFF: - tc_queue.appendleft((QueueCommands.PRINT, Info.STACK_3V3_OFF)) - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_9.parameter_address, - P60DockConfigTable.out_en_9.parameter_size, - Channel.off, + q.add_log_cmd(Info.STACK_3V3_OFF) + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_9.parameter_address, + P60DockConfigTable.out_en_9.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in P60OpCodes.STACK_5V_ON: - tc_queue.appendleft((QueueCommands.PRINT, Info.STACK_5V_ON)) - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_10.parameter_address, - P60DockConfigTable.out_en_10.parameter_size, - Channel.on, + q.add_log_cmd(Info.STACK_5V_ON) + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_10.parameter_address, + P60DockConfigTable.out_en_10.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in P60OpCodes.STACK_5V_OFF: - tc_queue.appendleft((QueueCommands.PRINT, Info.STACK_5V_OFF)) - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_10.parameter_address, - P60DockConfigTable.out_en_10.parameter_size, - Channel.off, + q.add_log_cmd(Info.STACK_5V_OFF) + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_10.parameter_address, + P60DockConfigTable.out_en_10.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Requesting HK Core HK Once") - ) + q.add_log_cmd("P60 Dock: Requesting HK Core HK Once") hk_sid = make_sid(object_id=P60_DOCK_HANDLER, set_id=SetIds.P60_CORE) - command = generate_one_hk_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Requesting HK Aux HK Once") - ) + q.add_log_cmd("P60 Dock: Requesting HK Aux HK Once") hk_sid = make_sid(object_id=P60_DOCK_HANDLER, set_id=SetIds.P60_AUX) - command = generate_one_hk_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Print Switches, Voltages, Currents") + q.add_log_cmd("P60 Dock: Print Switches, Voltages, Currents") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I + ) ) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.PRINT_LATCHUPS: - tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Print Latchups")) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + q.add_log_cmd("P60 Dock: Print Latchups") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.reboot: - tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Reboot")) - command = pack_reboot_command(object_id) - # command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("P60 Dock: Reboot") + q.add_pus_tc(pack_reboot_command(object_id)) if P60DockTestProcedure.all or P60DockTestProcedure.read_gnd_wdt: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Reading ground watchdog timer value") + q.add_log_cmd("P60 Dock: Reading ground watchdog timer value") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + P60DockHkTable.wdt_gnd_left.parameter_address, + P60DockHkTable.wdt_gnd_left.parameter_size, + ) ) - command = pack_get_param_command( - objb, - TableIds.hk, - P60DockHkTable.wdt_gnd_left.parameter_address, - P60DockHkTable.wdt_gnd_left.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.gnd_wdt_reset: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing ground watchdog reset") - ) - command = pack_gnd_wdt_reset_command(object_id) - # command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("P60 Dock: Testing ground watchdog reset") + q.add_pus_tc(pack_gnd_wdt_reset_command(object_id)) if P60DockTestProcedure.all or P60DockTestProcedure.ping: - tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Ping")) + q.add_log_cmd("P60 Dock: Ping") ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - command = pack_ping_command(object_id, ping_data) - # command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(pack_ping_command(object_id, ping_data)) if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_off: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing setting output channel 3 off") - ) + q.add_log_cmd("P60 Dock: Testing setting output channel 3 off") parameter = 0 # set channel off - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_3.parameter_address, - P60DockConfigTable.out_en_3.parameter_size, - parameter, + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_3.parameter_address, + P60DockConfigTable.out_en_3.parameter_size, + parameter, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.read_temperature1: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing temperature reading") + q.add_log_cmd("P60 Dock: Testing temperature reading") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + P60DockHkTable.temperature1.parameter_address, + P60DockHkTable.temperature1.parameter_size, + ) ) - command = pack_get_param_command( - objb, - TableIds.hk, - P60DockHkTable.temperature1.parameter_address, - P60DockHkTable.temperature1.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_on: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing Output Channel 3 state (PDU2)") + q.add_log_cmd("P60 Dock: Testing Output Channel 3 state (PDU2)") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.config, + P60DockConfigTable.out_en_3.parameter_address, + P60DockConfigTable.out_en_3.parameter_size, + ) ) - command = pack_get_param_command( - objb, - TableIds.config, - P60DockConfigTable.out_en_3.parameter_address, - P60DockConfigTable.out_en_3.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.read_cur_lu_lim_0: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "P60 Dock: Reading current limit value of output channel 0", + q.add_log_cmd("P60 Dock: Reading current limit value of output channel 0") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.config, + P60DockConfigTable.cur_lu_lim_0.parameter_address, + P60DockConfigTable.cur_lu_lim_0.parameter_size, ) ) - command = pack_get_param_command( - objb, - TableIds.config, - P60DockConfigTable.cur_lu_lim_0.parameter_address, - P60DockConfigTable.cur_lu_lim_0.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_on: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing setting output channel 3 on") - ) + q.add_log_cmd("P60 Dock: Testing setting output channel 3 on") parameter = 1 # set channel on - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_3.parameter_address, - P60DockConfigTable.out_en_3.parameter_size, - parameter, + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_3.parameter_address, + P60DockConfigTable.out_en_3.parameter_size, + parameter, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=27, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.invalid_table_id_test: - tc_queue.appendleft( - (QueueCommands.PRINT, "P60 Dock: Testing invalid table id handling") - ) + q.add_log_cmd("P60 Dock: Testing invalid table id handling") table_id_invalid = 5 - command = pack_get_param_command( - objb, - table_id_invalid, - P60DockHkTable.temperature1.parameter_address, - P60DockHkTable.temperature1.parameter_size, + q.add_pus_tc( + pack_get_param_command( + objb, + table_id_invalid, + P60DockHkTable.temperature1.parameter_address, + P60DockHkTable.temperature1.parameter_size, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.invalid_address_test: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "P60 Dock: Testing invalid address handling in get param command", - ) - ) + q.add_log_cmd("P60 Dock: Testing invalid address handling in get param command") invalid_address = bytearray([0x01, 0xF4]) - command = pack_get_param_command( - objb, - TableIds.hk, - invalid_address, - P60DockHkTable.temperature1.parameter_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=29, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "P60 Dock: Testing invalid address handling in set param command", + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + invalid_address, + P60DockHkTable.temperature1.parameter_size, ) ) + q.add_log_cmd("P60 Dock: Testing invalid address handling in set param command") invalid_address = bytearray([0x01, 0xF4]) parameter_size = 2 parameter = 1 - command = pack_set_param_command( - objb, invalid_address, parameter_size, parameter + q.add_pus_tc( + pack_set_param_command(objb, invalid_address, parameter_size, parameter) ) - # command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) if P60DockTestProcedure.all or P60DockTestProcedure.invalid_parameter_size_test: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "P60 Dock: Testing handling of invalid parameter sizes in get-param command", - ) + q.add_log_cmd( + "P60 Dock: Testing handling of invalid parameter sizes in get-param command" ) invalid_size = 5 - command = pack_get_param_command( - objb, - TableIds.hk, - P60DockHkTable.temperature1.parameter_address, - invalid_size, - ) - # command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "P60 Dock: Testing handling of invalid parameter size in set-param command", + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + P60DockHkTable.temperature1.parameter_address, + invalid_size, ) ) - parameter = 1 - command = pack_set_param_command( - objb, - P60DockConfigTable.out_en_3.parameter_address, - invalid_size, - parameter, + q.add_log_cmd( + "P60 Dock: Testing handling of invalid parameter size in set-param command" + ) + parameter = 1 + q.add_pus_tc( + pack_set_param_command( + objb, + P60DockConfigTable.out_en_3.parameter_address, + invalid_size, + parameter, + ) ) - # command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - return tc_queue diff --git a/pus_tc/devs/pdec_handler.py b/pus_tc/devs/pdec_handler.py index c62a639..85fa41c 100644 --- a/pus_tc/devs/pdec_handler.py +++ b/pus_tc/devs/pdec_handler.py @@ -5,9 +5,8 @@ @author J. Meier @date 22.11.2021 """ -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper class CommandIds: @@ -17,24 +16,13 @@ class CommandIds: PRINT_PDEC_MON = bytearray([0x0, 0x0, 0x0, 0x1]) -def pack_pdec_handler_test(object_id: bytearray, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing PDEC handler with object id: 0x" + object_id.hex(), - ) - ) - +def pack_pdec_handler_test(object_id: bytearray, q: QueueHelper, op_code: str): + q.add_log_cmd(f"Testing PDEC handler with object id: {object_id.hex()}") if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "PDEC Handler: Print CLCW")) + q.add_log_cmd("PDEC Handler: Print CLCW") command = object_id + CommandIds.PRINT_CLCW - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "1": - tc_queue.appendleft( - (QueueCommands.PRINT, "PDEC Handler: Print PDEC monitor register") - ) + q.add_log_cmd("PDEC Handler: Print PDEC monitor register") command = object_id + CommandIds.PRINT_PDEC_MON - command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) diff --git a/pus_tc/devs/pdu1.py b/pus_tc/devs/pdu1.py index 4654e47..c80f1a6 100644 --- a/pus_tc/devs/pdu1.py +++ b/pus_tc/devs/pdu1.py @@ -4,8 +4,8 @@ @date 17.12.2020 """ import gomspace.gomspace_common as gs -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.packer import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, make_sid, @@ -55,251 +55,263 @@ class PDU1TestProcedure: turn_channel_3_off = False -def pack_pdu1_commands(object_id: ObjectId, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft((QueueCommands.PRINT, "Commanding PDU1")) +def pack_pdu1_commands(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd("Commanding PDU1") objb = object_id.as_bytes if op_code == Pdu1OpCodes.TCS_BOARD_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn TCS board on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_0.parameter_address, - PDUConfigTable.out_en_0.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn TCS board on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_0.parameter_address, + PDUConfigTable.out_en_0.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.TCS_BOARD_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn TCS board off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_0.parameter_address, - PDUConfigTable.out_en_0.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn TCS board off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_0.parameter_address, + PDUConfigTable.out_en_0.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.STAR_TRACKER_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn star tracker on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn star tracker on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.STAR_TRACKER_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn star tracker off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn star tracker off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SUS_NOMINAL_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn SUS nominal on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_4.parameter_address, - PDUConfigTable.out_en_4.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn SUS nominal on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_4.parameter_address, + PDUConfigTable.out_en_4.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SUS_NOMINAL_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn SUS nominal off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_4.parameter_address, - PDUConfigTable.out_en_4.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn SUS nominal off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_4.parameter_address, + PDUConfigTable.out_en_4.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.ACS_A_SIDE_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn ACS Side A on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_7.parameter_address, - PDUConfigTable.out_en_7.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn ACS Side A on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_7.parameter_address, + PDUConfigTable.out_en_7.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.ACS_A_SIDE_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn ACS Side A off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_7.parameter_address, - PDUConfigTable.out_en_7.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn ACS Side A off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_7.parameter_address, + PDUConfigTable.out_en_7.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SUS_NOMINAL_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn SUS nominal off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_4.parameter_address, - PDUConfigTable.out_en_4.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn SUS nominal off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_4.parameter_address, + PDUConfigTable.out_en_4.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SCEX_ON.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment on") + q.add_log_cmd("PDU1: Turn Solar Cell Experiment on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_5.parameter_address, + PDUConfigTable.out_en_5.parameter_size, + Channel.on, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_5.parameter_address, - PDUConfigTable.out_en_5.parameter_size, - Channel.on, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SCEX_OFF.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU1: Turn Solar Cell Experiment off") + q.add_log_cmd("PDU1: Turn Solar Cell Experiment off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_5.parameter_address, + PDUConfigTable.out_en_5.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_5.parameter_address, - PDUConfigTable.out_en_5.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SYRLINKS_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn Syrlinks on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_1.parameter_address, - PDUConfigTable.out_en_1.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn Syrlinks on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_1.parameter_address, + PDUConfigTable.out_en_1.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.SYRLINKS_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn Syrlinks off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_1.parameter_address, - PDUConfigTable.out_en_1.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn Syrlinks off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_1.parameter_address, + PDUConfigTable.out_en_1.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.MGT_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn MGT on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn MGT on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.MGT_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn MGT off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn MGT off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.PLOC_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn PLOC on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_6.parameter_address, - PDUConfigTable.out_en_6.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn PLOC on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_6.parameter_address, + PDUConfigTable.out_en_6.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu1OpCodes.PLOC_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn PLOC off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_6.parameter_address, - PDUConfigTable.out_en_6.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn PLOC off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_6.parameter_address, + PDUConfigTable.out_en_6.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE: - tc_queue.appendleft((QueueCommands.PRINT, f"PDU1: {Info.REQUEST_CORE_HK_ONCE}")) + q.add_log_cmd(f"PDU1: {Info.REQUEST_CORE_HK_ONCE}") hk_sid = make_sid(object_id=PDU_1_HANDLER_ID, set_id=SetIds.PDU_1_CORE) - command = generate_one_diag_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_diag_command(sid=hk_sid)) if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE: - tc_queue.appendleft((QueueCommands.PRINT, f"PDU1: {Info.REQUEST_AUX_HK_ONCE}")) + q.add_log_cmd(f"PDU1: {Info.REQUEST_AUX_HK_ONCE}") hk_sid = make_sid(object_id=PDU_1_HANDLER_ID, set_id=SetIds.PDU_1_AUX) - command = generate_one_hk_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU1: Print Switches, Voltages, Currents") + q.add_log_cmd("PDU1: Print Switches, Voltages, Currents") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I + ) ) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.PRINT_LATCHUPS: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Print Latchups")) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + q.add_log_cmd("PDU1: Print Latchups") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU1TestProcedure.all or PDU1TestProcedure.ping: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Ping Test")) + q.add_log_cmd("PDU1: Ping Test") ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - command = pack_ping_command(object_id, ping_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(pack_ping_command(object_id, ping_data)) if PDU1TestProcedure.all or PDU1TestProcedure.read_temperature: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Testing temperature reading")) - command = pack_get_param_command( - objb, - TableIds.hk, - PDUHkTable.temperature.parameter_address, - PDUHkTable.temperature.parameter_size, + q.add_log_cmd("PDU1: Testing temperature reading") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + PDUHkTable.temperature.parameter_address, + PDUHkTable.temperature.parameter_size, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU1TestProcedure.all or PDU1TestProcedure.turn_channel_2_on: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU1: Turn channel 2 on (Star Tracker)") + q.add_log_cmd("PDU1: Turn channel 2 on (Star Tracker)") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.on, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.on, - ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU1TestProcedure.all or PDU1TestProcedure.turn_channel_2_off: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU1: Turn channel 2 off (Star Tracker)") + q.add_log_cmd("PDU1: Turn channel 2 off (Star Tracker)") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU1TestProcedure.all or PDU1TestProcedure.turn_channel_3_on: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn channel 3 on (MTQ)")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.on, + q.add_log_cmd("PDU1: Turn channel 3 on (MTQ)") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU1TestProcedure.all or PDU1TestProcedure.turn_channel_3_off: - tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn channel 3 off (MTQ)")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.off, + q.add_log_cmd("PDU1: Turn channel 3 off (MTQ)") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.SET_PARAM: - tc_queue.appendleft( - (QueueCommands.PRINT, f"PDU1: {Info.SET_PARAMETER}") - ) + q.add_log_cmd(f"PDU1: {Info.SET_PARAMETER}") memory_address = int(input("Specify memory address: 0x"), 16) - memory_address = struct.pack('!H', memory_address) + memory_address = struct.pack("!H", memory_address) parameter_size = int(input("Specify parameter size: ")) parameter = int(input("Specify parameter: ")) - command = gs.pack_set_param_command(object_id.as_bytes, memory_address, parameter_size, parameter) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc( + gs.pack_set_param_command( + object_id.as_bytes, memory_address, parameter_size, parameter + ) + ) diff --git a/pus_tc/devs/pdu2.py b/pus_tc/devs/pdu2.py index df4c883..60f7268 100644 --- a/pus_tc/devs/pdu2.py +++ b/pus_tc/devs/pdu2.py @@ -6,8 +6,7 @@ @author J. Meier @date 17.12.2020 """ -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.packer import TcQueueT +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, generate_one_diag_command, @@ -66,288 +65,271 @@ class PDU2TestProcedure: request_hk_table = False -def pack_pdu2_commands(object_id: ObjectId, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft((QueueCommands.PRINT, "Testing PDU2")) +def pack_pdu2_commands(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd("Testing PDU2") objb = object_id.as_bytes if op_code == Pdu2OpCodes.ACS_SIDE_B_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn ACS Side B on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_7.parameter_address, - PDUConfigTable.out_en_7.parameter_size, - Channel.on, + q.add_log_cmd("PDU2: Turn ACS Side B on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_7.parameter_address, + PDUConfigTable.out_en_7.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - return tc_queue if op_code == Pdu2OpCodes.ACS_SIDE_B_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn ACS Side B off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_7.parameter_address, - PDUConfigTable.out_en_7.parameter_size, - Channel.off, + q.add_log_cmd("PDU2: Turn ACS Side B off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_7.parameter_address, + PDUConfigTable.out_en_7.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - return tc_queue if op_code == Pdu2OpCodes.Q7S_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "Turning off Q7S OBC")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_0.parameter_address, - PDUConfigTable.out_en_0.parameter_size, - Channel.off, + q.add_log_cmd("Turning off Q7S OBC") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_0.parameter_address, + PDUConfigTable.out_en_0.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.SUS_REDUNDANT_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn SUS redundant on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_4.parameter_address, - PDUConfigTable.out_en_4.parameter_size, - Channel.on, + q.add_log_cmd("PDU2: Turn SUS redundant on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_4.parameter_address, + PDUConfigTable.out_en_4.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.SUS_REDUNDANT_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn SUS redundant off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_4.parameter_address, - PDUConfigTable.out_en_4.parameter_size, - Channel.off, + q.add_log_cmd("PDU2: Turn SUS redundant off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_4.parameter_address, + PDUConfigTable.out_en_4.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.RW_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn reaction wheels on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.on, + q.add_log_cmd("PDU2: Turn reaction wheels on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.RW_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn reaction wheels off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.off, + q.add_log_cmd("PDU2: Turn reaction wheels off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_PCDU_VBAT_NOM_ON.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn PDU2 PL PCDU Channel 1 on") + q.add_log_cmd("PDU2: Turn PDU2 PL PCDU Channel 1 on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_1.parameter_address, + PDUConfigTable.out_en_1.parameter_size, + Channel.on, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_1.parameter_address, - PDUConfigTable.out_en_1.parameter_size, - Channel.on, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_PCDU_VBAT_NOM_OFF.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn PDU2 PL PCDU Channel 1 off") + q.add_log_cmd("PDU2: Turn PDU2 PL PCDU Channel 1 off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_1.parameter_address, + PDUConfigTable.out_en_1.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_1.parameter_address, - PDUConfigTable.out_en_1.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_PCDU_VBAT_RED_ON.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn PDU2 PL PCDU Channel 6 on") + q.add_log_cmd("PDU2: Turn PDU2 PL PCDU Channel 6 on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_6.parameter_address, + PDUConfigTable.out_en_6.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_6.parameter_address, - PDUConfigTable.out_en_6.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_PCDU_VBAT_RED_OFF.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn PDU2 PL PCDU Channel 6 off") + q.add_log_cmd("PDU2: Turn PDU2 PL PCDU Channel 6 off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_6.parameter_address, + PDUConfigTable.out_en_6.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_6.parameter_address, - PDUConfigTable.out_en_6.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.TCS_HEATER_IN_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn TCS Heater Input on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.on, + q.add_log_cmd("PDU2: Turn TCS Heater Input on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.TCS_HEATER_IN_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn TCS Heater Input off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_3.parameter_address, - PDUConfigTable.out_en_3.parameter_size, - Channel.off, + q.add_log_cmd("PDU2: Turn TCS Heater Input off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_3.parameter_address, + PDUConfigTable.out_en_3.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.SOLAR_ARRAY_DEPL_ON.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn Solar Array Deployment On") + q.add_log_cmd("PDU2: Turn Solar Array Deployment On") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_5.parameter_address, + PDUConfigTable.out_en_5.parameter_size, + Channel.on, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_5.parameter_address, - PDUConfigTable.out_en_5.parameter_size, - Channel.on, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.SOLAR_ARRAY_DEPL_OFF.value: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Turn Solar Array Deployment Off") + q.add_log_cmd("PDU2: Turn Solar Array Deployment Off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_5.parameter_address, + PDUConfigTable.out_en_5.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_5.parameter_address, - PDUConfigTable.out_en_5.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_CAMERA_ON.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn payload camera on")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_8.parameter_address, - PDUConfigTable.out_en_8.parameter_size, - Channel.on, + q.add_log_cmd("PDU2: Turn payload camera on") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_8.parameter_address, + PDUConfigTable.out_en_8.parameter_size, + Channel.on, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code == Pdu2OpCodes.PL_CAMERA_OFF.value: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn payload camera off")) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_8.parameter_address, - PDUConfigTable.out_en_8.parameter_size, - Channel.off, + q.add_log_cmd("PDU2: Turn payload camera off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_8.parameter_address, + PDUConfigTable.out_en_8.parameter_size, + Channel.off, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE: - tc_queue.appendleft((QueueCommands.PRINT, f"PDU2: {Info.REQUEST_CORE_HK_ONCE}")) + q.add_log_cmd(f"PDU2: {Info.REQUEST_CORE_HK_ONCE}") hk_sid = make_sid(object_id=PDU_2_HANDLER_ID, set_id=SetIds.PDU_2_CORE) - command = generate_one_diag_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_diag_command(sid=hk_sid)) if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE: - tc_queue.appendleft((QueueCommands.PRINT, f"PDU2: {Info.REQUEST_AUX_HK_ONCE}")) + q.add_log_cmd(f"PDU2: {Info.REQUEST_AUX_HK_ONCE}") hk_sid = make_sid(object_id=PDU_2_HANDLER_ID, set_id=SetIds.PDU_2_AUX) - command = generate_one_hk_command(sid=hk_sid, ssc=0) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Print Switches, Currents, Voltahes") + q.add_log_cmd("PDU2: Print Switches, Currents, Voltahes") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I + ) ) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I - ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in GomspaceOpCodes.PRINT_LATCHUPS: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Print Latchups")) - command = generate_action_command( - object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + q.add_log_cmd("PDU2: Print Latchups") + q.add_pus_tc( + generate_action_command( + object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU2TestProcedure.all or PDU2TestProcedure.reboot: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Reboot")) - command = pack_reboot_command(object_id) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PDU2: Reboot") + q.add_pus_tc(pack_reboot_command(object_id)) if PDU2TestProcedure.all or PDU2TestProcedure.read_gnd_wdt: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Reading ground watchdog timer value") + q.add_log_cmd("PDU2: Reading ground watchdog timer value") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + PDUHkTable.wdt_gnd_left.parameter_address, + PDUHkTable.wdt_gnd_left.parameter_size, + ) ) - command = pack_get_param_command( - objb, - TableIds.hk, - PDUHkTable.wdt_gnd_left.parameter_address, - PDUHkTable.wdt_gnd_left.parameter_size, - ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU2TestProcedure.all or PDU2TestProcedure.gnd_wdt_reset: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Testing ground watchdog reset") - ) - command = pack_gnd_wdt_reset_command(object_id) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PDU2: Testing ground watchdog reset") + q.add_pus_tc(pack_gnd_wdt_reset_command(object_id)) if PDU2TestProcedure.all or PDU2TestProcedure.ping: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Ping Test")) + q.add_log_cmd("PDU2: Ping Test") ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - command = pack_ping_command(object_id, ping_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(pack_ping_command(object_id, ping_data)) if PDU2TestProcedure.all or PDU2TestProcedure.channel_2_on: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "PDU2: Testing setting output channel 2 on (TCS Heater)", + q.add_log_cmd("PDU2: Testing setting output channel 2 on (TCS Heater)") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.on, ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.on, - ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU2TestProcedure.all or PDU2TestProcedure.read_temperature: - tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Testing temperature reading")) - command = pack_get_param_command( - objb, - TableIds.hk, - PDUHkTable.temperature.parameter_address, - PDUHkTable.temperature.parameter_size, - ) - tc_queue.appendleft(command.pack_command_tuple()) - if PDU2TestProcedure.all or PDU2TestProcedure.read_channel_2_state: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Reading output channel 2 state (TCS Heater)") - ) - command = pack_get_param_command( - objb, - TableIds.config, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - ) - tc_queue.appendleft(command.pack_command_tuple()) - if PDU2TestProcedure.all or PDU2TestProcedure.read_cur_lu_lim_0: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "PDU2: Reading current limit value of output channel 0 (OBC)", + q.add_log_cmd("PDU2: Testing temperature reading") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.hk, + PDUHkTable.temperature.parameter_address, + PDUHkTable.temperature.parameter_size, ) ) - command = pack_get_param_command( - objb, - TableIds.config, - PDUConfigTable.cur_lu_lim_0.parameter_address, - PDUConfigTable.cur_lu_lim_0.parameter_size, + if PDU2TestProcedure.all or PDU2TestProcedure.read_channel_2_state: + q.add_log_cmd("PDU2: Reading output channel 2 state (TCS Heater)") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.config, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + ) + ) + if PDU2TestProcedure.all or PDU2TestProcedure.read_cur_lu_lim_0: + q.add_log_cmd("PDU2: Reading current limit value of output channel 0 (OBC)") + q.add_pus_tc( + pack_get_param_command( + objb, + TableIds.config, + PDUConfigTable.cur_lu_lim_0.parameter_address, + PDUConfigTable.cur_lu_lim_0.parameter_size, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU2TestProcedure.all or PDU2TestProcedure.channel_2_off: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Testing setting output channel 2 off") + q.add_log_cmd("PDU2: Testing setting output channel 2 off") + q.add_pus_tc( + pack_set_param_command( + objb, + PDUConfigTable.out_en_2.parameter_address, + PDUConfigTable.out_en_2.parameter_size, + Channel.off, + ) ) - command = pack_set_param_command( - objb, - PDUConfigTable.out_en_2.parameter_address, - PDUConfigTable.out_en_2.parameter_size, - Channel.off, - ) - tc_queue.appendleft(command.pack_command_tuple()) if PDU2TestProcedure.all or PDU2TestProcedure.request_hk_table: - tc_queue.appendleft( - (QueueCommands.PRINT, "PDU2: Requesting housekeeping table") - ) - command = pack_request_full_hk_table_command(object_id) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PDU2: Requesting housekeeping table") + q.add_pus_tc(pack_request_full_hk_table_command(object_id)) diff --git a/pus_tc/devs/ploc_mpsoc.py b/pus_tc/devs/ploc_mpsoc.py index c285680..7e3497c 100644 --- a/pus_tc/devs/ploc_mpsoc.py +++ b/pus_tc/devs/ploc_mpsoc.py @@ -13,6 +13,8 @@ from tmtccmd.config.definitions import QueueCommands from tmtccmd.logging import get_console_logger from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper +from tmtccmd.utility import ObjectId from utility.input_helper import InputHelper from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes @@ -67,142 +69,119 @@ class PlocReplyIds(enum.IntEnum): def pack_ploc_mpsoc_commands( - object_id: bytearray, tc_queue: TcQueueT, op_code: str + object_id: ObjectId, q: QueueHelper, op_code: str ) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Generate command for PLOC MPSoC with object id: 0x" + object_id.hex(), - ) + q.add_log_cmd( + f"Generate command for PLOC MPSoC with object id: {object_id.as_hex_string}" ) - + obyt = object_id.as_bytes if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Set mode off")) - command = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=9, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC MPSoC: Set mode off") + command = pack_mode_data(obyt, Modes.OFF, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "1": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Set mode on")) - command = pack_mode_data(object_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC MPSoC: Set mode on") + data = pack_mode_data(obyt, Modes.ON, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "2": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Mode Normal")) - command = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC MPSoC: Mode Normal") + data = pack_mode_data(object_id.as_bytes, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "3": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: TC mem write test")) + q.add_log_cmd("PLOC MPSoC: TC mem write test") memory_address = int( input("PLOC MPSoC: Tc Mem Write: Type memory address: 0x"), 16 ) memory_data = int(input("PLOC MPSoC: Tc Mem Write: Type memory data: 0x"), 16) # TODO: implement variable length mem write command mem_len = 1 # 1 32-bit word - command = generate_write_mem_command( - object_id, memory_address, memory_data, mem_len + data = generate_write_mem_command( + object_id.as_bytes, memory_address, memory_data, mem_len ) - command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "4": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: TC mem read test")) - command = prepare_mem_read_command(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "5": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Flash write")) - command = prepare_flash_write_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "6": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Flash delete")) - command = prepare_flash_delete_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "7": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Replay start")) - command = prepare_replay_start_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "8": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Replay stop")) - command = object_id + struct.pack("!I", CommandIds.TC_REPLAY_STOP) - command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "9": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Downlink pwr on")) - command = prepare_downlink_pwr_on_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "10": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Downlink pwr off")) - command = object_id + struct.pack("!I", CommandIds.TC_DOWNLINK_PWR_OFF) - command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "11": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Replay write sequence")) - command = prepare_replay_write_sequence_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=27, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "12": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC MPSoC: Reset OBSW sequence count") - ) - command = object_id + struct.pack("!I", CommandIds.OBSW_RESET_SEQ_COUNT) - command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "13": + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "4": + q.add_log_cmd("PLOC MPSoC: TC mem read test") + data = prepare_mem_read_command(object_id=object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "5": + q.add_log_cmd("PLOC MPSoC: Flash write") + data = prepare_flash_write_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "6": + q.add_log_cmd("PLOC MPSoC: Flash delete") + data = prepare_flash_delete_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "7": + q.add_log_cmd("PLOC MPSoC: Replay start") + data = prepare_replay_start_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "8": + q.add_log_cmd("PLOC MPSoC: Replay stop") + data = object_id.as_bytes + struct.pack("!I", CommandIds.TC_REPLAY_STOP) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "9": + q.add_log_cmd("PLOC MPSoC: Downlink pwr on") + data = prepare_downlink_pwr_on_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "10": + q.add_log_cmd("PLOC MPSoC: Downlink pwr off") + data = object_id.as_bytes + struct.pack("!I", CommandIds.TC_DOWNLINK_PWR_OFF) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "11": + q.add_log_cmd("PLOC MPSoC: Replay write sequence") + data = prepare_replay_write_sequence_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "12": + q.add_log_cmd("PLOC MPSoC: Reset OBSW sequence count") + data = object_id.as_bytes + struct.pack("!I", CommandIds.OBSW_RESET_SEQ_COUNT) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "13": num_words = 1 - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Read DEADBEEF address")) - command = ( - object_id + q.add_log_cmd("PLOC MPSoC: Read DEADBEEF address") + data = ( + object_id.as_bytes + struct.pack("!I", CommandIds.TC_MEM_READ) + struct.pack("!I", MemAddresses.DEADBEEF) + struct.pack("!H", num_words) ) - command = PusTelecommand(service=8, subservice=128, ssc=29, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "14": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Tc mode replay")) - command = object_id + struct.pack("!I", CommandIds.TC_MODE_REPLAY) - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "15": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Tc mode idle")) - command = object_id + struct.pack("!I", CommandIds.TC_MODE_IDLE) - command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "16": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Tc cam command send")) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "14": + q.add_log_cmd("PLOC MPSoC: Tc mode replay") + data = object_id.as_bytes + struct.pack("!I", CommandIds.TC_MODE_REPLAY) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "15": + q.add_log_cmd("PLOC MPSoC: Tc mode idle") + data = object_id.as_bytes + struct.pack("!I", CommandIds.TC_MODE_IDLE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "16": + q.add_log_cmd("PLOC MPSoC: Tc cam command send") cam_cmd = input("Specify cam command string: ") - command = ( - object_id + data = ( + object_id.as_bytes + struct.pack("!I", CommandIds.TC_CAM_CMD_SEND) + bytearray(cam_cmd, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "17": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Set UART TX tristate")) - command = object_id + struct.pack("!I", CommandIds.SET_UART_TX_TRISTATE) - command = PusTelecommand(service=8, subservice=128, ssc=33, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "18": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC MPSoC: Release UART TX")) - command = object_id + struct.pack("!I", CommandIds.RELEASE_UART_TX) - command = PusTelecommand(service=8, subservice=128, ssc=33, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - return tc_queue + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "17": + q.add_log_cmd("PLOC MPSoC: Set UART TX tristate") + data = object_id.as_bytes + struct.pack("!I", CommandIds.SET_UART_TX_TRISTATE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) + if op_code == "18": + q.add_log_cmd("PLOC MPSoC: Release UART TX") + data = object_id.as_bytes + struct.pack("!I", CommandIds.RELEASE_UART_TX) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) def generate_write_mem_command( - object_id: bytearray, memory_address: int, memory_data: int, mem_len: int + object_id: bytes, memory_address: int, memory_data: int, mem_len: int ) -> bytearray: - """This function generates the command to write to a memory address within the PLOC - @param object_id The object id of the PlocHandler - @param memory_address The PLOC memory address where to write to. - @param memory_data The data to write to the memory address specified by the bytearray memory_address. + """This function generates the command to write to a memory address within the PLOC. + + :param object_id: The object id of the PlocHandler + :param memory_address: The PLOC memory address where to write to. + :param memory_data: The data to write to the memory address specified by the + bytearray memory_address. + :param mem_len: """ command = ( object_id @@ -211,10 +190,10 @@ def generate_write_mem_command( + struct.pack("!H", mem_len) + struct.pack("!I", memory_data) ) - return command + return bytearray(command) -def prepare_mem_read_command(object_id: bytearray) -> bytearray: +def prepare_mem_read_command(object_id: bytes) -> bytearray: memory_address = int(input("PLOC MPSoC Tc Mem Read: Type memory address: 0x"), 16) num_words = int(input("PLOC MPSoC specify number of words (32-bit) to read: ")) command = ( @@ -223,10 +202,10 @@ def prepare_mem_read_command(object_id: bytearray) -> bytearray: + struct.pack("!I", memory_address) + struct.pack("!H", num_words) ) - return command + return bytearray(command) -def prepare_flash_write_cmd(object_id: bytearray) -> bytearray: +def prepare_flash_write_cmd(object_id: bytes) -> bytearray: obcFile = get_obc_file() mpsocFile = get_mpsoc_file() command = ( @@ -235,30 +214,30 @@ def prepare_flash_write_cmd(object_id: bytearray) -> bytearray: + bytearray(obcFile, "utf-8") + bytearray(mpsocFile, "utf-8") ) - return command + return bytearray(command) -def prepare_flash_delete_cmd(object_id: bytearray) -> bytearray: +def prepare_flash_delete_cmd(object_id: bytes) -> bytearray: file = get_mpsoc_file() command = ( object_id + struct.pack("!I", CommandIds.TC_FLASH_DELETE) + bytearray(file, "utf-8") ) - return command + return bytearray(command) -def prepare_replay_start_cmd(object_id: bytearray) -> bytearray: +def prepare_replay_start_cmd(object_id: bytes) -> bytearray: replay = int(input("Specify replay mode (0 - once, 1 - repeated): ")) command = ( object_id + struct.pack("!I", CommandIds.TC_REPLAY_START) + struct.pack("!B", replay) ) - return command + return bytearray(command) -def prepare_downlink_pwr_on_cmd(object_id: bytearray) -> bytearray: +def prepare_downlink_pwr_on_cmd(object_id: bytes) -> bytearray: mode = int(input("Specify JESD mode (0 - 5): ")) lane_rate = int(input("Specify lane rate (0 - 9): ")) command = ( @@ -267,10 +246,10 @@ def prepare_downlink_pwr_on_cmd(object_id: bytearray) -> bytearray: + struct.pack("!B", mode) + struct.pack("!B", lane_rate) ) - return command + return bytearray(command) -def prepare_replay_write_sequence_cmd(object_id: bytearray) -> bytearray: +def prepare_replay_write_sequence_cmd(object_id: bytes) -> bytearray: null_terminator = 0 use_decoding = int(input("Use decoding (set to 1): ")) file = get_sequence_file() @@ -280,7 +259,7 @@ def prepare_replay_write_sequence_cmd(object_id: bytearray) -> bytearray: + struct.pack("!B", use_decoding) + bytearray(file, "utf-8") ) - return command + return bytearray(command) def get_obc_file() -> str: diff --git a/pus_tc/devs/ploc_supervisor.py b/pus_tc/devs/ploc_supervisor.py index 45810d3..545385e 100644 --- a/pus_tc/devs/ploc_supervisor.py +++ b/pus_tc/devs/ploc_supervisor.py @@ -9,10 +9,10 @@ import struct from spacepackets.ecss.tc import PusTelecommand -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.packer import TcQueueT from tmtccmd.logging import get_console_logger +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes +from tmtccmd.utility import ObjectId from utility.input_helper import InputHelper LOGGER = get_console_logger() @@ -107,308 +107,235 @@ class SupvHkIds: def pack_ploc_supv_commands( - object_id: bytearray, tc_queue: TcQueueT, op_code: str + object_id: ObjectId, q: QueueHelper, op_code: str ) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing PLOC Supervisor with object id: 0x" + object_id.hex(), - ) - ) + q.add_log_cmd(f"Testing PLOC Supervisor with object id: {object_id.as_hex_string}") + obyt = object_id.as_bytes if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set mode off")) - command = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=9, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC Supervisor: Set mode off") + command = pack_mode_data(object_id.as_bytes, Modes.OFF, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "1": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set mode on")) - command = pack_mode_data(object_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC Supervisor: Set mode on") + command = pack_mode_data(object_id.as_bytes, Modes.ON, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "2": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Mode Normal")) - command = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC Supervisor: Mode Normal") + command = pack_mode_data(object_id.as_bytes, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=command)) if op_code == "3": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: TC Get Hk Report")) - command = object_id + struct.pack("!I", SupvActionIds.HK_REPORT) - command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC Supervisor: TC Get Hk Report") + command = obyt + struct.pack("!I", SupvActionIds.HK_REPORT) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) elif op_code == "5": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Start MPSoC")) - command = object_id + struct.pack("!I", SupvActionIds.START_MPSOC) - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "6": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Shutdown MPSoC")) - command = object_id + struct.pack("!I", SupvActionIds.SHUTWOWN_MPSOC) - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "7": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Select MPSoC boot image") - ) + q.add_log_cmd("PLOC Supervisor: Start MPSoC") + command = obyt + struct.pack("!I", SupvActionIds.START_MPSOC) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "6": + q.add_log_cmd("PLOC Supervisor: Shutdown MPSoC") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.SHUTWOWN_MPSOC) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "7": + q.add_log_cmd("PLOC Supervisor: Select MPSoC boot image") mem = int(input("MEM (NVM0 - 0 or NVM1 - 1): ")) bp0 = int(input("BP0 (0 or 1): ")) bp1 = int(input("BP1 (0 or 1): ")) bp2 = int(input("BP2 (0 or 1): ")) - command = pack_sel_boot_image_cmd(object_id, mem, bp0, bp1, bp2) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "8": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Set max restart tries") - ) + command = pack_sel_boot_image_cmd(object_id.as_bytes, mem, bp0, bp1, bp2) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "8": + q.add_log_cmd("PLOC Supervisor: Set max restart tries") restart_tries = int(input("Specify maximum restart tries: ")) command = ( - object_id + object_id.as_bytes + struct.pack("!I", SupvActionIds.SET_MAX_RESTART_TRIES) + struct.pack("!B", restart_tries) ) - command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "9": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Reset MPSoC")) - command = object_id + struct.pack("!I", SupvActionIds.RESET_MPSOC) - command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "10": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Set time reference") - ) - command = object_id + struct.pack("!I", SupvActionIds.SET_TIME_REF) - command = PusTelecommand(service=8, subservice=128, ssc=27, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "11": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set boot timeout")) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "9": + q.add_log_cmd("PLOC Supervisor: Reset MPSoC") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.RESET_MPSOC) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "10": + q.add_log_cmd("PLOC Supervisor: Set time reference") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.SET_TIME_REF) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "11": + q.add_log_cmd("PLOC Supervisor: Set boot timeout") boot_timeout = int(input("Specify boot timeout [ms]: ")) command = ( - object_id + object_id.as_bytes + struct.pack("!I", SupvActionIds.SET_BOOT_TIMEOUT) + struct.pack("!I", boot_timeout) ) - command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "12": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Disable HK")) - command = object_id + struct.pack("!I", SupvActionIds.DISABLE_HK) - command = PusTelecommand(service=8, subservice=128, ssc=29, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "13": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Request boot status report") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "12": + q.add_log_cmd("PLOC Supervisor: Disable HK") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.DISABLE_HK) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "13": + q.add_log_cmd("PLOC Supervisor: Request boot status report") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.GET_BOOT_STATUS_REPORT ) - command = object_id + struct.pack("!I", SupvActionIds.GET_BOOT_STATUS_REPORT) - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "17": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Enable latchup alert") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "17": + q.add_log_cmd("PLOC Supervisor: Enable latchup alert") + command = pack_lachtup_alert_cmd(object_id.as_bytes, True) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "18": + q.add_log_cmd("PLOC Supervisor: Disable latchup alert") + command = pack_lachtup_alert_cmd(object_id.as_bytes, False) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "20": + q.add_log_cmd("PLOC Supervisor: Set alert limit") + command = pack_set_alert_limit_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "23": + q.add_log_cmd("PLOC Supervisor: Set ADC enabled channels") + command = pack_set_adc_enabled_channels_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "24": + q.add_log_cmd("PLOC Supervisor: Set ADC window and stride") + command = pack_set_adc_window_and_stride_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "25": + q.add_log_cmd("PLOC Supervisor: Set ADC threshold") + command = pack_set_adc_threshold_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "26": + q.add_log_cmd("PLOC Supervisor: Request latchup status report") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.GET_LATCHUP_STATUS_REPORT ) - command = pack_lachtup_alert_cmd(object_id, True) - command = PusTelecommand(service=8, subservice=128, ssc=34, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "18": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Disable latchup alert") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "27": + q.add_log_cmd("PLOC Supervisor: Copy ADC data to MRAM") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.COPY_ADC_DATA_TO_MRAM ) - command = pack_lachtup_alert_cmd(object_id, False) - command = PusTelecommand(service=8, subservice=128, ssc=35, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "20": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set alert limit")) - command = pack_set_alert_limit_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=37, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "23": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Set ADC enabled channels") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "30": + q.add_log_cmd("PLOC Supervisor: Run auto EM tests") + command = pack_auto_em_tests_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "31": + q.add_log_cmd("PLOC Supervisor: Wipe MRAM") + command = pack_mram_wipe_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "35": + q.add_log_cmd("PLOC Supervisor: Set GPIO command") + command = pack_set_gpio_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "36": + q.add_log_cmd("PLOC Supervisor: Read GPIO command") + command = pack_read_gpio_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "37": + q.add_log_cmd("PLOC Supervisor: Restart supervisor") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.RESTART_SUPERVISOR ) - command = pack_set_adc_enabled_channels_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=40, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "24": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Set ADC window and stride") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "38": + q.add_log_cmd("PLOC Supervisor: Factory reset clear all") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.FACTORY_RESET_CLEAR_ALL ) - command = pack_set_adc_window_and_stride_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=41, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "25": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set ADC threshold")) - command = pack_set_adc_threshold_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=42, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "26": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Request latchup status report") - ) - command = object_id + struct.pack("!I", SupvActionIds.GET_LATCHUP_STATUS_REPORT) - command = PusTelecommand(service=8, subservice=128, ssc=43, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "27": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Copy ADC data to MRAM") - ) - command = object_id + struct.pack("!I", SupvActionIds.COPY_ADC_DATA_TO_MRAM) - command = PusTelecommand(service=8, subservice=128, ssc=44, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "30": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Run auto EM tests")) - command = pack_auto_em_tests_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=45, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "31": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Wipe MRAM")) - command = pack_mram_wipe_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=46, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "35": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Set GPIO command")) - command = pack_set_gpio_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=50, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "36": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Read GPIO command")) - command = pack_read_gpio_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=51, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "37": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Restart supervisor") - ) - command = object_id + struct.pack("!I", SupvActionIds.RESTART_SUPERVISOR) - command = PusTelecommand(service=8, subservice=128, ssc=52, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "38": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Factory reset clear all") - ) - command = object_id + struct.pack("!I", SupvActionIds.FACTORY_RESET_CLEAR_ALL) - command = PusTelecommand(service=8, subservice=128, ssc=53, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "39": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Factory reset clear mirror entries") - ) - command = object_id + struct.pack( + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "39": + q.add_log_cmd("PLOC Supervisor: Factory reset clear mirror entries") + command = object_id.as_bytes + struct.pack( "!I", SupvActionIds.FACTORY_RESET_CLEAR_MIRROR ) - command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "40": - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "PLOC Supervisor: Factory reset clear circular entries", - ) - ) - command = object_id + struct.pack( + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "40": + q.add_log_cmd("PLOC Supervisor: Factory reset clear circular entries") + command = object_id.as_bytes + struct.pack( "!I", SupvActionIds.FACTORY_RESET_CLEAR_CIRCULAR ) - command = PusTelecommand(service=8, subservice=128, ssc=55, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "42": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Perform update")) - command = pack_update_command(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=57, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "43": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Terminate supervisor process") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "42": + q.add_log_cmd("PLOC Supervisor: Perform update") + command = pack_update_command(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "43": + q.add_log_cmd("PLOC Supervisor: Terminate supervisor process") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.TERMINATE_SUPV_HELPER ) - command = object_id + struct.pack("!I", SupvActionIds.TERMINATE_SUPV_HELPER) - command = PusTelecommand(service=8, subservice=128, ssc=58, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "44": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Start MPSoC quiet")) - command = object_id + struct.pack("!I", SupvActionIds.START_MPSOC_QUIET) - command = PusTelecommand(service=8, subservice=128, ssc=59, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "45": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Set shutdown timeout") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "44": + q.add_log_cmd("PLOC Supervisor: Start MPSoC quiet") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.START_MPSOC_QUIET ) - command = pack_set_shutdown_timeout_command(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=60, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "46": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Factory flash")) - command = object_id + struct.pack("!I", SupvActionIds.FACTORY_FLASH) - command = PusTelecommand(service=8, subservice=128, ssc=61, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "47": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Enable auto TM")) - command = object_id + struct.pack("!I", SupvActionIds.ENABLE_AUTO_TM) - command = PusTelecommand(service=8, subservice=128, ssc=62, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "48": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Disable auto TM")) - command = object_id + struct.pack("!I", SupvActionIds.DISABLE_AUTO_TM) - command = PusTelecommand(service=8, subservice=128, ssc=63, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "51": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Logging request event buffers") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "45": + q.add_log_cmd("PLOC Supervisor: Set shutdown timeout") + command = pack_set_shutdown_timeout_command(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "46": + q.add_log_cmd("PLOC Supervisor: Factory flash") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.FACTORY_FLASH) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "47": + q.add_log_cmd("PLOC Supervisor: Enable auto TM") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.ENABLE_AUTO_TM) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "48": + q.add_log_cmd("PLOC Supervisor: Disable auto TM") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.DISABLE_AUTO_TM) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "51": + q.add_log_cmd("PLOC Supervisor: Logging request event buffers") + command = pack_logging_buffer_request(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "52": + q.add_log_cmd("PLOC Supervisor: Logging clear counters") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.LOGGING_CLEAR_COUNTERS ) - command = pack_logging_buffer_request(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=66, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "52": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Logging clear counters") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "53": + q.add_log_cmd("PLOC Supervisor: Logging set topic") + command = pack_logging_set_topic(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "54": + q.add_log_cmd("PLOC Supervisor: Logging request counters") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.LOGGING_REQUEST_COUNTERS ) - command = object_id + struct.pack("!I", SupvActionIds.LOGGING_CLEAR_COUNTERS) - command = PusTelecommand(service=8, subservice=128, ssc=67, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "53": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Logging set topic")) - command = pack_logging_set_topic(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=68, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "54": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Logging request counters") + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "55": + q.add_log_cmd("PLOC Supervisor: Request ADC report") + command = object_id.as_bytes + struct.pack( + "!I", SupvActionIds.REQUEST_ADC_REPORT ) - command = object_id + struct.pack("!I", SupvActionIds.LOGGING_REQUEST_COUNTERS) - command = PusTelecommand(service=8, subservice=128, ssc=69, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "55": - tc_queue.appendleft( - (QueueCommands.PRINT, "PLOC Supervisor: Request ADC report") - ) - command = object_id + struct.pack("!I", SupvActionIds.REQUEST_ADC_REPORT) - command = PusTelecommand(service=8, subservice=128, ssc=70, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "56": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Reset PL")) - command = object_id + struct.pack("!I", SupvActionIds.RESET_PL) - command = PusTelecommand(service=8, subservice=128, ssc=71, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "57": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Enable NVMs")) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "56": + q.add_log_cmd("PLOC Supervisor: Reset PL") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.RESET_PL) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "57": + q.add_log_cmd("PLOC Supervisor: Enable NVMs") nvm01 = int(input("Enable (1) or disable(0) NVM 0 and 1: ")) nvm3 = int(input("Enable (1) or disable(0) NVM 3: ")) command = ( - object_id + object_id.as_bytes + struct.pack("!I", SupvActionIds.ENABLE_NVMS) + struct.pack("B", nvm01) + struct.pack("B", nvm3) ) - command = PusTelecommand(service=8, subservice=128, ssc=72, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - elif op_code == "58": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Continue update")) - command = object_id + struct.pack("!I", SupvActionIds.CONTINUE_UPDATE) - command = PusTelecommand(service=8, subservice=128, ssc=73, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - return tc_queue + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) + if op_code == "58": + q.add_log_cmd("PLOC Supervisor: Continue update") + command = object_id.as_bytes + struct.pack("!I", SupvActionIds.CONTINUE_UPDATE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) def pack_sel_boot_image_cmd( - object_id: bytearray, mem: int, bp0: int, bp1: int, bp2: int + object_id: bytes, mem: int, bp0: int, bp1: int, bp2: int ) -> bytearray: """This function can be used to generate the command to select the image from which the MPSoC will boot @param object_id The object id of the PLOC supervisor handler. @@ -422,10 +349,10 @@ def pack_sel_boot_image_cmd( command = command + struct.pack("!B", bp0) command = command + struct.pack("!B", bp1) command = command + struct.pack("!B", bp2) - return command + return bytearray(command) -def pack_update_available_cmd(object_id: bytearray) -> bytearray: +def pack_update_available_cmd(object_id: bytes) -> bytearray: """ @brief This function packs the udpate availabe command. @param object_id The object id of the PLOC supervisor handler. @@ -441,10 +368,10 @@ def pack_update_available_cmd(object_id: bytearray) -> bytearray: command = command + struct.pack("!I", image_size) command = command + struct.pack("!I", image_crc) command = command + struct.pack("!I", number_of_packets) - return command + return bytearray(command) -def pack_watchdogs_enable_cmd(object_id: bytearray) -> bytearray: +def pack_watchdogs_enable_cmd(object_id: bytes) -> bytearray: """ @brief This function packs the command to enable or disable watchdogs on the PLOC. @param object_id The object id of the PLOC supervisor handler. @@ -458,7 +385,7 @@ def pack_watchdogs_enable_cmd(object_id: bytearray) -> bytearray: command = command + struct.pack("!B", watchdog_ps) command = command + struct.pack("!B", watchdog_pl) command = command + struct.pack("!B", watchdog_int) - return command + return bytearray(command) def pack_watchdog_config_timeout_cmd(object_id: bytearray) -> bytearray: @@ -475,7 +402,7 @@ def pack_watchdog_config_timeout_cmd(object_id: bytearray) -> bytearray: return command -def pack_lachtup_alert_cmd(object_id: bytearray, state: bool) -> bytearray: +def pack_lachtup_alert_cmd(object_id: bytes, state: bool) -> bytearray: """ @brief This function packs the command to enable or disable a certain latchup alerts. @param object_id The object id of the PLOC supervisor handler. @@ -488,7 +415,7 @@ def pack_lachtup_alert_cmd(object_id: bytearray, state: bool) -> bytearray: else: command = object_id + struct.pack("!I", SupvActionIds.DISABLE_LATCHUP_ALERT) command = command + struct.pack("!B", latchup_id) - return command + return bytearray(command) def pack_auto_calibrate_alert_cmd(object_id: bytearray) -> bytearray: @@ -521,7 +448,7 @@ def get_latchup_id() -> int: return int(input("Specify latchup ID: ")) -def pack_set_alert_limit_cmd(object_id: bytearray) -> bytearray: +def pack_set_alert_limit_cmd(object_id: bytes) -> bytearray: """ @brief This function packs the command to set the limit of a latchup alert. @param object_id The object id of the PLOC supervisor handler. @@ -532,10 +459,10 @@ def pack_set_alert_limit_cmd(object_id: bytearray) -> bytearray: command = object_id + struct.pack("!I", SupvActionIds.SET_ALERT_LIMIT) command = command + struct.pack("!B", latchup_id) command = command + struct.pack("!I", dutycycle) - return command + return bytearray(command) -def pack_set_adc_enabled_channels_cmd(object_id: bytearray) -> bytearray: +def pack_set_adc_enabled_channels_cmd(object_id: bytes) -> bytearray: """ @brief This function packs the command to enable or disable channels of the ADC. @param object_id The object id of the PLOC supervisor handler. @@ -543,54 +470,49 @@ def pack_set_adc_enabled_channels_cmd(object_id: bytearray) -> bytearray: ch = int(input("Specify ch: 0x"), 16) cmd = object_id + struct.pack("!I", SupvActionIds.SET_ADC_ENABLED_CHANNELS) cmd = cmd + struct.pack("!H", ch) - return cmd + return bytearray(cmd) -def pack_set_adc_window_and_stride_cmd(object_id: bytearray) -> bytearray: +def pack_set_adc_window_and_stride_cmd(object_id: bytes) -> bytearray: window_size = int(input("Specify window size: ")) striding_step_size = int(input("Specify striding step size: ")) - command = bytearray() command = object_id + struct.pack("!I", SupvActionIds.SET_ADC_WINDOW_AND_STRIDE) command = command + struct.pack("!H", window_size) command = command + struct.pack("!H", striding_step_size) - return command + return bytearray(command) -def pack_set_adc_threshold_cmd(object_id: bytearray) -> bytearray: +def pack_set_adc_threshold_cmd(object_id: bytes) -> bytearray: threshold = int(input("Specify threshold: ")) - command = bytearray() command = object_id + struct.pack("!I", SupvActionIds.SET_ADC_THRESHOLD) command = command + struct.pack("!I", threshold) - return command + return bytearray(command) -def pack_select_nvm_cmd(object_id: bytearray) -> bytearray: +def pack_select_nvm_cmd(object_id: bytes) -> bytearray: mem = int(input("Specify NVM (0 - NVM0, 1 - MVM1): ")) - command = bytearray() command = object_id + struct.pack("!I", SupvActionIds.SELECT_NVM) command = command + struct.pack("!B", mem) - return command + return bytearray(command) -def pack_auto_em_tests_cmd(object_id: bytearray) -> bytearray: +def pack_auto_em_tests_cmd(object_id: bytes) -> bytearray: test = int(input("Specify test (1 - complete, 2 - short): ")) - command = bytearray() command = object_id + struct.pack("!I", SupvActionIds.RUN_AUTO_EM_TESTS) command = command + struct.pack("!B", test) - return command + return bytearray(command) -def pack_mram_wipe_cmd(object_id: bytearray) -> bytearray: +def pack_mram_wipe_cmd(object_id: bytes) -> bytearray: start = int(input("Start address: 0x"), 16) stop = int(input("Stop address: 0x"), 16) - command = bytearray() command = object_id + struct.pack("!I", SupvActionIds.WIPE_MRAM) command = command + struct.pack("!I", start) command = command + struct.pack("!I", stop) - return command + return bytearray(command) -def pack_update_command(object_id: bytearray) -> bytearray: +def pack_update_command(object_id: bytes) -> bytearray: command = bytearray() memory_id = int(input("Specify memory ID: ")) start_address = int(input("Specify start address: 0x"), 16) @@ -602,10 +524,10 @@ def pack_update_command(object_id: bytearray) -> bytearray: command += struct.pack("!B", 0) command += struct.pack("!B", memory_id) command += struct.pack("!I", start_address) - return command + return bytearray(command) -def pack_set_shutdown_timeout_command(object_id: bytearray) -> bytearray: +def pack_set_shutdown_timeout_command(object_id: bytes) -> bytearray: command = bytearray() command += object_id command += struct.pack("!I", SupvActionIds.SET_SHUTDOWN_TIMEOUT) @@ -614,7 +536,7 @@ def pack_set_shutdown_timeout_command(object_id: bytearray) -> bytearray: return command -def pack_logging_buffer_request(object_id: bytearray) -> bytearray: +def pack_logging_buffer_request(object_id: bytes) -> bytearray: command = bytearray() command += object_id command += struct.pack("!I", SupvActionIds.LOGGING_REQUEST_EVENT_BUFFERS) @@ -623,7 +545,7 @@ def pack_logging_buffer_request(object_id: bytearray) -> bytearray: return command -def pack_set_gpio_cmd(object_id: bytearray) -> bytearray: +def pack_set_gpio_cmd(object_id: bytes) -> bytearray: port = int(input("Specify port: 0x"), 16) pin = int(input("Specify pin: 0x"), 16) val = int(input("Specify val: 0x"), 16) @@ -631,23 +553,23 @@ def pack_set_gpio_cmd(object_id: bytearray) -> bytearray: command = command + struct.pack("!B", port) command = command + struct.pack("!B", pin) command = command + struct.pack("!B", val) - return command + return bytearray(command) -def pack_read_gpio_cmd(object_id: bytearray) -> bytearray: +def pack_read_gpio_cmd(object_id: bytes) -> bytearray: port = int(input("Specify port: 0x"), 16) pin = int(input("Specify pin: 0x"), 16) command = object_id + struct.pack("!I", SupvActionIds.READ_GPIO) command = command + struct.pack("!B", port) command = command + struct.pack("!B", pin) - return command + return bytearray(command) -def pack_logging_set_topic(objetc_id: bytearray) -> bytearray: - command = objetc_id + struct.pack("!I", SupvActionIds.LOGGING_SET_TOPIC) +def pack_logging_set_topic(object_id: bytes) -> bytearray: + command = object_id + struct.pack("!I", SupvActionIds.LOGGING_SET_TOPIC) tpc = int(input("Specify logging topic: ")) command += struct.pack("!B", tpc) - return command + return bytearray(command) def get_update_file() -> str: diff --git a/pus_tc/devs/rad_sensor.py b/pus_tc/devs/rad_sensor.py index 7d66597..3886721 100644 --- a/pus_tc/devs/rad_sensor.py +++ b/pus_tc/devs/rad_sensor.py @@ -8,12 +8,10 @@ import struct from config.definitions import CustomServiceList -from tmtccmd.config import add_op_code_entry, add_service_op_code_entry -from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT, OpCodeDictKeys -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand from pus_tc.service_200_mode import pack_mode_data, Modes +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid from tmtccmd.utility import ObjectId @@ -70,41 +68,33 @@ def add_rad_sens_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_rad_sensor_test_into(object_id: ObjectId, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft( - (QueueCommands.PRINT, f"Commanding Radiation sensor handler {object_id}") - ) +def pack_rad_sensor_test_into(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd(f"Commanding Radiation sensor handler {object_id}") if op_code in OpCodes.ON: - rad_sensor_mode_cmd(object_id, Modes.ON, Info.ON, tc_queue) + rad_sensor_mode_cmd(object_id, Modes.ON, Info.ON, q) if op_code in OpCodes.NORMAL: - rad_sensor_mode_cmd(object_id, Modes.NORMAL, Info.NORMAL, tc_queue) + rad_sensor_mode_cmd(object_id, Modes.NORMAL, Info.NORMAL, q) if op_code in OpCodes.OFF: - rad_sensor_mode_cmd(object_id, Modes.OFF, Info.OFF, tc_queue) + rad_sensor_mode_cmd(object_id, Modes.OFF, Info.OFF, q) if op_code in OpCodes.REQ_HK_ONCE: - tc_queue.appendleft((QueueCommands.PRINT, f"Rad sensor: {Info.REQ_OS_HK}")) - cmd = generate_one_hk_command( - sid=make_sid(object_id.as_bytes, set_id=SetIds.HK), ssc=0 + q.add_log_cmd(f"Rad sensor: {Info.REQ_OS_HK}") + q.add_pus_tc( + generate_one_hk_command(sid=make_sid(object_id.as_bytes, set_id=SetIds.HK)) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.DEBUG_ON: - tc_queue.appendleft((QueueCommands.PRINT, f"Rad sensor: {Info.DEBUG_ON}")) + q.add_log_cmd(f"Rad sensor: {Info.DEBUG_ON}") command = object_id.as_bytes + struct.pack("!I", CommandIds.ENABLE_DEBUG_OUTPUT) - command = PusTelecommand(service=8, subservice=128, ssc=45, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code in OpCodes.DEBUG_OFF: - tc_queue.appendleft((QueueCommands.PRINT, f"Rad sensor: {Info.DEBUG_OFF}")) + q.add_log_cmd(f"Rad sensor: {Info.DEBUG_OFF}") command = object_id.as_bytes + struct.pack( "!I", CommandIds.DISABLE_DEBUG_OUTPUT ) - command = PusTelecommand(service=8, subservice=128, ssc=45, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) -def rad_sensor_mode_cmd( - object_id: ObjectId, mode: Modes, info: str, tc_queue: TcQueueT -): - tc_queue.appendleft((QueueCommands.PRINT, f"Rad sensor: {info}")) +def rad_sensor_mode_cmd(object_id: ObjectId, mode: Modes, info: str, q: QueueHelper): + q.add_log_cmd(f"Rad sensor: {info}") mode_data = pack_mode_data(object_id.as_bytes, mode, 0) - command = PusTelecommand(service=200, subservice=1, ssc=41, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) diff --git a/pus_tc/devs/reaction_wheels.py b/pus_tc/devs/reaction_wheels.py index 60edc36..25cf89a 100644 --- a/pus_tc/devs/reaction_wheels.py +++ b/pus_tc/devs/reaction_wheels.py @@ -5,14 +5,13 @@ @date 20.06.2021 """ import struct -from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, generate_one_diag_command, make_sid, ) -from tmtccmd.config.globals import add_op_code_entry, add_service_op_code_entry -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes, Subservices from config.definitions import CustomServiceList @@ -130,48 +129,44 @@ def add_rw_cmds(cmd_dict: ServiceOpCodeDictT): def pack_single_rw_test_into( - object_id: bytes, rw_idx: int, tc_queue: TcQueueT, op_code: str + object_id: bytes, rw_idx: int, q: QueueHelper, op_code: str ) -> TcQueueT: if op_code in OpCodesDevs.SPEED: speed = int(input("Specify speed [0.1 RPM]: ")) ramp_time = int(input("Specify ramp time [ms]: ")) - tc_queue.appendleft((QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.SPEED}")) - command = pack_set_speed_command(object_id, speed, ramp_time, 40) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.SPEED}") + q.add_pus_tc(pack_set_speed_command(object_id, speed, ramp_time)) if op_code in OpCodesDevs.ON: - tc_queue.appendleft((QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.ON}")) + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.ON}") mode_data = pack_mode_data(object_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=41, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) if op_code in OpCodesDevs.NML: - tc_queue.appendleft((QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.NML}")) + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.NML}") mode_data = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=42, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) if op_code in OpCodesDevs.OFF: - tc_queue.appendleft((QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.OFF}")) + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.OFF}") mode_data = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=43, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) if op_code in OpCodesDevs.GET_TM: - tc_queue.appendleft((QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.GET_TM}")) - command = generate_one_hk_command( - sid=make_sid(object_id=object_id, set_id=RwSetIds.TM_SET), ssc=0 + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.GET_TM}") + q.add_pus_tc( + generate_one_hk_command( + sid=make_sid(object_id=object_id, set_id=RwSetIds.TM_SET) + ) ) - tc_queue.appendleft(command.pack_command_tuple()) if op_code in OpCodesDevs.GET_STATUS: - tc_queue.appendleft( - (QueueCommands.PRINT, f"RW {rw_idx}: {InfoDevs.GET_STATUS}") + q.add_log_cmd(f"RW {rw_idx}: {InfoDevs.GET_STATUS}") + q.add_pus_tc( + generate_one_diag_command( + sid=make_sid(object_id=object_id, set_id=RwSetIds.STATUS_SET_ID) + ) ) - command = generate_one_diag_command( - sid=make_sid(object_id=object_id, set_id=RwSetIds.STATUS_SET_ID), ssc=0 - ) - tc_queue.appendleft(command.pack_command_tuple()) - return tc_queue + return q def pack_rw_ass_cmds(tc_queue: TcQueueT, object_id: bytes, op_code: str): @@ -196,7 +191,7 @@ def pack_rw_ass_cmds(tc_queue: TcQueueT, object_id: bytes, op_code: str): def pack_set_speed_command( - object_id: bytes, speed: int, ramp_time_ms: int, ssc: int + object_id: bytes, speed: int, ramp_time_ms: int ) -> PusTelecommand: """With this function a command is packed to set the speed of a reaction wheel :param object_id: The object id of the reaction wheel handler. @@ -204,7 +199,6 @@ def pack_set_speed_command( specified in 0.1 * RPM :param ramp_time_ms: The time after which the reaction wheel will reach the commanded speed. Valid times are 10 - 10000 ms - :param ssc: Source sequence count """ if speed > 0: if speed < 1000 or speed > 65000: @@ -231,5 +225,5 @@ def pack_set_speed_command( command += object_id + command_id command = command + struct.pack("!i", speed) command = command + ramp_time_ms.to_bytes(length=2, byteorder="big") - command = PusTelecommand(service=8, subservice=128, ssc=ssc, app_data=command) + command = PusTelecommand(service=8, subservice=128, app_data=command) return command diff --git a/pus_tc/devs/rtd.py b/pus_tc/devs/rtd.py index 8e3c614..669c0d5 100644 --- a/pus_tc/devs/rtd.py +++ b/pus_tc/devs/rtd.py @@ -1,13 +1,10 @@ from typing import Optional from config.definitions import CustomServiceList +from pus_tc.devs.pdec_handler import CommandIds from spacepackets.ecss import PusTelecommand -from tmtccmd.config import ( - ServiceOpCodeDictT, - add_op_code_entry, - add_service_op_code_entry, -) -from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.utility import ObjectId from tmtccmd.tc.pus_200_fsfw_modes import Modes, pack_mode_data, Subservices import config.object_ids as oids @@ -60,7 +57,7 @@ def specify_rtd_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_rtd_commands(op_code: str, object_id: Optional[ObjectId], tc_queue: TcQueueT): +def pack_rtd_commands(op_code: str, object_id: Optional[ObjectId], q: QueueHelper): if object_id is not None and object_id not in RTD_IDS: print("Specified object ID not a valid RTD ID") object_id = None @@ -72,30 +69,32 @@ def pack_rtd_commands(op_code: str, object_id: Optional[ObjectId], tc_queue: TcQ app_data = pack_mode_data( object_id=object_id.as_bytes, mode=Modes.ON, submode=0 ) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.NORMAL: app_data = pack_mode_data( object_id=object_id.as_bytes, mode=Modes.NORMAL, submode=0 ) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.OFF: app_data = pack_mode_data( object_id=object_id.as_bytes, mode=Modes.OFF, submode=0 ) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=app_data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.CONFIG_CMD: - command = object_id + CommandIds.PRINT_CLCW - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + command = object_id.as_bytes + CommandIds.PRINT_CLCW + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) def prompt_rtd_idx(): diff --git a/pus_tc/devs/tmp1075.py b/pus_tc/devs/tmp1075.py index ffc6524..ce095fc 100644 --- a/pus_tc/devs/tmp1075.py +++ b/pus_tc/devs/tmp1075.py @@ -5,11 +5,11 @@ @author J. Meier @date 06.01.2021 """ -from tmtccmd.config.definitions import QueueCommands - -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand from pus_tc.service_200_mode import pack_mode_data +from tmtccmd.tc import QueueHelper +from tmtccmd.tc.pus_200_fsfw_modes import Modes +from tmtccmd.utility import ObjectId class Tmp1075TestProcedure: @@ -33,41 +33,28 @@ class Tmp1075ActionIds: start_adc_conversion = bytearray([0x0, 0x0, 0x0, 0x02]) -def pack_tmp1075_test_into( - object_id: bytearray, op_code: str, tc_queue: TcQueueT -) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing Tmp1075 Temperature Sensor Handler with object id: 0x" - + object_id.hex(), - ) +def pack_tmp1075_test_into(object_id: ObjectId, op_code: str, q: QueueHelper): + q.add_log_cmd( + f"Testing Tmp1075 Temperature Sensor Handler with object id: {object_id.as_hex_string}" ) - + obyt = object_id.as_bytes if Tmp1075TestProcedure.all or Tmp1075TestProcedure.start_adc_conversion: - tc_queue.appendleft( - (QueueCommands.PRINT, "TMP1075: Starting new temperature conversion") - ) - command = object_id + Tmp1075ActionIds.start_adc_conversion - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - + q.add_log_cmd("TMP1075: Starting new temperature conversion") + command = obyt + Tmp1075ActionIds.start_adc_conversion + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if Tmp1075TestProcedure.all or Tmp1075TestProcedure.get_temp: - tc_queue.appendleft((QueueCommands.PRINT, "TMP1075: Read temperature")) - command = object_id + Tmp1075ActionIds.get_temp - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("TMP1075: Read temperature") + command = obyt + Tmp1075ActionIds.get_temp + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if Tmp1075TestProcedure.set_mode_normal: - tc_queue.appendleft((QueueCommands.PRINT, "TMP1075: Set Mode Normal")) - mode_data = pack_mode_data(object_id, 2, 0) - command = PusTelecommand(service=200, subservice=1, ssc=220, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("TMP1075: Set Mode Normal") + mode_data = pack_mode_data(obyt, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) if Tmp1075TestProcedure.set_mode_on: - tc_queue.appendleft((QueueCommands.PRINT, "TMP1075: Set Mode On")) - mode_data = pack_mode_data(object_id, 1, 0) - command = PusTelecommand(service=200, subservice=1, ssc=221, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("TMP1075: Set Mode On") + mode_data = pack_mode_data(obyt, Modes.ON, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) - return tc_queue + return q diff --git a/pus_tc/tc_packer_hook.py b/pus_tc/procedure_packer.py similarity index 80% rename from pus_tc/tc_packer_hook.py rename to pus_tc/procedure_packer.py index be637d4..35a8d5a 100644 --- a/pus_tc/tc_packer_hook.py +++ b/pus_tc/procedure_packer.py @@ -7,12 +7,14 @@ from typing import Union from pus_tc.devs.rtd import pack_rtd_commands from spacepackets.ecss import PusTelecommand -from tmtccmd.com_if.com_interface_base import CommunicationInterface -from tmtccmd.config.definitions import CoreServiceList, QueueCommands +from tmtccmd import DefaultProcedureInfo +from tmtccmd.config import CoreServiceList from tmtccmd.logging import get_console_logger -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.tc import FeedWrapper +from tmtccmd.tc.pus_5_event import ( + pack_generic_service5_test_into, + pack_generic_service_5_test_into, +) from tmtccmd.pus.pus_17_test import pack_service_17_ping_command from tmtccmd.logging import get_current_time_string @@ -77,114 +79,79 @@ import config.object_ids as oids LOGGER = get_console_logger() -def pre_tc_send_cb( - queue_entry: Union[bytes, QueueCommands], - com_if: CommunicationInterface, - queue_info: Union[PusTelecommand, any], - file_logger: logging.Logger, -): - if isinstance(queue_entry, bytes) or isinstance(queue_entry, bytearray): - log_raw_pus_tc( - packet=queue_entry, - srv_subservice=(queue_info.service, queue_info.subservice), - ) - 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) - - -def pack_service_queue_user( - service: Union[str, int], op_code: str, service_queue: TcQueueT -): +def handle_default_procedure(info: DefaultProcedureInfo, wrapper: FeedWrapper): + queue_helper = wrapper.queue_helper + service = info.service + op_code = info.op_code obj_id_man = get_object_ids() if service == CoreServiceList.SERVICE_5.value: - return pack_generic_service5_test_into(tc_queue=service_queue) + return pack_generic_service_5_test_into(q=queue_helper) if service == CoreServiceList.SERVICE_17.value: - return service_queue.appendleft( - pack_service_17_ping_command(ssc=1700).pack_command_tuple() - ) + queue_helper.add_pus_tc(pack_service_17_ping_command()) if service == CoreServiceList.SERVICE_200.value: - return pack_service200_test_into(tc_queue=service_queue) + return pack_service200_test_into(q=queue_helper) if service == CustomServiceList.P60DOCK.value: object_id = obj_id_man.get(P60_DOCK_HANDLER) - return pack_p60dock_cmds( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_p60dock_cmds(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.RTD.value: - return pack_rtd_commands( - object_id=None, tc_queue=service_queue, op_code=op_code - ) + return pack_rtd_commands(object_id=None, q=queue_helper, op_code=op_code) if service == CustomServiceList.PDU1.value: object_id = obj_id_man.get(PDU_1_HANDLER_ID) - return pack_pdu1_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_pdu1_commands(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.PDU2.value: object_id = obj_id_man.get(PDU_2_HANDLER_ID) - return pack_pdu2_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_pdu2_commands(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.ACU.value: object_id = obj_id_man.get(ACU_HANDLER_ID) - return pack_acu_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_acu_commands(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.BPX_BATTERY.value: - return pack_bpx_commands(tc_queue=service_queue, op_code=op_code) + return pack_bpx_commands(q=queue_helper, op_code=op_code) if service == CustomServiceList.TMP1075_1.value: object_id = TMP_1075_1_HANDLER_ID return pack_tmp1075_test_into( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.TMP1075_2.value: object_id = TMP_1075_2_HANDLER_ID return pack_tmp1075_test_into( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.HEATER.value: object_id = HEATER_ID - return pack_heater_cmds( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_heater_cmds(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.IMTQ.value: object_id = IMTQ_HANDLER_ID - return pack_imtq_test_into( - object_id=object_id, tc_queue=service_queue, op_code=op_code - ) + return pack_imtq_test_into(object_id=object_id, q=queue_helper, op_code=op_code) if service == CustomServiceList.PLOC_MPSOC.value: object_id = PLOC_MPSOC_ID return pack_ploc_mpsoc_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.REACTION_WHEEL_1.value: return pack_single_rw_test_into( - object_id=RW1_ID, rw_idx=1, tc_queue=service_queue, op_code=op_code + object_id=RW1_ID, rw_idx=1, q=queue_helper, op_code=op_code ) if service == CustomServiceList.REACTION_WHEEL_2.value: return pack_single_rw_test_into( - object_id=RW2_ID, rw_idx=2, tc_queue=service_queue, op_code=op_code + object_id=RW2_ID, rw_idx=2, q=queue_helper, op_code=op_code ) if service == CustomServiceList.REACTION_WHEEL_3.value: return pack_single_rw_test_into( - object_id=RW3_ID, rw_idx=3, tc_queue=service_queue, op_code=op_code + object_id=RW3_ID, rw_idx=3, q=queue_helper, op_code=op_code ) if service == CustomServiceList.REACTION_WHEEL_4.value: return pack_single_rw_test_into( - object_id=RW4_ID, rw_idx=4, tc_queue=service_queue, op_code=op_code + object_id=RW4_ID, rw_idx=4, q=queue_helper, op_code=op_code ) if service == CustomServiceList.RAD_SENSOR.value: object_id = obj_id_man.get(RAD_SENSOR_ID) return pack_rad_sensor_test_into( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.PLOC_SUPV.value: object_id = PLOC_SUPV_ID return pack_ploc_supv_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.STAR_TRACKER.value: object_id = STAR_TRACKER_ID @@ -246,6 +213,32 @@ def pack_service_queue_user( LOGGER.warning(f"Invalid Service {service}") +def pre_tc_send_cb( + queue_entry: Union[bytes, QueueCommands], + com_if: CommunicationInterface, + queue_info: Union[PusTelecommand, any], + file_logger: logging.Logger, +): + if isinstance(queue_entry, bytes) or isinstance(queue_entry, bytearray): + log_raw_pus_tc( + packet=queue_entry, + srv_subservice=(queue_info.service, queue_info.subservice), + ) + 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) + + +def pack_service_queue_user( + service: Union[str, int], op_code: str, service_queue: TcQueueT +): + pass + + def create_total_tc_queue_user() -> TcQueueT: if not os.path.exists("log"): os.mkdir("log") diff --git a/pus_tc/service_200_mode.py b/pus_tc/service_200_mode.py index 1f046e7..467d1fb 100644 --- a/pus_tc/service_200_mode.py +++ b/pus_tc/service_200_mode.py @@ -5,37 +5,31 @@ @author R. Mueller @date 02.05.2020 """ -from tmtccmd.config.definitions import QueueCommands from spacepackets.ecss.tc import PusTelecommand -from tmtccmd.tc.packer import TcQueueT +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes from config.object_ids import TEST_DEVICE_ID TEST_DEVICE_OBJ_ID = TEST_DEVICE_ID -def pack_service200_test_into(tc_queue: TcQueueT) -> TcQueueT: - tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 200")) +def pack_service200_test_into(q: QueueHelper): + q.add_log_cmd("Testing Service 200") # Object ID: Dummy Device obj_id = TEST_DEVICE_OBJ_ID # Set On Mode - tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 200: Set Mode On")) + q.add_log_cmd("Testing Service 200: Set Mode On") mode_data = pack_mode_data(obj_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=2000, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) # Set Normal mode - tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 200: Set Mode Normal")) + q.add_log_cmd("Testing Service 200: Set Mode Normal") mode_data = pack_mode_data(obj_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=2010, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) # Set Raw Mode - tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 200: Set Mode Raw")) + q.add_log_cmd("Testing Service 200: Set Mode Raw") mode_data = pack_mode_data(obj_id, Modes.RAW, 0) - command = PusTelecommand(service=200, subservice=1, ssc=2020, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) # Set Off Mode - tc_queue.appendleft((QueueCommands.PRINT, "Testing Service 200: Set Mode Off")) + q.add_log_cmd("Testing Service 200: Set Mode Off") mode_data = pack_mode_data(obj_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=2030, app_data=mode_data) - tc_queue.appendleft(command.pack_command_tuple()) - return tc_queue + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data)) diff --git a/pus_tc/system/proc.py b/pus_tc/system/proc.py index 261f745..f22c481 100644 --- a/pus_tc/system/proc.py +++ b/pus_tc/system/proc.py @@ -82,7 +82,12 @@ class KeyAndInfo: KAI = KeyAndInfo PROC_INFO_DICT = { - KAI.TV_SETUP_TCS_FT_ON[0]: [OpCodes.TV_SETUP_TCS_FT_ON, KAI.TV_SETUP_TCS_FT_ON[1], 120.0, 10.0], + KAI.TV_SETUP_TCS_FT_ON[0]: [ + OpCodes.TV_SETUP_TCS_FT_ON, + KAI.TV_SETUP_TCS_FT_ON[1], + 120.0, + 10.0, + ], KAI.TV_TEARDOWN_TCS_FT_OFF[0]: [ OpCodes.TV_TEARDOWN_TCS_FT_OFF, KAI.TV_TEARDOWN_TCS_FT_OFF[1], @@ -327,13 +332,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): (oids.GPS_CONTROLLER, GpsSetIds.HK), ] d_side_pairs = a_side_pairs + b_side_pairs - diag_list = [ - False, - False, - True, - False, - False - ] + diag_list = [False, False, True, False, False] pack_acs_command(tc_queue=tc_queue, op_code="acs-a") for a_side_dev in a_side_pairs: @@ -353,13 +352,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): pack_acs_command(tc_queue=tc_queue, op_code="acs-b") sid_list.clear() - diag_list = [ - False, - False, - True, - False, - False - ] + diag_list = [False, False, True, False, False] for b_side_dev in b_side_pairs: oid = b_side_dev[0] @@ -419,20 +412,24 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): ] # Command MGT to mode on - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="1") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="1") tc_queue.appendleft((QueueCommands.WAIT, 5)) # Command MGT to normal mode - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="2") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="2") for imtq_dev in imtq_pairs: oid = imtq_dev[0] set_id = imtq_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default() + tc_queue=tc_queue, + proc_key=key, + sid_list=sid_list, + diag_list=diag_list, + cfg=GenericHkListeningCfg.default(), ) - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="0") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="0") if op_code in OpCodes.MGT_FT_DP: key = KAI.MGT_FT_DP[0] @@ -473,10 +470,10 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): ] pack_acs_command(tc_queue=tc_queue, op_code="acs-d") # Command MGT to mode on - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="1") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="1") tc_queue.appendleft((QueueCommands.WAIT, 20)) # Command MGT to normal mode - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="2") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="2") for d_side_and_imtq_dev in d_side_and_imtq_pairs: oid = d_side_and_imtq_dev[0] @@ -493,7 +490,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): cfg=cfg, ) - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, tc_queue=tc_queue, op_code="0") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="0") pack_acs_command(tc_queue=tc_queue, op_code="acs-off") if op_code in OpCodes.SUS_FT: diff --git a/pus_tm/action_reply_handler.py b/pus_tm/action_reply_handler.py index eaf44b1..9c2392c 100644 --- a/pus_tm/action_reply_handler.py +++ b/pus_tm/action_reply_handler.py @@ -132,14 +132,14 @@ def handle_acu_replies( ): if action_id == GomspaceDeviceActionIds.PARAM_GET: header_list = [ - "Gomspace action ID" - "Table ID", + "Gomspace action ID" "Table ID", "Memory Address", - "Payload length" - "Payload" + "Payload length" "Payload", ] fmt_str = "!BBHH" - (action, table_id, address, payload_length) = struct.unpack(fmt_str, custom_data[:6]) + (action, table_id, address, payload_length) = struct.unpack( + fmt_str, custom_data[:6] + ) content_list = [ action, table_id, diff --git a/pus_tm/devs/mgms.py b/pus_tm/devs/mgms.py index 1683c29..48360ea 100644 --- a/pus_tm/devs/mgms.py +++ b/pus_tm/devs/mgms.py @@ -10,9 +10,15 @@ import config.object_ids as obj_ids def handle_mgm_hk_data( object_id: ObjectId, printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes ): - if object_id.as_bytes in [obj_ids.MGM_0_LIS3_HANDLER_ID, obj_ids.MGM_2_LIS3_HANDLER_ID]: + if object_id.as_bytes in [ + obj_ids.MGM_0_LIS3_HANDLER_ID, + obj_ids.MGM_2_LIS3_HANDLER_ID, + ]: handle_mgm_lis3_hk_data(object_id, printer, set_id, hk_data) - elif object_id.as_bytes in [obj_ids.MGM_1_RM3100_HANDLER_ID, obj_ids.MGM_3_RM3100_HANDLER_ID]: + elif object_id.as_bytes in [ + obj_ids.MGM_1_RM3100_HANDLER_ID, + obj_ids.MGM_3_RM3100_HANDLER_ID, + ]: handle_mgm_rm3100_hk_data(object_id, printer, set_id, hk_data) pass @@ -25,7 +31,7 @@ def handle_mgm_lis3_hk_data( fmt_str = "!ffff" inc_len = struct.calcsize(fmt_str) (field_x, field_y, field_z, temp) = struct.unpack( - fmt_str, hk_data[0: 0 + inc_len] + fmt_str, hk_data[0 : 0 + inc_len] ) pw.dlog(f"Received MGM LIS3 from object {object_id}") pw.dlog( diff --git a/pus_tm/devs/pcdu.py b/pus_tm/devs/pcdu.py index 01cfc49..068f4fd 100644 --- a/pus_tm/devs/pcdu.py +++ b/pus_tm/devs/pcdu.py @@ -180,13 +180,13 @@ def handle_pdu_data( current_list = [] for idx in range(len(PDU1_CHANNELS_NAMES)): current_list.append( - struct.unpack("!h", hk_data[current_idx: current_idx + 2])[0] + struct.unpack("!h", hk_data[current_idx : current_idx + 2])[0] ) current_idx += 2 voltage_list = [] for idx in range(len(PDU1_CHANNELS_NAMES)): voltage_list.append( - struct.unpack("!H", hk_data[current_idx: current_idx + 2])[0] + struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0] ) current_idx += 2 output_enb_list = [] @@ -205,7 +205,7 @@ def handle_pdu_data( fmt_str = "!IBf" inc_len = struct.calcsize(fmt_str) (boot_count, batt_mode, temperature) = struct.unpack( - fmt_str, hk_data[current_idx: current_idx + inc_len] + fmt_str, hk_data[current_idx : current_idx + inc_len] ) info = ( f"Boot Count {boot_count} | Battery Mode {batt_mode} | " diff --git a/pus_tm/event_handler.py b/pus_tm/event_handler.py index 9d0426d..2af9e77 100644 --- a/pus_tm/event_handler.py +++ b/pus_tm/event_handler.py @@ -40,8 +40,8 @@ def handle_event_packet( obj_ids = get_object_ids() obj_id_obj = obj_ids.get(tm.reporter_id.as_bytes) if obj_id_obj is None: - LOGGER.warning(f"Object ID 0x{tm.reporter_id.as_string} has no name") - obj_name = tm.reporter_id.as_string + LOGGER.warning(f"Object ID 0x{tm.reporter_id.as_hex_string} has no name") + obj_name = tm.reporter_id.as_hex_string else: obj_name = obj_id_obj.name generic_event_string = ( diff --git a/pus_tm/factory_hook.py b/pus_tm/factory_hook.py index 8bd8fe1..e3b4f30 100644 --- a/pus_tm/factory_hook.py +++ b/pus_tm/factory_hook.py @@ -1,21 +1,14 @@ """Core EIVE TM handler module """ -from spacepackets.ecss.tm import PusTelemetry -from tmtccmd.logging import get_console_logger -from tmtccmd.logging.pus import ( - log_raw_pus_tm, - log_raw_unknown_packet, - PacketTypes, - create_tmtc_logger, -) - -from tmtccmd.tm.pus_17_test import Service17TMExtended -from tmtccmd.tm.pus_20_fsfw_parameters import Service20FsfwTm -from tmtccmd.tm.pus_200_fsfw_modes import Service200FsfwTm -from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter - -from config.definitions import PUS_APID from config.object_ids import get_object_ids +from spacepackets.ecss import PusTelemetry +from spacepackets.util import PrintFormats +from tmtccmd import get_console_logger +from tmtccmd.logging.pus import RawTmtcTimedLogWrapper +from tmtccmd.pus import VerificationWrapper +from tmtccmd.tm import Service20FsfwTm, Service200FsfwTm +from tmtccmd.tm.pus_17_test import Service17TmExtended +from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter from .event_handler import handle_event_packet from .verification_handler import handle_service_1_packet @@ -25,60 +18,46 @@ from .action_reply_handler import handle_action_reply LOGGER = get_console_logger() -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) - - -def pus_factory_hook(raw_tm_packet: bytes): - if len(raw_tm_packet) < 8: +def pus_factory_hook( + packet: bytes, + verif_wrapper: VerificationWrapper, + printer: FsfwTmTcPrinter, + raw_logger: RawTmtcTimedLogWrapper, +): + if len(packet) < 8: LOGGER.warning("Detected packet shorter than 8 bytes!") return - service_type = raw_tm_packet[7] - subservice_type = raw_tm_packet[8] - file_logger = FSFW_PRINTER.file_logger + try: + tm_packet = PusTelemetry.unpack(packet) + except ValueError: + LOGGER.warning("Could not generate PUS TM object from raw data") + LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}") + return + service = tm_packet.service + file_logger = printer.file_logger obj_id_dict = get_object_ids() dedicated_handler = True - try: - tm_packet = None - if service_type == 1: - handle_service_1_packet(printer=FSFW_PRINTER, raw_tm=raw_tm_packet) - elif service_type == 3: - handle_hk_packet( - printer=FSFW_PRINTER, raw_tm=raw_tm_packet, obj_id_dict=obj_id_dict - ) - elif service_type == 5: - handle_event_packet( - raw_tm=raw_tm_packet, printer=FSFW_PRINTER, file_logger=file_logger - ) - elif service_type == 8: - handle_action_reply( - raw_tm=raw_tm_packet, printer=FSFW_PRINTER, obj_id_dict=obj_id_dict - ) - elif service_type == 17: - tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet) - dedicated_handler = False - elif service_type == 20: - tm_packet = Service20FsfwTm.unpack(raw_telemetry=raw_tm_packet) - dedicated_handler = False - elif service_type == 200: - tm_packet = Service200FsfwTm.unpack(raw_telemetry=raw_tm_packet) - dedicated_handler = False - 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) - dedicated_handler = True - if not dedicated_handler and tm_packet is not None: - FSFW_PRINTER.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet) - log_raw_pus_tm( - packet=raw_tm_packet, srv_subservice=(service_type, subservice_type) - ) - except ValueError: - LOGGER.warning("Invalid packet format detected") - log_raw_unknown_packet(packet=raw_tm_packet, packet_type=PacketTypes.TM) + if service == 1: + handle_service_1_packet(wrapper=verif_wrapper, raw_tm=packet) + elif service == 3: + handle_hk_packet(printer=printer, raw_tm=packet, obj_id_dict=obj_id_dict) + elif service == 5: + handle_event_packet(raw_tm=packet, printer=printer, file_logger=file_logger) + elif service == 8: + handle_action_reply(raw_tm=packet, printer=printer, obj_id_dict=obj_id_dict) + elif service == 17: + tm_packet = Service17TmExtended.unpack(raw_telemetry=packet) + dedicated_handler = False + elif service == 20: + tm_packet = Service20FsfwTm.unpack(raw_telemetry=packet) + dedicated_handler = False + elif service == 200: + tm_packet = Service200FsfwTm.unpack(raw_telemetry=packet) + dedicated_handler = False + else: + LOGGER.info(f"The service {service} is not implemented in Telemetry Factory") + tm_packet.print_source_data(PrintFormats.HEX) + dedicated_handler = True + if not dedicated_handler and tm_packet is not None: + printer.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet) + raw_logger.log_tm(tm_packet) diff --git a/pus_tm/system/tcs.py b/pus_tm/system/tcs.py index 45b6623..f6e9ec0 100644 --- a/pus_tm/system/tcs.py +++ b/pus_tm/system/tcs.py @@ -21,17 +21,32 @@ def handle_thermal_controller_hk_data( pw.dlog("Received sensor temperature data") # get all the floats - tm_data = struct.unpack("!ffffffffffffffffff", hk_data[:18 * 4]) - parsed_data = {"SENSOR_PLOC_HEATSPREADER": tm_data[0], "SENSOR_PLOC_MISSIONBOARD": tm_data[1], - "SENSOR_4K_CAMERA": tm_data[2], "SENSOR_DAC_HEATSPREADER": tm_data[3], - "SENSOR_STARTRACKER": tm_data[4], "SENSOR_RW1": tm_data[5], "SENSOR_DRO": tm_data[6], - "SENSOR_SCEX": tm_data[7], "SENSOR_X8": tm_data[8], "SENSOR_HPA": tm_data[9], - "SENSOR_TX_MODUL": tm_data[10], "SENSOR_MPA": tm_data[11], "SENSOR_ACU": tm_data[12], - "SENSOR_PLPCDU_HEATSPREADER": tm_data[13], "SENSOR_TCS_BOARD": tm_data[14], - "SENSOR_MAGNETTORQUER": tm_data[15], "TMP1075 1": tm_data[16], "TMP1075 2": tm_data[17]} + tm_data = struct.unpack("!ffffffffffffffffff", hk_data[: 18 * 4]) + parsed_data = { + "SENSOR_PLOC_HEATSPREADER": tm_data[0], + "SENSOR_PLOC_MISSIONBOARD": tm_data[1], + "SENSOR_4K_CAMERA": tm_data[2], + "SENSOR_DAC_HEATSPREADER": tm_data[3], + "SENSOR_STARTRACKER": tm_data[4], + "SENSOR_RW1": tm_data[5], + "SENSOR_DRO": tm_data[6], + "SENSOR_SCEX": tm_data[7], + "SENSOR_X8": tm_data[8], + "SENSOR_HPA": tm_data[9], + "SENSOR_TX_MODUL": tm_data[10], + "SENSOR_MPA": tm_data[11], + "SENSOR_ACU": tm_data[12], + "SENSOR_PLPCDU_HEATSPREADER": tm_data[13], + "SENSOR_TCS_BOARD": tm_data[14], + "SENSOR_MAGNETTORQUER": tm_data[15], + "TMP1075 1": tm_data[16], + "TMP1075 2": tm_data[17], + } # print(parsed_data) - tcp_server_sensor_temperatures.report_parsed_hk_data(object_id, set_id, parsed_data) + tcp_server_sensor_temperatures.report_parsed_hk_data( + object_id, set_id, parsed_data + ) elif set_id == SetIds.DEVICE_TEMPERATURE_SET: pw = PrintWrapper(printer) pw.dlog("Received device temperature data") @@ -67,7 +82,9 @@ def handle_thermal_controller_hk_data( "ADC_PL_PCDU_TEMPERATURE": tm_data[26], } # print(parsed_data) - tcp_server_device_temperatures.report_parsed_hk_data(object_id, set_id, parsed_data) + tcp_server_device_temperatures.report_parsed_hk_data( + object_id, set_id, parsed_data + ) elif set_id == SetIds.SUS_TEMPERATURE_SET: pass # pw = PrintWrapper(printer) @@ -90,5 +107,3 @@ def handle_thermal_controller_hk_data( # } # print(parsed_data) # TODO: Forward data to space simulator - - diff --git a/pus_tm/tm_tcp_server.py b/pus_tm/tm_tcp_server.py index 76eabba..2c4031a 100644 --- a/pus_tm/tm_tcp_server.py +++ b/pus_tm/tm_tcp_server.py @@ -11,7 +11,6 @@ LOGGER = get_console_logger() class TmTcpServer: - def __init__(self, ip_address: str, port: int): self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -70,7 +69,7 @@ class TmTcpServer: data_dict = { "type": "TM", "tmType": "Raw HK", - "objectId": object_id.as_string, + "objectId": object_id.as_hex_string, "setId": set_id, "rawData": base64.b64encode(hk_data).decode(), } @@ -81,7 +80,7 @@ class TmTcpServer: data_dict = { "type": "TM", "tmType": "Parsed HK", - "objectId": object_id.as_string, + "objectId": object_id.as_hex_string, "setId": set_id, "content": data_dictionary, } diff --git a/pus_tm/verification_handler.py b/pus_tm/verification_handler.py index 08c0099..dcf03d2 100644 --- a/pus_tm/verification_handler.py +++ b/pus_tm/verification_handler.py @@ -1,28 +1,39 @@ -from typing import cast - -from tmtccmd.tm.pus_1_verification import Service1TMExtended +from spacepackets.ecss.pus_1_verification import UnpackParams from tmtccmd.logging import get_console_logger -from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter +from tmtccmd.pus import VerificationWrapper +from tmtccmd.tm.pus_1_verification import Service1TmExtended 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) +def handle_service_1_packet(wrapper: VerificationWrapper, raw_tm: bytes): + if wrapper.console_logger is None or wrapper.file_logger is None: + raise ValueError( + "Console logger or file logger not valid. Please set a valid one" + ) + tm_packet = Service1TmExtended.unpack(data=raw_tm, params=UnpackParams(1, 1)) + res = wrapper.verificator.add_tm(tm_packet) + if res is None: + LOGGER.info( + f"Received Verification TM[{tm_packet.service}, {tm_packet.subservice}] " + f"with Request ID {tm_packet.tc_req_id.as_u32():#08x}" + ) + LOGGER.warning(f"No matching telecommand found for {tm_packet.tc_req_id}") + else: + wrapper.log_to_console(tm_packet, res) + wrapper.log_to_file(tm_packet, res) retval_dict = get_retval_dict() - if srv1_packet.has_tc_error_code: - retval_info = retval_dict.get(srv1_packet.error_code) + if tm_packet.has_failure_notice: + retval_info = retval_dict.get(tm_packet.error_code.val) if retval_info is None: LOGGER.info( - f"No returnvalue information found for error code {srv1_packet.error_code}" + f"No returnvalue information found for error code {tm_packet.error_code}" ) else: retval_string = ( - f"Error Code information for code {srv1_packet.error_code} | " + f"Error Code information for code {tm_packet.error_code} | " f"Name: {retval_info.name} | Info: {retval_info.info}" ) - LOGGER.info(retval_string) - printer.file_logger.info(retval_string) + wrapper.console_logger.info(retval_string) + wrapper.file_logger.info(retval_string) diff --git a/tmtcc.py b/tmtcc.py index 9f96990..f7adf36 100644 --- a/tmtcc.py +++ b/tmtcc.py @@ -1,10 +1,21 @@ import argparse +import logging import sys import traceback from typing import Optional from tmtccmd.config.definitions import CoreModeList + +from spacepackets.ecss import PusVerificator +from tmtccmd import get_console_logger, TcHandlerBase from tmtccmd.config.globals import update_global, CoreGlobalIds +from deps.tmtccmd.tmtccmd.logging.pus import RawTmtcTimedLogWrapper +from deps.tmtccmd.tmtccmd.pus import VerificationWrapper +from deps.tmtccmd.tmtccmd.tm import SpecificApidHandlerBase, GenericApidHandlerBase +from deps.tmtccmd.tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter +from tmtccmd.pus import FileSeqCountProvider +from tmtccmd.tc import ProcedureHelper, FeedWrapper, TcProcedureType + try: import spacepackets except ImportError as error: @@ -36,8 +47,51 @@ except ImportError as error: from config import __version__ from config.definitions import PUS_APID from config.hook_implementations import EiveHookObject -from pus_tm.factory_hook import ccsds_tm_handler -from pus_tc.tc_packer_hook import pre_tc_send_cb +from pus_tm.factory_hook import pus_factory_hook +from pus_tc.procedure_packer import pre_tc_send_cb + + +LOGGER = get_console_logger() + + +class PusHandler(SpecificApidHandlerBase): + def __init__( + self, + wrapper: VerificationWrapper, + printer: FsfwTmTcPrinter, + raw_logger: RawTmtcTimedLogWrapper, + ): + super().__init__(PUS_APID, None) + self.printer = printer + self.verif_wrapper = wrapper + self.raw_logger = raw_logger + + def handle_tm(self, packet: bytes, _user_args: any): + pus_factory_hook(packet, self.verif_wrapper, self.printer, self.raw_logger) + + +class UnknownApidHandler(GenericApidHandlerBase): + def handle_tm(self, apid: int, _packet: bytes, _user_args: any): + LOGGER.warning(f"Packet with unknwon APID {apid} detected") + + +class TcHandler(TcHandlerBase): + def __init__( + self, + seq_count_provider: FileSeqCountProvider, + pus_verificator: PusVerificator, + file_logger: logging.Logger, + raw_logger: RawTmtcTimedLogWrapper, + ): + super().__init__() + self.seq_count_provider = seq_count_provider + self.pus_verificator = pus_verificator + self.file_logger = file_logger + self.raw_logger = raw_logger + + def feed_cb(self, info: ProcedureHelper, wrapper: FeedWrapper): + if info.proc_type == TcProcedureType.DEFAULT: + handle_default_procedure(info.to_def_procedure(), wrapper) def tmtcc_pre_args() -> EiveHookObject: diff --git a/tmtccli.py b/tmtccli.py index 29f3615..0b22383 100755 --- a/tmtccli.py +++ b/tmtccli.py @@ -5,7 +5,6 @@ from tmtcc import ( tmtcc_pre_args, create_default_args_parser, add_default_tmtccmd_args, - parse_default_input_arguments, ) diff --git a/tmtcgui.py b/tmtcgui.py index df4f460..6c8a1fd 100755 --- a/tmtcgui.py +++ b/tmtcgui.py @@ -1,9 +1,6 @@ #!/usr/bin/env python3 """TMTC commander for EIVE""" -from tmtcc import ( - tmtcc_post_args, - tmtcc_pre_args -) +from tmtcc import tmtcc_post_args, tmtcc_pre_args def main(): diff --git a/tmtcloop.py b/tmtcloop.py index 0a7fdc8..d177c83 100755 --- a/tmtcloop.py +++ b/tmtcloop.py @@ -35,7 +35,7 @@ except ImportError as error: sys.exit(1) from config.definitions import PUS_APID -from pus_tc.tc_packer_hook import pre_tc_send_cb +from pus_tc.procedure_packer import pre_tc_send_cb from pus_tm.factory_hook import ccsds_tm_handler from tmtcc import tmtcc_pre_args From 2b285417a0c8269aa7d7e554d6cfb2e691dd9421 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jul 2022 17:59:09 +0200 Subject: [PATCH 04/10] continued update to new API --- deps/tmtccmd | 2 +- pus_tc/devs/ccsds_handler.py | 101 ++-- pus_tc/devs/gps.py | 14 +- pus_tc/devs/ploc_memory_dumper.py | 26 +- pus_tc/devs/plpcdu.py | 102 ++-- pus_tc/devs/reaction_wheels.py | 26 +- pus_tc/devs/solar_array_deployment.py | 12 +- pus_tc/devs/star_tracker.py | 640 ++++++++++---------------- pus_tc/devs/str_img_helper.py | 26 +- pus_tc/devs/syrlinks_hk_handler.py | 159 +++---- pus_tc/procedure_packer.py | 59 +-- pus_tc/system/acs.py | 29 +- pus_tc/system/common.py | 13 +- pus_tc/system/controllers.py | 19 +- pus_tc/system/core.py | 68 ++- pus_tc/system/proc.py | 387 +++++++--------- pus_tc/system/tcs.py | 8 +- pus_tc/system/time.py | 12 +- tmtcc.py | 36 +- 19 files changed, 727 insertions(+), 1012 deletions(-) diff --git a/deps/tmtccmd b/deps/tmtccmd index e5d12ca..2890c62 160000 --- a/deps/tmtccmd +++ b/deps/tmtccmd @@ -1 +1 @@ -Subproject commit e5d12ca4c0da06338e575701972aaf4180b49635 +Subproject commit 2890c62e31999706ff1a7164b8a9f7cbc7bc34d5 diff --git a/pus_tc/devs/ccsds_handler.py b/pus_tc/devs/ccsds_handler.py index a7e400d..8b21825 100644 --- a/pus_tc/devs/ccsds_handler.py +++ b/pus_tc/devs/ccsds_handler.py @@ -7,9 +7,9 @@ """ import struct -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper +from tmtccmd.utility import ObjectId class CommandIds: @@ -32,84 +32,47 @@ class CommandIds: UPDATE_ON_FALLING_EDGE = 8 -def pack_ccsds_handler_test( - object_id: bytearray, tc_queue: TcQueueT, op_code: str -) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing CCSDS handler with object id: 0x" + object_id.hex(), - ) - ) +def pack_ccsds_handler_test(object_id: ObjectId, q: QueueHelper, op_code: str): + obyt = object_id.as_bytes + q.add_log_cmd(f"Testing CCSDS handler with object id: {object_id.as_hex_string}") if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "CCSDS Handler: Set low rate")) - command = object_id + struct.pack("!I", CommandIds.SET_LOW_RATE) - command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Set low rate") + command = obyt + struct.pack("!I", CommandIds.SET_LOW_RATE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "1": - tc_queue.appendleft((QueueCommands.PRINT, "CCSDS Handler: Set high rate")) - command = object_id + struct.pack("!I", CommandIds.SET_HIGH_RATE) - command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Set high rate") + command = obyt + struct.pack("!I", CommandIds.SET_HIGH_RATE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "2": - tc_queue.appendleft( - (QueueCommands.PRINT, "CCSDS Handler: Enables the transmitter") - ) - command = object_id + struct.pack("!I", CommandIds.EN_TRANSMITTER) - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Enables the transmitter") + command = obyt + struct.pack("!I", CommandIds.EN_TRANSMITTER) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "3": - tc_queue.appendleft( - (QueueCommands.PRINT, "CCSDS Handler: Disables the transmitter") - ) - command = object_id + struct.pack("!I", CommandIds.DIS_TRANSMITTER) - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Disables the transmitter") + command = obyt + struct.pack("!I", CommandIds.DIS_TRANSMITTER) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "4": - tc_queue.appendleft( - (QueueCommands.PRINT, "CCSDS Handler: Set arbitrary bitrate") - ) + q.add_log_cmd("CCSDS Handler: Set arbitrary bitrate") bitrate = int(input("Specify bit rate (bps): ")) command = ( - object_id + obyt + struct.pack("!I", CommandIds.ARBITRARY_BITRATE) + struct.pack("!I", bitrate) ) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "5": - tc_queue.appendleft( - (QueueCommands.PRINT, "CCSDS Handler: Enable tx clock manipulator") - ) - command = object_id + struct.pack("!I", CommandIds.ENABLE_TX_CLK_MANIPULATOR) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Enable tx clock manipulator") + command = obyt + struct.pack("!I", CommandIds.ENABLE_TX_CLK_MANIPULATOR) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "6": - tc_queue.appendleft( - (QueueCommands.PRINT, "CCSDS Handler: Disable tx clock manipulator") - ) - command = object_id + struct.pack("!I", CommandIds.DISABLE_TX_CLK_MANIPULATOR) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Disable tx clock manipulator") + command = obyt + struct.pack("!I", CommandIds.DISABLE_TX_CLK_MANIPULATOR) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "7": - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "CCSDS Handler: Update tx data on rising edge of tx clock", - ) - ) - command = object_id + struct.pack("!I", CommandIds.UPDATE_ON_RISING_EDGE) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("CCSDS Handler: Update tx data on rising edge of tx clock") + command = obyt + struct.pack("!I", CommandIds.UPDATE_ON_RISING_EDGE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "8": - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "CCSDS Handler: Update tx data on falling edge of tx clock", - ) - ) - command = object_id + struct.pack("!I", CommandIds.UPDATE_ON_FALLING_EDGE) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) - - return tc_queue + q.add_log_cmd("CCSDS Handler: Update tx data on falling edge of tx clock") + command = obyt + struct.pack("!I", CommandIds.UPDATE_ON_FALLING_EDGE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) diff --git a/pus_tc/devs/gps.py b/pus_tc/devs/gps.py index c7577fc..1cc39ed 100644 --- a/pus_tc/devs/gps.py +++ b/pus_tc/devs/gps.py @@ -1,12 +1,9 @@ import enum from config.definitions import CustomServiceList -from tmtccmd.config import add_op_code_entry, add_service_op_code_entry +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command -from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT from tmtccmd.logging import get_console_logger -from tmtccmd.tc.definitions import TcQueueT -from tmtccmd.tc.pus_8_funccmd import generate_action_command LOGGER = get_console_logger() @@ -42,13 +39,12 @@ def add_gps_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_gps_command(object_id: bytes, tc_queue: TcQueueT, op_code: str): +def pack_gps_command(object_id: bytes, q: QueueHelper, op_code: str): if op_code in OpCodes.RESET_GNSS: # TODO: This needs to be re-implemented LOGGER.warning("Reset pin handling needs to be re-implemented") if op_code in OpCodes.REQ_OS_HK: - tc_queue.appendleft((QueueCommands.PRINT, f"GMSS: {Info.REQ_OS_HK}")) - cmd = generate_one_hk_command( - sid=make_sid(object_id=object_id, set_id=SetIds.HK), ssc=0 + q.add_log_cmd(f"GMSS: {Info.REQ_OS_HK}") + q.add_pus_tc( + generate_one_hk_command(sid=make_sid(object_id=object_id, set_id=SetIds.HK)) ) - tc_queue.appendleft(cmd.pack_command_tuple()) diff --git a/pus_tc/devs/ploc_memory_dumper.py b/pus_tc/devs/ploc_memory_dumper.py index 36edc8e..85f27fa 100644 --- a/pus_tc/devs/ploc_memory_dumper.py +++ b/pus_tc/devs/ploc_memory_dumper.py @@ -8,36 +8,30 @@ """ import struct -from tmtccmd.config.definitions import QueueCommands - -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper +from tmtccmd.utility import ObjectId class ActionIds: DUMP_MRAM = 1 -def pack_ploc_memory_dumper_cmd(object_id: bytearray, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing PLOC memory dumper with object id: 0x" + object_id.hex(), - ) +def pack_ploc_memory_dumper_cmd(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd( + f"Testing PLOC memory dumper with object id: {object_id.as_hex_string}" ) if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "PLOC Supervisor: Dump MRAM")) - command = pack_mram_dump_cmd(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("PLOC Supervisor: Dump MRAM") + command = pack_mram_dump_cmd(object_id.as_bytes) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) -def pack_mram_dump_cmd(object_id: bytearray) -> bytearray: +def pack_mram_dump_cmd(object_id: bytes) -> bytearray: start = int(input("Start address: 0x"), 16) end = int(input("End address: 0x"), 16) - command = bytearray() command = object_id + struct.pack("!I", ActionIds.DUMP_MRAM) command = command + struct.pack("!I", start) command = command + struct.pack("!I", end) - return command + return bytearray(command) diff --git a/pus_tc/devs/plpcdu.py b/pus_tc/devs/plpcdu.py index 1009794..77462b3 100644 --- a/pus_tc/devs/plpcdu.py +++ b/pus_tc/devs/plpcdu.py @@ -11,6 +11,8 @@ from tmtccmd.config import ( add_service_op_code_entry, ) from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( generate_one_hk_command, make_sid, @@ -197,18 +199,14 @@ def add_pl_pcdu_cmds(cmd_dict: ServiceOpCodeDictT): ) -def pack_pl_pcdu_commands(tc_queue: TcQueueT, op_code: str): +def pack_pl_pcdu_commands(q: QueueHelper, op_code: str): if op_code in OpCodes.SWITCH_ON: - pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, info=Info.SWITCH_ON, mode=Modes.ON, submode=0 - ) + pack_pl_pcdu_mode_cmd(q=q, info=Info.SWITCH_ON, mode=Modes.ON, submode=0) if op_code in OpCodes.SWITCH_OFF: - pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, info=Info.SWITCH_OFF, mode=Modes.OFF, submode=0 - ) + pack_pl_pcdu_mode_cmd(q=q, info=Info.SWITCH_OFF, mode=Modes.OFF, submode=0) if op_code in OpCodes.NORMAL_SSR: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_SSR, mode=Modes.NORMAL, submode=submode_mask_to_submode( @@ -217,64 +215,63 @@ def pack_pl_pcdu_commands(tc_queue: TcQueueT, op_code: str): ) if op_code in OpCodes.NORMAL_DRO: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_DRO, mode=Modes.NORMAL, submode=submode_mask_to_submode(NormalSubmodesMask.DRO_ON), ) if op_code in OpCodes.NORMAL_X8: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_X8, mode=Modes.NORMAL, submode=submode_mask_to_submode(NormalSubmodesMask.X8_ON), ) if op_code in OpCodes.NORMAL_TX: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_TX, mode=Modes.NORMAL, submode=submode_mask_to_submode(NormalSubmodesMask.TX_ON), ) if op_code in OpCodes.NORMAL_MPA: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_MPA, mode=Modes.NORMAL, submode=submode_mask_to_submode(NormalSubmodesMask.MPA_ON), ) if op_code in OpCodes.NORMAL_HPA: pack_pl_pcdu_mode_cmd( - tc_queue=tc_queue, + q=q, info=Info.NORMAL_HPA, mode=Modes.NORMAL, submode=submode_mask_to_submode(NormalSubmodesMask.HPA_ON), ) if op_code in OpCodes.REQ_OS_HK: - tc_queue.appendleft((QueueCommands.PRINT, f"PL PCDU: {Info.REQ_OS_HK}")) - cmd = generate_one_diag_command( - sid=make_sid(object_id=PL_PCDU_ID, set_id=SetIds.ADC), ssc=0 + q.add_log_cmd(f"PL PCDU: {Info.REQ_OS_HK}") + q.add_pus_tc( + generate_one_diag_command( + sid=make_sid(object_id=PL_PCDU_ID, set_id=SetIds.ADC) + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.SWITCH_HPA_ON_PROC: - hpa_on_procedure(tc_queue) + hpa_on_procedure(q) if op_code in OpCodes.INJECT_ALL_ON_FAILURE: pack_failure_injection_cmd( - tc_queue=tc_queue, + q=q, param_id=ParamIds.INJECT_ALL_ON_FAILURE, print_str="All On", ) -def hpa_on_procedure(tc_queue: TcQueueT): +def hpa_on_procedure(q: QueueHelper): delay_dro_to_x8 = request_wait_time() if delay_dro_to_x8 is None: delay_dro_to_x8 = 900 - tc_queue.appendleft( - ( - QueueCommands.PRINT, - f"Starting procedure to switch on PL PCDU HPA with DRO to X8 delay of {delay_dro_to_x8} seconds", - ) + q.add_log_cmd( + f"Starting procedure to switch on PL PCDU HPA with DRO to X8 " + f"delay of {delay_dro_to_x8} seconds" ) pl_pcdu_on = PusTelecommand( service=200, @@ -339,54 +336,52 @@ def hpa_on_procedure(tc_queue: TcQueueT): ) current_time = time.time() - enb_sched = generate_enable_tc_sched_cmd(ssc=0) + enb_sched = generate_enable_tc_sched_cmd() sched_time = current_time + 10 - tc_queue.appendleft(enb_sched.pack_command_tuple()) + q.add_pus_tc(enb_sched) tagged_on_cmd = generate_time_tagged_cmd( release_time=struct.pack("!I", sched_time), tc_to_insert=pl_pcdu_on, - ssc=1, ) - tc_queue.appendleft(tagged_on_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_on_cmd) sched_time += 5 tagged_ssr_cmd = generate_time_tagged_cmd( release_time=struct.pack("!I", sched_time), tc_to_insert=ssr_on, - ssc=2, ) - tc_queue.appendleft(tagged_ssr_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_ssr_cmd) sched_time += 5 tagged_dro_cmd = generate_time_tagged_cmd( - release_time=struct.pack("!I", sched_time), tc_to_insert=dro_on, ssc=3 + release_time=struct.pack("!I", sched_time), tc_to_insert=dro_on ) - tc_queue.appendleft(tagged_dro_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_dro_cmd) sched_time += delay_dro_to_x8 tagged_x8_cmd = generate_time_tagged_cmd( - release_time=struct.pack("!I", sched_time), tc_to_insert=x8_on, ssc=4 + release_time=struct.pack("!I", sched_time), tc_to_insert=x8_on ) - tc_queue.appendleft(tagged_x8_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_x8_cmd) sched_time += 5 tagged_tx_cmd = generate_time_tagged_cmd( - release_time=struct.pack("!I", sched_time), tc_to_insert=tx_on, ssc=5 + release_time=struct.pack("!I", sched_time), tc_to_insert=tx_on ) - tc_queue.appendleft(tagged_tx_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_tx_cmd) sched_time += 5 tagged_mpa_cmd = generate_time_tagged_cmd( - release_time=struct.pack("!I", sched_time), tc_to_insert=mpa_on, ssc=6 + release_time=struct.pack("!I", sched_time), tc_to_insert=mpa_on ) - tc_queue.appendleft(tagged_mpa_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_mpa_cmd) sched_time += 5 tagged_hpa_cmd = generate_time_tagged_cmd( - release_time=struct.pack("!I", sched_time), tc_to_insert=hpa_on, ssc=7 + release_time=struct.pack("!I", sched_time), tc_to_insert=hpa_on ) - tc_queue.appendleft(tagged_hpa_cmd.pack_command_tuple()) + q.add_pus_tc(tagged_hpa_cmd) def request_wait_time() -> Optional[float]: @@ -457,28 +452,23 @@ def pack_wait_time_cmd(tc_queue: TcQueueT, param_id: int, print_str: str): unique_id=param_id, parameter=wait_time, ) - cmd = pack_fsfw_load_param_cmd(ssc=0, app_data=param_data) + cmd = pack_fsfw_load_param_cmd(app_data=param_data) tc_queue.appendleft(cmd.pack_command_tuple()) -def pack_failure_injection_cmd(tc_queue: TcQueueT, param_id: int, print_str: str): - tc_queue.appendleft((QueueCommands.PRINT, f"Inserting {print_str} error")) +def pack_failure_injection_cmd(q: QueueHelper, param_id: int, print_str: str): + q.add_log_cmd(f"Inserting {print_str} error") param_data = pack_boolean_parameter_app_data( object_id=PL_PCDU_ID, domain_id=0, unique_id=param_id, parameter=True ) - cmd = pack_fsfw_load_param_cmd(ssc=0, app_data=param_data) - tc_queue.appendleft(cmd.pack_command_tuple()) + q.add_pus_tc(pack_fsfw_load_param_cmd(app_data=param_data)) -def pack_pl_pcdu_mode_cmd(tc_queue: TcQueueT, info: str, mode: Modes, submode: int): - tc_queue.appendleft( - ( - QueueCommands.PRINT, - info, +def pack_pl_pcdu_mode_cmd(q: QueueHelper, info: str, mode: Modes, submode: int): + q.add_log_cmd(info) + mode_data = pack_mode_data(object_id=PL_PCDU_ID, mode=mode, submode=submode) + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=mode_data ) ) - mode_data = pack_mode_data(object_id=PL_PCDU_ID, mode=mode, submode=submode) - mode_cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=mode_data - ) - tc_queue.appendleft(mode_cmd.pack_command_tuple()) diff --git a/pus_tc/devs/reaction_wheels.py b/pus_tc/devs/reaction_wheels.py index 25cf89a..591b69f 100644 --- a/pus_tc/devs/reaction_wheels.py +++ b/pus_tc/devs/reaction_wheels.py @@ -130,7 +130,7 @@ def add_rw_cmds(cmd_dict: ServiceOpCodeDictT): def pack_single_rw_test_into( object_id: bytes, rw_idx: int, q: QueueHelper, op_code: str -) -> TcQueueT: +): if op_code in OpCodesDevs.SPEED: speed = int(input("Specify speed [0.1 RPM]: ")) ramp_time = int(input("Specify ramp time [ms]: ")) @@ -166,28 +166,30 @@ def pack_single_rw_test_into( sid=make_sid(object_id=object_id, set_id=RwSetIds.STATUS_SET_ID) ) ) - return q -def pack_rw_ass_cmds(tc_queue: TcQueueT, object_id: bytes, op_code: str): +def pack_rw_ass_cmds(q: QueueHelper, object_id: bytes, op_code: str): if op_code in OpCodesAss.OFF: data = pack_mode_data(object_id=object_id, mode=Modes.OFF, submode=0) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodesAss.ON: data = pack_mode_data(object_id=object_id, mode=Modes.ON, submode=0) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodesAss.NML: data = pack_mode_data(object_id=object_id, mode=Modes.NORMAL, submode=0) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) def pack_set_speed_command( diff --git a/pus_tc/devs/solar_array_deployment.py b/pus_tc/devs/solar_array_deployment.py index f6a9b69..111496f 100644 --- a/pus_tc/devs/solar_array_deployment.py +++ b/pus_tc/devs/solar_array_deployment.py @@ -5,18 +5,16 @@ @author J. Meier @date 15.02.2021 """ -from tmtccmd.config.definitions import QueueCommands -from tmtccmd.tc.definitions import TcQueueT -from tmtccmd.tc.packer import PusTelecommand +from spacepackets.ecss import PusTelecommand +from tmtccmd.tc import QueueHelper class ActionIds: DEPLOY_SOLAR_ARRAYS = bytearray([0x0, 0x0, 0x0, 0x5]) -def pack_solar_array_deployment_test_into(object_id: bytearray, tc_queue: TcQueueT): - tc_queue.appendleft((QueueCommands.PRINT, "Testing S/A Deployment")) +def pack_solar_array_deployment_test_into(object_id: bytearray, q: QueueHelper): + q.add_log_cmd("Testing S/A Deployment") command = object_id + ActionIds.DEPLOY_SOLAR_ARRAYS - command = PusTelecommand(service=8, subservice=128, ssc=200, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) diff --git a/pus_tc/devs/star_tracker.py b/pus_tc/devs/star_tracker.py index d8c9a94..9345b68 100644 --- a/pus_tc/devs/star_tracker.py +++ b/pus_tc/devs/star_tracker.py @@ -7,12 +7,12 @@ """ import struct -from tmtccmd.config.definitions import QueueCommands - -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes from tmtccmd.logging import get_console_logger + +from tmtccmd.tc import QueueHelper +from tmtccmd.utility import ObjectId from utility.input_helper import InputHelper @@ -150,623 +150,483 @@ class Submode: FIRMWARE = 2 -def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Generate command for star tracker with object id: 0x" + object_id.hex(), - ) +def pack_star_tracker_commands(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd( + f"Generate command for star tracker with object id: {object_id.as_hex_string}" ) - + obyt = object_id.as_bytes if op_code == "0": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Mode On, Submode Bootloader") - ) - command = pack_mode_data(object_id, Modes.ON, Submode.BOOTLOADER) - command = PusTelecommand(service=200, subservice=1, ssc=9, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Mode On, Submode Bootloader") + data = pack_mode_data(obyt, Modes.ON, Submode.BOOTLOADER) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "1": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Mode On, Submode Firmware") - ) - command = pack_mode_data(object_id, Modes.ON, Submode.FIRMWARE) - command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Mode On, Submode Firmware") + data = pack_mode_data(obyt, Modes.ON, Submode.FIRMWARE) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "2": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Normal")) - command = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Mode Normal") + data = pack_mode_data(obyt, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "3": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Off")) - command = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=12, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Mode Off") + data = pack_mode_data(obyt, Modes.OFF, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "4": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mode Raw")) - command = pack_mode_data(object_id, 3, 0) - command = PusTelecommand(service=200, subservice=1, ssc=13, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Mode Raw") + data = pack_mode_data(obyt, Modes.RAW, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "5": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Ping")) - command = object_id + struct.pack("!I", StarTrackerActionIds.PING) - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Ping") + data = obyt + struct.pack("!I", StarTrackerActionIds.PING) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "6": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Switch to bootloader program") - ) - command = object_id + struct.pack( + q.add_log_cmd("Star tracker: Switch to bootloader program") + data = obyt + struct.pack( "!I", StarTrackerActionIds.SWITCH_TO_BOOTLOADER_PROGRAM ) - command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "7": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Temperature request")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_TEMPERATURE) - command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Temperature request") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_TEMPERATURE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "8": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request version")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_VERSION) - command = PusTelecommand(service=8, subservice=128, ssc=33, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request version") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_VERSION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "9": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request interface")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_INTERFACE) - command = PusTelecommand(service=8, subservice=128, ssc=34, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request interface") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_INTERFACE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "10": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request power")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_POWER) - command = PusTelecommand(service=8, subservice=128, ssc=35, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request power") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_POWER) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "11": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set subscription parameters") - ) + q.add_log_cmd("Star tracker: Set subscription parameters") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.SUBSCRIPTION) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=36, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "12": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Boot")) - command = object_id + struct.pack("!I", StarTrackerActionIds.BOOT) - command = PusTelecommand(service=8, subservice=128, ssc=37, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Boot") + data = obyt + struct.pack("!I", StarTrackerActionIds.BOOT) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "13": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request time")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_TIME) - command = PusTelecommand(service=8, subservice=128, ssc=38, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request time") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_TIME) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "14": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request solution")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_SOLUTION) - command = PusTelecommand(service=8, subservice=128, ssc=39, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request solution") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_SOLUTION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "15": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Upload image")) + q.add_log_cmd("Star tracker: Upload image") image = get_upload_image() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.UPLOAD_IMAGE) + bytearray(image, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=40, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "16": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download image")) + q.add_log_cmd("Star tracker: Download image") path = input("Specify storage location (default - /mnt/sd0/startracker): ") if not path: path = FileDefs.download_path - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_IMAGE) + bytearray(path, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=53, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "17": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set limits")) + q.add_log_cmd("Star tracker: Set limits") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.LIMITS) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=42, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "18": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set tracking parameters") - ) + q.add_log_cmd("Star tracker: Set tracking parameters") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.TRACKING) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=43, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "19": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Mounting")) + q.add_log_cmd("Star tracker: Mounting") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.MOUNTING) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=44, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "20": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Camera")) + q.add_log_cmd("Star tracker: Camera") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CAMERA) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=45, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "22": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Centroiding")) + q.add_log_cmd("Star tracker: Centroiding") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CENTROIDING) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=47, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "23": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: LISA")) + q.add_log_cmd("Star tracker: LISA") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.LISA) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=48, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "24": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Matching")) + q.add_log_cmd("Star tracker: Matching") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.MATCHING) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=49, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "25": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Validation")) + q.add_log_cmd("Star tracker: Validation") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.VALIDATION) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=50, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "26": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Algo")) + q.add_log_cmd("Star tracker: Algo") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.ALGO) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=51, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "27": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Take image")) + q.add_log_cmd("Star tracker: Take image") actionid = int(input("Specify parameter ID (take image - 4): ")) - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.TAKE_IMAGE) + struct.pack("!B", actionid) ) - command = PusTelecommand(service=8, subservice=128, ssc=52, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "28": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Stop str helper")) - command = object_id + struct.pack("!I", StarTrackerActionIds.STOP_STR_HELPER) - command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Stop str helper") + data = obyt + struct.pack("!I", StarTrackerActionIds.STOP_STR_HELPER) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "30": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set name of download image") - ) + q.add_log_cmd("Star tracker: Set name of download image") filename = input("Specify download image name: ") - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CHANGE_DOWNLOAD_IMAGE) + bytearray(filename, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=54, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "31": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request histogram")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_HISTOGRAM) - command = PusTelecommand(service=8, subservice=128, ssc=55, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request histogram") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_HISTOGRAM) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "32": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request contrast")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_CONTRAST) - command = PusTelecommand(service=8, subservice=128, ssc=56, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request contrast") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_CONTRAST) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "33": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set json filename")) + q.add_log_cmd("Star tracker: Set json filename") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.SET_JSON_FILE_NAME) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=57, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "35": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Flash read")) - command = pack_read_command(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=59, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Flash read") + data = pack_read_command(obyt) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "36": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set flash read filename") - ) + q.add_log_cmd("Star tracker: Set flash read filename") filename = input("Specify filename: ") - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.SET_FLASH_READ_FILENAME) + bytearray(filename, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=60, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "37": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Get checksum")) - command = pack_checksum_command(object_id) - command = PusTelecommand(service=8, subservice=128, ssc=61, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Get checksum") + data = pack_checksum_command(obyt) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "38": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set time")) + q.add_log_cmd("Star tracker: Set time") unix_time = 1640783543 - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.SET_TIME) + struct.pack("!Q", unix_time) ) - command = PusTelecommand(service=8, subservice=128, ssc=61, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "39": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download Centroid")) + q.add_log_cmd("Star tracker: Download Centroid") id = 0 - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_CENTROID) + struct.pack("!B", id) ) - command = PusTelecommand(service=8, subservice=128, ssc=62, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "41": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Download matched star") - ) + q.add_log_cmd("Star tracker: Download matched star") id = 0 - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_MATCHED_STAR) + struct.pack("!B", id) ) - command = PusTelecommand(service=8, subservice=128, ssc=64, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "42": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download DB Image")) + q.add_log_cmd("Star tracker: Download DB Image") id = 0 - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_DBIMAGE) + struct.pack("!B", id) ) - command = PusTelecommand(service=8, subservice=128, ssc=65, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "43": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download Blob Pixel")) + q.add_log_cmd("Star tracker: Download Blob Pixel") id = 0 type = 1 # 0 - normal, 1 - fast - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_BLOBPIXEL) + struct.pack("!B", id) + struct.pack("!B", type) ) - command = PusTelecommand(service=8, subservice=128, ssc=65, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "44": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download FPGA Image")) + q.add_log_cmd("Star tracker: Download FPGA Image") position = int(input("Start position: ")) length = int(input("Size to download: ")) - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DOWNLOAD_FPGA_IMAGE) + struct.pack("!I", position) + struct.pack("!I", length) + bytearray(FileDefs.downloadFpgaImagePath, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=66, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "45": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Change donwload FPGA image file name") - ) - command = ( - object_id + q.add_log_cmd("Star tracker: Change donwload FPGA image file name") + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CHANGE_FPGA_DOWNLOAD_FILE) + bytearray(FileDefs.downloadFpgaImageName, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=67, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "46": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Upload FPGA image")) - command = ( - object_id + q.add_log_cmd("Star tracker: Upload FPGA image") + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.UPLOAD_FPGA_IMAGE) + bytearray(FileDefs.uploadFpgaImageName, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=68, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "47": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: FPGA action")) + q.add_log_cmd("Star tracker: FPGA action") id = 3 - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.FPGA_ACTION) + struct.pack("!B", id) ) - command = PusTelecommand(service=8, subservice=128, ssc=69, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "48": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Unlock")) - command = object_id + struct.pack("!I", StarTrackerActionIds.UNLOCK) - command = PusTelecommand(service=8, subservice=128, ssc=70, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Unlock") + data = obyt + struct.pack("!I", StarTrackerActionIds.UNLOCK) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "49": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request camera parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_CAMERA_PARAMS) - command = PusTelecommand(service=8, subservice=128, ssc=71, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request camera parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_CAMERA_PARAMS) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "50": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Request limits")) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_LIMITS) - command = PusTelecommand(service=8, subservice=128, ssc=72, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request limits") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_LIMITS) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "51": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set image processor parameters") - ) + q.add_log_cmd("Star tracker: Set image processor parameters") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.IMAGE_PROCESSOR) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=70, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "52": - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Star tracker: EGSE load ground config camera parameters", - ) - ) - command = ( - object_id + q.add_log_cmd("Star tracker: EGSE load ground config camera parameters") + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CAMERA) + bytearray(FileDefs.egse_ground_config, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=71, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "53": - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Star tracker: EGSE load flight config camera parameters", - ) - ) - command = ( - object_id + q.add_log_cmd("Star tracker: EGSE load flight config camera parameters") + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.CAMERA) + bytearray(FileDefs.egse_flight_config, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=72, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "54": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request log level parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_LOG_LEVEL) - command = PusTelecommand(service=8, subservice=128, ssc=74, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request log level parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_LOG_LEVEL) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "55": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request mounting parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_MOUNTING) - command = PusTelecommand(service=8, subservice=128, ssc=75, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request mounting parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_MOUNTING) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "56": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request image processor parameters") - ) - command = object_id + struct.pack( - "!I", StarTrackerActionIds.REQ_IMAGE_PROCESSOR - ) - command = PusTelecommand(service=8, subservice=128, ssc=76, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request image processor parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_IMAGE_PROCESSOR) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "57": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request centroiding parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_CENTROIDING) - command = PusTelecommand(service=8, subservice=128, ssc=75, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request centroiding parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_CENTROIDING) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "58": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request lisa parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_LISA) - command = PusTelecommand(service=8, subservice=128, ssc=76, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request lisa parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_LISA) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "59": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request matching parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_MATCHING) - command = PusTelecommand(service=8, subservice=128, ssc=77, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request matching parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_MATCHING) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "60": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request tracking parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_TRACKING) - command = PusTelecommand(service=8, subservice=128, ssc=78, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request tracking parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_TRACKING) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "61": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request validation parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_VALIDATION) - command = PusTelecommand(service=8, subservice=128, ssc=79, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request validation parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_VALIDATION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "62": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request algo parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_ALGO) - command = PusTelecommand(service=8, subservice=128, ssc=80, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request algo parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_ALGO) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "63": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request subscription parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_SUBSCRIPTION) - command = PusTelecommand(service=8, subservice=128, ssc=81, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request subscription parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_SUBSCRIPTION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "64": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request log subscription parameters") - ) - command = object_id + struct.pack( - "!I", StarTrackerActionIds.REQ_LOG_SUBSCRIPTION - ) - command = PusTelecommand(service=8, subservice=128, ssc=82, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request log subscription parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_LOG_SUBSCRIPTION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "65": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Request debug camera parameters") - ) - command = object_id + struct.pack("!I", StarTrackerActionIds.REQ_DEBUG_CAMERA) - command = PusTelecommand(service=8, subservice=128, ssc=83, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Star tracker: Request debug camera parameters") + data = obyt + struct.pack("!I", StarTrackerActionIds.REQ_DEBUG_CAMERA) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "66": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set log level parameters") - ) + q.add_log_cmd("Star tracker: Set log level parameters") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.LOGLEVEL) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=84, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "67": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set log subscription parameters") - ) + q.add_log_cmd("Star tracker: Set log subscription parameters") + json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.LOG_SUBSCRIPTION) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=85, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "68": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Set debug camera parameters") - ) + q.add_log_cmd("Star tracker: Set debug camera parameters") json_file = get_config_file() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.DEBUG_CAMERA) + bytearray(json_file, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=86, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "69": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Firmware update")) + q.add_log_cmd("Star tracker: Firmware update") firmware = get_firmware() - command = ( - object_id + data = ( + obyt + struct.pack("!I", StarTrackerActionIds.FIRMWARE_UPDATE) + bytearray(firmware, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=87, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "70": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Disable timestamp generation") - ) - command = object_id + struct.pack( + q.add_log_cmd("Star tracker: Disable timestamp generation") + command = obyt + struct.pack( "!I", StarTrackerActionIds.DISBALE_TIMESTAMP_GENERATION ) - command = PusTelecommand(service=8, subservice=128, ssc=88, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "71": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker: Enable timestamp generation") - ) - command = object_id + struct.pack( + q.add_log_cmd("Star tracker: Enable timestamp generation") + command = obyt + struct.pack( "!I", StarTrackerActionIds.ENABLE_TIMESTAMP_GENERATION ) - command = PusTelecommand(service=8, subservice=128, ssc=89, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) -def pack_read_command(object_id: bytearray) -> bytearray: +def pack_read_command(object_id: bytes) -> bytearray: start_region = StartRegion.STAR_TRACKER_FIRMWARE size = PartitionSize.STAR_TRACKER_FIRMWARE path = input("Specify storage location (default - /mnt/sd0/startracker): ") if not path: path = FileDefs.download_path - command = ( + data = ( object_id + struct.pack("!I", StarTrackerActionIds.FLASH_READ) + struct.pack("!B", start_region) + struct.pack("!I", size) + bytearray(path, "utf-8") ) - return command + return bytearray(data) -def pack_checksum_command(object_id: bytearray) -> bytearray: +def pack_checksum_command(object_id: bytes) -> bytearray: start_region = StartRegion.STAR_TRACKER_FIRMWARE address = 0 size = PartitionSize.STAR_TRACKER_FIRMWARE - command = ( + data = ( object_id + struct.pack("!I", StarTrackerActionIds.CHECKSUM) + struct.pack("!B", start_region) + struct.pack("!I", address) + struct.pack("!I", size) ) - return command + return bytearray(data) def get_config_file() -> str: diff --git a/pus_tc/devs/str_img_helper.py b/pus_tc/devs/str_img_helper.py index 35c3ff4..266011b 100644 --- a/pus_tc/devs/str_img_helper.py +++ b/pus_tc/devs/str_img_helper.py @@ -10,10 +10,9 @@ """ import struct -from tmtccmd.config.definitions import QueueCommands - -from tmtccmd.tc.packer import TcQueueT from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper +from tmtccmd.utility import ObjectId class Commands: @@ -25,24 +24,15 @@ class ImagePathDefs: uploadFile = "/mnt/sd0/startracker/gemma.bin" -def pack_str_img_helper_command( - object_id: bytearray, tc_queue: TcQueueT, op_code: str -) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing star tracker image helper object id: 0x" + object_id.hex(), - ) +def pack_str_img_helper_command(object_id: ObjectId, q: QueueHelper, op_code: str): + q.add_log_cmd( + f"Testing star tracker image helper object id: {object_id.as_hex_string}" ) - if op_code == "0": - tc_queue.appendleft( - (QueueCommands.PRINT, "Star tracker image helper: Upload image") - ) + q.add_log_cmd("Star tracker image helper: Upload image") command = ( - object_id + object_id.as_bytes + struct.pack("!I", Commands.UPLOAD_IMAGE) + bytearray(ImagePathDefs.uploadFile, "utf-8") ) - command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) diff --git a/pus_tc/devs/syrlinks_hk_handler.py b/pus_tc/devs/syrlinks_hk_handler.py index 48adbcd..6e919b6 100644 --- a/pus_tc/devs/syrlinks_hk_handler.py +++ b/pus_tc/devs/syrlinks_hk_handler.py @@ -8,11 +8,15 @@ from tmtccmd.config.definitions import QueueCommands from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command from spacepackets.ecss.tc import PusTelecommand from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes import struct +from tmtccmd.utility import ObjectId + class SetIds: RX_REGISTERS_DATASET = 1 @@ -38,116 +42,87 @@ class CommandIds: def pack_syrlinks_command( - object_id: bytearray, tc_queue: TcQueueT, op_code: str + object_id: ObjectId, q: QueueHelper, op_code: str ) -> TcQueueT: - tc_queue.appendleft( - ( - QueueCommands.PRINT, - "Testing Syrlinks with object id: 0x" + object_id.hex(), - ) - ) - + obyt = object_id.as_bytes + q.add_log_cmd(f"Testing Syrlinks with object id: {object_id.as_hex_string}") if op_code == "0": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Set mode off")) - command = pack_mode_data(object_id, Modes.OFF, 0) - command = PusTelecommand(service=200, subservice=1, ssc=9, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Set mode off") + data = pack_mode_data(obyt, Modes.OFF, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "1": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Set mode on")) - command = pack_mode_data(object_id, Modes.ON, 0) - command = PusTelecommand(service=200, subservice=1, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Set mode on") + data = pack_mode_data(obyt, Modes.ON, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "2": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Mode Normal")) - command = pack_mode_data(object_id, Modes.NORMAL, 0) - command = PusTelecommand(service=200, subservice=1, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Mode Normal") + data = pack_mode_data(obyt, Modes.NORMAL, 0) + q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data)) if op_code == "3": - tc_queue.appendleft((QueueCommands.PRINT, "syrlinks: Set TX mode standby")) - command = object_id + struct.pack("!I", CommandIds.SET_TX_MODE_STANDBY) - command = PusTelecommand(service=8, subservice=128, ssc=10, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("syrlinks: Set TX mode standby") + data = obyt + struct.pack("!I", CommandIds.SET_TX_MODE_STANDBY) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "4": - tc_queue.appendleft((QueueCommands.PRINT, "syrlinks: Set TX mode modulation")) - command = object_id + struct.pack("!I", CommandIds.SET_TX_MODE_MODULATION) - command = PusTelecommand(service=8, subservice=128, ssc=11, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("syrlinks: Set TX mode modulation") + data = obyt + struct.pack("!I", CommandIds.SET_TX_MODE_MODULATION) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "5": - tc_queue.appendleft((QueueCommands.PRINT, "syrlinks: Set TX mode CW")) - command = object_id + struct.pack("!I", CommandIds.SET_TX_MODE_CW) - command = PusTelecommand(service=8, subservice=128, ssc=12, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("syrlinks: Set TX mode CW") + data = obyt + struct.pack("!I", CommandIds.SET_TX_MODE_CW) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data)) if op_code == "6": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Get RX Registers")) - sid = make_sid(object_id, SetIds.RX_REGISTERS_DATASET) - command = generate_one_hk_command(sid, 200) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Get RX Registers") + sid = make_sid(obyt, SetIds.RX_REGISTERS_DATASET) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "7": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Get TX Registers")) - sid = make_sid(object_id, SetIds.TX_REGISTERS_DATASET) - command = generate_one_hk_command(sid, 201) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Get TX Registers") + sid = make_sid(obyt, SetIds.TX_REGISTERS_DATASET) + q.add_pus_tc(generate_one_hk_command(sid)) if op_code == "8": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Read TX status")) - command = object_id + struct.pack("!I", CommandIds.READ_TX_STATUS) - command = PusTelecommand(service=8, subservice=128, ssc=13, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read TX status") + command = obyt + struct.pack("!I", CommandIds.READ_TX_STATUS) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "9": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Read TX waveform")) - command = object_id + struct.pack("!I", CommandIds.READ_TX_WAVEFORM) - command = PusTelecommand(service=8, subservice=128, ssc=14, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read TX waveform") + command = obyt + struct.pack("!I", CommandIds.READ_TX_WAVEFORM) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "10": - tc_queue.appendleft( - (QueueCommands.PRINT, "Syrlinks: Read TX AGC value high byte") - ) - command = object_id + struct.pack("!I", CommandIds.READ_TX_AGC_VALUE_HIGH_BYTE) - command = PusTelecommand(service=8, subservice=128, ssc=15, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read TX AGC value high byte") + command = obyt + struct.pack("!I", CommandIds.READ_TX_AGC_VALUE_HIGH_BYTE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "11": - tc_queue.appendleft( - (QueueCommands.PRINT, "Syrlinks: Read TX AGC value low byte") - ) - command = object_id + struct.pack("!I", CommandIds.READ_TX_AGC_VALUE_LOW_BYTE) - command = PusTelecommand(service=8, subservice=128, ssc=16, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read TX AGC value low byte") + command = obyt + struct.pack("!I", CommandIds.READ_TX_AGC_VALUE_LOW_BYTE) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "12": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Write LCL config")) - command = object_id + struct.pack("!I", CommandIds.WRITE_LCL_CONFIG) - command = PusTelecommand(service=8, subservice=128, ssc=17, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Write LCL config") + command = obyt + struct.pack("!I", CommandIds.WRITE_LCL_CONFIG) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "13": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Read RX status registers")) - command = object_id + struct.pack("!I", CommandIds.READ_RX_STATUS_REGISTERS) - command = PusTelecommand(service=8, subservice=128, ssc=18, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read RX status registers") + command = obyt + struct.pack("!I", CommandIds.READ_RX_STATUS_REGISTERS) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "14": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Read LCL config register")) - command = object_id + struct.pack("!I", CommandIds.READ_LCL_CONFIG_REGISTER) - command = PusTelecommand(service=8, subservice=128, ssc=19, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Read LCL config register") + command = obyt + struct.pack("!I", CommandIds.READ_LCL_CONFIG_REGISTER) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "15": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Set waveform OQPSK")) - command = object_id + struct.pack("!I", CommandIds.SET_WAVEFORM_OQPSK) - command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Set waveform OQPSK") + command = obyt + struct.pack("!I", CommandIds.SET_WAVEFORM_OQPSK) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "16": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Set waveform BPSK")) - command = object_id + struct.pack("!I", CommandIds.SET_WAVEFORM_BPSK) - command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Set waveform BPSK") + command = obyt + struct.pack("!I", CommandIds.SET_WAVEFORM_BPSK) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "17": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Set second config")) - command = object_id + struct.pack("!I", CommandIds.SET_SECOND_CONFIG) - command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Set second config") + command = obyt + struct.pack("!I", CommandIds.SET_SECOND_CONFIG) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "18": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Enable debug printout")) - command = object_id + struct.pack("!I", CommandIds.ENABLE_DEBUG) - command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Enable debug printout") + command = obyt + struct.pack("!I", CommandIds.ENABLE_DEBUG) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) if op_code == "19": - tc_queue.appendleft((QueueCommands.PRINT, "Syrlinks: Disable debug printout")) - command = object_id + struct.pack("!I", CommandIds.DISABLE_DEBUG) - command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd("Syrlinks: Disable debug printout") + command = obyt + struct.pack("!I", CommandIds.DISABLE_DEBUG) + q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) diff --git a/pus_tc/procedure_packer.py b/pus_tc/procedure_packer.py index 35a8d5a..6c7c8e9 100644 --- a/pus_tc/procedure_packer.py +++ b/pus_tc/procedure_packer.py @@ -1,8 +1,6 @@ """Hook function which packs telecommands based on service and operation code string """ import logging -import os -from collections import deque from typing import Union from pus_tc.devs.rtd import pack_rtd_commands @@ -12,7 +10,6 @@ from tmtccmd.config import CoreServiceList from tmtccmd.logging import get_console_logger from tmtccmd.tc import FeedWrapper from tmtccmd.tc.pus_5_event import ( - pack_generic_service5_test_into, pack_generic_service_5_test_into, ) from tmtccmd.pus.pus_17_test import pack_service_17_ping_command @@ -44,10 +41,8 @@ from pus_tc.devs.plpcdu import pack_pl_pcdu_commands from pus_tc.devs.str_img_helper import pack_str_img_helper_command from pus_tc.system.tcs import pack_tcs_sys_commands from pus_tc.system.proc import pack_proc_commands -from pus_tc.system.controllers import pack_cmd_ctrl_to_prompted_mode from config.definitions import CustomServiceList from config.object_ids import ( - get_object_ids, P60_DOCK_HANDLER, PDU_1_HANDLER_ID, PDU_2_HANDLER_ID, @@ -65,7 +60,6 @@ from config.object_ids import ( PLOC_SUPV_ID, STAR_TRACKER_ID, PLOC_MEMORY_DUMPER_ID, - GPS_CONTROLLER, CCSDS_HANDLER_ID, PDEC_HANDLER_ID, STR_IMG_HELPER_ID, @@ -156,60 +150,56 @@ def handle_default_procedure(info: DefaultProcedureInfo, wrapper: FeedWrapper): if service == CustomServiceList.STAR_TRACKER.value: object_id = STAR_TRACKER_ID return pack_star_tracker_commands( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.STR_IMG_HELPER.value: object_id = STR_IMG_HELPER_ID return pack_str_img_helper_command( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.CORE.value: - return pack_core_commands(tc_queue=service_queue, op_code=op_code) + return pack_core_commands(q=queue_helper, op_code=op_code) if service == CustomServiceList.PLOC_MEMORY_DUMPER.value: object_id = PLOC_MEMORY_DUMPER_ID return pack_ploc_memory_dumper_cmd( - object_id=object_id, tc_queue=service_queue, op_code=op_code + object_id=object_id, q=queue_helper, op_code=op_code ) if service == CustomServiceList.ACS.value: - return pack_acs_command(tc_queue=service_queue, op_code=op_code) + return pack_acs_command(q=queue_helper, op_code=op_code) if service == CustomServiceList.GPS_CTRL.value: return pack_gps_command( - object_id=oids.GPS_CONTROLLER, tc_queue=service_queue, op_code=op_code + object_id=oids.GPS_CONTROLLER, q=queue_helper, op_code=op_code ) if service == CustomServiceList.CCSDS_HANDLER.value: return pack_ccsds_handler_test( - object_id=CCSDS_HANDLER_ID, tc_queue=service_queue, op_code=op_code + object_id=CCSDS_HANDLER_ID, q=queue_helper, op_code=op_code ) if service == CustomServiceList.PDEC_HANDLER.value: return pack_ccsds_handler_test( - object_id=PDEC_HANDLER_ID, tc_queue=service_queue, op_code=op_code + object_id=PDEC_HANDLER_ID, q=queue_helper, op_code=op_code ) if service == CustomServiceList.SYRLINKS.value: return pack_syrlinks_command( - object_id=SYRLINKS_HANDLER_ID, tc_queue=service_queue, op_code=op_code + object_id=SYRLINKS_HANDLER_ID, q=queue_helper, 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 + object_id=SOLAR_ARRAY_DEPLOYMENT_ID, q=queue_helper ) if service == CustomServiceList.PROCEDURE.value: - return pack_proc_commands(tc_queue=service_queue, op_code=op_code) + return pack_proc_commands(q=queue_helper, op_code=op_code) if service == CustomServiceList.SUS_ASS.value: - return pack_sus_cmds(tc_queue=service_queue, op_code=op_code) + return pack_sus_cmds(q=queue_helper, op_code=op_code) if service == CustomServiceList.PL_PCDU.value: - return pack_pl_pcdu_commands(tc_queue=service_queue, op_code=op_code) + return pack_pl_pcdu_commands(q=queue_helper, op_code=op_code) if service == CustomServiceList.ACS_ASS.value: - return pack_acs_command(tc_queue=service_queue, op_code=op_code) + return pack_acs_command(q=queue_helper, op_code=op_code) if service == CustomServiceList.TCS_ASS.value: - return pack_tcs_sys_commands(tc_queue=service_queue, op_code=op_code) + return pack_tcs_sys_commands(q=queue_helper, op_code=op_code) if service == CustomServiceList.TIME.value: - return pack_set_current_time_ascii_command(tc_queue=service_queue, ssc=0) + return pack_set_current_time_ascii_command(q=queue_helper) if service == CustomServiceList.RW_ASSEMBLY.value: - 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) + return pack_rw_ass_cmds(q=queue_helper, object_id=RW_ASSEMBLY, op_code=op_code) LOGGER.warning(f"Invalid Service {service}") @@ -231,18 +221,3 @@ def pre_tc_send_cb( elif isinstance(queue_entry, QueueCommands): if queue_entry == QueueCommands.PRINT: file_logger.info(queue_info) - - -def pack_service_queue_user( - service: Union[str, int], op_code: str, service_queue: TcQueueT -): - pass - - -def create_total_tc_queue_user() -> TcQueueT: - if not os.path.exists("log"): - os.mkdir("log") - tc_queue = deque() - pack_generic_service5_test_into(tc_queue) - tc_queue.appendleft(pack_service_17_ping_command(ssc=1700).pack_command_tuple()) - return tc_queue diff --git a/pus_tc/system/acs.py b/pus_tc/system/acs.py index 76b3dcc..f995f67 100644 --- a/pus_tc/system/acs.py +++ b/pus_tc/system/acs.py @@ -1,5 +1,6 @@ import enum -from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import Modes from config.object_ids import ACS_BOARD_ASS_ID, SUS_BOARD_ASS_ID @@ -29,13 +30,13 @@ class DualSideSubmodes(enum.IntEnum): DUAL_SIDE = 2 -def pack_acs_command(tc_queue: TcQueueT, op_code: str): +def pack_acs_command(q: QueueHelper, op_code: str): if op_code in AcsOpCodes.ACS_ASS_A_SIDE: command_mode( object_id=ACS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.A_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to ACS board assembly A side", ) if op_code in AcsOpCodes.ACS_ASS_B_SIDE: @@ -43,7 +44,7 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.B_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to ACS board assembly B side", ) if op_code in AcsOpCodes.ACS_ASS_DUAL_MODE: @@ -51,7 +52,7 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.DUAL_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to ACS board assembly dual mode", ) if op_code in AcsOpCodes.ACS_ASS_A_ON: @@ -59,7 +60,7 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.ON, submode=DualSideSubmodes.A_SIDE, - tc_queue=tc_queue, + q=q, info="Switching ACS board assembly A side on", ) if op_code in AcsOpCodes.ACS_ASS_B_ON: @@ -67,7 +68,7 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.ON, submode=DualSideSubmodes.B_SIDE, - tc_queue=tc_queue, + q=q, info="Switching ACS board assembly B side on", ) if op_code in AcsOpCodes.ACS_ASS_DUAL_ON: @@ -75,7 +76,7 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.ON, submode=DualSideSubmodes.B_SIDE, - tc_queue=tc_queue, + q=q, info="Switching ACS board assembly dual side on", ) if op_code in AcsOpCodes.ACS_ASS_OFF: @@ -83,18 +84,18 @@ def pack_acs_command(tc_queue: TcQueueT, op_code: str): object_id=ACS_BOARD_ASS_ID, mode=Modes.OFF, submode=0, - tc_queue=tc_queue, + q=q, info="Switching to ACS board assembly off", ) -def pack_sus_cmds(tc_queue: TcQueueT, op_code: str): +def pack_sus_cmds(q: QueueHelper, op_code: str): if op_code in SusOpCodes.SUS_ASS_NOM_SIDE: command_mode( object_id=SUS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.A_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to SUS board to nominal side", ) if op_code in SusOpCodes.SUS_ASS_RED_SIDE: @@ -102,7 +103,7 @@ def pack_sus_cmds(tc_queue: TcQueueT, op_code: str): object_id=SUS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.B_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to SUS board to redundant side", ) if op_code in SusOpCodes.SUS_ASS_OFF: @@ -110,7 +111,7 @@ def pack_sus_cmds(tc_queue: TcQueueT, op_code: str): object_id=SUS_BOARD_ASS_ID, mode=Modes.OFF, submode=0, - tc_queue=tc_queue, + q=q, info="Switching SUS board off", ) if op_code in SusOpCodes.SUS_ASS_DUAL_MODE: @@ -118,6 +119,6 @@ def pack_sus_cmds(tc_queue: TcQueueT, op_code: str): object_id=SUS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=DualSideSubmodes.DUAL_SIDE, - tc_queue=tc_queue, + q=q, info="Switching to SUS board to dual side", ) diff --git a/pus_tc/system/common.py b/pus_tc/system/common.py index f6fc397..aecbb5f 100644 --- a/pus_tc/system/common.py +++ b/pus_tc/system/common.py @@ -1,7 +1,7 @@ from typing import Union -from tmtccmd.tc.definitions import TcQueueT, QueueCommands from spacepackets.ecss.tc import PusTelecommand +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import pack_mode_data, Modes, Subservices @@ -9,16 +9,17 @@ def command_mode( object_id: bytes, mode: Union[int, Modes], submode: int, - tc_queue: TcQueueT, + q: QueueHelper, info: str, ): - tc_queue.appendleft((QueueCommands.PRINT, info)) + q.add_log_cmd(info) mode_data = pack_mode_data( object_id=object_id, mode=mode, submode=submode, ) - cmd = PusTelecommand( - service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=mode_data + q.add_pus_tc( + PusTelecommand( + service=200, subservice=Subservices.TC_MODE_COMMAND, app_data=mode_data + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) diff --git a/pus_tc/system/controllers.py b/pus_tc/system/controllers.py index 2f072cd..eaf3854 100644 --- a/pus_tc/system/controllers.py +++ b/pus_tc/system/controllers.py @@ -1,5 +1,4 @@ -from tmtccmd.tc.definitions import TcQueueT -from tmtccmd.config import QueueCommands +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import Modes from tmtccmd.utility import ObjectId @@ -19,7 +18,7 @@ class Info: CORE_CONTROLLER = "ACS controller" -def pack_cmd_ctrl_to_prompted_mode(tc_queue: TcQueueT, object_id: ObjectId): +def pack_cmd_ctrl_to_prompted_mode(q: QueueHelper, object_id: ObjectId): parameters = prompt_parameters( [ {"name": "Mode", "defaultValue": "2"}, @@ -35,37 +34,37 @@ def pack_cmd_ctrl_to_prompted_mode(tc_queue: TcQueueT, object_id: ObjectId): object_id=object_id.as_bytes, mode=mode, submode=submode, - tc_queue=tc_queue, + q=q, info=f"Commanding {object_id} to {mode}, {submode}", ) -def pack_cmd_ctrl_to_off(tc_queue: TcQueueT, object_id: ObjectId): +def pack_cmd_ctrl_to_off(q: QueueHelper, object_id: ObjectId): command_mode( object_id=object_id.as_bytes, mode=Modes.OFF, submode=0, - tc_queue=tc_queue, + q=q, info=f"Commanding {object_id} OFF", ) -def pack_cmd_ctrl_to_on(tc_queue: TcQueueT, object_id: ObjectId): +def pack_cmd_ctrl_to_on(q: QueueHelper, object_id: ObjectId): command_mode( object_id=object_id.as_bytes, mode=Modes.ON, submode=0, - tc_queue=tc_queue, + q=q, info=f"Commanding {object_id} ON", ) -def pack_cmd_ctrl_to_nml(tc_queue: TcQueueT, object_id: ObjectId): +def pack_cmd_ctrl_to_nml(q: QueueHelper, object_id: ObjectId): command_mode( object_id=object_id.as_bytes, mode=Modes.NORMAL, submode=0, - tc_queue=tc_queue, + q=q, info=f"Commanding {object_id} NORMAL", ) diff --git a/pus_tc/system/core.py b/pus_tc/system/core.py index f44ad87..01ecca5 100644 --- a/pus_tc/system/core.py +++ b/pus_tc/system/core.py @@ -4,6 +4,8 @@ from config.definitions import CustomServiceList from tmtccmd.config import add_op_code_entry, add_service_op_code_entry from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_8_funccmd import generate_action_command from tmtccmd.logging import get_console_logger from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command @@ -122,47 +124,48 @@ def add_core_controller_definitions(cmd_dict: ServiceOpCodeDictT): ) -def pack_core_commands(tc_queue: TcQueueT, op_code: str): +def pack_core_commands(q: QueueHelper, op_code: str): if op_code in OpCodes.REBOOT_XSC: reboot_self, chip_select, copy_select = determine_reboot_params() perform_reboot_cmd( - tc_queue=tc_queue, + q=q, reboot_self=reboot_self, chip=chip_select, copy=copy_select, ) if op_code in OpCodes.REBOOT_FULL: - tc_queue.appendleft((QueueCommands.PRINT, f"Core Command: {Info.REBOOT_FULL}")) - cmd = generate_action_command( - object_id=CORE_CONTROLLER_ID, action_id=ActionIds.FULL_REBOOT + q.add_log_cmd(f"Core Command: {Info.REBOOT_FULL}") + q.add_pus_tc( + generate_action_command( + object_id=CORE_CONTROLLER_ID, action_id=ActionIds.FULL_REBOOT + ) ) - tc_queue.appendleft(cmd.pack_command_tuple()) if op_code in OpCodes.XSC_REBOOT_SELF: - perform_reboot_cmd(tc_queue=tc_queue, reboot_self=True) + perform_reboot_cmd(q=q, reboot_self=True) if op_code in OpCodes.XSC_REBOOT_0_0: perform_reboot_cmd( - tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_0_NOM + q=q, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_0_NOM ) if op_code in OpCodes.XSC_REBOOT_0_1: perform_reboot_cmd( - tc_queue=tc_queue, + q=q, reboot_self=False, chip=Chip.CHIP_0, copy=Copy.COPY_1_GOLD, ) if op_code in OpCodes.XSC_REBOOT_1_0: perform_reboot_cmd( - tc_queue=tc_queue, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_0_NOM + q=q, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_0_NOM ) if op_code in OpCodes.XSC_REBOOT_1_1: perform_reboot_cmd( - tc_queue=tc_queue, + q=q, reboot_self=False, chip=Chip.CHIP_1, copy=Copy.COPY_1_GOLD, ) if op_code in OpCodes.DISABLE_REBOOT_FILE_HANDLING: - tc_queue.appendleft((QueueCommands.PRINT, "Disabling reboot file handling")) + q.add_log_cmd("Disabling reboot file handling") app_data = bytearray([0]) generate_action_command( object_id=CORE_CONTROLLER_ID, @@ -170,7 +173,7 @@ def pack_core_commands(tc_queue: TcQueueT, op_code: str): app_data=app_data, ) if op_code in OpCodes.ENABLE_REBOOT_FILE_HANDLING: - tc_queue.appendleft((QueueCommands.PRINT, "Enabling reboot file handling")) + q.add_log_cmd("Enabling reboot file handling") app_data = bytearray([1]) generate_action_command( object_id=CORE_CONTROLLER_ID, @@ -178,35 +181,34 @@ def pack_core_commands(tc_queue: TcQueueT, op_code: str): app_data=app_data, ) if op_code in OpCodes.RESET_ALL_REBOOT_COUNTERS: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting all reboot counters")) + q.add_log_cmd("Resetting all reboot counters") generate_action_command( object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_ALL_REBOOT_COUNTERS ) if op_code in OpCodes.RESET_REBOOT_COUNTER_00: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 0 0")) + q.add_log_cmd("Resetting reboot counter 0 0") generate_action_command( object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_00 ) if op_code in OpCodes.RESET_REBOOT_COUNTER_01: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 0 1")) + q.add_log_cmd("Resetting reboot counter 0 1") generate_action_command( object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_01 ) if op_code in OpCodes.RESET_REBOOT_COUNTER_10: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 1 0")) + q.add_log_cmd("Resetting reboot counter 1 0") generate_action_command( object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_10 ) if op_code in OpCodes.RESET_REBOOT_COUNTER_11: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting reboot counter 1 1")) + q.add_log_cmd("Resetting reboot counter 1 1") generate_action_command( object_id=CORE_CONTROLLER_ID, action_id=ActionIds.RESET_REBOOT_COUNTER_11 ) if op_code in OpCodes.GET_HK: - tc_queue.appendleft((QueueCommands.PRINT, "Requesting housekeeping set")) + q.add_log_cmd("Requesting housekeeping set") sid = make_sid(object_id=CORE_CONTROLLER_ID, set_id=SetIds.HK) - command = generate_one_hk_command(sid, 201) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_pus_tc(generate_one_hk_command(sid)) def determine_reboot_params() -> (bool, Chip, Copy): @@ -241,31 +243,25 @@ def determine_reboot_params() -> (bool, Chip, Copy): def perform_reboot_cmd( - tc_queue: TcQueueT, + q: QueueHelper, reboot_self: bool, chip: Chip = Chip.NONE, copy: Copy = Copy.NONE, ): tc_data = bytearray() if reboot_self: - tc_queue.appendleft( - (QueueCommands.PRINT, "Packing reboot command for current image") - ) + q.add_log_cmd("Packing reboot command for current image") tc_data.append(True) else: tc_data.append(False) tc_data.append(chip) tc_data.append(copy) - tc_queue.append( - ( - QueueCommands.PRINT, - f"Packing reboot command for chip {chip} and copy {copy}", - ) + q.add_log_cmd(f"Packing reboot command for chip {chip} and copy {copy}") + q.add_pus_tc( + generate_action_command( + object_id=CORE_CONTROLLER_ID, + action_id=ActionIds.XSC_REBOOT, + app_data=tc_data, + ssc=0, ) - action_cmd = generate_action_command( - object_id=CORE_CONTROLLER_ID, - action_id=ActionIds.XSC_REBOOT, - app_data=tc_data, - ssc=0, ) - tc_queue.appendleft(action_cmd.pack_command_tuple()) diff --git a/pus_tc/system/proc.py b/pus_tc/system/proc.py index f22c481..84e0209 100644 --- a/pus_tc/system/proc.py +++ b/pus_tc/system/proc.py @@ -1,19 +1,14 @@ from __future__ import annotations -import struct import time +from datetime import timedelta from typing import List from config.definitions import CustomServiceList from config.object_ids import get_object_ids from pus_tc.system.tcs import pack_tcs_sys_commands -from tmtccmd.config import ( - QueueCommands, - ServiceOpCodeDictT, - add_op_code_entry, - add_service_op_code_entry, -) -from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_11_tc_sched import ( generate_time_tagged_cmd, generate_enable_tc_sched_cmd, @@ -126,10 +121,8 @@ class GenericHkListeningCfg: return GenericHkListeningCfg(False, False, False) -def generic_print(tc_queue: TcQueueT, info: dict): - tc_queue.appendleft( - (QueueCommands.PRINT, f"Executing {info[1]} Procedure (OpCodes: {info[0]})") - ) +def generic_print(q: QueueHelper, info: dict): + q.add_log_cmd(f"Executing {info[1]} Procedure (OpCodes: {info[0]})") def add_proc_cmds(cmd_dict: ServiceOpCodeDictT): @@ -147,7 +140,7 @@ def add_proc_cmds(cmd_dict: ServiceOpCodeDictT): def pack_generic_hk_listening_cmds( - tc_queue: TcQueueT, + q: QueueHelper, proc_key: str, sid_list: list[bytearray], diag_list: list[bool], @@ -155,83 +148,77 @@ def pack_generic_hk_listening_cmds( ): info = PROC_INFO_DICT[proc_key] collection_time = info[2] - generic_print(tc_queue=tc_queue, info=info) + generic_print(q=q, info=info) for i in range(len(sid_list)): enable_listen_to_hk_for_x_seconds( diag=diag_list[i], - tc_queue=tc_queue, + q=q, device=proc_key, sid=sid_list[i], interval_seconds=info[3], ) if not cfg.use_tc_sched: - tc_queue.appendleft((QueueCommands.WAIT, 2.0)) + q.add_wait_seconds(2.0) if cfg.mgt: - activate_mgts_alternately( - tc_queue=tc_queue, - ) + activate_mgts_alternately(q) elif cfg.one_rw: activate_all_rws_in_sequence( - tc_queue=tc_queue, test_speed=20000, test_ramp_time=10000, init_ssc=0 + q=q, test_speed=20000, test_ramp_time=10000, init_ssc=0 ) elif cfg.two_rws: - activate_all_rws_two_consecutively(tc_queue=tc_queue, init_ssc=0) + activate_all_rws_two_consecutively(q=q) else: pass if not cfg.use_tc_sched: - tc_queue.appendleft((QueueCommands.WAIT, collection_time)) + q.add_wait_seconds(collection_time) disable_cmd_list = [] for i in range(len(sid_list)): disable_cmd_list.append( gen_disable_listen_to_hk_for_x_seconds( diag=diag_list[i], - tc_queue=tc_queue, + q=q, device=proc_key, sid=sid_list[i], ) ) if cfg.one_rw or cfg.two_rws: - activate_all_rws_in_sequence( - tc_queue=tc_queue, test_speed=0, test_ramp_time=5000, init_ssc=0 - ) - tc_queue.appendleft((QueueCommands.WAIT, 60)) + activate_all_rws_in_sequence(q=q, test_speed=0, test_ramp_time=5000, init_ssc=0) + q.add_wait_seconds(60.0) current_time = time.time() current_time += collection_time if not cfg.use_tc_sched: for cmd in disable_cmd_list: - tc_queue.appendleft(cmd.pack_command_tuple()) + q.add_pus_tc(cmd) else: for cmd in disable_cmd_list: - tc_queue.appendleft( + q.add_pus_tc( generate_time_tagged_cmd( - release_time=struct.pack("!I", int(current_time)), - tc_to_insert=cmd, - ssc=0, + release_time=struct.pack("!I", int(current_time)), tc_to_insert=cmd ) ) if not cfg.use_tc_sched: - tc_queue.appendleft((QueueCommands.WAIT, 60)) + q.add_wait_seconds(60.0) sid_list.clear() diag_list.clear() -def pack_proc_commands(tc_queue: TcQueueT, op_code: str): +def pack_proc_commands(q: QueueHelper, op_code: str): sid_list = [] obj_id_dict = get_object_ids() if op_code in OpCodes.RESET_SCHED: - tc_queue.appendleft((QueueCommands.PRINT, "Resetting/Clearing TC schedule")) - tc_queue.appendleft(generate_reset_tc_sched_cmd().pack_command_tuple()) + q.add_log_cmd("Resetting/Clearing TC schedule") + q.add_pus_tc(generate_reset_tc_sched_cmd()) if op_code in OpCodes.BAT_FT: key = KAI.BAT_FT[0] sid_list.append(make_sid(oids.BPX_HANDLER_ID, BpxSetIds.GET_HK_SET)) diag_list = [False] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, @@ -243,7 +230,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): sid_list.append(make_sid(oids.CORE_CONTROLLER_ID, CoreSetIds.HK)) diag_list = [False] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, @@ -279,7 +266,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): set_id = pcdu_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, @@ -291,7 +278,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): sid_list.append(make_sid(oids.RAD_SENSOR_ID, RadSetIds.HK)) diag_list = [False] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, @@ -300,20 +287,14 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): if op_code in OpCodes.TV_SETUP_TCS_FT_ON: # Enable scheduling - tc_queue.appendleft(generate_enable_tc_sched_cmd(ssc=22).pack_command_tuple()) + q.add_pus_tc(generate_enable_tc_sched_cmd()) # check whether tcs_assembly also has to be commanded to NORMAL Mode - pack_tcs_sys_commands( - tc_queue=tc_queue, op_code=TcsOpCodes.TCS_BOARD_ASS_NORMAL[0] - ) - pack_cmd_ctrl_to_nml( - tc_queue=tc_queue, object_id=obj_id_dict.get(oids.THERMAL_CONTROLLER_ID) - ) + pack_tcs_sys_commands(q=q, op_code=TcsOpCodes.TCS_BOARD_ASS_NORMAL[0]) + pack_cmd_ctrl_to_nml(q=q, object_id=obj_id_dict.get(oids.THERMAL_CONTROLLER_ID)) if op_code in OpCodes.TV_TEARDOWN_TCS_FT_OFF: # TCS board should always be on anyway, do not command it off here - pack_cmd_ctrl_to_off( - tc_queue=tc_queue, object_id=obj_id_dict.get(oids.THERMAL_CONTROLLER_ID) - ) + pack_cmd_ctrl_to_off(q=q, object_id=obj_id_dict.get(oids.THERMAL_CONTROLLER_ID)) if op_code in OpCodes.ACS_FT: key = KAI.ACS_FT[0] @@ -333,23 +314,23 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): ] d_side_pairs = a_side_pairs + b_side_pairs diag_list = [False, False, True, False, False] - pack_acs_command(tc_queue=tc_queue, op_code="acs-a") + pack_acs_command(q=q, op_code="acs-a") for a_side_dev in a_side_pairs: oid = a_side_dev[0] set_id = a_side_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="acs-off") - tc_queue.appendleft((QueueCommands.WAIT, 5.0)) - pack_acs_command(tc_queue=tc_queue, op_code="acs-b") + pack_acs_command(q=q, op_code="acs-off") + q.add_wait_seconds(5.0) + pack_acs_command(q=q, op_code="acs-b") sid_list.clear() diag_list = [False, False, True, False, False] @@ -359,16 +340,16 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): set_id = b_side_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="acs-off") - tc_queue.appendleft((QueueCommands.WAIT, 5.0)) - pack_acs_command(tc_queue=tc_queue, op_code="acs-d") + pack_acs_command(q=q, op_code="acs-off") + q.add_wait_seconds(5.0) + pack_acs_command(q=q, op_code="acs-d") sid_list.clear() @@ -389,14 +370,14 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): False, ] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="acs-off") + pack_acs_command(q=q, op_code="acs-off") if op_code in OpCodes.MGT_FT: key = KAI.MGT_FT[0] @@ -412,24 +393,24 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): ] # Command MGT to mode on - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="1") - tc_queue.appendleft((QueueCommands.WAIT, 5)) + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="1") + q.add_wait_seconds(5.0) # Command MGT to normal mode - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="2") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="2") for imtq_dev in imtq_pairs: oid = imtq_dev[0] set_id = imtq_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="0") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="0") if op_code in OpCodes.MGT_FT_DP: key = KAI.MGT_FT_DP[0] @@ -468,12 +449,12 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): True, True, ] - pack_acs_command(tc_queue=tc_queue, op_code="acs-d") + pack_acs_command(q=q, op_code="acs-d") # Command MGT to mode on - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="1") - tc_queue.appendleft((QueueCommands.WAIT, 20)) + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="1") + q.add_wait_seconds(20.0) # Command MGT to normal mode - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="2") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="2") for d_side_and_imtq_dev in d_side_and_imtq_pairs: oid = d_side_and_imtq_dev[0] @@ -483,20 +464,20 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): cfg = GenericHkListeningCfg.default() cfg.mgt = True pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=cfg, ) - pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=tc_queue, op_code="0") - pack_acs_command(tc_queue=tc_queue, op_code="acs-off") + pack_imtq_test_into(oids.IMTQ_HANDLER_ID, q=q, op_code="0") + pack_acs_command(q=q, op_code="acs-off") if op_code in OpCodes.SUS_FT: key = KAI.SUS_FT[0] - pack_sus_cmds(tc_queue=tc_queue, op_code="sus-nom") + pack_sus_cmds(q=q, op_code="sus-nom") sus_n_ids = [ oids.SUS_0_N_LOC_XFYFZM_PT_XF, @@ -527,16 +508,16 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): for nom_sus in sus_n_ids: sid_list.append(make_sid(nom_sus, SetIds.HK)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="sus-off") - tc_queue.appendleft((QueueCommands.WAIT, 5.0)) - pack_sus_cmds(tc_queue=tc_queue, op_code="sus-red") + pack_acs_command(q=q, op_code="sus-off") + q.add_wait_seconds(5.0) + pack_sus_cmds(q=q, op_code="sus-red") diag_list = [ True, @@ -551,16 +532,16 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): for red_sus in sus_r_ids: sid_list.append(make_sid(red_sus, SetIds.HK)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="sus-off") - tc_queue.appendleft((QueueCommands.WAIT, 5.0)) - pack_sus_cmds(tc_queue=tc_queue, op_code="sus-d") + pack_acs_command(q=q, op_code="sus-off") + q.add_wait_seconds(5.0) + pack_sus_cmds(q=q, op_code="sus-d") # SUSs for nom_sus in sus_n_ids: @@ -582,36 +563,32 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): True, ] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_acs_command(tc_queue=tc_queue, op_code="sus-off") + pack_acs_command(q=q, op_code="sus-off") if op_code in OpCodes.STR_FT: key = KAI.STR_FT[0] - pack_star_tracker_commands( - object_id=oids.STAR_TRACKER_ID, tc_queue=tc_queue, op_code="2" - ) + pack_star_tracker_commands(object_id=oids.STAR_TRACKER_ID, q=q, op_code="2") # STR sid_list.append(make_sid(oids.STAR_TRACKER_ID, StrSetIds.TEMPERATURE)) diag_list = [False] pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg.default(), ) - pack_star_tracker_commands( - object_id=oids.STAR_TRACKER_ID, tc_queue=tc_queue, op_code="3" - ) + pack_star_tracker_commands(object_id=oids.STAR_TRACKER_ID, q=q, op_code="3") if op_code in OpCodes.RW_FT_ONE_RW: key = KAI.RW_FT_ONE_RW[0] @@ -644,7 +621,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): False, ] # RW NORMAL - pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, tc_queue=tc_queue, op_code="nml") + pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, q=q, op_code="nml") # RW HK für alle RWs nur einzeln for rw_dev in rw_pairs: @@ -652,14 +629,14 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): set_id = rw_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg(mgt=False, one_rw=True, two_rws=False), ) # RW OFF - pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, tc_queue=tc_queue, op_code="off") + pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, q=q, op_code="off") # ass command with 2 rws to speed if op_code in OpCodes.RW_FT_TWO_RWS: @@ -701,7 +678,7 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): False, ] # RW NORMAL - pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, tc_queue=tc_queue, op_code="nml") + pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, q=q, op_code="nml") # RW for rw_dev in rw_pairs: @@ -709,190 +686,162 @@ def pack_proc_commands(tc_queue: TcQueueT, op_code: str): set_id = rw_dev[1] sid_list.append(make_sid(oid, set_id)) pack_generic_hk_listening_cmds( - tc_queue=tc_queue, + q=q, proc_key=key, sid_list=sid_list, diag_list=diag_list, cfg=GenericHkListeningCfg(mgt=False, one_rw=False, two_rws=True), ) # RW OFF - pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, tc_queue=tc_queue, op_code="off") + pack_rw_ass_cmds(object_id=oids.RW_ASSEMBLY, q=q, op_code="off") def enable_listen_to_hk_for_x_seconds( - tc_queue: TcQueueT, + q: QueueHelper, diag: bool, device: str, sid: bytes, interval_seconds: float, ): - tc_queue.appendleft((QueueCommands.PRINT, f"Enabling periodic HK for {device}")) + q.add_log_cmd(f"Enabling periodic HK for {device}") cmd_tuple = enable_periodic_hk_command_with_interval( diag=diag, sid=sid, interval_seconds=interval_seconds, ssc=0 ) for cmd in cmd_tuple: - tc_queue.appendleft(cmd.pack_command_tuple()) + q.add_pus_tc(cmd) def gen_disable_listen_to_hk_for_x_seconds( - tc_queue: TcQueueT, + q: QueueHelper, diag: bool, device: str, sid: bytes, ) -> PusTelecommand: - tc_queue.appendleft((QueueCommands.PRINT, f"Disabling periodic HK for {device}")) - return disable_periodic_hk_command(diag=diag, sid=sid, ssc=0) + q.add_log_cmd(f"Disabling periodic HK for {device}") + return disable_periodic_hk_command(diag=diag, sid=sid) def activate_mgts_alternately( - tc_queue: TcQueueT, + q: QueueHelper, ): - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=2000, - y_dipole=0, - z_dipole=0, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=2000, + y_dipole=0, + z_dipole=0, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=-2000, - y_dipole=0, - z_dipole=0, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=-2000, + y_dipole=0, + z_dipole=0, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=0, - y_dipole=2000, - z_dipole=0, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=0, + y_dipole=2000, + z_dipole=0, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=0, - y_dipole=-2000, - z_dipole=0, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=0, + y_dipole=-2000, + z_dipole=0, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=0, - y_dipole=0, - z_dipole=2000, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=0, + y_dipole=0, + z_dipole=2000, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) - command = pack_dipole_command( - object_id=oids.IMTQ_HANDLER_ID, - x_dipole=0, - y_dipole=0, - z_dipole=-2000, - duration=30000, + q.add_pus_tc( + pack_dipole_command( + object_id=oids.IMTQ_HANDLER_ID, + x_dipole=0, + y_dipole=0, + z_dipole=-2000, + duration=30000, + ) ) - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 40.0)) + q.add_wait_seconds(40.0) -def rw_speed_cmd_single( - tc_queue: TcQueueT, oid: bytes, init_ssc: int, speed: int, ramp_time: int -) -> int: - command = pack_set_speed_command( - object_id=oid, speed=speed, ramp_time_ms=ramp_time, ssc=init_ssc +def rw_speed_cmd_single(q: QueueHelper, oid: bytes, speed: int, ramp_time: int): + q.add_pus_tc( + pack_set_speed_command(object_id=oid, speed=speed, ramp_time_ms=ramp_time) ) - init_ssc += 1 - tc_queue.appendleft(command.pack_command_tuple()) - tc_queue.appendleft((QueueCommands.WAIT, 70.0)) - command = pack_set_speed_command( - object_id=oid, speed=0, ramp_time_ms=ramp_time, ssc=init_ssc - ) - tc_queue.appendleft(command.pack_command_tuple()) - return init_ssc + 1 + q.add_wait(timedelta(seconds=70.0)) + q.add_pus_tc(pack_set_speed_command(object_id=oid, speed=0, ramp_time_ms=ramp_time)) def rw_speed_up_cmd_consec( - tc_queue: TcQueueT, obids: List[bytes], init_ssc: int, speed: int, ramp_time: int -) -> int: + q: QueueHelper, obids: List[bytes], speed: int, ramp_time: int +): for oid in obids: - command = pack_set_speed_command( - object_id=oid, speed=speed, ramp_time_ms=ramp_time, ssc=init_ssc + q.add_pus_tc( + pack_set_speed_command(object_id=oid, speed=speed, ramp_time_ms=ramp_time) ) - tc_queue.appendleft(command.pack_command_tuple()) - init_ssc += 1 - return init_ssc -def rw_speed_down_cmd_consec( - tc_queue: TcQueueT, obids: List[bytes], init_ssc: int, ramp_time: int -) -> int: +def rw_speed_down_cmd_consec(q: QueueHelper, obids: List[bytes], ramp_time: int): for oid in obids: - command = pack_set_speed_command( - object_id=oid, speed=0, ramp_time_ms=ramp_time, ssc=init_ssc + q.add_pus_tc( + pack_set_speed_command(object_id=oid, speed=0, ramp_time_ms=ramp_time) ) - tc_queue.appendleft(command.pack_command_tuple()) - init_ssc += 1 - return init_ssc def activate_all_rws_in_sequence( - tc_queue: TcQueueT, init_ssc: int, test_speed: int, test_ramp_time: int -) -> int: + q: QueueHelper, init_ssc: int, test_speed: int, test_ramp_time: int +): new_ssc = init_ssc # RW1 speed cmd - tc_queue.appendleft((QueueCommands.WAIT, 58)) - new_ssc = rw_speed_cmd_single( - tc_queue, oids.RW1_ID, new_ssc, test_speed, test_ramp_time - ) - tc_queue.appendleft((QueueCommands.WAIT, 30)) - new_ssc = rw_speed_cmd_single( - tc_queue, oids.RW2_ID, new_ssc, test_speed, test_ramp_time - ) - tc_queue.appendleft((QueueCommands.WAIT, 30)) - new_ssc = rw_speed_cmd_single( - tc_queue, oids.RW3_ID, new_ssc, test_speed, test_ramp_time - ) - tc_queue.appendleft((QueueCommands.WAIT, 30)) - new_ssc = rw_speed_cmd_single( - tc_queue, oids.RW4_ID, new_ssc, test_speed, test_ramp_time - ) - tc_queue.appendleft((QueueCommands.WAIT, 30)) + q.add_wait(timedelta(seconds=58.0)) + rw_speed_cmd_single(q, oids.RW1_ID, test_speed, test_ramp_time) + q.add_wait_seconds(30.0) + rw_speed_cmd_single(q, oids.RW2_ID, test_speed, test_ramp_time) + q.add_wait_seconds(30.0) + rw_speed_cmd_single(q, oids.RW3_ID, test_speed, test_ramp_time) + q.add_wait_seconds(30.0) + rw_speed_cmd_single(q, oids.RW4_ID, test_speed, test_ramp_time) + q.add_wait_seconds(30.0) return new_ssc -def activate_all_rws_two_consecutively(tc_queue: TcQueueT, init_ssc: int) -> int: - new_ssc = init_ssc +def activate_all_rws_two_consecutively(q: QueueHelper): # RW1+3 speed cmd - tc_queue.appendleft((QueueCommands.WAIT, 5.0)) - new_ssc = rw_speed_up_cmd_consec( - tc_queue, [oids.RW1_ID, oids.RW3_ID], new_ssc, -20000, 10000 - ) - tc_queue.appendleft((QueueCommands.WAIT, 70.0)) - new_ssc = rw_speed_down_cmd_consec( - tc_queue, [oids.RW1_ID, oids.RW3_ID], new_ssc, 10000 - ) - tc_queue.appendleft((QueueCommands.WAIT, 15.0)) + q.add_wait_seconds(5.0) + rw_speed_up_cmd_consec(q, [oids.RW1_ID, oids.RW3_ID], -20000, 10000) + q.add_wait_seconds(70.0) + rw_speed_down_cmd_consec(q, [oids.RW1_ID, oids.RW3_ID], 10000) + q.add_wait_seconds(15.0) # RW2+4 speed cmd - new_ssc = rw_speed_up_cmd_consec( - tc_queue, [oids.RW2_ID, oids.RW4_ID], new_ssc, -20000, 10000 - ) - tc_queue.appendleft((QueueCommands.WAIT, 70.0)) - new_ssc = rw_speed_down_cmd_consec( - tc_queue, [oids.RW2_ID, oids.RW4_ID], new_ssc, 10000 - ) - tc_queue.appendleft((QueueCommands.WAIT, 15.0)) - return new_ssc + rw_speed_up_cmd_consec(q, [oids.RW2_ID, oids.RW4_ID], -20000, 10000) + q.add_wait_seconds(70.0) + rw_speed_down_cmd_consec(q, [oids.RW2_ID, oids.RW4_ID], 10000) + q.add_wait_seconds(15.0) diff --git a/pus_tc/system/tcs.py b/pus_tc/system/tcs.py index 47ab31d..b8e8df5 100644 --- a/pus_tc/system/tcs.py +++ b/pus_tc/system/tcs.py @@ -1,4 +1,4 @@ -from tmtccmd.tc.definitions import TcQueueT, QueueCommands +from tmtccmd.tc import QueueHelper from tmtccmd.tc.pus_200_fsfw_modes import Modes from .common import command_mode @@ -15,13 +15,13 @@ class Info: TCS_BOARD_ASS_OFF = "Switching TCS board assembly off" -def pack_tcs_sys_commands(tc_queue: TcQueueT, op_code: str): +def pack_tcs_sys_commands(q: QueueHelper, op_code: str): if op_code in OpCodes.TCS_BOARD_ASS_NORMAL: command_mode( object_id=TCS_BOARD_ASS_ID, mode=Modes.NORMAL, submode=0, - tc_queue=tc_queue, + q=q, info=Info.TCS_BOARD_ASS_NORMAL, ) if op_code in OpCodes.TCS_BOARD_ASS_OFF: @@ -29,6 +29,6 @@ def pack_tcs_sys_commands(tc_queue: TcQueueT, op_code: str): object_id=TCS_BOARD_ASS_ID, mode=Modes.OFF, submode=0, - tc_queue=tc_queue, + q=q, info=Info.TCS_BOARD_ASS_OFF, ) diff --git a/pus_tc/system/time.py b/pus_tc/system/time.py index c66bc17..6663595 100644 --- a/pus_tc/system/time.py +++ b/pus_tc/system/time.py @@ -1,10 +1,9 @@ from datetime import datetime from spacepackets.ecss import PusTelecommand -from tmtccmd.config import QueueCommands -from tmtccmd.tc.definitions import TcQueueT from tmtccmd.logging import get_console_logger +from tmtccmd.tc import QueueHelper LOGGER = get_console_logger() @@ -17,12 +16,9 @@ class Info: SET_CURRENT_TIME = "Setting current time in ASCII format" -def pack_set_current_time_ascii_command(tc_queue: TcQueueT, ssc: int): +def pack_set_current_time_ascii_command(q: QueueHelper): time_test_current_time = datetime.utcnow().isoformat() + "Z" + "\0" current_time_ascii = time_test_current_time.encode("ascii") LOGGER.info(f"Current time in ASCII format: {current_time_ascii}") - tc_queue.appendleft((QueueCommands.PRINT, Info.SET_CURRENT_TIME)) - command = PusTelecommand( - service=9, subservice=128, ssc=ssc, app_data=current_time_ascii - ) - tc_queue.appendleft(command.pack_command_tuple()) + q.add_log_cmd(Info.SET_CURRENT_TIME) + q.add_pus_tc(PusTelecommand(service=9, subservice=128, app_data=current_time_ascii)) diff --git a/tmtcc.py b/tmtcc.py index f7adf36..188429f 100644 --- a/tmtcc.py +++ b/tmtcc.py @@ -7,14 +7,22 @@ from tmtccmd.config.definitions import CoreModeList from spacepackets.ecss import PusVerificator from tmtccmd import get_console_logger, TcHandlerBase +from tmtccmd.com_if import ComInterface from tmtccmd.config.globals import update_global, CoreGlobalIds from deps.tmtccmd.tmtccmd.logging.pus import RawTmtcTimedLogWrapper from deps.tmtccmd.tmtccmd.pus import VerificationWrapper from deps.tmtccmd.tmtccmd.tm import SpecificApidHandlerBase, GenericApidHandlerBase from deps.tmtccmd.tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter +from tmtccmd.logging import get_current_time_string from tmtccmd.pus import FileSeqCountProvider -from tmtccmd.tc import ProcedureHelper, FeedWrapper, TcProcedureType +from tmtccmd.tc import ( + ProcedureHelper, + FeedWrapper, + TcProcedureType, + QueueEntryHelper, + TcQueueEntryType, +) try: import spacepackets @@ -48,8 +56,7 @@ from config import __version__ from config.definitions import PUS_APID from config.hook_implementations import EiveHookObject from pus_tm.factory_hook import pus_factory_hook -from pus_tc.procedure_packer import pre_tc_send_cb - +from pus_tc.procedure_packer import pre_tc_send_cb, handle_default_procedure LOGGER = get_console_logger() @@ -93,6 +100,29 @@ class TcHandler(TcHandlerBase): if info.proc_type == TcProcedureType.DEFAULT: handle_default_procedure(info.to_def_procedure(), wrapper) + def send_cb(self, entry_helper: QueueEntryHelper, com_if: ComInterface): + 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.seq_count = ( + self.seq_count_provider.next_seq_count() + ) + pus_tc_wrapper.pus_tc.apid = PUS_APID + # Add TC after Sequence Count stamping + self.pus_verificator.add_tc(pus_tc_wrapper.pus_tc) + raw_tc = pus_tc_wrapper.pus_tc.pack() + self.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.file_logger.info( + f"{get_current_time_string(True)}: {tc_info_string}" + ) + com_if.send(raw_tc) + elif entry_helper.entry_type == TcQueueEntryType.LOG: + log_entry = entry_helper.to_log_entry() + LOGGER.info(log_entry.log_str) + self.file_logger.info(log_entry.log_str) + def tmtcc_pre_args() -> EiveHookObject: print(f"-- eive tmtc v{__version__} --") From 0a4cd5cfe28f94639c5fe249584414ad6417243a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jul 2022 18:09:24 +0200 Subject: [PATCH 05/10] tmtcc.py executable --- .run/ACU.run.xml | 6 +- .run/BPX.run.xml | 2 +- .run/BPX_Request_HK.run.xml | 2 +- .run/BPX_Reset_Reboot_Counter.run.xml | 2 +- .run/GPS_0.run.xml | 2 +- .run/GPS_1.run.xml | 2 +- .run/Heater_Test.run.xml | 2 +- .run/IMTQ_Get_Commanded_Dipole.run.xml | 2 +- .run/IMTQ_Neg_X_Test.run.xml | 2 +- .run/IMTQ_Neg_Y_Test.run.xml | 4 +- .run/IMTQ_Neg_Z_Test.run.xml | 4 +- .run/IMTQ_Pos_X_Test.run.xml | 4 +- .run/IMTQ_Pos_Y_Test.run.xml | 4 +- .run/IMTQ_Pos_Z_Test.run.xml | 2 +- .run/IMTQ_Test_UDP.run.xml | 2 +- .run/P60_Dock_Commanding.run.xml | 2 +- .run/PDU1_Commanding.run.xml | 2 +- .run/PDU2_Commanding.run.xml | 2 +- .run/PLOC_MPSoC.run.xml | 2 +- .run/PLOC_SUPV.run.xml | 2 +- .run/Ping_Command.run.xml | 2 +- .run/RW1_Test.run.xml | 2 +- .run/RW2_Test_.run.xml | 2 +- .run/RW3_Test_.run.xml | 2 +- .run/RW4_Test_.run.xml | 2 +- .run/Reboot_0_1.run.xml | 2 +- .run/Reboot_1_0.run.xml | 2 +- .run/Reboot_1_1.run.xml | 2 +- .run/Reboot_Prompt.run.xml | 2 +- .run/Reboot_Self.run.xml | 2 +- .run/S_A_Deployment_Test.run.xml | 2 +- .run/Service 17.run.xml | 2 +- .run/Star_Tracker.run.xml | 2 +- .run/Syrlinks.run.xml | 2 +- .run/Syrlinks_Test_UDP.run.xml | 2 +- .run/TMP1075_1_Dock_Test_UDP.run.xml | 2 +- .run/TMP1075_2_Dock_Test_UDP.run.xml | 2 +- .run/TV Test.run.xml | 2 +- .run/_IMTQ_Command_Dipole.run.xml | 2 +- .run/ccsds_handler.run.xml | 2 +- .run/pdec_handler.run.xml | 2 +- .run/tmtcc_Service_17.run.xml | 2 +- .run/tmtcc_Service_2.run.xml | 2 +- .run/tmtcc_Service_200.run.xml | 2 +- .run/tmtcc_Service_3.run.xml | 2 +- .run/tmtcc_Service_8.run.xml | 2 +- .run/tmtccli.run.xml | 2 +- .run/tmtcclient_Help.run.xml | 2 +- .run/tmtccmd_Listener_Mode.run.xml | 2 +- .run/tmtcgui.run.xml | 4 +- tmtcc.py | 122 +++++++++++++++++++------ tmtccli.py | 20 ---- tmtcgui.py | 12 --- 53 files changed, 151 insertions(+), 117 deletions(-) delete mode 100755 tmtccli.py delete mode 100755 tmtcgui.py diff --git a/.run/ACU.run.xml b/.run/ACU.run.xml index 2898755..a06fadc 100644 --- a/.run/ACU.run.xml +++ b/.run/ACU.run.xml @@ -6,13 +6,13 @@ -