Index: leahi_dialin/dd/proxies/td_proxy.py =================================================================== diff -u -r44459bf3f991b530142dd5676702171abc465800 -r99dfe2380283ce79c4ca62ead2ab425f74bea053 --- leahi_dialin/dd/proxies/td_proxy.py (.../td_proxy.py) (revision 44459bf3f991b530142dd5676702171abc465800) +++ leahi_dialin/dd/proxies/td_proxy.py (.../td_proxy.py) (revision 99dfe2380283ce79c4ca62ead2ab425f74bea053) @@ -7,42 +7,45 @@ # # @file td_proxy.py # -# @author (last) Micahel Garthwaite -# @date (last) 18-Aug-2023 +# @author (last) Zoltan Miskolci +# @date (last) 04-May-2026 # @author (original) Peter Lucia # @date (original) 02-Apr-2020 # ############################################################################ -import struct + +# Module imports from logging import Logger -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions -from leahi_dialin.protocols.CAN import DenaliMessage, DenaliCanMessenger, DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish -from leahi_dialin.utils.conversions import integer_to_bytearray, byte_to_bytearray, float_to_bytearray +# Project imports +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_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 TDProxy(AbstractSubSystem): """ Dialysate Delivery (DD) Dialin API sub-class for TD proxy ( injection ) related commands. """ - def __init__(self, can_interface: DenaliCanMessenger, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ TDProxy constructor - @param can_interface: the Denali CAN interface object + @param can_interface: the CAN interface object """ - super().__init__() self.can_interface = can_interface self.logger = logger if self.can_interface is not None: - channel_id = DenaliChannels.td_to_dd_ch_id - msg_id = MsgIds.MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, msg_id, - self._handler_dialysate_delivery_request_response) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_to_dd_ch_id, + message_id = MsgIds.MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA.value, + function = self._handler_dialysate_delivery_request_response) self.dialysate_delivery_request_start = 0 self.dialysate_delivery_request_dial_rate = 0.0 @@ -53,6 +56,7 @@ self.dialysate_delivery_request_bicarb = 0 self.dd_td_to_dd_request_response_timestamp = 0.0 + @publish(["dd_td_to_dd_request_response_timestamp", "dialysate_delivery_request_start","dialysate_delivery_request_dial_rate", "dialysate_delivery_request_uf_rate","dialysate_delivery_request_dial_temp", @@ -66,26 +70,23 @@ @param message: published dialysate delivery request response data message @return: None """ - self.dialysate_delivery_request_start = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - self.dialysate_delivery_request_dial_rate = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - self.dialysate_delivery_request_uf_rate = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] - self.dialysate_delivery_request_dial_temp = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4]))[0] - self.dialysate_delivery_request_bypass = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5]))[0] - self.dialysate_delivery_request_acid = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6]))[0] - self.dialysate_delivery_request_bicarb = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7]))[0] + msg_list =[] + msg_list.append(('self.dialysate_delivery_request_start', DataTypes.U32)) + msg_list.append(('self.dialysate_delivery_request_dial_rate', DataTypes.F32)) + msg_list.append(('self.dialysate_delivery_request_uf_rate', DataTypes.F32)) + msg_list.append(('self.dialysate_delivery_request_dial_temp', DataTypes.F32)) + msg_list.append(('self.dialysate_delivery_request_bypass', DataTypes.U32)) + msg_list.append(('self.dialysate_delivery_request_acid', DataTypes.U32)) + msg_list.append(('self.dialysate_delivery_request_bicarb', DataTypes.U32)) + self.process_into_vars(decoder_list = msg_list, + message = message) self.dd_td_to_dd_request_response_timestamp = timestamp def cmd_td_send_dd_gen_dialysate_request(self, start: bool = 0, dial_rate: float = 0, uf_rate: float = 0, - dial_temp: float = 0, bypass: int = 0, acid: int = 0, bicarb: int = 0): + dial_temp: float = 0, bypass: int = 0, acid_conv_factor: float = 0.0, + bicarb_conv_factor: float = 0.0, sodium: int = 0, bicarb_volume: int = 0, sub_rate: float = 0): """ Constructs and sends a TD gen dialysate request to the DD. @@ -96,40 +97,55 @@ uf = float_to_bytearray(uf_rate) temp = float_to_bytearray(dial_temp) byp = integer_to_bytearray(bypass) - acd = integer_to_bytearray(acid) - bic = integer_to_bytearray(bicarb) - payload = stt + dial + uf + temp + byp + acd + bic - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA.value, - payload=payload) + acd = float_to_bytearray(acid_conv_factor) + bic = float_to_bytearray(bicarb_conv_factor) + sod = integer_to_bytearray(sodium) + bvl = integer_to_bytearray(bicarb_volume) + sub = float_to_bytearray(sub_rate) + payload = stt + dial + uf + temp + byp + acd + bic + sod + bvl + sub - self.logger.debug("Sending TD gen dialysate data request to DD.") - self.can_interface.send(message, 0) + cmd_generic_override(payload = payload, + reset = None, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA, + entity_name = 'TD Gen Dialysate Request', + override_text = 'N/A', + logger = self.logger, + can_interface = self.can_interface) + def cmd_td_send_dd_start_pre_gen_request(self, start: bool = 0, dialysate_rate: float = 0.0, dialysate_temp: float = 0.0, - acid_type: int = 0, bicarb_type: int = 0 ): + acid_conv_factor: float = 0.0, bicarb_conv_factor: float = 0.0, sodium: int = 0, bicarb_volume: int = 0): """ - Constructs and sends a TD start pre gen dialysate request to the DD. - :param start: start and stop boolean - :param dialysate_rate: dialysate rate in ml/min - :param dialysate_temp: dialysate temp in c - :param acid_type: acid type - :param bicarb_type: bicarb type + Constructs and sends a TD start pre gen dialysate request to the DD. + + :param start: (Boolean) start and stop boolean + :param dialysate_rate: (Float) dialysate rate in ml/min + :param dialysate_temp: (Float) dialysate temp in c + :param acid_conv_factor: (Float) acid conversion factor + :param bicarb_conv_factor: (Float) bicarb conversion factor + :param sodium: (Integer) bicarb conversion factor + :param bicarb_volume: (Integer) bicarb volume :return: """ stt = integer_to_bytearray(start) dial = float_to_bytearray(dialysate_rate) temp = float_to_bytearray(dialysate_temp) - acd = integer_to_bytearray(acid_type) - bic = integer_to_bytearray(bicarb_type) - payload = stt + dial + temp + acd + bic + acd = float_to_bytearray(acid_conv_factor) + bic = float_to_bytearray(bicarb_conv_factor) + sod = integer_to_bytearray(sodium) + bvl = integer_to_bytearray(bicarb_volume) + payload = stt + dial + temp + acd + bic + sod + bvl - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_PRE_GEN_DIALYSATE_REQUEST_DATA.value, - payload=payload) + cmd_generic_override(payload = payload, + reset = None, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_PRE_GEN_DIALYSATE_REQUEST_DATA, + entity_name = 'TD Pre-Gen Dialysate Request', + override_text = 'N/A', + logger = self.logger, + can_interface = self.can_interface) - self.logger.debug("Sending TD start pre gen request to DD.") - self.can_interface.send(message, 0) def cmd_td_override_treatment_parameter(self, paramID: int, value, reset: int = 0): """ @@ -154,9 +170,11 @@ val = integer_to_bytearray(int(value)) payload = rst + val + pid - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, - message_id=MsgIds.MSG_ID_DD_TREATMENT_PARAMS_OVERRIDE_REQUEST.value, - payload=payload) - - self.logger.debug("Sending DD treatment parameter override: id={}, value={}, reset={}".format( paramID, value, reset)) - self.can_interface.send(message, 0) + cmd_generic_override(payload = payload, + reset = None, + channel_id = CanChannels.dialin_to_dd_ch_id, + msg_id = MsgIds.MSG_ID_DD_TREATMENT_PARAMS_OVERRIDE_REQUEST, + entity_name = f'DD treatment parameter override: id={paramID}, value={value}, reset={reset}', + override_text = 'N/A', + logger = self.logger, + can_interface = self.can_interface)