acu hk parsing

This commit is contained in:
Robin Müller 2022-08-27 16:45:35 +02:00
parent ce837353ca
commit cd21267796
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -461,6 +461,12 @@ def handle_get_param_data_reply(
elif action_id == GomspaceDeviceActionIds.REQUEST_CONFIG_TABLE:
print(f"Received config table with size {len(custom_data)} for object {obj_id}")
if obj_id.as_bytes == PDU_1_HANDLER_ID or obj_id.as_bytes == PDU_2_HANDLER_ID:
pdu_config_table_handler(pw, custom_data)
elif obj_id.as_bytes == ACU_HANDLER_ID:
acu_config_table_handler(pw, custom_data)
def pdu_config_table_handler(pw: PrintWrapper, custom_data: bytes):
out_on_cnt = unpack_array_in_data(custom_data, 0x52, 2, 9, "H")
out_off_cnt = unpack_array_in_data(custom_data, 0x64, 2, 9, "H")
init_out_norm = unpack_array_in_data(custom_data, 0x76, 1, 9, "B")
@ -468,21 +474,11 @@ def handle_get_param_data_reply(
init_on_dly = unpack_array_in_data(custom_data, 0x8A, 2, 9, "H")
init_off_dly = unpack_array_in_data(custom_data, 0x9C, 2, 9, "H")
safe_off_dly = unpack_array_in_data(custom_data, 0xAE, 1, 9, "B")
batt_hwmax = struct.unpack(
f"{OBC_ENDIANNESS}H", custom_data[0x11C : 0x11C + 2]
)[0]
batt_max = struct.unpack(
f"{OBC_ENDIANNESS}H", custom_data[0x11E : 0x11E + 2]
)[0]
batt_norm = struct.unpack(
f"{OBC_ENDIANNESS}H", custom_data[0x120 : 0x120 + 2]
)[0]
batt_safe = struct.unpack(
f"{OBC_ENDIANNESS}H", custom_data[0x122 : 0x122 + 2]
)[0]
batt_crit = struct.unpack(
f"{OBC_ENDIANNESS}H", custom_data[0x124 : 0x124 + 2]
)[0]
batt_hwmax = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x11C : 0x11C + 2])[0]
batt_max = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x11E : 0x11E + 2])[0]
batt_norm = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x120 : 0x120 + 2])[0]
batt_safe = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x122 : 0x122 + 2])[0]
batt_crit = struct.unpack(f"{OBC_ENDIANNESS}H", custom_data[0x124 : 0x124 + 2])[0]
pw.dlog(f"{'out_on_cnt'.ljust(15)}: {out_on_cnt}")
pw.dlog(f"{'out_off_cnt'.ljust(15)}: {out_off_cnt}")
pw.dlog(f"{'init_out_norm'.ljust(15)}: {init_out_norm}")
@ -497,6 +493,25 @@ def handle_get_param_data_reply(
pw.dlog(f"{'batt_crit'.ljust(15)}: {batt_crit}")
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 unpack_array_in_data(
data: bytes, start_addr: int, width: int, entries: int, struct_spec: str
) -> List: