Index: leahi_dialin/fp/filtration_purification.py =================================================================== diff -u -r99611eb808f4c73f50f70d68cc8331642a436d05 -r88eea899fa8d03596f944505285bf3049e64312b --- leahi_dialin/fp/filtration_purification.py (.../filtration_purification.py) (revision 99611eb808f4c73f50f70d68cc8331642a436d05) +++ leahi_dialin/fp/filtration_purification.py (.../filtration_purification.py) (revision 88eea899fa8d03596f944505285bf3049e64312b) @@ -8,14 +8,13 @@ # @file filtration_purification.py # # @author (last) Zoltan Miskolci -# @date (last) 09-Jan-2026 +# @date (last) 05-May-2026 # @author (original) Peter Lucia # @date (original) 02-Apr-2020 # ############################################################################ -import struct - +# Project imports from .modules.alarms import FPAlarms from .modules.boost_pump import FPBoostPump from .modules.conductivity_sensors import FPConductivitySensors @@ -34,10 +33,12 @@ from ..common.constants import NO_RESET from ..common import fp_enum_repository -from ..common.msg_defs import MsgIds, MsgFieldPositions, MsgFieldPositionsFWVersions +from ..common.generic_defs import DataTypes +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override -from ..protocols.CAN import DenaliMessage, DenaliCanMessenger, DenaliChannels -from ..utils.base import AbstractSubSystem, publish, LogManager +from ..protocols.CAN import CanMessage, CanMessenger, CanChannels +from leahi_dialin.utils.abstract_classes import AbstractSubSystem +from leahi_dialin.utils.base import publish, LogManager from ..utils.conversions import integer_to_bytearray, bytearray_to_byte @@ -71,43 +72,49 @@ self.logger = self._log_manager.logger # Create listener - self.can_interface = DenaliCanMessenger(can_interface=can_interface, + self.can_interface = CanMessenger(can_interface=can_interface, logger=self.logger) self.can_interface.start() self.callback_id = None # register handler for FP operation mode broadcast messages if self.can_interface is not None: - channel_id = DenaliChannels.fp_sync_broadcast_ch_id - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_FP_OP_MODE_DATA.value, - self._handler_fp_op_mode_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.fp_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_FP_OP_MODE_DATA.value, + function = self._handler_fp_op_mode_sync) # FP's version is DD's version since they are the same FW. - self.can_interface.register_receiving_publication_function(DenaliChannels.dd_sync_broadcast_ch_id, - MsgIds.MSG_ID_DD_VERSION_RESPONSE.value, - self._handler_fp_version_response_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_VERSION_RESPONSE.value, + function = self._handler_fp_version_response_sync) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_FP_DEBUG_EVENT.value, - self._handler_fp_debug_event_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.fp_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_FP_DEBUG_EVENT.value, + function = self._handler_fp_debug_event_sync) - self.can_interface.register_receiving_publication_function(channel_id, - MsgIds.MSG_ID_FP_DEF_STATUS_RESPONSE.value, - self._handler_fp_defeatured_response) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_to_dialin_ch_id, + message_id = MsgIds.MSG_ID_FP_DEF_STATUS_RESPONSE.value, + function = self._handler_fp_defeatured_response) + + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_to_dialin_ch_id, + message_id = MsgIds.MSG_ID_FP_BOOST_PUMP_INSTALL_STATUS_RESPONSE.value, + function = self._handler_fp_boost_pump_installed_response) # Dialin will send a login message during construction. This is for the leahi subsystems to start # publishing CAN data when there is no UI connected as the UI typically does this job. self.cmd_log_in_to_fp() - # create properties + # configuration records self.fp_defeatured = False #: The FP is defeaturized or not self.fp_defeatured_timestamp = 0.0 #: The timestamp of the latest defeatured message + self.fp_p40_installed = False #: The P40 Boost Pump is installed or not + self.fp_p40_installed_timestamp = 0.0 #: The timestamp of the latest P40 Boost Pump is installed message + + # create properties self.fp_op_mode_timestamp = 0.0 #: The timestamp of the latest operation mode message self.fp_debug_events_timestamp = 0.0 #: The timestamp of the latest events message self.fp_version_response_timestamp = 0.0 #: The timestamp of the latest FP version info message self.fp_operation_mode = fp_enum_repository.FPOpModes.MODE_INIT.value #: The Operation Mode's value self.fp_operation_sub_mode = 0 #: The Operation Sub-Mode's value self.fp_logged_in = False #: The value showing if the user is logged in or not - self.fp_set_logged_in_status(False) self.fp_version = None #: The FP's version value self.fp_fpga_version = None #: The FP's FPGA version value self.fp_debug_events = [''] * self._FP_DEBUG_EVENT_LIST_COUNT #: The Debug Event's list @@ -132,16 +139,6 @@ self.dd_proxy = DDProxy(self.can_interface, self.logger, fp = self) #: The DD Proxy module (imitates commands sent by DD) - def fp_set_logged_in_status(self, logged_in: bool = False): - """ - Callback for fp logged in status change. - - @param logged_in: Logged in status for FP - @return: None - """ - self.fp_logged_in = logged_in - - @publish(["msg_id_fp_debug_event", "fp_debug_events_timestamp","fp_debug_events"]) def _handler_fp_debug_event_sync(self, message, timestamp = 0.0): """ @@ -179,33 +176,28 @@ @return: None if not successful, the version string if unpacked successfully """ - major = struct.unpack(' 0 for each in [major, minor, micro, build, compatibility]]): - self.fp_version = f"v{major[0]}.{minor[0]}.{micro[0]}-{build[0]}.{compatibility[0]}" - self.logger.debug(f"FP VERSION: {self.fp_version}") + result = self.process_into_vars(decoder_list = msg_list, + message = message) - if all([len(each) > 0 for each in [fpga_id, fpga_major, fpga_minor, fpga_lab]]): - self.fp_fpga_version = f"v{fpga_id[0]}.{fpga_major[0]}.{fpga_minor[0]}-{fpga_lab[0]}" - self.logger.debug(f"FP FPGA VERSION: {self.fp_fpga_version}") + if all([each is not None for each in [result['major'], result['minor'], result['micro'], result['build'], result['compatibility']]]): + self.fp_version = f"v{result['major']}.{result['minor']}.{result['micro']}-{result['build']}.{result['compatibility']}" + self.logger.debug(f'FP VERSION: {self.fp_version}') + if all([each is not None for each in [result['fpga_id'], result['fpga_major'], result['fpga_minor'], result['fpga_lab']]]): + self.fp_fpga_version = f"v{result['fpga_id']}.{result['fpga_major']}.{result['fpga_minor']}-{result['fpga_lab']}" + self.logger.debug(f'FP FPGA VERSION: {self.fp_fpga_version}') + self.fp_version_response_timestamp = timestamp @@ -218,13 +210,12 @@ @param message: published FP operation mode broadcast message @return: None """ - mode = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) - smode = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])) + msg_list = [] + msg_list.append(('self.fp_operation_mode', DataTypes.U32)) + msg_list.append(('self.fp_operation_sub_mode', DataTypes.U32)) - self.fp_operation_mode = mode[0] - self.fp_operation_sub_mode = smode[0] + self.process_into_vars(decoder_list = msg_list, + message = message) self.fp_op_mode_timestamp = timestamp @@ -233,15 +224,33 @@ """ Handler for response from FP regarding its defeatured status. - @param message: defeatured respnse from FP + @param message: defeatured response from FP @return: None """ - self.fp_defeatured = struct.unpack('?', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) + msg_list = [] + msg_list.append(('self.fp_defeatured', DataTypes.BOOL)) + self.process_into_vars(decoder_list = msg_list, + message = message) self.fp_defeatured_timestamp = timestamp + @publish(["msg_id_fp_boost_pump_installed_status_response", "fp_p40_installed"]) + def _handler_fp_boost_pump_installed_response(self, message, timestamp = 0.0): + """ + Handler for response from FP regarding its boost pump installation status. + + @param message: defeatured response from FP + @return: None + """ + msg_list = [] + msg_list.append(('self.fp_p40_installed', DataTypes.BOOL)) + + self.process_into_vars(decoder_list = msg_list, + message = message) + self.fp_p40_installed_timestamp = timestamp + + def cmd_request_defeatured_status(self) -> int: """ Constructs and sends the FP defeatured status request @@ -250,8 +259,7 @@ @return: 1 if successful, zero otherwise """ - - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_fp_ch_id, + message = CanMessage.build_message(channel_id=CanChannels.dialin_to_fp_ch_id, message_id=MsgIds.MSG_ID_FP_DEF_STATUS_REQUEST.value) self.logger.debug('Getting FP defeatured status') @@ -261,13 +269,38 @@ if received_message is not None: self.logger.debug("Received FW ACK after requesting FP defeatured configuration record.") # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + return received_message['message'][CanMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Timeout!!!!") return False + def cmd_request_boost_pump_install_status(self) -> int: + """ + Constructs and sends the FP Boost Pump Installed status request + Constraints: + Must be logged into FP. + @return: 1 if successful, zero otherwise + """ + # ToDo: Update the msg id when FW part of LDT-3779 is implemented + message = CanMessage.build_message(channel_id=CanChannels.dialin_to_fp_ch_id, + message_id=MsgIds.MSG_ID_FP_BOOST_PUMP_INSTALL_STATUS_REQUEST.value) + + self.logger.debug('Getting FP P40 Boost Pump installed status') + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + self.logger.debug("Received FW ACK after requesting FP P40 Boost Pump installed configuration record.") + # response payload is OK or not OK + return received_message['message'][CanMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + + + def cmd_op_mode_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the measured op mode broadcast interval override command @@ -282,7 +315,7 @@ return cmd_generic_broadcast_interval_override( ms = ms, reset = reset, - channel_id = DenaliChannels.dialin_to_fp_ch_id, + channel_id = CanChannels.dialin_to_fp_ch_id, msg_id = MsgIds.MSG_ID_FP_OPERATION_MODE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, module_name = 'FP Operation Mode', logger = self.logger, @@ -297,7 +330,7 @@ @param resend: (bool) if False (default), try to login once. Otherwise, tries to login indefinitely @return: 1 if logged in, 0 if log in failed """ - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_fp_ch_id, + message = CanMessage.build_message(channel_id=CanChannels.dialin_to_fp_ch_id, message_id=MsgIds.MSG_ID_FP_TESTER_LOGIN_REQUEST.value, payload=list(map(int, map(ord, self.FP_LOGIN_PASSWORD)))) @@ -307,15 +340,15 @@ received_message = self.can_interface.send(message, resend=resend) if received_message is not None: - if received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] == 1: + if received_message['message'][CanMessage.PAYLOAD_START_INDEX] == 1: self.logger.debug("Success: Logged In") - self.fp_set_logged_in_status(True) + self.fp_logged_in = True self.cmd_request_defeatured_status() #self._send_ro_checkin_message() # Timer starts interval first #self.can_interface.transmit_interval_dictionary[self.callback_id].start() else: self.logger.debug("Failure: Log In Failed.") - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + return received_message['message'][CanMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Login Timeout!!!!") return False @@ -337,7 +370,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_fp_ch_id, + channel_id = CanChannels.dialin_to_fp_ch_id, msg_id = MsgIds.MSG_ID_FP_SET_OP_MODE_REQUEST, entity_name = 'FP Operation Mode', override_text = fp_enum_repository.FPOpModes(new_mode).name, @@ -380,7 +413,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_fp_ch_id, + channel_id = CanChannels.dialin_to_fp_ch_id, msg_id = MsgIds.MSG_ID_FP_SET_OP_SUB_MODE_REQUEST, entity_name = 'FP Operation Sub Mode', override_text = new_sub_mode_enum.name, @@ -399,7 +432,7 @@ return cmd_generic_override( payload = None, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_fp_ch_id, + channel_id = CanChannels.dialin_to_fp_ch_id, msg_id = MsgIds.MSG_ID_FP_SOFTWARE_RESET_REQUEST, entity_name = 'FP Software Reset', override_text = '', @@ -424,7 +457,7 @@ return cmd_generic_override( payload = payload, reset = NO_RESET, - channel_id = DenaliChannels.dialin_to_fp_ch_id, + channel_id = CanChannels.dialin_to_fp_ch_id, msg_id = MsgIds.MSG_ID_FP_SAFETY_SHUTDOWN_OVERRIDE_REQUEST, entity_name = 'FP Safety Shutdown', override_text = str(active),