Index: leahi_dialin/dd/proxies/td_proxy.py =================================================================== diff -u -rdfbb4f080638b65d9836b22bd5c76d46d53abba5 -r941ca56f3f41c92c4b025a0713ee1d99c792aab8 --- leahi_dialin/dd/proxies/td_proxy.py (.../td_proxy.py) (revision dfbb4f080638b65d9836b22bd5c76d46d53abba5) +++ leahi_dialin/dd/proxies/td_proxy.py (.../td_proxy.py) (revision 941ca56f3f41c92c4b025a0713ee1d99c792aab8) @@ -13,13 +13,15 @@ # @date (original) 02-Apr-2020 # ############################################################################ + import struct from logging import Logger from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.override_templates import cmd_generic_override 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 +from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray class TDProxy(AbstractSubSystem): @@ -33,7 +35,6 @@ @param can_interface: the Denali CAN interface object """ - super().__init__() self.can_interface = can_interface self.logger = logger @@ -53,6 +54,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", @@ -85,7 +87,7 @@ 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): """ Constructs and sends a TD gen dialysate request to the DD. @@ -96,13 +98,80 @@ 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 = bic +acd + byp + temp + uf + dial + stt - payload = stt + dial + uf + temp + byp + acd + bic - message = DenaliMessage.build_message(channel_id=DenaliChannels.td_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) + payload = stt + dial + uf + temp + byp + acd + bic + sod + bvl - 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 = DenaliChannels.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_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 + :return: + """ + stt = integer_to_bytearray(start) + dial = float_to_bytearray(dialysate_rate) + temp = float_to_bytearray(dialysate_temp) + 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 + + cmd_generic_override(payload = payload, + reset = None, + channel_id = DenaliChannels.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) + + + def cmd_td_override_treatment_parameter(self, paramID: int, value, reset: int = 0): + """ + Constructs and sends a treatment parameter override request. + @param paramID : integer - Treatment parameter ID + @param value : float or integer - Override value + @param reset : integer 1 to reset override, 0 to apply override + @returns None + """ + + rst = integer_to_bytearray(reset) + pid = integer_to_bytearray(paramID) + # Dialysate rate, UF rate and dialysate temperature are f32 + float_params = [ 0, 1, 2 ] + # Acid type and bicarbonate type are u32 + uint_params = [ 3, 4 ] + if paramID in float_params: + val = float_to_bytearray(float(value)) + elif paramID in uint_params: + val = integer_to_bytearray(int(value)) + else: + val = integer_to_bytearray(int(value)) + payload = rst + val + pid + + cmd_generic_override(payload = payload, + reset = None, + channel_id = DenaliChannels.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)