Index: leahi_dialin/td/modules/treatment.py =================================================================== diff -u -rec8a2600b9e8cf6fe7e02c200a1c24221ca86863 -r1813f6556e8a726a6e300caffe0bcafc40010aa9 --- leahi_dialin/td/modules/treatment.py (.../treatment.py) (revision ec8a2600b9e8cf6fe7e02c200a1c24221ca86863) +++ leahi_dialin/td/modules/treatment.py (.../treatment.py) (revision 1813f6556e8a726a6e300caffe0bcafc40010aa9) @@ -7,21 +7,22 @@ # # @file treatment.py # -# @author (last) Michael Garthwaite -# @date (last) 22-Apr-2025 +# @author (last) Zoltan Miskolci +# @date (last) 08-Jan-2026 # @author (original) Michael Garthwaite # @date (original) 22-Apr-2025 # ############################################################################ + import struct from logging import Logger -from .constants import RESET, NO_RESET +from leahi_dialin.common.constants import NO_RESET from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.override_templates import cmd_generic_override from leahi_dialin.common.td_defs import TDTreatmentParameters -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 +from leahi_dialin.protocols.CAN import DenaliChannels +from leahi_dialin.utils.base import AbstractSubSystem, publish from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray @@ -123,6 +124,7 @@ self.uf_vol = 0.0 self.tx_param_req_timestamp = 0 + @publish(["msg_id_td_treatment_param_ranges", "min_tx_time","max_tx_time","min_uf_volume","max_uf_volume", "min_dial_rate","max_dial_rate","tx_params_timestamp"]) def _handler_treatment_param_ranges_sync(self, message, timestamp=0.0): @@ -132,7 +134,6 @@ @param message: published treatment parameter range data message @return: none """ - self.min_tx_time = struct.unpack('i', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.max_tx_time = struct.unpack('i', bytearray( @@ -148,6 +149,7 @@ self.tx_params_timestamp = timestamp + @publish(["msg_id_td_saline_bolus_data", "tgt_saline_volume","cum_saline_volume","bol_saline_volume", "saline_bolus_state","saline_bolus_timestamp"]) def _handler_saline_bolus_sync(self, message, timestamp=0.0): @@ -157,7 +159,6 @@ @param message: published saline bolus data message @return: none """ - self.tgt_saline_volume = struct.unpack('i', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.cum_saline_volume = struct.unpack('f', bytearray( @@ -169,6 +170,7 @@ self.saline_bolus_timestamp = timestamp + @publish(["msg_id_td_uf_data", "set_uf_volume","tgt_uf_rate","uf_volume_delivered", "uf_state","uf_timestamp"]) def _handler_uf_sync(self, message, timestamp=0.0): @@ -178,7 +180,6 @@ @param message: published ultrafiltration data message @return: none """ - self.set_uf_volume = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.tgt_uf_rate = struct.unpack('f', bytearray( @@ -190,6 +191,7 @@ self.uf_timestamp = timestamp + @publish(["msg_id_td_treatment_time_data", "tx_time_prescribed","tx_time_elapsed","tx_time_remaining", "tx_time_timestamp"]) def _handler_treatment_time_sync(self, message, timestamp=0.0): @@ -199,7 +201,6 @@ @param message: published treatment time data message @return: none """ - self.tx_time_prescribed = struct.unpack('i', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.tx_time_elapsed = struct.unpack('i', bytearray( @@ -209,6 +210,7 @@ self.tx_time_timestamp = timestamp + @publish(["msg_id_td_treatment_state_data", "tx_sub_mode","blood_prime_state","dialysis_state","isolated_uf_state", "tx_stop_state","rinseback_state","tx_recirc_state","tx_end_state","tx_state_timestamp"]) def _handler_treatment_state_sync(self, message, timestamp=0.0): @@ -218,7 +220,6 @@ @param message: published treatment state data message @return: none """ - self.tx_sub_mode = struct.unpack('i', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.blood_prime_state = struct.unpack('i', bytearray( @@ -238,6 +239,7 @@ self.tx_state_timestamp = timestamp + @publish(["msg_id_td_rsp_current_treatment_parameters", "blood_flow_rate", "dialysate_flow_rate", "tx_duration", "saline_bolus_volume", "hep_stop_time", "hep_time", "acid_con", "bicarb_con", "dialyzer_type", "bp_interval", "rb_flow_rate", "rb_volume", @@ -250,7 +252,6 @@ @param message: published treatment parameter response data message @return: none """ - self.blood_flow_rate = struct.unpack('i', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.dialysate_flow_rate = struct.unpack('i', bytearray( @@ -294,6 +295,7 @@ self.tx_param_req_timestamp = timestamp + def cmd_set_treatment_parameter(self, tx_param_id: int = 0, tx_param_value = 0 ): """ Constructs and sends set treatment parameter command to the TD. @@ -305,8 +307,6 @@ @return: 1 if successful, zero otherwise """ - idx = integer_to_bytearray(tx_param_id) - if tx_param_id <= TDTreatmentParameters.TREATMENT_PARAM_RINSEBACK_VOLUME.value: tpv = integer_to_bytearray(tx_param_value) @@ -316,19 +316,16 @@ else: tpv = integer_to_bytearray(tx_param_value) + idx = integer_to_bytearray(tx_param_id) payload = idx + tpv - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_td_ch_id, - message_id=MsgIds.MSG_ID_TD_SET_TREATMENT_PARAMETER.value, - payload=payload) - - # Send message - received_message = self.can_interface.send(message) - - # 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.debug("Timeout!!!!") - return False \ No newline at end of file + param_name = TDTreatmentParameters(tx_param_id).name + return cmd_generic_override( + payload = payload, + reset = NO_RESET, + channel_id = DenaliChannels.dialin_to_td_ch_id, + msg_id = MsgIds.MSG_ID_TD_SET_TREATMENT_PARAMETER, + entity_name = f'TD {param_name}', + override_text = str(tx_param_value), + logger = self.logger, + can_interface = self.can_interface)