Index: leahi_dialin/td/modules/blood_flow.py =================================================================== diff -u -r33150daab2a54bde85830da329b931202ab5f961 -re45b20cdc5d4c5dcff8cef530b173ca94cb2e422 --- leahi_dialin/td/modules/blood_flow.py (.../blood_flow.py) (revision 33150daab2a54bde85830da329b931202ab5f961) +++ leahi_dialin/td/modules/blood_flow.py (.../blood_flow.py) (revision e45b20cdc5d4c5dcff8cef530b173ca94cb2e422) @@ -8,21 +8,24 @@ # @file blood_flow.py # # @author (last) Zoltan Miskolci -# @date (last) 08-Jan-2026 +# @date (last) 05-May-2026 # @author (original) Peter Lucia # @date (original) 02-Apr-2020 # ############################################################################ -import struct +# Module imports from logging import Logger +# Project imports from leahi_dialin.common.constants import NO_RESET, PUMP_CONTROL_MODE_CLOSED_LOOP -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.common import td_enum_repository -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 @@ -31,7 +34,7 @@ Treatment Device (TD) Dialin API sub-class for blood-flow related commands. """ - def __init__(self, can_interface, logger: Logger): + def __init__(self, can_interface: CanMessenger, logger: Logger): """ TDBloodFlow constructor """ @@ -40,10 +43,9 @@ self.logger = logger if self.can_interface is not None: - channel_id = DenaliChannels.td_sync_broadcast_ch_id - self.msg_id_td_blood_pump_data = MsgIds.MSG_ID_TD_BLOOD_PUMP_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, self.msg_id_td_blood_pump_data, - self._handler_blood_flow_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_DATA.value, + function = self._handler_blood_flow_sync) self.td_blood_flow_timestamp = 0.0 #: The timestamp of the last message @@ -71,25 +73,20 @@ @param message: published blood flow data message @return: none """ - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.SET_BLOOD_FLOW_RATE.name] = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_FLOW_RATE.name] = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_ROTOR_SPEED.name] = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_SPEED.name] = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_TORQUE.name] = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.SET_RPM.name] = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.ROTOR_COUNT.name] = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.PRES_BLOOD_FLOW_RATE.name] = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_8:MsgFieldPositions.END_POS_FIELD_8]))[0] - self.h4_motor[td_enum_repository.TDBloodFlowMotorAttributes.ROTOR_HALL_STATE.name] = struct.unpack('I', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_9:MsgFieldPositions.END_POS_FIELD_9]))[0] + sensor_list =[] + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.SET_BLOOD_FLOW_RATE.name, DataTypes.U32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_FLOW_RATE.name, DataTypes.F32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_ROTOR_SPEED.name, DataTypes.F32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_SPEED.name, DataTypes.F32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.MEASURED_BLOOD_PUMP_TORQUE.name, DataTypes.F32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.SET_RPM.name, DataTypes.F32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.ROTOR_COUNT.name, DataTypes.U32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.PRES_BLOOD_FLOW_RATE.name, DataTypes.U32)) + sensor_list.append((td_enum_repository.TDBloodFlowMotorAttributes.ROTOR_HALL_STATE.name, DataTypes.U32)) + self.process_into_dict(dict_to_update = self.h4_motor, + decoder_list = sensor_list, + message = message) self.td_blood_flow_timestamp = timestamp @@ -107,7 +104,7 @@ return cmd_generic_broadcast_interval_override( ms = ms, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_PUBLISH_INTERVAL_OVERRIDE_REQUEST, module_name = 'TD Blood Flow', logger = self.logger, @@ -131,7 +128,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_SET_FLOW_RATE_REQUEST, entity_name = f'TD Blood Flow flow rate', override_text = f'{str(flow)} mL/min', @@ -154,7 +151,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_SET_SPEED_REQUEST, entity_name = f'TD Blood Flow RPM', override_text = f'{str(rpm)}', @@ -179,7 +176,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_MEASURED_FLOW_RATE_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow measured flow rate', override_text = f'{str(flow)} mL/min', @@ -205,7 +202,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_MEASURED_MOTOR_SPEED_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow measured motor RPM', override_text = f'{str(spd)}', @@ -231,7 +228,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_MEASURED_ROTOR_SPEED_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow measured rotor RPM', override_text = f'{str(spd)}', @@ -258,7 +255,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_PUMP_ROTOR_COUNT_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow rotor count', override_text = f'{str(rot_count)}', @@ -277,7 +274,7 @@ return cmd_generic_override( payload = None, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_HOME_BLOOD_PUMP_REQUEST, entity_name = f'TD Blood Flow homing', override_text = f'Active', @@ -296,7 +293,7 @@ return cmd_generic_override( payload = None, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_HARD_STOP_BLOOD_PUMP, entity_name = f'TD Blood Flow Pump hard stop', override_text = f'Active', @@ -320,7 +317,7 @@ return cmd_generic_override( payload=payload, reset=reset, - channel_id=DenaliChannels.dialin_to_td_ch_id, + channel_id=CanChannels.dialin_to_td_ch_id, msg_id=MsgIds.MSG_ID_TD_BLOOD_FLOW_STROKE_VOLUME_OVERRIDE_REQUEST, entity_name='TD Blood Flow stroke volume', override_text=f'{volume}', @@ -346,7 +343,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_FLOW_WEAR_A_TERM_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow wear A term', override_text = f'{str(a_term)}', @@ -371,7 +368,7 @@ return cmd_generic_override( payload = payload, reset = reset, - channel_id = DenaliChannels.dialin_to_td_ch_id, + channel_id = CanChannels.dialin_to_td_ch_id, msg_id = MsgIds.MSG_ID_TD_BLOOD_FLOW_WEAR_B_TERM_OVERRIDE_REQUEST, entity_name = f'TD Blood Flow wear B term', override_text = f'{str(b_term)}',