eive-tmtc/pus_tc/devs/p60dock.py

305 lines
13 KiB
Python
Raw Normal View History

2020-12-29 11:29:03 +01:00
# -*- coding: utf-8 -*-
"""
@file tmtcc_tc_p60dock.py
@brief P60 Dock tests
@author J. Meier
@date 13.12.2020
"""
2021-05-17 17:42:04 +02:00
from tmtccmd.config.definitions import QueueCommands
from tmtccmd.tc.packer import TcQueueT
from tmtccmd.tc.service_3_housekeeping import generate_one_hk_command, make_sid
2020-12-29 11:29:03 +01:00
from gomspace.gomspace_common import *
from config.object_ids import P60_DOCK_HANDLER
2020-12-29 11:29:03 +01:00
2021-09-20 11:47:04 +02:00
class P60OpCodes(enum.Enum):
TEST = "0"
STACK_3V3_ON = "1"
STACK_3V3_OFF = "2"
2022-01-27 15:59:19 +01:00
STACK_5V_ON = "3"
STACK_5V_OFF = "4"
2021-09-20 11:47:04 +02:00
2020-12-29 11:29:03 +01:00
class P60DockTestProcedure:
"""
@brief Use this class to define the tests to perform for the P60Dock.
@details Setting all to True will run all tests.
Setting all to False will only run the tests set to True.
"""
2022-01-18 14:03:56 +01:00
2021-02-09 12:35:10 +01:00
all = False
2020-12-29 11:29:03 +01:00
reboot = False
read_gnd_wdt = False
gnd_wdt_reset = False
ping = False
channel_3_off = False # pdu2
2022-01-27 15:59:19 +01:00
read_temperature1 = False
2020-12-29 11:29:03 +01:00
read_channel_3_state = False # pdu2
read_cur_lu_lim_0 = False
channel_3_on = False # pdu2
2022-01-18 14:03:56 +01:00
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
)
2021-02-09 12:35:10 +01:00
invalid_parameter_size_test = False
2020-12-29 11:29:03 +01:00
class P60DockConfigTable:
2021-08-17 11:49:37 +02:00
out_en_0 = TableEntry(bytearray([0x00, 0x68]), TableEntry.uint8_size) # ACU VCC
out_en_1 = TableEntry(bytearray([0x00, 0x69]), TableEntry.uint8_size) # PDU1 VCC
out_en_2 = TableEntry(bytearray([0x00, 0x6A]), TableEntry.uint8_size) # unused
out_en_3 = TableEntry(bytearray([0x00, 0x6B]), TableEntry.uint8_size) # PDU2 VCC
out_en_4 = TableEntry(bytearray([0x00, 0x6C]), TableEntry.uint8_size) # ACU VBAT
out_en_5 = TableEntry(bytearray([0x00, 0x6D]), TableEntry.uint8_size) # unused
out_en_6 = TableEntry(bytearray([0x00, 0x6E]), TableEntry.uint8_size) # PDU1 VBAT
out_en_7 = TableEntry(bytearray([0x00, 0x6F]), TableEntry.uint8_size) # PDU2 VBAT
out_en_8 = TableEntry(bytearray([0x00, 0x70]), TableEntry.uint8_size) # Stack VBAT
out_en_9 = TableEntry(bytearray([0x00, 0x71]), TableEntry.uint8_size) # Stack 3V3
out_en_10 = TableEntry(bytearray([0x00, 0x72]), TableEntry.uint8_size) # Stack 5V
2022-01-18 14:03:56 +01:00
out_en_11 = TableEntry(
bytearray([0x00, 0x73]), TableEntry.uint8_size
) # GS 3V3 (unused)
out_en_12 = TableEntry(
bytearray([0x00, 0x74]), TableEntry.uint8_size
) # GS 5V (unused)
2020-12-29 11:29:03 +01:00
# When channel consumes more than cur_lu_lim, channel is turned of immediately
cur_lu_lim_0 = TableEntry(bytearray([0x00, 0xF8]), TableEntry.uint16_size)
class P60DockHkTable:
temperature1 = TableEntry(bytearray([0x00, 0x44]), TableEntry.uint16_size)
temperature2 = TableEntry(bytearray([0x00, 0x46]), TableEntry.uint16_size)
# Ground WDT value (remaining seconds until reboot)
wdt_gnd_left = TableEntry(bytearray([0x00, 0xA8]), TableEntry.uint32_size)
2021-09-20 11:47:04 +02:00
def pack_p60dock_test_into(object_id: bytearray, tc_queue: TcQueueT, op_code: str):
if op_code == P60OpCodes.STACK_3V3_ON.value:
2021-08-17 11:49:37 +02:00
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning stack 3V3 on"))
2021-09-08 13:20:22 +02:00
command = pack_set_param_command(
2022-01-18 14:03:56 +01:00
object_id,
P60DockConfigTable.out_en_9.parameter_address,
P60DockConfigTable.out_en_9.parameter_size,
Channel.on,
2021-09-08 13:20:22 +02:00
)
2021-08-17 11:49:37 +02:00
tc_queue.appendleft(command.pack_command_tuple())
2021-09-20 11:47:04 +02:00
if op_code == P60OpCodes.STACK_3V3_OFF.value:
2021-08-17 11:49:37 +02:00
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning stack 3V3 off"))
2021-09-08 13:20:22 +02:00
command = pack_set_param_command(
2022-01-18 14:03:56 +01:00
object_id,
P60DockConfigTable.out_en_9.parameter_address,
P60DockConfigTable.out_en_9.parameter_size,
Channel.off,
2021-09-08 13:20:22 +02:00
)
2021-08-17 11:49:37 +02:00
tc_queue.appendleft(command.pack_command_tuple())
2022-01-27 15:59:19 +01:00
if op_code == P60OpCodes.STACK_5V_ON.value:
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning stack 5V on"))
command = pack_set_param_command(
object_id,
P60DockConfigTable.out_en_10.parameter_address,
P60DockConfigTable.out_en_10.parameter_size,
Channel.on,
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == P60OpCodes.STACK_5V_OFF.value:
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning stack 5V off"))
command = pack_set_param_command(
object_id,
P60DockConfigTable.out_en_10.parameter_address,
P60DockConfigTable.out_en_10.parameter_size,
Channel.off,
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code == GomspaceOpCodes.REQUEST_HK_ONCE.value:
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Requesting HK Table Once"))
hk_sid = make_sid(object_id=P60_DOCK_HANDLER, set_id=SetIds.P60_DOCK)
command = generate_one_hk_command(sid=hk_sid, ssc=0)
tc_queue.appendleft(command.pack_command_tuple())
2021-09-20 11:47:04 +02:00
if op_code == GomspaceOpCodes.PRINT_SWITCH_V_I.value:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Print Switches, Voltages, Currents")
)
2021-09-20 11:47:04 +02:00
command = generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.PRINT_SWITCH_V_I
)
tc_queue.appendleft(command.pack_command_tuple())
2022-03-14 14:46:00 +01:00
if op_code == GomspaceOpCodes.PRINT_LATCHUPS.value:
2022-03-16 18:44:28 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Print Latchups"))
2022-03-14 14:46:00 +01:00
command = generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.PRINT_LATCHUPS
)
tc_queue.appendleft(command.pack_command_tuple())
2020-12-29 11:29:03 +01:00
if P60DockTestProcedure.all or P60DockTestProcedure.reboot:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Reboot"))
2020-12-29 11:29:03 +01:00
command = pack_reboot_command(object_id)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.read_gnd_wdt:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Reading ground watchdog timer value")
)
2021-02-03 14:14:54 +01:00
command = pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id,
TableIds.hk,
P60DockHkTable.wdt_gnd_left.parameter_address,
P60DockHkTable.wdt_gnd_left.parameter_size,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.gnd_wdt_reset:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Testing ground watchdog reset")
)
2020-12-29 11:29:03 +01:00
command = pack_gnd_wdt_reset_command(object_id)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.ping:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Ping"))
2020-12-29 11:29:03 +01:00
ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
command = pack_ping_command(object_id, ping_data)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_off:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Testing setting output channel 3 off")
)
2020-12-29 11:29:03 +01:00
parameter = 0 # set channel off
2022-01-18 14:03:56 +01:00
command = pack_set_param_command(
object_id,
P60DockConfigTable.out_en_3.parameter_address,
P60DockConfigTable.out_en_3.parameter_size,
parameter,
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.read_temperature1:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
2022-01-27 15:59:19 +01:00
(QueueCommands.PRINT, "P60 Dock: Testing temperature reading")
2022-01-18 14:03:56 +01:00
)
2021-02-03 14:14:54 +01:00
command = pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id,
TableIds.hk,
P60DockHkTable.temperature1.parameter_address,
P60DockHkTable.temperature1.parameter_size,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_on:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Testing Output Channel 3 state (PDU2)")
)
command = pack_get_param_command(
object_id,
TableIds.config,
P60DockConfigTable.out_en_3.parameter_address,
P60DockConfigTable.out_en_3.parameter_size,
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=25, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.read_cur_lu_lim_0:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(
QueueCommands.PRINT,
"P60 Dock: Reading current limit value of output channel 0",
)
)
2021-02-03 14:14:54 +01:00
command = pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id,
TableIds.config,
P60DockConfigTable.cur_lu_lim_0.parameter_address,
P60DockConfigTable.cur_lu_lim_0.parameter_size,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=26, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.channel_3_on:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Testing setting output channel 3 on")
)
2020-12-29 11:29:03 +01:00
parameter = 1 # set channel on
2022-01-18 14:03:56 +01:00
command = pack_set_param_command(
object_id,
P60DockConfigTable.out_en_3.parameter_address,
P60DockConfigTable.out_en_3.parameter_size,
parameter,
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=27, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.invalid_table_id_test:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "P60 Dock: Testing invalid table id handling")
)
2020-12-29 11:29:03 +01:00
table_id_invalid = 5
2021-02-03 14:14:54 +01:00
command = pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id,
table_id_invalid,
P60DockHkTable.temperature1.parameter_address,
P60DockHkTable.temperature1.parameter_size,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=28, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.invalid_address_test:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(
QueueCommands.PRINT,
"P60 Dock: Testing invalid address handling in get param command",
)
)
2020-12-29 11:29:03 +01:00
invalid_address = bytearray([0x01, 0xF4])
2022-01-18 14:03:56 +01:00
command = pack_get_param_command(
object_id,
TableIds.hk,
invalid_address,
P60DockHkTable.temperature1.parameter_size,
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=29, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(
QueueCommands.PRINT,
"P60 Dock: Testing invalid address handling in set param command",
)
)
2020-12-29 11:29:03 +01:00
invalid_address = bytearray([0x01, 0xF4])
parameter_size = 2
parameter = 1
2022-01-18 14:03:56 +01:00
command = pack_set_param_command(
object_id, invalid_address, parameter_size, parameter
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=30, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
if P60DockTestProcedure.all or P60DockTestProcedure.invalid_parameter_size_test:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft(
2022-01-18 14:03:56 +01:00
(
QueueCommands.PRINT,
"P60 Dock: Testing handling of invalid parameter sizes in get-param command",
)
2021-02-03 14:14:54 +01:00
)
2020-12-29 11:29:03 +01:00
invalid_size = 5
2021-02-03 14:14:54 +01:00
command = pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id,
TableIds.hk,
P60DockHkTable.temperature1.parameter_address,
invalid_size,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=31, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
2021-02-03 14:14:54 +01:00
tc_queue.appendleft(
2022-01-18 14:03:56 +01:00
(
QueueCommands.PRINT,
"P60 Dock: Testing handling of invalid parameter size in set-param command",
)
2021-02-03 14:14:54 +01:00
)
2020-12-29 11:29:03 +01:00
parameter = 1
2021-02-03 14:14:54 +01:00
command = pack_set_param_command(
2022-01-18 14:03:56 +01:00
object_id,
P60DockConfigTable.out_en_3.parameter_address,
invalid_size,
parameter,
2021-02-03 14:14:54 +01:00
)
2021-09-08 13:20:22 +02:00
# command = PusTelecommand(service=8, subservice=128, ssc=32, app_data=command)
2020-12-29 11:29:03 +01:00
tc_queue.appendleft(command.pack_command_tuple())
return tc_queue