some restructuring

This commit is contained in:
Robin Müller 2022-11-14 10:56:14 +01:00
parent 89285ad511
commit 6db683b831
4 changed files with 65 additions and 35 deletions

View File

@ -21,4 +21,26 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration default="false" name="ACU" type="PythonConfigurationType" factoryName="Python" folderName="Power">
<module name="tmtc" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtcc.py" />
<option name="PARAMETERS" value="-s acu -l" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="true" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

View File

@ -3,14 +3,18 @@
@author J. Meier, R. Mueller
@date 21.12.2020
"""
import struct
from config.definitions import CustomServiceList
from pus_tm.defs import PrintWrapper
from tmtc.power.common_power import (
pack_common_gomspace_cmds,
add_gomspace_cmd_defs,
req_hk_cmds,
pack_common_power_cmds,
SetIds,
OBC_ENDIANNESS,
unpack_array_in_data,
)
from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
@ -165,3 +169,22 @@ def pack_test_cmds(object_id: ObjectIdU32, q: DefaultPusQueueHelper):
ACUConfigTable.ov_mode.parameter_size,
)
)
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}")

View File

@ -1,3 +1,6 @@
import struct
from typing import List
from gomspace.gomspace_common import (
pack_set_u8_param_command,
Channel,
@ -309,3 +312,18 @@ def add_gomspace_cmd_defs(oce: OpCodeEntry):
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)
OBC_ENDIANNESS = "<"
def unpack_array_in_data(
data: bytes, start_addr: int, width: int, entries: int, struct_spec: str
) -> List:
return [
struct.unpack(
f"{OBC_ENDIANNESS}{struct_spec}",
data[start_addr + (i * width) : start_addr + ((i + 1) * width)],
)[0]
for i in range(entries)
]

View File

@ -1,7 +1,8 @@
import struct
from typing import List, Tuple
from tmtc.power.common_power import SetIds
from tmtc.power.acu import acu_config_table_handler
from tmtc.power.common_power import SetIds, unpack_array_in_data, OBC_ENDIANNESS
from tmtccmd.util import ObjectIdBase
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
from pus_tm.defs import PrintWrapper
@ -431,9 +432,6 @@ def handle_acu_hk_data(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes):
printer.print_validity_buffer(validity_buffer=hk_data[current_idx:], num_vars=8)
OBC_ENDIANNESS = "<"
def handle_get_param_data_reply(
obj_id: ObjectIdBase, action_id: int, pw: PrintWrapper, custom_data: bytearray
):
@ -514,25 +512,6 @@ def pdu_config_table_handler(
pw.dlog(f"{'wdt_can'.ljust(15)}: {wdt_can}")
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}")
def p60_dock_config_table_handler(pw: PrintWrapper, custom_data: bytes):
ch_names = parse_name_list(custom_data[0:0x68], 13)
out_on_cnt = unpack_array_in_data(custom_data, 0x76, 2, 13, "H")
@ -571,15 +550,3 @@ def parse_name_list(data: bytes, name_len: int):
idx += len(name)
idx += 1
return ch_list
def unpack_array_in_data(
data: bytes, start_addr: int, width: int, entries: int, struct_spec: str
) -> List:
return [
struct.unpack(
f"{OBC_ENDIANNESS}{struct_spec}",
data[start_addr + (i * width) : start_addr + ((i + 1) * width)],
)[0]
for i in range(entries)
]