eive-tmtc/pus_tc/devs/acu.py

216 lines
9.0 KiB
Python
Raw Normal View History

2020-12-29 11:29:03 +01:00
# -*- coding: utf-8 -*-
2022-05-23 11:24:55 +02:00
"""ACU commands
@author J. Meier, R. Mueller
2020-12-29 11:29:03 +01:00
@date 21.12.2020
"""
2022-05-23 11:24:55 +02:00
from config.definitions import CustomServiceList
from tmtccmd.config import add_op_code_entry, add_service_op_code_entry
from tmtccmd.tc.packer import TcQueueT
2022-05-23 11:24:55 +02:00
from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT
2022-05-23 11:25:33 +02:00
from tmtccmd.tc.pus_3_fsfw_hk import (
make_sid,
generate_one_diag_command,
generate_one_hk_command,
)
2022-05-23 11:24:55 +02:00
import gomspace.gomspace_common as gs
from gomspace.gomspace_common import GomspaceOpCodes
from gomspace.gomspace_common import Info as GsInfo
from config.object_ids import ACU_HANDLER_ID
2022-03-04 11:02:10 +01:00
from pus_tc.devs.p60dock import P60DockConfigTable
2022-05-23 11:24:55 +02:00
from tmtccmd.tc.pus_8_funccmd import generate_action_command
from tmtccmd.utility import ObjectId
class ACUConfigTable:
mppt_mode = gs.TableEntry(bytearray([0x00, 0x00]), gs.TableEntry.uint8_size)
mppt_d_mode = gs.TableEntry(bytearray([0x00, 0x01]), gs.TableEntry.uint8_size)
vboost = gs.TableEntry(bytearray([0x00, 0x02]), gs.TableEntry.uint16_size)
vbat_max_hi = gs.TableEntry(bytearray([0x00, 0x10]), gs.TableEntry.uint16_size)
vbat_max_lo = gs.TableEntry(bytearray([0x00, 0x12]), gs.TableEntry.uint16_size)
ov_mode = gs.TableEntry(bytearray([0x00, 0x1A]), gs.TableEntry.uint8_size)
class ACUHkTable:
temperature1 = gs.TableEntry(bytearray([0x00, 0x1C]), gs.TableEntry.uint16_size)
temperature2 = gs.TableEntry(bytearray([0x00, 0x1D]), gs.TableEntry.uint16_size)
temperature3 = gs.TableEntry(bytearray([0x00, 0x1E]), gs.TableEntry.uint16_size)
# Ground WDT value (remaining seconds until reboot)
wdt_gnd_left = gs.TableEntry(bytearray([0x00, 0x74]), gs.TableEntry.uint32_size)
class OpCodes:
TEST = ["0", "test"]
class Info:
TEST = "ACU Test"
def add_acu_cmds(cmd_dict: ServiceOpCodeDictT):
op_code_dict = dict()
add_op_code_entry(
op_code_dict=op_code_dict,
keys=GomspaceOpCodes.REQUEST_CORE_HK_ONCE,
2022-05-23 11:25:33 +02:00
info=GsInfo.REQUEST_CORE_HK_ONCE,
2022-05-23 11:24:55 +02:00
)
add_op_code_entry(
op_code_dict=op_code_dict,
keys=GomspaceOpCodes.REQUEST_AUX_HK_ONCE,
2022-05-23 11:25:33 +02:00
info=GsInfo.REQUEST_AUX_HK_ONCE,
2022-05-23 11:24:55 +02:00
)
add_op_code_entry(
op_code_dict=op_code_dict,
keys=GomspaceOpCodes.REQUEST_AUX_HK_ONCE,
2022-05-23 11:25:33 +02:00
info=GsInfo.REQUEST_AUX_HK_ONCE,
2022-05-23 11:24:55 +02:00
)
2022-05-23 11:25:33 +02:00
add_op_code_entry(op_code_dict=op_code_dict, keys=OpCodes.TEST, info=Info.TEST)
2022-05-23 11:24:55 +02:00
add_service_op_code_entry(
srv_op_code_dict=cmd_dict,
op_code_entry=op_code_dict,
name=CustomServiceList.ACU.value,
2022-05-23 11:25:33 +02:00
info="ACU Device",
2022-05-23 11:24:55 +02:00
)
def pack_acu_commands(
object_id: ObjectId, tc_queue: TcQueueT, op_code: str
) -> TcQueueT:
tc_queue.appendleft((QueueCommands.PRINT, "Handling ACU command"))
if op_code in GomspaceOpCodes.PRINT_SWITCH_V_I:
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Print channel stats"))
command = generate_action_command(
object_id=object_id.as_bytes,
2022-05-23 11:25:33 +02:00
action_id=gs.GomspaceDeviceActionIds.PRINT_SWITCH_V_I,
2022-05-23 11:24:55 +02:00
)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in GomspaceOpCodes.REQUEST_CORE_HK_ONCE:
2022-05-23 11:25:33 +02:00
tc_queue.appendleft(
(QueueCommands.PRINT, f"PDU1: {GsInfo.REQUEST_CORE_HK_ONCE}")
)
2022-05-23 11:24:55 +02:00
hk_sid = make_sid(object_id=object_id.as_bytes, set_id=gs.SetIds.ACU_CORE)
command = generate_one_diag_command(sid=hk_sid, ssc=0)
tc_queue.appendleft(command.pack_command_tuple())
if op_code in GomspaceOpCodes.REQUEST_AUX_HK_ONCE:
2022-05-23 11:25:33 +02:00
tc_queue.appendleft(
(QueueCommands.PRINT, f"PDU1: {GsInfo.REQUEST_AUX_HK_ONCE}")
)
2022-05-23 11:24:55 +02:00
hk_sid = make_sid(object_id=object_id.as_bytes, set_id=gs.SetIds.ACU_AUX)
command = generate_one_hk_command(sid=hk_sid, ssc=0)
tc_queue.appendleft(command.pack_command_tuple())
pack_test_cmds(object_id=object_id, tc_queue=tc_queue)
return tc_queue
2020-12-29 11:29:03 +01:00
class ACUTestProcedure:
"""
@brief Use this class to define the tests to perform for the ACU.
@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
2020-12-29 11:29:03 +01:00
all = False
reboot = False
read_gnd_wdt = False
gnd_wdt_reset = False
ping = False
read_temperature1 = False
read_temperature2 = False
2022-05-23 11:24:55 +02:00
read_temperature3 = False
read_mppt_mode = False
read_vboost = False
read_vbat_max_hi = False
read_vbat_max_lo = False
read_ov_mode = False
off = False
2020-12-29 11:29:03 +01:00
2022-05-23 11:24:55 +02:00
def pack_test_cmds(object_id: ObjectId, tc_queue: TcQueueT):
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.reboot:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reboot"))
2022-05-23 11:24:55 +02:00
command = gs.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 ACUTestProcedure.all or ACUTestProcedure.read_gnd_wdt:
2022-01-18 14:03:56 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, "ACU: Reading ground watchdog timer value")
)
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.hk,
2022-01-18 14:03:56 +01:00
ACUHkTable.wdt_gnd_left.parameter_address,
ACUHkTable.wdt_gnd_left.parameter_size,
2021-08-03 15:28:28 +02: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 ACUTestProcedure.all or ACUTestProcedure.gnd_wdt_reset:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Testing ground watchdog reset"))
2022-05-23 11:24:55 +02:00
command = gs.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 ACUTestProcedure.all or ACUTestProcedure.ping:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Ping Test"))
2020-12-29 11:29:03 +01:00
ping_data = bytearray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
2022-05-23 11:24:55 +02:00
command = gs.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 ACUTestProcedure.all or ACUTestProcedure.read_temperature3:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading temperature 3"))
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.hk,
2022-01-18 14:03:56 +01:00
ACUHkTable.temperature3.parameter_address,
ACUHkTable.temperature3.parameter_size,
)
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 ACUTestProcedure.all or ACUTestProcedure.read_vboost:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vboost value"))
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.config,
2022-01-18 14:03:56 +01:00
ACUConfigTable.vboost.parameter_address,
ACUConfigTable.vboost.parameter_size,
)
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 ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_hi:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vbat_max_hi"))
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.config,
2022-01-18 14:03:56 +01:00
ACUConfigTable.vbat_max_hi.parameter_address,
ACUConfigTable.vbat_max_hi.parameter_size,
)
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 ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_lo:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading vbat_max_lo"))
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.config,
2022-01-18 14:03:56 +01:00
ACUConfigTable.vbat_max_lo.parameter_address,
ACUConfigTable.vbat_max_lo.parameter_size,
)
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 ACUTestProcedure.all or ACUTestProcedure.read_ov_mode:
2021-02-03 14:14:54 +01:00
tc_queue.appendleft((QueueCommands.PRINT, "ACU: Reading ov_mode"))
2022-05-23 11:24:55 +02:00
command = gs.pack_get_param_command(
object_id.as_bytes,
gs.TableIds.config,
2022-01-18 14:03:56 +01:00
ACUConfigTable.ov_mode.parameter_address,
ACUConfigTable.ov_mode.parameter_size,
)
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())
2022-05-23 11:24:55 +02:00
if ACUTestProcedure.all or ACUTestProcedure.off:
tc_queue.appendleft((QueueCommands.PRINT, "P60 Dock: Turning off ACU"))
command = gs.pack_set_param_command(
ACU_HANDLER_ID,
P60DockConfigTable.out_en_0.parameter_address,
P60DockConfigTable.out_en_0.parameter_size,
gs.Channel.off,
)
2022-05-23 11:25:33 +02:00
tc_queue.appendleft(command.pack_command_tuple())