Index: leahi_dialin/dd/modules/rinse_pump.py =================================================================== diff -u -r42064e6cae7bbfd89bcebafc14e9d5865c53cb8e -r1f2bf6d939eb4033dbedb7d7005494cc12fccbc6 --- leahi_dialin/dd/modules/rinse_pump.py (.../rinse_pump.py) (revision 42064e6cae7bbfd89bcebafc14e9d5865c53cb8e) +++ leahi_dialin/dd/modules/rinse_pump.py (.../rinse_pump.py) (revision 1f2bf6d939eb4033dbedb7d7005494cc12fccbc6) @@ -7,50 +7,56 @@ # # @file rinse_pump.py # -# @author (last) Jonny Paguio -# @date (last) 13-Oct-2025 +# @author (last) Zoltan Miskolci +# @date (last) 04-May-2026 # @author (original) Jonny Paguio # @date (original) 13-Oct-2025 # ############################################################################ -import struct + +# Module imports from logging import Logger -from .constants import RESET, NO_RESET -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions -from leahi_dialin.protocols.CAN import DenaliMessage, DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish, DialinEnum -from leahi_dialin.utils.checks import check_broadcast_interval_override_ms +# Project imports +from leahi_dialin.common.constants import NO_RESET +from leahi_dialin.common.generic_defs import DataTypes +from leahi_dialin.common.msg_defs import MsgIds +from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override +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 + class DDRinsePump(AbstractSubSystem): """ Rinse Pump Dialysate Delivery (DD) Dialin API sub-class for Rinse Pump 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_rinse_pump_data = MsgIds.MSG_ID_DD_RINSE_PUMP_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_dd_rinse_pump_data, - self._handler_rinse_pump_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_RINSE_PUMP_DATA.value, + function = self._handler_rinse_pump_sync) - self.d79_state = 0 - self.dd_rinse_pump_timestamp = 0 + self.dd_rinse_pump_timestamp = 0 #: The timestamp of the latest message + self.d79_state = 0 #: The State of the D79 Pump + self.d79_pump_pwm = 0.0 #: The PWM of the D79 Pump + self.d79_pump_rpm = 0 #: The RPM of the D79 Pump + @publish(["msg_id_dd_rinse_pump_data", - "d79_state", + "d79_state", "d79_pump_pwm", "d79_pump_rpm", "dd_rinse_pump_timestamp"]) def _handler_rinse_pump_sync(self, message, timestamp=0.0): """ @@ -59,12 +65,16 @@ @param message: published rinse pump data message @return: None """ + msg_list =[] + msg_list.append(('self.d79_state', DataTypes.U32)) + msg_list.append(('self.d79_pump_pwm', DataTypes.F32)) + msg_list.append(('self.d79_pump_rpm', DataTypes.U32)) - self.d79_state = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - + self.process_into_vars(decoder_list = msg_list, + message = message) self.dd_rinse_pump_timestamp = timestamp + def cmd_rinse_pump_data_publish_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the rinse pump data publish interval override command @@ -76,27 +86,61 @@ @param reset: integer - 1 to reset a previous override, 0 to override @return: 1 if successful, zero otherwise """ + return cmd_generic_broadcast_interval_override( + ms = ms, + reset = reset, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_RINSE_PUMP_DATA_PUBLISH_INTERVAL_OVERRIDE_REQUEST, + module_name = 'DD Rinse Pump', + logger = self.logger, + can_interface = self.can_interface) - if not check_broadcast_interval_override_ms(ms): - return False + def cmd_rinse_pump_pwm_percent_override(self, pwm_pct: float, reset: int = NO_RESET) -> int: + """ + Constructs and sends the rinse pump PWM override request + Constraints: + Must be logged into DD. + Given interval must be non-zero and less than 100. + + @param pwm_pct: float - PWM in percent + @param reset: integer - 1 to reset a previous override, 0 to override + @return: 1 if successful, zero otherwise + """ reset_byte_array = integer_to_bytearray(reset) - ms_byte_array = integer_to_bytearray(ms) - payload = reset_byte_array + ms_byte_array + float_pct_byte_array = float_to_bytearray(pwm_pct) + payload = reset_byte_array + float_pct_byte_array - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_RINSE_PUMP_DATA_PUBLISH_INTERVAL_OVERRIDE_REQUEST.value, - payload=payload) + return cmd_generic_override( + payload = payload, + reset = reset, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_RINSE_PUMP_PWM_PERCENT_OVERRIDE_REQUEST, + entity_name = f'DD Rinse Pump PWM', + override_text = str(pwm_pct), + logger = self.logger, + can_interface = self.can_interface) + - self.logger.debug("override DD Rinse Pump data publish interval") + def cmd_rinse_pump_on_off_request(self, on_off: int) -> int: + """ + Constructs and sends the rinse pump On/Off request + Constraints: + Must be logged into DD. + Given integer must be 0 (Off) or 1 (On) - # Send message - received_message = self.can_interface.send(message) + @param on_off: integer - On/Off value + @return: 1 if successful, zero otherwise + """ + on_off_byte_array = integer_to_bytearray(on_off) + payload = on_off_byte_array - # If there is content... - if received_message is not None: - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] - else: - self.logger.error("Timeout!!!!") - return False \ No newline at end of file + return cmd_generic_override( + payload = payload, + reset = NO_RESET, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_RINSE_PUMP_TURN_ON_OFF_REQUEST, + entity_name = f'DD Rinse Pump state', + override_text = 'On' if on_off == 1 else 'Off', + logger = self.logger, + can_interface = self.can_interface)