eive-tmtc/eive_tmtc/tmtc/power/acu.py

201 lines
7.2 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-11-14 10:56:14 +01:00
import struct
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.pus_tm.defs import PrintWrapper
from eive_tmtc.tmtc.power.common_power import (
2023-11-29 17:04:30 +01:00
add_gomspace_nodes,
2022-10-18 10:44:32 +02:00
pack_common_gomspace_cmds,
2022-08-27 16:28:33 +02:00
add_gomspace_cmd_defs,
req_hk_cmds,
2022-10-18 10:44:32 +02:00
pack_common_power_cmds,
2023-01-12 15:48:49 +01:00
SetId,
2022-11-14 10:56:14 +01:00
OBC_ENDIANNESS,
unpack_array_in_data,
2022-08-27 16:28:33 +02:00
)
2023-11-29 17:04:30 +01:00
from tmtccmd.config import CmdTreeNode, TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
2022-07-04 15:22:53 +02:00
2023-11-10 19:23:06 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
2022-11-29 16:53:29 +01:00
import eive_tmtc.gomspace.gomspace_common as gs
from eive_tmtc.config.object_ids import ACU_HANDLER_ID
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2022-05-23 11:24:55 +02:00
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)
2023-01-16 14:13:06 +01:00
class OpCode:
2022-05-23 11:24:55 +02:00
TEST = ["0", "test"]
class Info:
TEST = "ACU Test"
2023-11-29 17:04:30 +01:00
def create_acu_node() -> CmdTreeNode:
node = CmdTreeNode(
"acu", "P60 PCDU ACU device", hide_children_which_are_leaves=True
)
add_gomspace_nodes(node)
node.add_child(CmdTreeNode(OpCode.TEST[0], Info.TEST))
return node
@tmtc_definitions_provider
def add_acu_cmds(defs: TmtcDefinitionWrapper):
2022-07-05 02:12:54 +02:00
oce = OpCodeEntry()
2022-08-27 01:01:04 +02:00
add_gomspace_cmd_defs(oce)
2022-08-27 16:28:33 +02:00
2023-01-16 14:13:06 +01:00
oce.add(keys=OpCode.TEST, info=Info.TEST)
2022-07-05 02:12:54 +02:00
defs.add_service(
2022-05-23 11:24:55 +02:00
name=CustomServiceList.ACU.value,
2022-05-23 11:25:33 +02:00
info="ACU Device",
2022-07-05 02:12:54 +02:00
op_code_entry=oce,
2022-05-23 11:24:55 +02:00
)
2023-11-22 10:17:05 +01:00
def pack_acu_commands(object_id: ObjectIdU32, q: DefaultPusQueueHelper, cmd_str: str):
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Handling ACU command")
2023-11-22 10:17:05 +01:00
pack_common_power_cmds("ACU", object_id, q, cmd_str)
pack_common_gomspace_cmds("ACU", object_id, q, cmd_str)
acu_req_hk_cmds(q, cmd_str)
2022-07-04 15:22:53 +02:00
pack_test_cmds(object_id=object_id, q=q)
2022-05-23 11:24:55 +02:00
2020-12-29 11:29:03 +01:00
2022-08-27 16:28:33 +02:00
def acu_req_hk_cmds(q: DefaultPusQueueHelper, op_code: str):
2024-05-08 10:49:20 +02:00
req_hk_cmds("ACU", q, op_code, ACU_HANDLER_ID, (SetId.CORE, SetId.AUX))
2022-08-27 16:28:33 +02:00
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-08-08 16:32:18 +02:00
def pack_test_cmds(object_id: ObjectIdU32, q: DefaultPusQueueHelper):
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.reboot:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reboot")
q.add_pus_tc(gs.pack_reboot_command(object_id))
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_gnd_wdt:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading ground watchdog timer value")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.HK,
2022-07-04 15:22:53 +02:00
ACUHkTable.wdt_gnd_left.parameter_address,
ACUHkTable.wdt_gnd_left.parameter_size,
)
2021-08-03 15:28:28 +02:00
)
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.gnd_wdt_reset:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Testing ground watchdog reset")
q.add_pus_tc(gs.pack_gnd_wdt_reset_command(object_id))
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.ping:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("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-07-04 15:22:53 +02:00
q.add_pus_tc(gs.pack_ping_command(object_id, ping_data))
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_temperature3:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading temperature 3")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.HK,
2022-07-04 15:22:53 +02:00
ACUHkTable.temperature3.parameter_address,
ACUHkTable.temperature3.parameter_size,
)
2022-01-18 14:03:56 +01:00
)
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_vboost:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading vboost value")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.CONFIG,
2022-07-04 15:22:53 +02:00
ACUConfigTable.vboost.parameter_address,
ACUConfigTable.vboost.parameter_size,
)
2022-01-18 14:03:56 +01:00
)
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_hi:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading vbat_max_hi")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.CONFIG,
2022-07-04 15:22:53 +02:00
ACUConfigTable.vbat_max_hi.parameter_address,
ACUConfigTable.vbat_max_hi.parameter_size,
)
2022-01-18 14:03:56 +01:00
)
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_vbat_max_lo:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading vbat_max_lo")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.CONFIG,
2022-07-04 15:22:53 +02:00
ACUConfigTable.vbat_max_lo.parameter_address,
ACUConfigTable.vbat_max_lo.parameter_size,
)
2022-01-18 14:03:56 +01:00
)
2020-12-29 11:29:03 +01:00
if ACUTestProcedure.all or ACUTestProcedure.read_ov_mode:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("ACU: Reading ov_mode")
q.add_pus_tc(
gs.pack_get_param_command(
object_id.as_bytes,
2022-09-01 16:58:31 +02:00
gs.TableIds.CONFIG,
2022-07-04 15:22:53 +02:00
ACUConfigTable.ov_mode.parameter_address,
ACUConfigTable.ov_mode.parameter_size,
)
2022-01-18 14:03:56 +01:00
)
2022-11-14 10:56:14 +01:00
def acu_config_table_handler(pw: PrintWrapper, custom_data: bytes):
mppt_mode = custom_data[0]
mppt_delta_mode = custom_data[1]
vboost_list = unpack_array_in_data(custom_data, 0x02, 2, 6, "H")
vbat_max_hi = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x10 : 0x10 + 2])[0]
vbat_max_lo = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x12 : 0x12 + 2])[0]
mppt_period = struct.unpack(f"{OBC_ENDIANNESS}I", custom_data[0x14 : 0x14 + 4])[0]
max_dv = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x18 : 0x18 + 2])[0]
ov_mode = custom_data[0x1A]
pw.dlog(f"{'mppt_mode'.ljust(15)}: {mppt_mode}")
pw.dlog(f"{'mppt_delta_mode'.ljust(15)}: {mppt_delta_mode}")
pw.dlog(f"{'vboost_list'.ljust(15)}: {vboost_list}")
pw.dlog(f"{'vbat_max_hi'.ljust(15)}: {vbat_max_hi}")
pw.dlog(f"{'vbat_max_lo'.ljust(15)}: {vbat_max_lo}")
pw.dlog(f"{'mppt_period'.ljust(15)}: {mppt_period}")
pw.dlog(f"{'max_dv'.ljust(15)}: {max_dv}")
pw.dlog(f"{'ov_mode'.ljust(15)}: {ov_mode}")