From 58ec3c66409be1e8b9c403f73062f0e187fba021 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 24 Dec 2021 07:32:35 +0100 Subject: [PATCH 1/4] service 8 checksum reply --- config/hook_implementations.py | 3 ++ config/object_ids.py | 5 +++- pus_tc/star_tracker.py | 55 ++++++++++++++++++++++++++++++++-- pus_tm/service_8_hook.py | 20 +++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/config/hook_implementations.py b/config/hook_implementations.py index ab4a94b..7e335cb 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -317,6 +317,9 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): "31": ("Star Tracker: Request contrast", {OpCodeDictKeys.TIMEOUT: 2.0}), "32": ("Star Tracker: Set json filename", {OpCodeDictKeys.TIMEOUT: 2.0}), "33": ("Star Tracker: Write", {OpCodeDictKeys.TIMEOUT: 2.0}), + "34": ("Star Tracker: Read", {OpCodeDictKeys.TIMEOUT: 2.0}), + "35": ("Star Tracker: Set Read filename", {OpCodeDictKeys.TIMEOUT: 2.0}), + "36": ("Star Tracker: Get checksum", {OpCodeDictKeys.TIMEOUT: 2.0}), } service_star_tracker_tuple = ("Star tracker", op_code_dict_srv_star_tracker) diff --git a/config/object_ids.py b/config/object_ids.py index 9e68646..0c95006 100644 --- a/config/object_ids.py +++ b/config/object_ids.py @@ -78,7 +78,10 @@ def get_object_ids() -> Dict[bytes, list]: GPS_HANDLER_1_ID: "GPS 1", RAD_SENSOR_ID: "Radiation Sensor", PLOC_SUPV_ID: "PLOC Supervisor", + PLOC_MPSOC_ID: "PLOC MPSoC", CORE_CONTROLLER_ID: "Core Controller", - CORE_CONTROLLER_ID: "CCSDS Handler", + CCSDS_HANDLER_ID: "CCSDS Handler", + PDEC_HANDLER_ID: "PDEC Handler", + STAR_TRACKER_ID: "Star Tracker Handler", }) return object_id_dict diff --git a/pus_tc/star_tracker.py b/pus_tc/star_tracker.py index 8f09a4e..eafe2bf 100644 --- a/pus_tc/star_tracker.py +++ b/pus_tc/star_tracker.py @@ -40,13 +40,14 @@ class StarTrackerActionIds: VALIDATION = 48 ALGO = 49 CHECKSUM = 50 - RAED = 51 + READ = 51 WRITE = 52 TAKE_IMAGE = 15 STOP_IMAGE_LOADER = 55 RESET_ERROR = 56 CHANGE_DOWNLOAD_IMAGE = 57 SET_JSON_FILE_NAME = 58 + SET_READ_FILENAME = 59 class ImagePathDefs: @@ -55,6 +56,22 @@ class ImagePathDefs: downloadPath = "/mnt/sd0/startracker" jsonFile = "/mnt/sd0/startracker/test.json" flashFile = "/mnt/sd0/startracker/flash.bin" + flashReadPath = "/mnt/sd0/startracker" + + +class Region: + # Definition according to datasheet (which turned out to be partially faulty) + BOOTLOADER = 0 + STAR_TRACKER_FIRMWARE = 1 + FREE_1 = 2 + FREE_2 = 3 + + +class PartitionSize: + BOOTLOADER = 128000 + STAR_TRACKER_FIRMWARE = 896000 + FREE_1 = 128000 + FREE_2 = 896000 def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str) -> TcQueueT: @@ -250,11 +267,45 @@ def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code command = pack_write_command(object_id) command = PusTelecommand(service=8, subservice=128, ssc=58, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "34": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: 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()) + if op_code == "35": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set read filename")) + filename = input("Specify filename: ") + command = object_id + StarTrackerActionIds.SET_READ_FILENAME + bytearray(filename, 'utf-8') + command = PusTelecommand(service=8, subservice=128, ssc=60, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "36": + 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()) def pack_write_command(object_id: bytearray) -> bytearray: - region = 1 + region = Region.FREE_1 address = 0 command = object_id + struct.pack('!I', StarTrackerActionIds.WRITE) + struct.pack('!B', region) + \ struct.pack('!I', address) + bytearray(ImagePathDefs.flashFile, 'utf-8') return command + + +def pack_read_command(object_id: bytearray) -> bytearray: + region = Region.STAR_TRACKER_FIRMWARE + address = 0 + size = PartitionSize.STAR_TRACKER_FIRMWARE + command = object_id + struct.pack('!I', StarTrackerActionIds.READ) + struct.pack('!B', region) + \ + struct.pack('!I', address) + struct.pack('!I', size) + bytearray(ImagePathDefs.flashReadPath, 'utf-8') + return command + + +def pack_checksum_command(object_id: bytearray) -> bytearray: + region = Region.STAR_TRACKER_FIRMWARE + address = 0 + size = PartitionSize.STAR_TRACKER_FIRMWARE + command = object_id + struct.pack('!I', StarTrackerActionIds.CHECKSUM) + struct.pack('!B', region) + \ + struct.pack('!I', address) + struct.pack('!I', size) + return command diff --git a/pus_tm/service_8_hook.py b/pus_tm/service_8_hook.py index 358be86..d5eff26 100644 --- a/pus_tm/service_8_hook.py +++ b/pus_tm/service_8_hook.py @@ -4,6 +4,10 @@ from config.object_ids import * from pus_tc.imtq import ImtqActionIds from pus_tc.ploc_mpsoc import PlocReplyIds from pus_tc.ploc_supervisor import SupvActionIds +from pus_tc.star_tracker import StarTrackerActionIds +from tmtccmd.utility.logger import get_console_logger + +LOGGER = get_console_logger() def user_analyze_service_8_data( @@ -35,6 +39,8 @@ def user_analyze_service_8_data( return handle_ploc_replies(action_id, custom_data) elif object_id == PLOC_SUPV_ID: return handle_supervisor_replies(action_id, custom_data) + elif object_id == STAR_TRACKER_ID: + return handle_startracker_replies(action_id, custom_data) else: header_list = [] content_list = [] @@ -68,3 +74,17 @@ def handle_supervisor_replies(action_id: int, custom_data: bytearray) -> Tuple[l header_list = ['MRAM Dump'] content_list = [custom_data[:len(custom_data)]] return header_list, content_list + + +def handle_startracker_replies(action_id: int, custom_data: bytearray) -> Tuple[list, list]: + header_list = [] + content_list = [] + if action_id == StarTrackerActionIds.CHECKSUM: + if len(custom_data) != 5: + LOGGER.warning("Star tracker reply has invalid length {0}".format(len(custom_data))) + return header_list, content_list + header_list = ['Checksum', 'Checksum valid'] + print(custom_data[4]) + checksum_valid_flag = custom_data[4] >> 8 + content_list = ['0x' + custom_data[:4].hex(), checksum_valid_flag] + return header_list, content_list \ No newline at end of file -- 2.43.0 From e3950bbbcca825b07c40b16658127210a9fe5fe2 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 29 Dec 2021 20:33:49 +0100 Subject: [PATCH 2/4] more star tracker commands --- config/hook_implementations.py | 7 ++++ pus_tc/star_tracker.py | 58 ++++++++++++++++++++++++++++++++++ spacepackets | 2 +- tmtccmd | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/config/hook_implementations.py b/config/hook_implementations.py index 7e335cb..e214843 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -320,6 +320,13 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): "34": ("Star Tracker: Read", {OpCodeDictKeys.TIMEOUT: 2.0}), "35": ("Star Tracker: Set Read filename", {OpCodeDictKeys.TIMEOUT: 2.0}), "36": ("Star Tracker: Get checksum", {OpCodeDictKeys.TIMEOUT: 2.0}), + "37": ("Star Tracker: Set time", {OpCodeDictKeys.TIMEOUT: 2.0}), + "38": ("Star Tracker: Download centroid", {OpCodeDictKeys.TIMEOUT: 2.0}), + "39": ("Star Tracker: Upload centroid (not implemented by arcsec?)", {OpCodeDictKeys.TIMEOUT: 2.0}), + "40": ("Star Tracker: Download matched star", {OpCodeDictKeys.TIMEOUT: 2.0}), + "41": ("Star Tracker: Download DB Image", {OpCodeDictKeys.TIMEOUT: 2.0}), + "42": ("Star Tracker: Download Blob Pixel", {OpCodeDictKeys.TIMEOUT: 2.0}), + "43": ("Star Tracker: Download FPGA Image", {OpCodeDictKeys.TIMEOUT: 2.0}), } service_star_tracker_tuple = ("Star tracker", op_code_dict_srv_star_tracker) diff --git a/pus_tc/star_tracker.py b/pus_tc/star_tracker.py index eafe2bf..bcd1e5e 100644 --- a/pus_tc/star_tracker.py +++ b/pus_tc/star_tracker.py @@ -24,6 +24,8 @@ class StarTrackerActionIds: SWITCH_TO_BOOTLOADER_PROGRAM = 7 DOWNLOAD_IMAGE = 9 UPLOAD_IMAGE = 10 + DOWNLOAD_CENTROID = 16 + UPLOAD_CENTROID = 17 SUBSCRIBE_TO_TM = 18 REQ_SOLUTION = 24 REQ_TEMPERATURE = 25 @@ -43,11 +45,16 @@ class StarTrackerActionIds: READ = 51 WRITE = 52 TAKE_IMAGE = 15 + DOWNLOAD_MATCHED_STAR = 53 STOP_IMAGE_LOADER = 55 RESET_ERROR = 56 CHANGE_DOWNLOAD_IMAGE = 57 SET_JSON_FILE_NAME = 58 SET_READ_FILENAME = 59 + SET_TIME = 60 + DOWNLOAD_DBIMAGE = 61 + DOWNLOAD_BLOBPIXEL = 62 + DOWNLOAD_FPGA_IMAGE = 63 class ImagePathDefs: @@ -57,6 +64,8 @@ class ImagePathDefs: jsonFile = "/mnt/sd0/startracker/test.json" flashFile = "/mnt/sd0/startracker/flash.bin" flashReadPath = "/mnt/sd0/startracker" + uploadCentroidJson = "/mnt/sd0/startracker/upload-centroid.json" + downloadFpgaImagePath = "/mnt/sd0/startracker" class Region: @@ -283,6 +292,55 @@ def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code command = pack_checksum_command(object_id) command = PusTelecommand(service=8, subservice=128, ssc=61, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "37": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Set time")) + unix_time = 1640783543 + command = object_id + 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()) + if op_code == "38": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download Centroid")) + id = 0 + command = object_id + 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()) + if op_code == "39": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Upload Centroid")) + command = object_id + struct.pack('!I', StarTrackerActionIds.UPLOAD_CENTROID) + \ + bytearray(ImagePathDefs.uploadCentroidJson, 'utf-8') + command = PusTelecommand(service=8, subservice=128, ssc=63, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "40": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download matched star")) + id = 0 + command = object_id + 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()) + if op_code == "41": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download DB Image")) + id = 0 + command = object_id + 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()) + if op_code == "42": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download Blob Pixel")) + id = 0 + type = 1 # 0 - normal, 1 - fast + command = object_id + 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()) + if op_code == "43": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Download FPGA Image")) + position = 0 + length = 4100 + command = object_id + struct.pack('!I', StarTrackerActionIds.DOWNLOAD_FPGA_IMAGE) + \ + struct.pack('!I', position) + struct.pack('!I', length) + bytearray( + ImagePathDefs.downloadFpgaImagePath, 'utf-8') + command = PusTelecommand(service=8, subservice=128, ssc=66, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) def pack_write_command(object_id: bytearray) -> bytearray: diff --git a/spacepackets b/spacepackets index 0365df0..2eafa25 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit 0365df03ed2ff8f3def8496c76f578ed3a5984cc +Subproject commit 2eafa2560d5d2da5d82328eac37e41ae7f664194 diff --git a/tmtccmd b/tmtccmd index 71213f6..5fdeec2 160000 --- a/tmtccmd +++ b/tmtccmd @@ -1 +1 @@ -Subproject commit 71213f68e2947afda9551539a97c540e14d1e7b6 +Subproject commit 5fdeec29ee878a3daa4bee5e3f36a39be3b70b31 -- 2.43.0 From 418ecb815b00d5d2081b8d55a480f4c13a0f7139 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 30 Dec 2021 12:55:24 +0100 Subject: [PATCH 3/4] star tracker fpga upload command --- config/hook_implementations.py | 3 +++ pus_tc/star_tracker.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/config/hook_implementations.py b/config/hook_implementations.py index e214843..53dacba 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -327,6 +327,9 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): "41": ("Star Tracker: Download DB Image", {OpCodeDictKeys.TIMEOUT: 2.0}), "42": ("Star Tracker: Download Blob Pixel", {OpCodeDictKeys.TIMEOUT: 2.0}), "43": ("Star Tracker: Download FPGA Image", {OpCodeDictKeys.TIMEOUT: 2.0}), + "44": ("Star Tracker: Change download FPGA image name", {OpCodeDictKeys.TIMEOUT: 2.0}), + "45": ("Star Tracker: Upload FPGA image", {OpCodeDictKeys.TIMEOUT: 2.0}), + "46": ("Star Tracker: FPGA action", {OpCodeDictKeys.TIMEOUT: 2.0}), } service_star_tracker_tuple = ("Star tracker", op_code_dict_srv_star_tracker) diff --git a/pus_tc/star_tracker.py b/pus_tc/star_tracker.py index bcd1e5e..bbd482e 100644 --- a/pus_tc/star_tracker.py +++ b/pus_tc/star_tracker.py @@ -55,6 +55,9 @@ class StarTrackerActionIds: DOWNLOAD_DBIMAGE = 61 DOWNLOAD_BLOBPIXEL = 62 DOWNLOAD_FPGA_IMAGE = 63 + CHANGE_FPGA_DOWNLOAD_FILE = 64 + UPLOAD_FPGA_IMAGE = 65 + FPGA_ACTION = 66 class ImagePathDefs: @@ -66,6 +69,8 @@ class ImagePathDefs: flashReadPath = "/mnt/sd0/startracker" uploadCentroidJson = "/mnt/sd0/startracker/upload-centroid.json" downloadFpgaImagePath = "/mnt/sd0/startracker" + downloadFpgaImageName = "testname" + uploadFpgaImageName = "/mnt/sd0/startracker/fpga-image.bin" class Region: @@ -341,6 +346,24 @@ def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code ImagePathDefs.downloadFpgaImagePath, 'utf-8') command = PusTelecommand(service=8, subservice=128, ssc=66, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "44": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Chnage donwload FPGA image file name")) + command = object_id + struct.pack('!I', StarTrackerActionIds.CHANGE_FPGA_DOWNLOAD_FILE) + \ + bytearray(ImagePathDefs.downloadFpgaImageName, 'utf-8') + command = PusTelecommand(service=8, subservice=128, ssc=67, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "45": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Upload FPGA image")) + command = object_id + struct.pack('!I', StarTrackerActionIds.UPLOAD_FPGA_IMAGE) + \ + bytearray(ImagePathDefs.uploadFpgaImageName, 'utf-8') + command = PusTelecommand(service=8, subservice=128, ssc=68, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + if op_code == "46": + tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: FPGA action")) + id = 3 + command = object_id + 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()) def pack_write_command(object_id: bytearray) -> bytearray: -- 2.43.0 From 734dc5aef88d9fef4ad59817b6ea315db954205c Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Sat, 1 Jan 2022 11:17:01 +0100 Subject: [PATCH 4/4] renamed str image loader to str helper --- config/hook_implementations.py | 2 +- pus_tc/star_tracker.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/hook_implementations.py b/config/hook_implementations.py index 53dacba..b49aa93 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -310,7 +310,7 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): "24": ("Star Tracker: Validation", {OpCodeDictKeys.TIMEOUT: 2.0}), "25": ("Star Tracker: Algo", {OpCodeDictKeys.TIMEOUT: 2.0}), "26": ("Star Tracker: Take image", {OpCodeDictKeys.TIMEOUT: 2.0}), - "27": ("Star Tracker: Stop image loader", {OpCodeDictKeys.TIMEOUT: 2.0}), + "27": ("Star Tracker: Stop str helper", {OpCodeDictKeys.TIMEOUT: 2.0}), "28": ("Star Tracker: Reset error signal", {OpCodeDictKeys.TIMEOUT: 2.0}), "29": ("Star Tracker: Set name of download image", {OpCodeDictKeys.TIMEOUT: 2.0}), "30": ("Star Tracker: Request histogram", {OpCodeDictKeys.TIMEOUT: 2.0}), diff --git a/pus_tc/star_tracker.py b/pus_tc/star_tracker.py index bbd482e..82462b0 100644 --- a/pus_tc/star_tracker.py +++ b/pus_tc/star_tracker.py @@ -20,8 +20,9 @@ class StarTrackerActionIds: REQ_VERSION = 2 REQ_INTERFACE = 3 REQ_TIME = 4 - REQ_POWER = 11 SWITCH_TO_BOOTLOADER_PROGRAM = 7 + REQ_POWER = 11 + TAKE_IMAGE = 15 DOWNLOAD_IMAGE = 9 UPLOAD_IMAGE = 10 DOWNLOAD_CENTROID = 16 @@ -44,9 +45,8 @@ class StarTrackerActionIds: CHECKSUM = 50 READ = 51 WRITE = 52 - TAKE_IMAGE = 15 DOWNLOAD_MATCHED_STAR = 53 - STOP_IMAGE_LOADER = 55 + STOP_STR_HELPER = 55 RESET_ERROR = 56 CHANGE_DOWNLOAD_IMAGE = 57 SET_JSON_FILE_NAME = 58 @@ -244,8 +244,8 @@ def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code command = PusTelecommand(service=8, subservice=128, ssc=52, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) if op_code == "27": - tc_queue.appendleft((QueueCommands.PRINT, "Star tracker: Stop image loader")) - command = object_id + struct.pack('!I', StarTrackerActionIds.STOP_IMAGE_LOADER) + 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()) if op_code == "28": -- 2.43.0