Index: leahi_dialin/dd/modules/gen_dialysate.py =================================================================== diff -u -r39190f5b592ef515e19ae1b5455a32b84f853cf5 -re45b20cdc5d4c5dcff8cef530b173ca94cb2e422 --- leahi_dialin/dd/modules/gen_dialysate.py (.../gen_dialysate.py) (revision 39190f5b592ef515e19ae1b5455a32b84f853cf5) +++ leahi_dialin/dd/modules/gen_dialysate.py (.../gen_dialysate.py) (revision e45b20cdc5d4c5dcff8cef530b173ca94cb2e422) @@ -8,20 +8,23 @@ # @file gen_dialysate.py # # @author (last) Zoltan Miskolci -# @date (last) 07-Jan-2026 +# @date (last) 04-May-2026 # @author (original) Micahel Garthwaite # @date (original) 29-Oct-2020 # ############################################################################ -import struct +# Module imports from logging import Logger +# Project imports from leahi_dialin.common.constants import NO_RESET -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.generic_defs import DataTypes +from leahi_dialin.common.msg_ids import MsgIds from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override -from leahi_dialin.protocols.CAN import DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish +from leahi_dialin.protocols.CAN import CanMessenger, CanChannels +from leahi_dialin.utils.abstract_classes import AbstractSubSystem +from leahi_dialin.utils.base import publish from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray @@ -32,20 +35,19 @@ Dialysate Delivery (DD) Dialin API sub-class for gen dialysate related commands. """ - def __init__(self, can_interface, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ - @param can_interface: Denali Can Messenger object + @param can_interface: Can Messenger object """ super().__init__() self.can_interface = can_interface self.logger = logger if self.can_interface is not None: - channel_id = DenaliChannels.dd_sync_broadcast_ch_id - self.msg_id_dd_gen_dialysate_mode_data = MsgIds.MSG_ID_DD_GEN_DIALYSATE_MODE_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_dd_gen_dialysate_mode_data, - self._handler_gen_dialysate_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_GEN_DIALYSATE_MODE_DATA.value, + function = self._handler_gen_dialysate_sync) self.dd_gen_dialysate_timestamp = 0 #: The timestamp of the last message self.execution_state = 0 #: The Execution state @@ -66,26 +68,14 @@ @param message: published gen dialysate data message @return: None """ - sensor_list =[] - sensor_list.append(['self.execution_state', 'I']) - sensor_list.append(['self.dialysate_delivery_in_progress', 'I']) - # sensor_list.append(['self.d6_level', 'I']) - # sensor_list.append(['self.d63_level', 'f']) - # sensor_list.append(['self.d46_level', 'I']) - # sensor_list.append(['self.d9_pressure', 'f']) - # sensor_list.append(['self.d18_pressure', 'f']) - # sensor_list.append(['self.d51_pressure', 'f']) - sensor_list.append(['self.dialysate_good_to_deliver', 'I']) - sensor_list.append(['self.target_qd', 'f']) - - i = 1 - for sensor in sensor_list: - start_pos = eval(f'MsgFieldPositions.START_POS_FIELD_{i}') - end_pos = eval(f'MsgFieldPositions.END_POS_FIELD_{i}') - value = struct.unpack(sensor[1],bytearray(message['message'][start_pos:end_pos]))[0] - exec(f'{sensor[0]} = {value}') - i += 1 + msg_list = [] + msg_list.append(('self.execution_state', DataTypes.U32)) + msg_list.append(('self.dialysate_delivery_in_progress', DataTypes.U32)) + msg_list.append(('self.dialysate_good_to_deliver', DataTypes.U32)) + msg_list.append(('self.target_qd', DataTypes.F32)) + self.process_into_vars(decoder_list = msg_list, + message = message) self.dd_gen_dialysate_timestamp = timestamp @@ -103,7 +93,7 @@ return cmd_generic_broadcast_interval_override( ms = ms, reset = reset, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_GEND_MODE_DATA_PUBLISH_OVERRIDE_REQUEST, module_name = 'DD Gen Dialysate', logger = self.logger, @@ -125,7 +115,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_DIAL_DELIVERY_IN_PROGRESS_OVERRIDE_REQUEST, entity_name = f'DD Dialysate Delivery in progress', override_text = str(in_progress), @@ -148,7 +138,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_DIAL_DELIVERY_GOOD_TO_DELIVER_OVERRIDE_REQUEST, entity_name = f'DD Dialysate Delivery is good to deliver', override_text = str(delivery), @@ -171,7 +161,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_HYD_CHAMBER_TARGET_TEMP_OVERRIDE_REQUEST, entity_name = f'DD Hydraulics Chamber target Temperature', override_text = str(temperature), @@ -193,7 +183,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_GEND_EXEC_STATE_OVERRIDE_REQUEST, entity_name = f'DD Dialysate Delivery set state', override_text = str(state), @@ -216,7 +206,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_dd_ch_id, + channel_id = CanChannels.dialin_to_dd_ch_id, msg_id = MsgIds.MSG_ID_DD_STOP_GEN_DIALYSATE_MODE_OVERRIDE_REQUEST, entity_name = f'DD Dialysate Delivery pre gen mode', override_text = str(state),