eive-tmtc/eive_tmtc/tmtc/acs/star_tracker.py

1298 lines
49 KiB
Python
Raw Normal View History

2021-08-16 10:03:40 +02:00
# -*- coding: utf-8 -*-
"""
@file star_tracker.py
@brief Star tracker commanding
@author J. Meier
@date 14.08.2021
"""
2023-03-08 19:57:28 +01:00
import datetime
2023-01-16 14:13:06 +01:00
import enum
2023-02-01 11:17:04 +01:00
import logging
2021-08-16 10:03:40 +02:00
import struct
2024-02-29 12:07:03 +01:00
from typing import List, Tuple
2021-08-16 10:03:40 +02:00
2023-03-08 19:57:28 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2023-03-10 13:16:14 +01:00
from eive_tmtc.utility.input_helper import InputHelper
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tc import PusTelecommand
2024-02-19 15:27:27 +01:00
from tmtccmd.config import CmdTreeNode
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.tc.s3_fsfw_hk import (
2023-10-19 16:01:50 +02:00
create_request_one_diag_command,
create_request_one_hk_command,
enable_periodic_hk_command_with_interval,
disable_periodic_hk_command,
make_sid,
)
2024-02-19 15:27:27 +01:00
from tmtccmd.pus.s20_fsfw_param import create_load_param_cmd, create_scalar_u8_parameter
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s8_fsfw_action import create_action_cmd
from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.pus.s200_fsfw_mode import pack_mode_data, Mode
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2024-05-08 10:49:20 +02:00
from tmtccmd.fsfw.tmtc_printer import get_validity_buffer_str
2023-04-04 01:24:33 +02:00
from eive_tmtc.config.object_ids import STR_ASSEMBLY, STAR_TRACKER_ID
2022-03-17 19:42:27 +01:00
2023-02-01 11:17:04 +01:00
_LOGGER = logging.getLogger(__name__)
2021-08-16 10:03:40 +02:00
2024-02-19 12:20:32 +01:00
class FirmwareTarget(enum.IntEnum):
MAIN = 1
BACKUP = 10
class ParamId(enum.IntEnum):
FIRMWARE_TARGET = 1
2024-02-19 15:27:27 +01:00
FIRMWARE_TARGET_PERSISTENT = 2
2024-02-19 12:20:32 +01:00
2023-01-16 14:13:06 +01:00
class StarTrackerActionId(enum.IntEnum):
2021-08-16 10:03:40 +02:00
PING = 0
2021-12-02 08:01:18 +01:00
BOOT = 1
REQ_VERSION = 2
REQ_INTERFACE = 3
REQ_TIME = 4
2022-01-17 08:40:16 +01:00
UNLOCK = 6
2021-12-14 19:25:23 +01:00
SWITCH_TO_BOOTLOADER_PROGRAM = 7
2022-01-01 11:17:01 +01:00
REQ_POWER = 11
TAKE_IMAGE = 15
2021-12-06 15:44:34 +01:00
DOWNLOAD_IMAGE = 9
UPLOAD_IMAGE = 10
2021-12-29 20:33:49 +01:00
DOWNLOAD_CENTROID = 16
UPLOAD_CENTROID = 17
2022-02-11 08:46:48 +01:00
SUBSCRIPTION = 18
IMAGE_PROCESSOR = 19
2021-12-02 08:01:18 +01:00
REQ_SOLUTION = 24
2021-08-16 10:03:40 +02:00
REQ_TEMPERATURE = 25
REQ_HISTOGRAM = 28
2021-12-19 11:35:16 +01:00
REQ_CONTRAST = 29
2021-12-06 15:44:34 +01:00
LIMITS = 40
2021-12-13 07:55:34 +01:00
MOUNTING = 41
CAMERA = 42
BLOB = 43
CENTROIDING = 44
LISA = 45
MATCHING = 46
TRACKING = 47
VALIDATION = 48
ALGO = 49
2021-12-19 14:49:22 +01:00
CHECKSUM = 50
2022-02-27 16:17:24 +01:00
FLASH_READ = 51
FLASH_WRITE = 52
2021-12-29 20:33:49 +01:00
DOWNLOAD_MATCHED_STAR = 53
2022-01-01 11:17:01 +01:00
STOP_STR_HELPER = 55
2021-12-13 07:55:34 +01:00
RESET_ERROR = 56
CHANGE_DOWNLOAD_IMAGE = 57
2021-12-19 14:49:22 +01:00
SET_JSON_FILE_NAME = 58
2022-02-27 16:17:24 +01:00
SET_FLASH_READ_FILENAME = 59
2021-12-29 20:33:49 +01:00
DOWNLOAD_DBIMAGE = 61
DOWNLOAD_BLOBPIXEL = 62
DOWNLOAD_FPGA_IMAGE = 63
2021-12-30 12:55:24 +01:00
CHANGE_FPGA_DOWNLOAD_FILE = 64
UPLOAD_FPGA_IMAGE = 65
FPGA_ACTION = 66
REQ_CAMERA_PARAMS = 67
REQ_LIMITS = 68
2022-02-11 08:46:48 +01:00
REQ_LOG_LEVEL = 69
REQ_MOUNTING = 70
REQ_IMAGE_PROCESSOR = 71
REQ_CENTROIDING = 72
REQ_LISA = 73
REQ_MATCHING = 74
REQ_TRACKING = 75
REQ_VALIDATION = 76
REQ_ALGO = 77
REQ_SUBSCRIPTION = 78
REQ_LOG_SUBSCRIPTION = 79
REQ_DEBUG_CAMERA = 80
LOGLEVEL = 81
LOG_SUBSCRIPTION = 82
DEBUG_CAMERA = 83
2024-02-19 12:17:34 +01:00
# Legacy variable.
2022-02-14 16:52:32 +01:00
FIRMWARE_UPDATE = 84
2024-02-19 12:17:34 +01:00
FIRMWARE_UPDATE_MAIN = 84
FIRMWARE_UPDATE_BACKUP = 101
2023-07-13 10:53:42 +02:00
SET_TIME_FROM_SYS_TIME = 87
2023-10-19 16:52:08 +02:00
ADD_SECONDARY_TM_TO_NORMAL_MODE = 95
RESET_SECONDARY_TM_SET = 96
READ_SECONDARY_TM_SET = 97
2023-11-21 15:23:41 +01:00
RELOAD_JSON_CFG_FILE = 100
2021-12-06 15:44:34 +01:00
2023-11-21 15:23:41 +01:00
class OpCode:
2023-03-03 16:38:17 +01:00
ON_BOOTLOADER = "on_bootloader"
ON_FIRMWARE = "on_firmware"
NORMAL = "nml"
OFF = "off"
PING = "ping"
2023-10-27 10:36:51 +02:00
ONE_SHOOT_HK = "one_shot_hk"
2023-10-19 16:01:50 +02:00
ENABLE_HK = "enable_hk"
DISABLE_HK = "disable_hk"
2023-10-19 16:52:08 +02:00
ADD_SECONDARY_TM_TO_NORMAL_MODE = "add_secondary_tm"
RESET_SECONDARY_TM_SET = "reset_secondary_tm"
READ_SECONDARY_TM_SET = "read_secondary_tm"
2023-03-21 17:00:53 +01:00
TAKE_IMAGE = "take_image"
UPLOAD_IMAGE = "upload_image"
2023-10-27 12:28:55 +02:00
DOWNLOAD_IMAGE = "download_image"
SET_IMG_PROCESSOR_MODE = "set_img_proc_mode"
2024-02-19 12:17:34 +01:00
FW_UPDATE_MAIN = "fw_update_main"
2023-07-13 10:53:42 +02:00
SET_TIME_FROM_SYS_TIME = "set_time"
2023-11-21 15:23:41 +01:00
RELOAD_JSON_CFG_FILE = "reload_json_cfg"
2024-02-19 12:17:34 +01:00
FW_UPDATE_BACKUP = "fw_update_backup"
2024-02-19 15:27:27 +01:00
SELECT_TARGET_FIRMWARE_MAIN = "fw_main"
SELECT_TARGET_FIRMWARE_BACKUP = "fw_backup"
SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT = "fw_main_persistent"
SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT = "fw_backup_persistent"
2024-03-13 10:00:45 +01:00
REQUEST_VERSION = "request_version"
2023-03-21 17:00:53 +01:00
class Info:
2024-03-13 10:00:45 +01:00
ON_BOOTLOADER = "Switch to Mode On, Submode Bootloder"
ON_FIRMWARE = "Switch to Mode On, Submode Firmware"
NORMAL = "Switch to Mode Normal"
OFF = "Switch to Mode Off"
PING = "Send Ping"
2023-10-19 16:01:50 +02:00
ONE_SHOOT_HK = "One shoot HK Set"
ENABLE_HK = "Enable Periodic HK"
DISABLE_HK = "Disable Periodic HK"
2023-10-19 16:52:08 +02:00
ADD_SECONDARY_TM_TO_NORMAL_MODE = "Add specific Dataset to secondary TM"
RESET_SECONDARY_TM_SET = "Reset secondary TM to Temperature Set only"
READ_SECONDARY_TM_SET = "Read list of secondary TM Sets"
2023-10-27 12:28:55 +02:00
UPLOAD_IMAGE = "Upload Optical Image"
2023-10-27 15:02:25 +02:00
DOWNLOAD_IMAGE = "Download Optical Image"
TAKE_IMAGE = "Take Image"
SET_IMG_PROCESSOR_MODE = "Set Image Processor Mode"
2024-02-19 12:17:34 +01:00
FW_UPDATE_MAIN = "Update Main Firmware Slot"
FW_UPDATE_BACKUP = "Update Backup Firmware Slot"
2023-07-13 10:53:42 +02:00
SET_TIME_FROM_SYS_TIME = "Set time from system time"
2023-11-21 15:23:41 +01:00
RELOAD_JSON_CFG_FILE = "Reload JSON configuration file. Reboot still required."
2024-02-19 15:27:27 +01:00
SELECT_TARGET_FIRMWARE_MAIN = "Select main firmware slot"
SELECT_TARGET_FIRMWARE_BACKUP = "Select backup firmware slot"
SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT = "Select main firmware slot persistently"
SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT = (
"Select backup firmware slot persistently"
)
2024-03-13 10:00:45 +01:00
REQUEST_VERSION = "Request the active Firmware Version"
2023-03-21 17:00:53 +01:00
2022-05-27 14:29:56 +02:00
2023-01-24 12:38:32 +01:00
class SetId(enum.IntEnum):
VERSION = 2
INTERFACE = 3
POWER = 11
TEMPERATURE = 25
2023-01-24 12:38:32 +01:00
SOLUTION = 24
HISTOGRAM = 28
2023-10-27 11:24:39 +02:00
CONTRAST = 29
2023-01-24 12:38:32 +01:00
CHECKSUM = 50
CAMERA = 67
LIMITS = 68
CENTROIDING = 72
LISA = 73
2023-10-18 16:18:46 +02:00
AUTO_BLOB = 89
MATCHED_CENTROIDS = 90
BLOB = 91
BLOBS = 92
CENTROID = 93
CENTROIDS = 94
2024-02-29 12:07:03 +01:00
BLOB_STATS = 102
2023-10-19 16:01:50 +02:00
class DataSetRequest(enum.IntEnum):
ONESHOT = 0
ENABLE = 1
DISABLE = 2
2022-02-14 16:52:32 +01:00
class FileDefs:
2022-02-27 16:17:24 +01:00
download_path = "/mnt/sd0/startracker"
json_file = "/mnt/sd0/startracker/full.json"
egse_ground_config = "/home/pi/arcsec/json/ground-config.json"
egse_flight_config = "/home/pi/arcsec/json/flight-config.json"
egse_solution_upload_img_config = "/home/pi/arcsec/json/upload-image-solution.json"
egse_histogram_upload_img_config = (
"/home/pi/arcsec/json/upload-image-histogram.json"
)
q7s_ground_config = "/mnt/sd0/startracker/ground-config.json"
2022-02-27 16:17:24 +01:00
q7s_flight_config = "/mnt/sd0/startracker/flight-config.json"
2022-03-01 16:58:06 +01:00
firmware2_1 = "/home/pi/arcsec/firmware/sagitta-2-1.bin"
firmware22_1 = "/home/pi/arcsec/firmware/sagitta-22-1.bin"
firmware_origin = "/home/pi/arcsec/firmware/sagitta-origin.bin"
2023-04-13 12:08:00 +02:00
FW_SLOT_Q7S = "/mnt/sd0/startracker/updates/sagitta-update.bin"
2022-02-11 08:46:48 +01:00
2022-02-14 16:52:32 +01:00
json_dict = {
"1": ("Q7S flight config", FileDefs.q7s_flight_config),
"2": ("Q7S ground config", FileDefs.q7s_ground_config),
"3": ("EGSE flight config", FileDefs.egse_flight_config),
"4": ("EGSE ground config", FileDefs.egse_ground_config),
"5": (
2022-02-27 16:17:24 +01:00
"EGSE get solution, upload image config",
FileDefs.egse_solution_upload_img_config,
),
"6": (
2022-02-27 16:17:24 +01:00
"EGSE get histogram, upload image config",
FileDefs.egse_solution_upload_img_config,
),
2022-02-14 16:52:32 +01:00
}
2023-04-13 12:08:00 +02:00
FW_DICT = {
"0": ("Firmware Update Q7S", FileDefs.FW_SLOT_Q7S),
"1": ("Firmware Major = 2, Minor = 1", FileDefs.firmware2_1),
"2": ("Firmware Major = 22, Minor = 1", FileDefs.firmware22_1),
"3": ("Firmware Origin", FileDefs.firmware_origin),
2022-02-11 08:46:48 +01:00
}
2023-04-14 17:42:09 +02:00
UPLOAD_IMAGE_DICT = {
"0": ("custom path", "Custom Path"),
"1": ("q7s gemma", "/mnt/sd0/startracker/gemma.bin"),
"2": ("egse gemma", "/home/pi/arcsec/star-images/gemma.bin"),
"3": ("q7s polaris", "/mnt/sd0/startracker/polaris.bin"),
"4": ("egse polaris", "/home/pi/arcsec/star-images/polaris.bin"),
2022-02-27 16:17:24 +01:00
}
2021-12-24 07:32:35 +01:00
2022-02-27 16:17:24 +01:00
class StartRegion:
2021-12-24 07:32:35 +01:00
# Definition according to datasheet (which turned out to be partially faulty)
BOOTLOADER = 0
STAR_TRACKER_FIRMWARE = 1
class PartitionSize:
2022-02-27 16:17:24 +01:00
# Size of most recent firmware image
STAR_TRACKER_FIRMWARE = 464572
2021-08-16 10:03:40 +02:00
class Submode(enum.IntEnum):
DEFAULT = 0
2022-02-23 18:16:10 +01:00
BOOTLOADER = 1
FIRMWARE = 2
2023-04-04 01:24:33 +02:00
def prompt_object_id_mode_cmd() -> bytes:
cmd_assy = input("Command Assembly (0) or Device Handler (1) ?: ")
if cmd_assy == "0":
return STR_ASSEMBLY
else:
return STAR_TRACKER_ID
2023-06-19 17:16:00 +02:00
def pack_star_tracker_commands( # noqa C901
2023-11-22 10:17:05 +01:00
object_id: ObjectIdU32, q: DefaultPusQueueHelper, cmd_str: str
2022-08-08 16:32:18 +02:00
):
2022-07-04 17:59:09 +02:00
q.add_log_cmd(
f"Generate command for star tracker with object id: {object_id.as_hex_string}"
2021-08-16 10:03:40 +02:00
)
2022-07-04 17:59:09 +02:00
obyt = object_id.as_bytes
if cmd_str == OpCode.ON_BOOTLOADER:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mode On, Submode Bootloader")
2023-04-04 01:24:33 +02:00
data = pack_mode_data(prompt_object_id_mode_cmd(), Mode.ON, Submode.BOOTLOADER)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
if cmd_str == OpCode.ON_FIRMWARE:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mode On, Submode Firmware")
2023-04-04 01:24:33 +02:00
data = pack_mode_data(prompt_object_id_mode_cmd(), Mode.ON, Submode.FIRMWARE)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
if cmd_str == OpCode.NORMAL:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mode Normal")
2023-04-04 01:24:33 +02:00
data = pack_mode_data(prompt_object_id_mode_cmd(), Mode.NORMAL, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
if cmd_str == OpCode.OFF:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mode Off")
2023-04-04 01:24:33 +02:00
data = pack_mode_data(prompt_object_id_mode_cmd(), Mode.OFF, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
if cmd_str == OpCode.ONE_SHOOT_HK:
2023-10-19 16:01:50 +02:00
q.add_log_cmd(Info.ONE_SHOOT_HK)
request_dataset(q, DataSetRequest.ONESHOT)
if cmd_str == OpCode.ENABLE_HK:
2023-10-19 16:01:50 +02:00
q.add_log_cmd(Info.ENABLE_HK)
request_dataset(q, DataSetRequest.ENABLE)
if cmd_str == OpCode.DISABLE_HK:
2023-10-19 16:01:50 +02:00
q.add_log_cmd(Info.DISABLE_HK)
request_dataset(q, DataSetRequest.DISABLE)
2023-11-22 10:17:05 +01:00
if cmd_str == "4":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mode Raw")
2023-01-16 15:05:33 +01:00
data = pack_mode_data(obyt, Mode.RAW, 0)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=data))
if cmd_str == OpCode.PING:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Ping")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.PING)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "6":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Switch to bootloader program")
data = obyt + struct.pack(
2023-01-16 14:13:06 +01:00
"!I", StarTrackerActionId.SWITCH_TO_BOOTLOADER_PROGRAM
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "7":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Temperature request")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_TEMPERATURE)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "9":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request interface")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_INTERFACE)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "10":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request power")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_POWER)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "11":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set subscription parameters")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.SUBSCRIPTION)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "12":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Boot")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.BOOT)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "13":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request time")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_TIME)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.UPLOAD_IMAGE:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Upload image")
2022-02-27 16:17:24 +01:00
image = get_upload_image()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.UPLOAD_IMAGE)
+ bytearray(image, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.DOWNLOAD_IMAGE:
2023-10-27 12:28:55 +02:00
q.add_log_cmd(f"STR: {Info.DOWNLOAD_IMAGE}")
2022-02-05 15:44:50 +01:00
path = input("Specify storage location (default - /mnt/sd0/startracker): ")
if not path:
2022-02-27 16:17:24 +01:00
path = FileDefs.download_path
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DOWNLOAD_IMAGE)
+ bytearray(path, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "17":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set limits")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.LIMITS)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "18":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set tracking parameters")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.TRACKING)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "19":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Mounting")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.MOUNTING)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "20":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Camera")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.CAMERA)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "22":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Centroiding")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.CENTROIDING)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "23":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: LISA")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.LISA)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "24":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Matching")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.MATCHING)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "25":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Validation")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.VALIDATION)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "26":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Algo")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.ALGO)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.TAKE_IMAGE:
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Take image")
actionid = int(
input("Specify parameter ID (4: take image, 7: get histogram): ")
)
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.TAKE_IMAGE)
+ struct.pack("!B", actionid)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "28":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Stop str helper")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.STOP_STR_HELPER)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "30":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set name of download image")
2021-12-13 07:55:34 +01:00
filename = input("Specify download image name: ")
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.CHANGE_DOWNLOAD_IMAGE)
+ bytearray(filename, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "31":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request histogram")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_HISTOGRAM)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "32":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request contrast")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_CONTRAST)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "33":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set json filename")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.SET_JSON_FILE_NAME)
+ bytearray(json_file, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "35":
2022-07-04 17:59:09 +02:00
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))
2023-11-22 10:17:05 +01:00
if cmd_str == "36":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set flash read filename")
2021-12-24 07:32:35 +01:00
filename = input("Specify filename: ")
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.SET_FLASH_READ_FILENAME)
+ bytearray(filename, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "37":
2022-07-04 17:59:09 +02:00
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 cmd_str == OpCode.SET_TIME_FROM_SYS_TIME:
2023-07-13 10:53:42 +02:00
q.add_log_cmd(Info.SET_TIME_FROM_SYS_TIME)
2023-07-19 14:41:19 +02:00
data = obyt + struct.pack("!I", StarTrackerActionId.SET_TIME_FROM_SYS_TIME)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "39":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Download Centroid")
2021-12-29 20:33:49 +01:00
id = 0
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DOWNLOAD_CENTROID)
+ struct.pack("!B", id)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "41":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Download matched star")
2021-12-29 20:33:49 +01:00
id = 0
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DOWNLOAD_MATCHED_STAR)
+ struct.pack("!B", id)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "42":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Download DB Image")
2021-12-29 20:33:49 +01:00
id = 0
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DOWNLOAD_DBIMAGE)
+ struct.pack("!B", id)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "43":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Download Blob Pixel")
2021-12-29 20:33:49 +01:00
id = 0
2022-01-18 14:03:56 +01:00
type = 1 # 0 - normal, 1 - fast
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DOWNLOAD_BLOBPIXEL)
+ struct.pack("!B", id)
+ struct.pack("!B", type)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "47":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: FPGA action")
2021-12-30 12:55:24 +01:00
id = 3
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.FPGA_ACTION)
+ struct.pack("!B", id)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "48":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Unlock")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.UNLOCK)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "49":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request camera parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_CAMERA_PARAMS)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "50":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request limits")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_LIMITS)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.SET_IMG_PROCESSOR_MODE:
q.add_log_cmd(Info.SET_IMG_PROCESSOR_MODE)
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.IMAGE_PROCESSOR)
+ bytearray(json_file, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "52":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: EGSE load ground config camera parameters")
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.CAMERA)
+ bytearray(FileDefs.egse_ground_config, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "53":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: EGSE load flight config camera parameters")
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.CAMERA)
+ bytearray(FileDefs.egse_flight_config, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "54":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request log level parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_LOG_LEVEL)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "55":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request mounting parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_MOUNTING)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "56":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request image processor parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_IMAGE_PROCESSOR)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "57":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request centroiding parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_CENTROIDING)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "58":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request lisa parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_LISA)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "59":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request matching parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_MATCHING)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "60":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request tracking parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_TRACKING)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "61":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request validation parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_VALIDATION)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "62":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request algo parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_ALGO)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "63":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request subscription parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_SUBSCRIPTION)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "64":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request log subscription parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_LOG_SUBSCRIPTION)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "65":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Request debug camera parameters")
2023-01-16 14:13:06 +01:00
data = obyt + struct.pack("!I", StarTrackerActionId.REQ_DEBUG_CAMERA)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "66":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set log level parameters")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.LOGLEVEL)
+ bytearray(json_file, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "67":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set log subscription parameters")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.LOG_SUBSCRIPTION)
+ bytearray(json_file, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2023-11-22 10:17:05 +01:00
if cmd_str == "68":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("Star tracker: Set debug camera parameters")
2022-02-27 16:17:24 +01:00
json_file = get_config_file()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
+ struct.pack("!I", StarTrackerActionId.DEBUG_CAMERA)
+ bytearray(json_file, "utf-8")
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
2024-02-19 12:17:34 +01:00
if cmd_str == OpCode.FW_UPDATE_MAIN:
q.add_log_cmd(Info.FW_UPDATE_MAIN)
2022-02-14 16:52:32 +01:00
firmware = get_firmware()
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
obyt
2024-02-19 12:17:34 +01:00
+ struct.pack("!I", StarTrackerActionId.FIRMWARE_UPDATE_MAIN)
+ firmware.encode()
)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.FW_UPDATE_BACKUP:
q.add_log_cmd(Info.FW_UPDATE_BACKUP)
firmware = get_firmware()
data = (
obyt
+ struct.pack("!I", StarTrackerActionId.FIRMWARE_UPDATE_BACKUP)
2023-04-13 12:08:00 +02:00
+ firmware.encode()
2022-02-27 16:17:24 +01:00
)
2022-07-04 17:59:09 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=data))
if cmd_str == OpCode.ADD_SECONDARY_TM_TO_NORMAL_MODE:
2023-10-26 13:15:51 +02:00
q.add_log_cmd(Info.ADD_SECONDARY_TM_TO_NORMAL_MODE)
2023-10-19 16:52:08 +02:00
for val in SetId:
print("{:<2}: {:<20}".format(val, val.name))
2023-10-26 13:15:51 +02:00
set_id = int(input("Specify the dataset \n" ""))
2023-10-19 16:52:08 +02:00
q.add_pus_tc(
create_action_cmd(
STAR_TRACKER_ID,
StarTrackerActionId.ADD_SECONDARY_TM_TO_NORMAL_MODE,
2023-10-26 16:52:29 +02:00
struct.pack("!I", set_id),
2023-10-19 16:52:08 +02:00
)
)
if cmd_str == OpCode.RESET_SECONDARY_TM_SET:
2023-10-26 13:15:51 +02:00
q.add_log_cmd(Info.RESET_SECONDARY_TM_SET)
2023-10-19 16:52:08 +02:00
q.add_pus_tc(
create_action_cmd(
STAR_TRACKER_ID,
StarTrackerActionId.RESET_SECONDARY_TM_SET,
)
)
if cmd_str == OpCode.READ_SECONDARY_TM_SET:
2023-10-26 13:15:51 +02:00
q.add_log_cmd(Info.READ_SECONDARY_TM_SET)
q.add_pus_tc(
create_action_cmd(
STAR_TRACKER_ID, StarTrackerActionId.READ_SECONDARY_TM_SET
)
)
if cmd_str == OpCode.RELOAD_JSON_CFG_FILE:
2023-11-21 15:23:41 +01:00
q.add_log_cmd(Info.RELOAD_JSON_CFG_FILE)
q.add_pus_tc(
create_action_cmd(STAR_TRACKER_ID, StarTrackerActionId.RELOAD_JSON_CFG_FILE)
)
2024-02-19 15:27:27 +01:00
if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_MAIN:
q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_MAIN)
q.add_pus_tc(create_update_firmware_target_cmd(False, FirmwareTarget.MAIN))
if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_BACKUP:
q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP)
q.add_pus_tc(create_update_firmware_target_cmd(False, FirmwareTarget.BACKUP))
if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_MAIN_PERSISTENT:
q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP)
q.add_pus_tc(create_update_firmware_target_cmd(True, FirmwareTarget.MAIN))
if cmd_str == OpCode.SELECT_TARGET_FIRMWARE_BACKUP_PERSISTENT:
q.add_log_cmd(Info.SELECT_TARGET_FIRMWARE_BACKUP)
q.add_pus_tc(create_update_firmware_target_cmd(True, FirmwareTarget.BACKUP))
2024-03-13 10:00:45 +01:00
if cmd_str == OpCode.REQUEST_VERSION:
q.add_log_cmd(Info.REQUEST_VERSION)
q.add_pus_tc(
create_action_cmd(
object_id=STAR_TRACKER_ID, action_id=StarTrackerActionId.REQ_VERSION
)
)
2024-02-19 15:27:27 +01:00
def create_update_firmware_target_cmd(
persistent: bool, fw_target: FirmwareTarget
) -> PusTelecommand:
if persistent:
param_id = ParamId.FIRMWARE_TARGET_PERSISTENT
else:
param_id = ParamId.FIRMWARE_TARGET
return create_load_param_cmd(
2024-05-08 10:49:20 +02:00
parameter=create_scalar_u8_parameter(
2024-02-19 15:27:27 +01:00
STAR_TRACKER_ID,
0,
param_id,
fw_target,
2024-05-08 10:49:20 +02:00
),
apid=0,
2024-02-19 15:27:27 +01:00
)
2021-12-24 07:32:35 +01:00
2023-10-27 10:36:51 +02:00
def request_dataset(q: DefaultPusQueueHelper, req_type: DataSetRequest):
2023-10-19 16:01:50 +02:00
for val in SetId:
print("{:<2}: {:<20}".format(val, val.name))
2023-10-27 10:36:51 +02:00
set_id = int(input("Specify the dataset \n" ""))
if set_id in [SetId.SOLUTION, SetId.TEMPERATURE]:
is_diag = True
else:
is_diag = False
match req_type:
2023-10-19 16:01:50 +02:00
case DataSetRequest.ONESHOT:
2023-10-27 10:36:51 +02:00
if is_diag:
2023-10-19 16:01:50 +02:00
q.add_pus_tc(
2023-10-27 10:36:51 +02:00
create_request_one_diag_command(make_sid(STAR_TRACKER_ID, set_id))
2023-10-19 16:01:50 +02:00
)
2023-10-27 10:36:51 +02:00
else:
2023-10-19 16:01:50 +02:00
q.add_pus_tc(
2023-10-27 10:36:51 +02:00
create_request_one_hk_command(make_sid(STAR_TRACKER_ID, set_id))
2023-10-19 16:01:50 +02:00
)
case DataSetRequest.ENABLE:
interval = float(
input("Please specify interval in floating point seconds: ")
)
2023-10-27 10:36:51 +02:00
if is_diag:
2023-10-19 16:01:50 +02:00
cmd_tuple = enable_periodic_hk_command_with_interval(
2023-10-27 10:36:51 +02:00
True, make_sid(STAR_TRACKER_ID, set_id), interval
2023-10-19 16:01:50 +02:00
)
2023-10-27 10:36:51 +02:00
else:
2023-10-19 16:01:50 +02:00
cmd_tuple = enable_periodic_hk_command_with_interval(
2023-10-27 10:36:51 +02:00
False, make_sid(STAR_TRACKER_ID, set_id), interval
2023-10-19 16:01:50 +02:00
)
2023-10-27 10:36:51 +02:00
q.add_pus_tc(cmd_tuple[0])
q.add_pus_tc(cmd_tuple[1])
2023-10-19 16:01:50 +02:00
case DataSetRequest.DISABLE:
2023-10-27 10:36:51 +02:00
if is_diag:
2023-10-19 16:01:50 +02:00
q.add_pus_tc(
2023-10-27 10:36:51 +02:00
disable_periodic_hk_command(True, make_sid(STAR_TRACKER_ID, set_id))
2023-10-19 16:01:50 +02:00
)
2023-10-27 10:36:51 +02:00
else:
2023-10-19 16:01:50 +02:00
q.add_pus_tc(
2023-10-27 10:36:51 +02:00
disable_periodic_hk_command(
False, make_sid(STAR_TRACKER_ID, set_id)
)
2023-10-19 16:01:50 +02:00
)
2022-07-04 17:59:09 +02:00
def pack_read_command(object_id: bytes) -> bytearray:
2022-02-27 16:17:24 +01:00
start_region = StartRegion.STAR_TRACKER_FIRMWARE
2021-12-24 07:32:35 +01:00
size = PartitionSize.STAR_TRACKER_FIRMWARE
2022-02-27 16:17:24 +01:00
path = input("Specify storage location (default - /mnt/sd0/startracker): ")
if not path:
path = FileDefs.download_path
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
object_id
+ struct.pack("!I", StarTrackerActionId.FLASH_READ)
+ struct.pack("!B", start_region)
+ struct.pack("!I", size)
+ bytearray(path, "utf-8")
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
return bytearray(data)
2021-12-24 07:32:35 +01:00
2022-07-04 17:59:09 +02:00
def pack_checksum_command(object_id: bytes) -> bytearray:
2022-02-27 16:17:24 +01:00
start_region = StartRegion.STAR_TRACKER_FIRMWARE
2021-12-24 07:32:35 +01:00
address = 0
size = PartitionSize.STAR_TRACKER_FIRMWARE
2022-07-04 17:59:09 +02:00
data = (
2023-03-10 13:38:21 +01:00
object_id
+ struct.pack("!I", StarTrackerActionId.CHECKSUM)
+ struct.pack("!B", start_region)
+ struct.pack("!I", address)
+ struct.pack("!I", size)
2022-01-18 14:03:56 +01:00
)
2022-07-04 17:59:09 +02:00
return bytearray(data)
2022-02-11 08:46:48 +01:00
def get_config_file() -> str:
2023-02-01 11:17:04 +01:00
_LOGGER.info("Specify json file")
2022-02-14 16:52:32 +01:00
input_helper = InputHelper(json_dict)
key = input_helper.get_key()
2022-02-27 16:17:24 +01:00
json_file = json_dict[key][1]
return json_file
2022-02-11 08:46:48 +01:00
2022-02-14 16:52:32 +01:00
def get_firmware() -> str:
2023-02-01 11:17:04 +01:00
_LOGGER.info("Specify firmware file")
2023-04-13 12:08:00 +02:00
bin_select = int(input("Use hardcoded paths (0) or specify path manually (1) ?: "))
if bin_select == 0:
input_helper = InputHelper(FW_DICT)
key = input_helper.get_key()
firmware = FW_DICT[key][1]
else:
firmware = input("Specify absolute path of the firmware update file: ")
2022-02-14 16:52:32 +01:00
return firmware
2022-02-27 16:17:24 +01:00
def get_upload_image() -> str:
2023-02-01 11:17:04 +01:00
_LOGGER.info("Specify image to upload")
2023-04-14 17:42:09 +02:00
input_helper = InputHelper(UPLOAD_IMAGE_DICT)
2022-02-27 16:17:24 +01:00
key = input_helper.get_key()
2023-04-14 17:42:09 +02:00
if UPLOAD_IMAGE_DICT[key][0] == "custom path":
image = input("Please specify custom absolute path: ")
else:
image = UPLOAD_IMAGE_DICT[key][1]
2022-02-27 16:17:24 +01:00
return image
2023-03-03 16:38:17 +01:00
2023-05-24 13:44:45 +02:00
def handle_str_hk_data(set_id: int, hk_data: bytes, pw: PrintWrapper):
2023-03-08 19:57:28 +01:00
pw.dlog(f"Received STR HK set with set ID {set_id}")
if set_id == SetId.SOLUTION:
handle_solution_set(hk_data, pw)
2023-10-27 09:58:53 +02:00
elif set_id == SetId.HISTOGRAM:
handle_histogram_set(hk_data, pw)
2023-03-13 10:53:41 +01:00
elif set_id == SetId.TEMPERATURE:
handle_temperature_set(hk_data, pw)
2023-10-26 16:54:41 +02:00
elif set_id == SetId.AUTO_BLOB:
handle_auto_blob_set(hk_data, pw)
2023-10-09 16:31:04 +02:00
elif set_id == SetId.MATCHED_CENTROIDS:
handle_matched_centroids_set(hk_data, pw)
elif set_id == SetId.BLOB:
handle_blob_set(hk_data, pw)
elif set_id == SetId.BLOBS:
handle_blobs_set(hk_data, pw)
elif set_id == SetId.CENTROID:
handle_centroid_set(hk_data, pw)
elif set_id == SetId.CENTROIDS:
handle_centroids_set(hk_data, pw)
2023-10-27 11:24:39 +02:00
elif set_id == SetId.CONTRAST:
handle_contrast_set(hk_data, pw)
2024-02-29 12:07:03 +01:00
elif set_id == SetId.BLOB_STATS:
handle_blob_stats_set(hk_data, pw)
2024-03-13 10:00:45 +01:00
elif set_id == SetId.VERSION:
handle_version_set(hk_data, pw)
2023-03-08 19:57:28 +01:00
else:
_LOGGER.warning(f"HK parsing for Star Tracker set ID {set_id} unimplemented")
2023-03-13 10:51:55 +01:00
def unpack_time_hk(hk_data: bytes, current_idx: int, pw: PrintWrapper) -> int:
2023-03-08 19:57:28 +01:00
ticks_time_fmt = "!IQ"
fmt_len = struct.calcsize(ticks_time_fmt)
(ticks, unix_time) = struct.unpack(
2023-03-10 13:38:21 +01:00
ticks_time_fmt, hk_data[current_idx : current_idx + fmt_len]
2023-03-08 19:57:28 +01:00
)
2023-10-26 20:45:14 +02:00
try:
unix_as_dt = datetime.datetime.fromtimestamp(
int(round(unix_time / 1e6)), tz=datetime.timezone.utc
)
pw.dlog(f"Ticks: {ticks} | UNIX time: {unix_time}")
pw.dlog(f"UNIX as datetime: {unix_as_dt}")
except ValueError as e:
_LOGGER.exception(e)
2023-03-08 19:57:28 +01:00
current_idx += fmt_len
2023-03-13 10:51:55 +01:00
return current_idx
2024-03-13 10:00:45 +01:00
def handle_version_set(hk_data: bytes, pw: PrintWrapper):
pw.dlog("Received Version Set")
2024-03-13 10:18:37 +01:00
if len(hk_data) != 16:
_LOGGER.warning(
f"Version dataset HK with length {len(hk_data)} of unexpected size"
)
2024-03-13 10:00:45 +01:00
current_idx = unpack_time_hk(hk_data, 0, pw)
program = struct.unpack("!B", hk_data[current_idx : current_idx + 1])[0]
pw.dlog(f"Program: {program}")
current_idx += 1
major = struct.unpack("!B", hk_data[current_idx : current_idx + 1])[0]
pw.dlog(f"Major: {major}")
current_idx += 1
minor = struct.unpack("!B", hk_data[current_idx : current_idx + 1])[0]
pw.dlog(f"Minor: {minor}")
current_idx += 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=5))
2024-03-13 10:00:45 +01:00
2023-03-13 10:51:55 +01:00
def handle_temperature_set(hk_data: bytes, pw: PrintWrapper):
pw.dlog("Received temperature set")
if len(hk_data) < 24:
_LOGGER.warning(f"Temperature dataset HK with length {len(hk_data)} too short")
current_idx = unpack_time_hk(hk_data, 0, pw)
temps_fmt = "!fff"
fmt_len = struct.calcsize(temps_fmt)
(mcu_temp, cmos_temp, fpga_temp) = struct.unpack(
temps_fmt, hk_data[current_idx : current_idx + fmt_len]
)
pw.dlog(f"MCU Temperature: {mcu_temp}")
pw.dlog(f"CMOS Temperature: {cmos_temp}")
pw.dlog(f"FPGA Temperature: {fpga_temp}")
current_idx += fmt_len
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], 5))
2023-03-13 10:51:55 +01:00
def handle_solution_set(hk_data: bytes, pw: PrintWrapper):
pw.dlog("Received solution set")
if len(hk_data) < 78:
_LOGGER.warning(
f"Solution dataset HK data with length {len(hk_data)} too short"
)
return
current_idx = unpack_time_hk(hk_data, 0, pw)
2023-03-08 19:57:28 +01:00
calib_quaternions_fmt = "!ffff"
fmt_len = struct.calcsize(calib_quaternions_fmt)
(calib_q_w, calib_q_x, calib_q_y, calib_q_z) = struct.unpack(
2023-03-10 13:38:21 +01:00
calib_quaternions_fmt, hk_data[current_idx : current_idx + fmt_len]
2023-03-08 19:57:28 +01:00
)
pw.dlog("Calibrated Quaternions")
pw.dlog(f"Quaternion w: {calib_q_w}")
pw.dlog(f"Quaternion x: {calib_q_x}")
pw.dlog(f"Quaternion y: {calib_q_y}")
pw.dlog(f"Quaternion z: {calib_q_z}")
current_idx += fmt_len
track_fmt = "!fffff"
fmt_len = struct.calcsize(track_fmt)
(track_confidence, track_q_w, track_q_x, track_q_y, track_q_z) = struct.unpack(
2023-03-10 13:38:21 +01:00
track_fmt, hk_data[current_idx : current_idx + fmt_len]
2023-03-08 19:57:28 +01:00
)
pw.dlog(f"Track Confidence: {track_confidence}")
pw.dlog(f"Track QW: {track_q_w}")
pw.dlog(f"Track QX: {track_q_x}")
pw.dlog(f"Track QY: {track_q_y}")
pw.dlog(f"Track QZ: {track_q_z}")
current_idx += fmt_len
track_removed = hk_data[current_idx]
pw.dlog(f"Number of stars removed from tracking solution: {track_removed}")
current_idx += 1
stars_centroided = hk_data[current_idx]
pw.dlog(f"Centroided stars: {stars_centroided}")
current_idx += 1
stars_matched_database = hk_data[current_idx]
pw.dlog(f"Stars matched: {stars_matched_database}")
current_idx += 1
# Result of LISA: Lost in space algorithm
lisa_fmt = "!fffffB"
2023-03-13 10:52:31 +01:00
fmt_len = struct.calcsize(lisa_fmt)
2023-03-10 13:38:21 +01:00
(
lisa_q_w,
lisa_q_x,
lisa_q_y,
lisa_q_z,
lisa_percentage_close_stars,
lisa_number_close_stars,
) = struct.unpack(lisa_fmt, hk_data[current_idx : current_idx + fmt_len])
2023-03-08 19:57:28 +01:00
pw.dlog(f"LISA QW: {lisa_q_w}")
pw.dlog(f"LISA QX: {lisa_q_x}")
pw.dlog(f"LISA QY: {lisa_q_y}")
pw.dlog(f"LISA QZ: {lisa_q_z}")
2023-03-10 13:38:21 +01:00
pw.dlog(
f"Percentage of close stars in LISA solution: {lisa_percentage_close_stars}"
)
2023-03-10 13:16:14 +01:00
pw.dlog(f"Number of close stars in LISA solution: {lisa_number_close_stars}")
2023-03-08 19:57:28 +01:00
current_idx += fmt_len
2023-04-14 17:42:09 +02:00
str_mode = hk_data[current_idx]
pw.dlog(f"STR mode: {str_mode}")
current_idx += 1
is_trustworthy = hk_data[current_idx]
pw.dlog(f"Trustworthy solution: {is_trustworthy}")
2023-03-08 19:57:28 +01:00
current_idx += 1
2023-03-13 10:57:23 +01:00
stable_count = struct.unpack("!I", hk_data[current_idx : current_idx + 4])[0]
2023-03-08 19:57:28 +01:00
pw.dlog(f"Stable count: {stable_count}")
current_idx += 4
solution_strategy = hk_data[current_idx]
pw.dlog(f"Solution strategy: {solution_strategy}")
2023-03-21 17:00:53 +01:00
current_idx += 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], 23))
2023-03-08 19:57:28 +01:00
2023-10-09 16:31:04 +02:00
def handle_blob_set(hk_data: bytes, pw: PrintWrapper):
2023-10-18 16:18:46 +02:00
pw.dlog("Received Blob Set")
2023-10-09 16:31:04 +02:00
if len(hk_data) < 14:
_LOGGER.warning(f"Blob dataset HK data with length {len(hk_data)} too short")
return
current_idx = unpack_time_hk(hk_data, 0, pw)
2023-10-26 17:14:18 +02:00
blob_count = struct.unpack("!I", hk_data[current_idx : current_idx + 4])[0]
2023-10-09 16:31:04 +02:00
pw.dlog(f"Blob count: {blob_count}")
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx + 4 :], num_vars=3))
2023-10-09 16:31:04 +02:00
def handle_blobs_set(hk_data: bytes, pw: PrintWrapper):
2023-10-18 16:18:46 +02:00
pw.dlog("Received Blobs Set")
2023-10-09 16:31:04 +02:00
if len(hk_data) < 6 + 2 * 2 * 8:
_LOGGER.warning(f"Blobs dataset HK data with length {len(hk_data)} too short")
return
current_idx = unpack_time_hk(hk_data, 0, pw)
fmt_str = "!HHH"
inc_len = struct.calcsize(fmt_str)
count, count_used, nr_4lines_skipped = struct.unpack(
fmt_str, hk_data[current_idx : current_idx + inc_len]
)
current_idx += inc_len
pw.dlog(
f"Count {count} | Count Used {count_used} | Number of skipped 4lines {nr_4lines_skipped}"
)
2023-10-18 16:18:46 +02:00
fmt_coords = "!HHHHHHHH"
inc_len = struct.calcsize(fmt_coords)
x_coords = struct.unpack(fmt_coords, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
y_coords = struct.unpack(fmt_coords, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
pw.dlog("{:<8} {:<8}".format("X", "Y"))
for idx in range(8):
pw.dlog("{:<8} {:<8}".format(x_coords[idx], y_coords[idx]))
2023-10-27 09:58:53 +02:00
assert current_idx == len(hk_data) - 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=7))
2023-10-09 16:31:04 +02:00
def handle_centroid_set(hk_data: bytes, pw: PrintWrapper):
2023-10-26 17:48:18 +02:00
pw.dlog("Received Centroid Set")
2023-10-09 16:31:04 +02:00
if len(hk_data) < 14:
raise ValueError(
f"Centroid dataset HK data with length {len(hk_data)} too short"
)
current_idx = unpack_time_hk(hk_data, 0, pw)
2023-10-26 17:14:18 +02:00
centroid_count = struct.unpack("!I", hk_data[current_idx : current_idx + 4])[0]
2023-10-27 09:58:53 +02:00
current_idx += 4
2023-10-18 16:18:46 +02:00
pw.dlog(f"Centroid count: {centroid_count}")
2023-10-27 09:58:53 +02:00
assert current_idx == len(hk_data) - 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=3))
2023-10-09 16:31:04 +02:00
def handle_centroids_set(hk_data: bytes, pw: PrintWrapper):
2023-10-18 16:18:46 +02:00
pw.dlog("Received Centroids Set")
2023-10-09 16:31:04 +02:00
current_idx = unpack_time_hk(hk_data, 0, pw)
2023-10-26 17:14:18 +02:00
centroids_count = struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0]
current_idx += 2
2023-10-09 16:31:04 +02:00
pw.dlog(f"Centroids count: {centroids_count}")
2023-10-27 09:58:53 +02:00
fmt_coords = "!ffffffffffffffff"
2023-10-18 16:18:46 +02:00
inc_len = struct.calcsize(fmt_coords)
x_coords = struct.unpack(fmt_coords, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
y_coords = struct.unpack(fmt_coords, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
2023-10-27 09:58:53 +02:00
fmt_coords = "!BBBBBBBBBBBBBBBB"
inc_len = struct.calcsize(fmt_coords)
2023-10-18 16:18:46 +02:00
magnitude = struct.unpack(fmt_coords, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
2023-10-27 09:58:53 +02:00
pw.dlog("{:<8} {:<8} {:<8} {:<8}".format("Index", "X", "Y", "Magnitude"))
2023-10-18 16:18:46 +02:00
for idx in range(16):
pw.dlog(
2023-10-27 09:58:53 +02:00
"{:<8} {:<8.3f} {:<8.3f} {:<8}".format(
idx, x_coords[idx], y_coords[idx], magnitude[idx]
)
2023-10-18 16:18:46 +02:00
)
2023-10-27 09:58:53 +02:00
assert current_idx == len(hk_data) - 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=6))
2023-10-09 16:31:04 +02:00
def handle_matched_centroids_set(hk_data: bytes, pw: PrintWrapper):
2023-10-18 16:18:46 +02:00
pw.dlog("Received Matched Centroids Set")
2023-10-26 17:48:18 +02:00
if len(hk_data) < 4 + 8 + 1 + 4 * 16 * 5:
raise ValueError(
f"Matched Centroids dataset HK data with length {len(hk_data)} too short. Expected 333 bytes."
)
2023-10-09 16:31:04 +02:00
current_idx = unpack_time_hk(hk_data, 0, pw)
num_matched_centroids = hk_data[current_idx]
current_idx += 1
2023-10-09 16:39:09 +02:00
pw.dlog(f"Number of matched centroids {num_matched_centroids}")
2023-10-18 16:18:46 +02:00
fmt_ids = "!IIIIIIIIIIIIIIII"
inc_len = struct.calcsize(fmt_ids)
star_id = struct.unpack(fmt_ids, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
fmt_floats = "!ffffffffffffffff"
inc_len = struct.calcsize(fmt_floats)
x_coords = struct.unpack(fmt_floats, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
y_coords = struct.unpack(fmt_floats, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
x_errors = struct.unpack(fmt_floats, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
y_errors = struct.unpack(fmt_floats, hk_data[current_idx : current_idx + inc_len])
current_idx += inc_len
pw.dlog(
2023-10-27 09:58:53 +02:00
"{:<8} {:<10} {:<10} {:<10} {:<10} {:<10}".format(
"Index", "Star ID", "X", "Y", "X Error", "Y Error"
2023-10-18 16:18:46 +02:00
)
)
for idx in range(16):
pw.dlog(
2023-10-27 09:58:53 +02:00
"{:<8} {:<10} {:<10.3f} {:<10.3f} {:<10.3f} {:<10.3f}".format(
2023-10-26 20:45:14 +02:00
idx,
star_id[idx],
x_coords[idx],
y_coords[idx],
x_errors[idx],
y_errors[idx],
2023-10-18 16:18:46 +02:00
)
)
2023-10-27 09:58:53 +02:00
assert current_idx == len(hk_data) - 1
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=8))
2023-10-18 16:18:46 +02:00
def handle_auto_blob_set(hk_data: bytes, pw: PrintWrapper):
pw.dlog("Received Auto Blob Set")
2023-10-26 17:48:18 +02:00
if len(hk_data) < 4 + 8 + 4:
raise ValueError(
f"Matched Centroids dataset HK data with length {len(hk_data)} too short. Expected 16 bytes."
)
2023-10-18 16:18:46 +02:00
current_idx = unpack_time_hk(hk_data, 0, pw)
fmt_threshold = "!f"
inc_len = struct.calcsize(fmt_threshold)
threshold = struct.unpack(
fmt_threshold, hk_data[current_idx : current_idx + inc_len]
)[0]
2023-10-27 11:24:39 +02:00
current_idx += inc_len
2023-10-27 09:58:53 +02:00
assert current_idx == len(hk_data) - 1
2023-10-27 11:24:39 +02:00
pw.dlog(f"Threshold {threshold}")
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=3))
2023-10-09 16:31:04 +02:00
2023-10-27 11:24:39 +02:00
def handle_histo_or_contrast_set(name: str, hk_data: bytes, pw: PrintWrapper):
pw.dlog(f"Received {name} Set")
2023-10-27 09:58:53 +02:00
current_idx = unpack_time_hk(hk_data, 0, pw)
fmt_str = "!IIIIIIIII"
bins_list = []
inc_len = struct.calcsize(fmt_str)
a_bins = struct.unpack(fmt_str, hk_data[current_idx : current_idx + inc_len])
bins_list.append(a_bins)
current_idx += inc_len
b_bins = struct.unpack(fmt_str, hk_data[current_idx : current_idx + inc_len])
bins_list.append(b_bins)
current_idx += inc_len
c_bins = struct.unpack(fmt_str, hk_data[current_idx : current_idx + inc_len])
bins_list.append(c_bins)
current_idx += inc_len
d_bins = struct.unpack(fmt_str, hk_data[current_idx : current_idx + inc_len])
bins_list.append(d_bins)
pw.dlog(
2023-10-27 11:24:39 +02:00
f"{name} Sections: A Upper Left | B Upper Right | C Lower Left | D Lower Right"
2023-10-27 09:58:53 +02:00
)
2023-10-27 11:24:39 +02:00
pw.dlog("{:<12} {:<10} {:<10} {:<10} {:<10}".format("Range", "A", "B", "C", "D"))
2023-10-27 10:36:51 +02:00
for idx in range(9):
2023-10-27 09:58:53 +02:00
if idx == 0:
2023-10-27 10:36:51 +02:00
val_range = "0 (0-0)"
elif idx == 1:
val_range = "1 (1-1)"
else:
val_range = f"{idx} ({pow(2, idx - 1)}-{pow(2, idx) - 1})"
2023-10-27 09:58:53 +02:00
pw.dlog(
2023-10-27 11:24:39 +02:00
"{:<12} {:<10} {:<10} {:<10} {:<10}".format(
2023-10-27 10:36:51 +02:00
val_range,
bins_list[0][idx],
bins_list[1][idx],
bins_list[2][idx],
bins_list[3][idx],
2023-10-27 09:58:53 +02:00
)
)
2023-10-27 11:24:39 +02:00
def handle_histogram_set(hk_data: bytes, pw: PrintWrapper):
handle_histo_or_contrast_set("Histogram", hk_data, pw)
def handle_contrast_set(hk_data: bytes, pw: PrintWrapper):
handle_histo_or_contrast_set("Contrast", hk_data, pw)
2023-10-27 09:58:53 +02:00
2024-02-29 12:07:03 +01:00
def handle_blob_stats_set(hk_data: bytes, pw: PrintWrapper):
pw.dlog("Received Blob Stats Set")
if len(hk_data) < 65:
raise ValueError(
f"Matched BlobStats set with length {len(hk_data)} too short. Expected 65 bytes."
)
current_idx = unpack_time_hk(hk_data, 0, pw)
def fill_list(current_idx: int) -> Tuple[List[int], int]:
list_to_fill = []
for _ in range(16):
list_to_fill.append(hk_data[current_idx])
current_idx += 1
return list_to_fill, current_idx
noise_list, current_idx = fill_list(current_idx)
threshold_list, current_idx = fill_list(current_idx)
lvalid_list, current_idx = fill_list(current_idx)
oflow_list, current_idx = fill_list(current_idx)
pw.dlog("Index | Noise | Threshold | LValid | Oflow")
for i in range(16):
pw.dlog(
"{:<3} {:<3} {:<3} {:<3} {:<3}".format(
i, noise_list[i], threshold_list[i], lvalid_list[i], oflow_list[i]
)
)
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[current_idx:], num_vars=6))
2024-02-29 12:07:03 +01:00
2023-10-19 16:52:08 +02:00
def handle_star_tracker_action_replies(
action_id: int, pw: PrintWrapper, custom_data: bytes
):
if action_id == StarTrackerActionId.CHECKSUM:
handle_checksum(pw, custom_data)
elif action_id == StarTrackerActionId.READ_SECONDARY_TM_SET:
handle_read_secondary_tm_set(pw, custom_data)
def handle_checksum(pw: PrintWrapper, custom_data: bytes):
if len(custom_data) != 5:
_LOGGER.warning(
"Star tracker reply has invalid length {0}".format(len(custom_data))
)
return
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]
pw.dlog(f"{header_list}")
pw.dlog(f"{content_list}")
def handle_read_secondary_tm_set(pw: PrintWrapper, custom_data: bytes):
pw.dlog("Received secondary TM Sets")
2023-10-26 16:52:29 +02:00
if len(custom_data) % 4 != 0:
raise ValueError(f"Received data of unexpected length {len(custom_data)}")
data_length = int(len(custom_data) / 4)
fmt_str = "!" + "I" * data_length
2023-10-19 16:52:08 +02:00
inc_len = struct.calcsize(fmt_str)
2023-10-23 15:47:48 +02:00
set_ids = struct.unpack(fmt_str, custom_data[:inc_len])
2023-10-19 16:52:08 +02:00
pw.dlog("The following Datasets are currently Part of the secondary TM list")
2023-10-23 15:47:48 +02:00
for set_id in set_ids:
2023-10-26 16:52:29 +02:00
if set_id in SetId._value2member_map_:
pw.dlog(SetId(set_id).name)
else:
pw.dlog(f"Unknown Set ID {set_id}")
2023-10-19 16:52:08 +02:00
2023-11-28 17:41:46 +01:00
def create_str_node() -> CmdTreeNode:
2024-03-13 10:00:45 +01:00
# Zip the two classes together into a dictionary
op_code_strs = [
getattr(OpCode, key) for key in dir(OpCode) if not key.startswith("__")
]
info_strs = [getattr(Info, key) for key in dir(OpCode) if not key.startswith("__")]
combined_dict = dict(zip(op_code_strs, info_strs))
node = CmdTreeNode(
"str", "Star Tracker Device", hide_children_which_are_leaves=True
)
2024-03-13 10:00:45 +01:00
for op_code, info in combined_dict.items():
node.add_child(CmdTreeNode(op_code, info))
2023-11-28 17:41:46 +01:00
return node