from gomspace.gomspace_common import ( pack_set_u8_param_command, Channel, GomspaceOpCodes, GsInfo, GomspaceDeviceActionIds, prompt_and_pack_set_integer_param_command, prompt_and_pack_get_param_command, pack_request_config_command, pack_gnd_wdt_reset_command, ParamTypes, ) from gomspace.gomspace_pdu_definitions import OUT_ENABLE_LIST from spacepackets.ecss import PusTelecommand from tmtccmd.config import OpCodeEntry from tmtccmd.tc import DefaultPusQueueHelper from tmtccmd.tc.pus_3_fsfw_hk import ( make_sid, generate_one_diag_command, generate_one_hk_command, ) from tmtccmd.tc.pus_8_funccmd import make_fsfw_action_cmd from tmtccmd.util import ObjectIdU32, ObjectIdBase class PowerInfo: INFO_CORE = "Core Information" INFO_AUX = "Auxiliary Information" INFO_ALL = "All Information" RESET_ALL_GND_WDTS = "Reset all Ground Watchdogs" class PowerOpCodes: # PDU 1 TCS_ON = ["tcs_on"] TCS_OFF = ["tcs_off"] SYRLINKS_ON = ["syrlinks_on"] SYRLINKS_OFF = ["syrlinks_off"] STAR_TRACKER_ON = ["str_on"] STAR_TRACKER_OFF = ["str_off"] MGT_ON = ["mgt_on"] MGT_OFF = ["mgt_off"] SUS_N_ON = ["sus_nom_on"] SUS_N_OFF = ["sus_nom_off"] SCEX_ON = ["scex_on"] SCEX_OFF = ["scex_off"] PLOC_ON = ["ploc_on"] PLOC_OFF = ["ploc_off"] ACS_A_ON = ["acs_a_on"] ACS_A_OFF = ["acs_a_off"] # PDU 2 PL_PCDU_VBAT_NOM_ON = ["plpcdu_vbat_nom_on"] PL_PCDU_VBAT_NOM_OFF = ["plpcdu_vbat_nom_off"] RW_ON = ["rw_on"] RW_OFF = ["rw_off"] HEATER_ON = ["heater_on"] HEATER_OFF = ["heater_off"] SUS_R_ON = ["sus_red_on"] SUS_R_OFF = ["sus_red_off"] SOLAR_ARRAY_DEPL_ON = ["sa_depl_on"] SOLAR_ARRAY_DEPL_OFF = ["sa_depl_off"] PL_PCDU_VBAT_RED_ON = ["plpcdu_vbat_red_on"] PL_PCDU_VBAT_RED_OFF = ["plpcdu_vbat_red_off"] ACS_B_ON = ["acs_b_on"] ACS_B_OFF = ["acs_b_off"] PL_CAM_ON = ["cam_on"] PL_CAM_OFF = ["cam_off"] INFO_CORE = ["info"] INFO_AUX = ["info_aux"] INFO_ALL = ["info_all"] RESET_ALL_GND_WDTS = ["reset_gnd_wdts"] def pack_gomspace_cmds( prefix: str, object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str ): objb = object_id.as_bytes if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I: q.add_log_cmd(f"{prefix}: {GsInfo.PRINT_SWITCH_V_I}") q.add_pus_tc( make_fsfw_action_cmd( object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I ) ) if op_code in GomspaceOpCodes.PRINT_LATCHUPS: q.add_log_cmd(f"{prefix}: {GsInfo.PRINT_LATCHUPS}") q.add_pus_tc( make_fsfw_action_cmd( object_id=objb, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS ) ) if op_code in GomspaceOpCodes.SET_INTEGER_PARAM: q.add_log_cmd(f"{prefix}: {GsInfo.SET_PARAMETER}") print("Please specify the parameter type from index") for idx, v in enumerate(ParamTypes): print(f"{idx}: {v.name}") ptype = int(input("Index: ")) prompt_and_pack_set_integer_param_command(q, object_id, ParamTypes(ptype)) if op_code in GomspaceOpCodes.GET_PARAM: q.add_log_cmd(f"{prefix}: {GsInfo.GET_PARAMETER}") prompt_and_pack_get_param_command(q, object_id) if op_code in GomspaceOpCodes.REQUEST_CONFIG_TABLE: q.add_log_cmd(f"{prefix}: {GsInfo.REQUEST_CONFIG_TABLE}") q.add_pus_tc(pack_request_config_command(object_id.as_bytes)) if op_code in GomspaceOpCodes.SAVE_TABLE: q.add_log_cmd(f"{prefix}: {GsInfo.SAVE_TABLE}") source_table = int( input( "Source table [0: Board Config, 1: Module Config, " "2: Calibration Parameter, 4: TM Data]: " ) ) if source_table not in [0, 1, 2, 4]: raise ValueError("Invalid source table index") # Not used for now """ target_table = int(input( "Target table. [Default: Source table]: " )) """ q.add_pus_tc( make_fsfw_action_cmd( object_id=object_id.as_bytes, action_id=GomspaceDeviceActionIds.SAVE_TABLE, user_data=bytes([source_table]), ) ) if op_code in GomspaceOpCodes.SAVE_TABLE_DEFAULT: source_table = int( input( "Source table [0: Board Config, 1: Module Config, 2: Calibration Parameter]: " ) ) if source_table not in [0, 1, 2]: raise ValueError("Invalid source table index") q.add_pus_tc( make_fsfw_action_cmd( object_id=object_id.as_bytes, action_id=GomspaceDeviceActionIds.SAVE_TABLE_DEFAULT, user_data=bytes([source_table]), ) ) if op_code in GomspaceOpCodes.LOAD_TABLE: target_table = int( input( "Target table ID [0: Board Config, 1: Module Config, 2: Calibration Parameter, " "4: HK TM]: " ) ) if target_table not in [0, 1, 2, 4]: raise ValueError("Invalid source table index") if target_table != 4: source_table = int( input( "Source table (file or default) [0: Board Config, 1: Module Config, " "2: Calibration Parameter, value + 4 for default table]: " ) ) if source_table not in [0, 1, 2, 4, 5, 6]: raise ValueError("Invalid source table index") else: # Will be ignored source_table = 4 q.add_pus_tc( make_fsfw_action_cmd( object_id=object_id.as_bytes, action_id=GomspaceDeviceActionIds.LOAD_TABLE, user_data=bytes([source_table, target_table]), ) ) if op_code in GomspaceOpCodes.RESET_GND_WATCHDOG: q.add_log_cmd(f"{prefix}: {GsInfo.RESET_GND_WATCHDOG}") q.add_pus_tc(pack_gnd_wdt_reset_command(object_id)) def pack_reset_gnd_wdt_cmd( q: DefaultPusQueueHelper, prefix: str, object_id: ObjectIdBase ): q.add_log_cmd(f"{prefix}: {GsInfo.RESET_GND_WATCHDOG}") q.add_pus_tc(pack_gnd_wdt_reset_command(object_id)) def req_hk_cmds( prefix: str, q: DefaultPusQueueHelper, op_code: str, obj_id: bytes, set_id_pair: [int, int], ): if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE: q.add_log_cmd(f"{prefix}: {GsInfo.REQUEST_CORE_HK_ONCE}") hk_sid = make_sid(object_id=obj_id, set_id=set_id_pair[0]) q.add_pus_tc(generate_one_diag_command(sid=hk_sid)) if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE: q.add_log_cmd(f"{prefix}: {GsInfo.REQUEST_AUX_HK_ONCE}") hk_sid = make_sid(object_id=obj_id, set_id=set_id_pair[1]) q.add_pus_tc(generate_one_hk_command(sid=hk_sid)) def pack_pdu_disable_safe_off_cmd() -> PusTelecommand: pass def generic_on_cmd( object_id: bytes, q: DefaultPusQueueHelper, info_str: str, out_idx: int ): q.add_log_cmd(info_str + " on") q.add_pus_tc( pack_set_u8_param_command( object_id, OUT_ENABLE_LIST[out_idx].parameter_address, Channel.on, ) ) def generic_off_cmd( object_id: bytes, q: DefaultPusQueueHelper, info_str: str, out_idx: int ): q.add_log_cmd(info_str + " off") q.add_pus_tc( pack_set_u8_param_command( object_id, OUT_ENABLE_LIST[out_idx].parameter_address, Channel.off, ) ) def add_gomspace_cmd_defs(oce: OpCodeEntry): oce.add( keys=GomspaceOpCodes.REQUEST_CORE_HK_ONCE, info=GsInfo.REQUEST_CORE_HK_ONCE, ) oce.add( keys=GomspaceOpCodes.REQUEST_AUX_HK_ONCE, info=GsInfo.REQUEST_AUX_HK_ONCE, ) oce.add(keys=GomspaceOpCodes.GET_PARAM, info=GsInfo.GET_PARAMETER) oce.add(keys=GomspaceOpCodes.PRINT_LATCHUPS, info=GsInfo.PRINT_LATCHUPS) oce.add(keys=GomspaceOpCodes.SET_INTEGER_PARAM, info=GsInfo.SET_PARAMETER) oce.add(keys=GomspaceOpCodes.REQUEST_CONFIG_TABLE, info=GsInfo.REQUEST_CONFIG_TABLE) oce.add(keys=GomspaceOpCodes.SAVE_TABLE, info=GsInfo.SAVE_TABLE) oce.add(keys=GomspaceOpCodes.SAVE_TABLE_DEFAULT, info=GsInfo.SAVE_TABLE_DEFAULT) oce.add(keys=GomspaceOpCodes.LOAD_TABLE, info=GsInfo.LOAD_TABLE) oce.add(keys=GomspaceOpCodes.RESET_GND_WATCHDOG, info=GsInfo.RESET_GND_WATCHDOG)