From dedb28497f62314498034cd87d1e2a4361b92950 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 2 Dec 2021 08:01:18 +0100 Subject: [PATCH] str image helpercommands --- config/definitions.py | 1 + config/hook_implementations.py | 15 ++++++++ config/object_ids.py | 1 + pus_tc/pdu1.py | 19 ++++------ pus_tc/pdu2.py | 2 +- pus_tc/star_tracker.py | 66 ++++++++++++++++++++++++++++------ pus_tc/str_img_helper.py | 38 ++++++++++++++++++++ pus_tc/tc_packer_hook.py | 12 +++++-- 8 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 pus_tc/str_img_helper.py diff --git a/config/definitions.py b/config/definitions.py index e37f26d..3de789c 100644 --- a/config/definitions.py +++ b/config/definitions.py @@ -38,3 +38,4 @@ class CustomServiceList(enum.Enum): STAR_TRACKER = 'star_tracker' CCSDS_HANDLER = 'ccsds_handler' PDEC_HANDLER = 'pdec_handler' + STR_IMG_HELPER = 'str_img_helper' diff --git a/config/hook_implementations.py b/config/hook_implementations.py index 99e21c1..e52f696 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -279,6 +279,15 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): op_code_dict_srv_star_tracker = { "0": ("Star Tracker: Ping", {OpCodeDictKeys.TIMEOUT: 2.0}), + "1": ("Star Tracker: Reboot", {OpCodeDictKeys.TIMEOUT: 2.0}), + "2": ("Star Tracker: Request temperature", {OpCodeDictKeys.TIMEOUT: 2.0}), + "3": ("Star Tracker: Request version", {OpCodeDictKeys.TIMEOUT: 2.0}), + "4": ("Star Tracker: Request interface", {OpCodeDictKeys.TIMEOUT: 2.0}), + "5": ("Star Tracker: Request power", {OpCodeDictKeys.TIMEOUT: 2.0}), + "6": ("Star Tracker: Subscribe to telemetry", {OpCodeDictKeys.TIMEOUT: 2.0}), + "7": ("Star Tracker: Boot image (requires bootloader mode)", {OpCodeDictKeys.TIMEOUT: 2.0}), + "8": ("Star Tracker: Request time", {OpCodeDictKeys.TIMEOUT: 2.0}), + "9": ("Star Tracker: Request solution", {OpCodeDictKeys.TIMEOUT: 2.0}) } service_star_tracker_tuple = ("Star tracker", op_code_dict_srv_star_tracker) @@ -295,6 +304,11 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): } service_pdec_handler_tuple = ("PDEC Handler", op_code_dict_srv_pdec_handler) + op_code_dict_srv_str_img_helper = { + "0": ("Star Tracker Image Helper: Upload image", {OpCodeDictKeys.TIMEOUT: 2.0}), + } + service_str_img_helper_tuple = ("PDEC Handler", op_code_dict_srv_str_img_helper) + service_op_code_dict[CustomServiceList.P60DOCK.value] = service_p60_tuple service_op_code_dict[CustomServiceList.PDU1.value] = service_pdu1_tuple service_op_code_dict[CustomServiceList.PDU2.value] = service_pdu2_tuple @@ -311,3 +325,4 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): service_op_code_dict[CustomServiceList.PLOC_MEMORY_DUMPER.value] = service_ploc_memory_dumper_tuple service_op_code_dict[CustomServiceList.CCSDS_HANDLER.value] = service_ccsds_handler_tuple service_op_code_dict[CustomServiceList.PDEC_HANDLER.value] = service_pdec_handler_tuple + service_op_code_dict[CustomServiceList.STR_IMG_HELPER.value] = service_str_img_helper_tuple diff --git a/config/object_ids.py b/config/object_ids.py index 1b91269..e9d32d8 100644 --- a/config/object_ids.py +++ b/config/object_ids.py @@ -53,6 +53,7 @@ RAD_SENSOR_ID = bytes([0x44, 0x32, 0x00, 0xA5]) PLOC_SUPV_ID = bytes([0x44, 0x33, 0x00, 0x16]) PLOC_UPDATER_ID = bytes([0x44, 0x33, 0x00, 0x00]) PLOC_MEMORY_DUMPER_ID = bytes([0x44, 0x33, 0x00, 0x01]) +STR_IMG_HELPER_ID = bytes([0x44, 0x33, 0x00, 0x02]) PLOC_MPSOC_ID = bytes([0x44, 0x33, 0x00, 0x15]) diff --git a/pus_tc/pdu1.py b/pus_tc/pdu1.py index d5ee2ec..906d3dd 100644 --- a/pus_tc/pdu1.py +++ b/pus_tc/pdu1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""PDU2 is mounted on the X4 slot of the P60 dock +"""PDU2 is mounted on the X2 slot of the P60 dock @author J. Meier @date 17.12.2020 """ @@ -65,16 +65,16 @@ def pack_pdu1_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): PDUConfigTable.out_en_2.parameter_size, Channel.on ) 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(object_id, 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.STAR_TRACKER_OFF.value: tc_queue.appendleft((QueueCommands.PRINT, "PDU1: Turn star tracker off")) command = pack_set_param_command(object_id, 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(object_id, 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( @@ -96,13 +96,6 @@ def pack_pdu1_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): PDUConfigTable.out_en_7.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( - object_id, 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( diff --git a/pus_tc/pdu2.py b/pus_tc/pdu2.py index 10a348e..300eec5 100644 --- a/pus_tc/pdu2.py +++ b/pus_tc/pdu2.py @@ -2,7 +2,7 @@ """ @file tmtcc_tc_pdu2.py @brief PDU2 tests -@details PDU2 is mounted on the X2 slot of the P60 dock +@details PDU2 is mounted on the X4 slot of the P60 dock @author J. Meier @date 17.12.2020 """ diff --git a/pus_tc/star_tracker.py b/pus_tc/star_tracker.py index e11fab1..aa36b74 100644 --- a/pus_tc/star_tracker.py +++ b/pus_tc/star_tracker.py @@ -15,10 +15,18 @@ from spacepackets.ecss.tc import PusTelecommand class StarTrackerActionIds: PING = 0 + BOOT = 1 + REQ_VERSION = 2 + REQ_INTERFACE = 3 + REQ_TIME = 4 + REQ_POWER = 11 + REBOOT = 7 + SUBSCRIBE_TO_TM = 18 + REQ_SOLUTION = 24 REQ_TEMPERATURE = 25 -def pack_star_tracker_commands_into(object_id: bytearray, tc_queue: TcQueueT, op_code: str) -> TcQueueT: +def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str) -> TcQueueT: tc_queue.appendleft( (QueueCommands.PRINT, "Generate command for star tracker with object id: 0x" + object_id.hex()) @@ -26,14 +34,52 @@ def pack_star_tracker_commands_into(object_id: bytearray, tc_queue: TcQueueT, op if op_code == "0": tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Ping")) - command = pack_ping_command(object_id) + 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()) - - -def pack_ping_command(object_id: bytearray) -> bytearray: - data = int(input("Specify ping data: ")) - command = bytearray() - command = object_id + struct.pack('!I', StarTrackerActionIds.PING) - command = command + struct.pack('!I', data) - return command + if op_code == "1": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Reboot star tracker")) + command = object_id + struct.pack('!I', StarTrackerActionIds.REBOOT) + command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "2": + 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()) + if op_code == "3": + 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()) + if op_code == "4": + 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()) + if op_code == "5": + 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()) + if op_code == "6": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Subscribe to telemetry")) + tm_id = int(input("Specify Id of tm: ")) + command = object_id + struct.pack('!I', StarTrackerActionIds.SUBSCRIBE_TO_TM) + struct.pack('B', tm_id) + command = PusTelecommand(service=8, subservice=128, ssc=36, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "7": + 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()) + if op_code == "8": + 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()) + if op_code == "9": + 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()) diff --git a/pus_tc/str_img_helper.py b/pus_tc/str_img_helper.py new file mode 100644 index 0000000..c4eb85d --- /dev/null +++ b/pus_tc/str_img_helper.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +@file str_img_helper.py +@brief Commanding of the star tracker image helper object which is responsible for uploading + and downloading images to/from the star tracker. +@details Images to uplaod must be previously transferred to the OBC with the CFDP protocol. + Also downloaded images will be stored on the filesystem of the OBC and can be transferred via CFDP. +@author J. Meier +@date 29.11.2021 +""" +import struct + +from tmtccmd.config.definitions import QueueCommands + +from tmtccmd.tc.packer import TcQueueT +from spacepackets.ecss.tc import PusTelecommand + + +class Commands: + UPLOAD_IMAGE = 0 + DOWNLOAD_IMAGE = 1 + + +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()) + ) + + if op_code == "0": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker image helper: Upload image")) + command = object_id + 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()) diff --git a/pus_tc/tc_packer_hook.py b/pus_tc/tc_packer_hook.py index ff12bce..0ee0663 100644 --- a/pus_tc/tc_packer_hook.py +++ b/pus_tc/tc_packer_hook.py @@ -26,15 +26,16 @@ from pus_tc.ploc_upater import pack_ploc_updater_test_into from pus_tc.ploc_memory_dumper import pack_ploc_memory_dumper_cmd from pus_tc.ccsds_handler import pack_ccsds_handler_test from pus_tc.core import pack_core_commands -from pus_tc.star_tracker import pack_star_tracker_commands_into +from pus_tc.star_tracker import pack_star_tracker_commands from pus_tc.gps import pack_gps_command from pus_tc.acs import pack_acs_command +from pus_tc.str_img_helper import pack_str_img_helper_command from config.definitions import CustomServiceList from config.object_ids import P60_DOCK_HANDLER, PDU_1_HANDLER_ID, PDU_2_HANDLER_ID, \ ACU_HANDLER_ID, TMP_1075_1_HANDLER_ID, TMP_1075_2_HANDLER_ID, HEATER_ID, IMTQ_HANDLER_ID, \ PLOC_MPSOC_ID, RW1_ID, RW2_ID, RW3_ID, RW4_ID, RAD_SENSOR_ID, PLOC_SUPV_ID, PLOC_UPDATER_ID, \ STAR_TRACKER_ID, PLOC_MEMORY_DUMPER_ID, GPS_HANDLER_0_ID, GPS_HANDLER_1_ID, CCSDS_HANDLER_ID, \ - PDEC_HANDLER_ID + PDEC_HANDLER_ID, STR_IMG_HELPER_ID LOGGER = get_console_logger() @@ -103,7 +104,12 @@ def pack_service_queue_user(service: Union[str, int], op_code: str, service_queu ) if service == CustomServiceList.STAR_TRACKER.value: object_id = STAR_TRACKER_ID - return pack_star_tracker_commands_into( + return pack_star_tracker_commands( + object_id=object_id, tc_queue=service_queue, op_code=op_code + ) + if service == CustomServiceList.STR_IMG_HELPER.value: + object_id = STR_IMG_HELPER_ID + return pack_str_img_helper_command( object_id=object_id, tc_queue=service_queue, op_code=op_code ) if service == CustomServiceList.CORE.value: