eive-tmtc/pus_tc/pdu2.py

221 lines
8.6 KiB
Python

# -*- coding: utf-8 -*-
"""
@file tmtcc_tc_pdu2.py
@brief PDU2 tests
@details PDU2 is mounted on the X4 slot of the P60 dock
@author J. Meier
@date 17.12.2020
"""
from tmtccmd.config.definitions import QueueCommands
from tmtccmd.tc.packer import TcQueueT
from gomspace.gomspace_common import *
from gomspace.gomspace_pdu_definitions import *
class Pdu2OpCodes(enum.Enum):
ACS_SIDE_B_ON = "1"
ACS_SIDE_B_OFF = "2"
SUS_REDUNDANT_ON = "3"
SUS_REDUNDANT_OFF = "4"
RW_ON = "5"
RW_OFF = "6"
# There is not really a point of the on command, the SW can not be commanded if the OBC is off
Q7S_OFF = "7"
class PDU2TestProcedure:
"""
@brief Use this class to define the tests to perform for the PDU2.
@details Setting all to True will run all tests.
Setting all to False will only run the tests set to True.
"""
all = False
reboot = False
read_gnd_wdt = False
gnd_wdt_reset = False
ping = False
channel_2_off = False # Reaction wheels 5V
read_temperature = False
read_channel_2_state = False # Reaction wheels 5V
read_cur_lu_lim_0 = False # OBC
channel_2_on = False # Reaction wheels 5V
invalid_table_id_test = (
False # Test to check if software properly handles invalid table ids
)
invalid_address_test = (
False # Test to check if software properly handles invalid addresses
)
invalid_parameter_size_test = False
request_hk_table = False
def pack_pdu2_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str):
tc_queue.appendleft((QueueCommands.PRINT, "Testing PDU2"))
if op_code == Pdu2OpCodes.ACS_SIDE_B_ON.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn ACS Side B on"))
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_7.parameter_address,
PDUConfigTable.out_en_7.parameter_size,
Channel.on,
)
tc_queue.appendleft(command.pack_command_tuple())
return tc_queue
if op_code == Pdu2OpCodes.ACS_SIDE_B_OFF.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn ACS Side B off"))
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_7.parameter_address,
PDUConfigTable.out_en_7.parameter_size,
Channel.off,
)
tc_queue.appendleft(command.pack_command_tuple())
return tc_queue
if op_code == Pdu2OpCodes.Q7S_OFF.value:
tc_queue.appendleft((QueueCommands.PRINT, "Turning off Q7S OBC"))
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_0.parameter_address,
PDUConfigTable.out_en_0.parameter_size,
Channel.off,
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == Pdu2OpCodes.SUS_REDUNDANT_ON.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn SUS redundant on"))
command = pack_set_param_command(
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 == Pdu2OpCodes.SUS_REDUNDANT_OFF.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn SUS redundant off"))
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_4.parameter_address,
PDUConfigTable.out_en_4.parameter_size,
Channel.off,
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == Pdu2OpCodes.RW_ON.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn reaction wheels on"))
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_2.parameter_address,
PDUConfigTable.out_en_2.parameter_size,
Channel.on,
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == Pdu2OpCodes.RW_OFF.value:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Turn reaction wheels off"))
command = pack_set_param_command(
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 == GomspaceOpCodes.PRINT_SWITCH_V_I.value:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Print Switches, Currents, Voltahes")
)
command = generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.reboot:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Reboot"))
command = pack_reboot_command(object_id)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.read_gnd_wdt:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Reading ground watchdog timer value")
)
command = pack_get_param_command(
object_id,
TableIds.hk,
PDUHkTable.wdt_gnd_left.parameter_address,
PDUHkTable.wdt_gnd_left.parameter_size,
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.gnd_wdt_reset:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Testing ground watchdog reset")
)
command = pack_gnd_wdt_reset_command(object_id)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.ping:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Ping Test"))
ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
command = pack_ping_command(object_id, ping_data)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.channel_2_on:
tc_queue.appendleft(
(
QueueCommands.PRINT,
"PDU2: Testing setting output channel 2 on (TCS Heater)",
)
)
command = pack_set_param_command(
object_id,
PDUConfigTable.out_en_2.parameter_address,
PDUConfigTable.out_en_2.parameter_size,
Channel.on,
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.read_temperature:
tc_queue.appendleft((QueueCommands.PRINT, "PDU2: Testing temperature reading"))
command = pack_get_param_command(
object_id,
TableIds.hk,
PDUHkTable.temperature.parameter_address,
PDUHkTable.temperature.parameter_size,
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.read_channel_2_state:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Reading output channel 2 state (TCS Heater)")
)
command = pack_get_param_command(
object_id,
TableIds.config,
PDUConfigTable.out_en_2.parameter_address,
PDUConfigTable.out_en_2.parameter_size,
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.read_cur_lu_lim_0:
tc_queue.appendleft(
(
QueueCommands.PRINT,
"PDU2: Reading current limit value of output channel 0 (OBC)",
)
)
command = pack_get_param_command(
object_id,
TableIds.config,
PDUConfigTable.cur_lu_lim_0.parameter_address,
PDUConfigTable.cur_lu_lim_0.parameter_size,
)
tc_queue.appendleft(command.pack_command_tuple())
if PDU2TestProcedure.all or PDU2TestProcedure.channel_2_off:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Testing setting output channel 2 off")
)
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 PDU2TestProcedure.all or PDU2TestProcedure.request_hk_table:
tc_queue.appendleft(
(QueueCommands.PRINT, "PDU2: Requesting housekeeping table")
)
command = pack_request_full_hk_table_command(object_id)
tc_queue.appendleft(command.pack_command_tuple())