Index: leahi_dialin/dd/dialysate_delivery.py =================================================================== diff -u -r2dab2b0329a56006e07cd36a3883ed099d7a367a -r256ffed682a9c78ee890a3f3132eb6c6518e7ee8 --- leahi_dialin/dd/dialysate_delivery.py (.../dialysate_delivery.py) (revision 2dab2b0329a56006e07cd36a3883ed099d7a367a) +++ leahi_dialin/dd/dialysate_delivery.py (.../dialysate_delivery.py) (revision 256ffed682a9c78ee890a3f3132eb6c6518e7ee8) @@ -15,9 +15,11 @@ ############################################################################ import struct +from .modules.alarms import DDAlarms from .modules.balancing_chamber import DDBalancingChamber from .modules.concentrate_pump import DDConcentratePumps from .modules.conductivity_sensors import DDConductivitySensors +from .modules.constants import NO_RESET, RESET from .modules.dialysate_pump import DDDialysatePumps from .modules.gen_dialysate import DDGenDialysate from .modules.heaters import DDHeaters @@ -27,12 +29,13 @@ from .modules.pressure_sensors import DDPressureSensors from .modules.pre_gen_dialysate import DDPreGenDialysate from .modules.temperature_sensors import DDTemperatureSensors +from .modules.ultrafiltration import DDUltrafiltration from .modules.valves import DDValves from .proxies.ro_proxy import ROProxy from .proxies.td_proxy import TDProxy -from ..common.msg_defs import MsgIds, MsgFieldPositions +from ..common.msg_defs import MsgIds, MsgFieldPositions, MsgFieldPositionsFWVersions from ..common.dd_defs import DDOpModes from ..protocols.CAN import DenaliMessage, DenaliCanMessenger, DenaliChannels from ..utils.base import AbstractSubSystem, publish, LogManager @@ -53,18 +56,6 @@ # DD login password DD_LOGIN_PASSWORD = '123' - # UI version message field positions - START_POS_MAJOR = DenaliMessage.PAYLOAD_START_INDEX - END_POS_MAJOR = START_POS_MAJOR + 1 - START_POS_MINOR = END_POS_MAJOR - END_POS_MINOR = START_POS_MINOR + 1 - START_POS_MICRO = END_POS_MINOR - END_POS_MICRO = START_POS_MICRO + 1 - START_POS_BUILD = END_POS_MICRO - END_POS_BUILD = START_POS_BUILD + 2 - START_POS_COMPATIBILITY_REV = END_POS_BUILD - END_POS_COMPATIBILITY_REV = START_POS_COMPATIBILITY_REV + 4 - def __init__(self, can_interface="can0", log_level=None): """ DD object provides test/service commands for the DD sub-system. @@ -96,24 +87,27 @@ self._handler_dd_op_mode_sync) self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_DD_VERSION_RESPONSE.value, + self._handler_dd_version_response_sync) + + self.can_interface.register_receiving_publication_function(channel_id, MsgIds.MSG_ID_DD_DEBUG_EVENT.value, self._handler_dd_debug_event_sync) # create properties self.dd_op_mode_timestamp = 0.0 self.dd_debug_events_timestamp = 0.0 - self.ui_version_info_response_timestamp = 0.0 + self.dd_version_response_timestamp = 0.0 self.dd_operation_mode = DDOpModes.MODE_INIT.value self.dd_operation_sub_mode = 0 self.dd_logged_in = False self.dd_set_logged_in_status(False) - self.ui_version = None self.dd_debug_events = [''] * self._DD_DEBUG_EVENT_LIST_COUNT self.dd_debug_event_index = 0 self.dd_last_debug_event = '' # Create command groups - + self.alarms = DDAlarms(self.can_interface, self.logger) self.balancing_chamber = DDBalancingChamber(self.can_interface, self.logger) self.concentrate_pumps = DDConcentratePumps(self.can_interface, self.logger) self.conductivity_sensors = DDConductivitySensors(self.can_interface, self.logger) @@ -126,6 +120,7 @@ self.pressure_sensors = DDPressureSensors(self.can_interface, self.logger) self.pre_gen_dialysate = DDPreGenDialysate(self.can_interface, self.logger) self.temperature_sensors = DDTemperatureSensors(self.can_interface, self.logger) + self.ultrafiltration = DDUltrafiltration(self.can_interface, self.logger) self.valves = DDValves(self.can_interface, self.logger) self.ro_proxy = ROProxy(self.can_interface, self.logger) @@ -181,6 +176,44 @@ self.dd_operation_sub_mode = smode[0] self.dd_op_mode_timestamp = timestamp + @publish(["dd_version, dd_fpga_version"]) + def _handler_dd_version_response_sync(self,message, timestamp = 0.0): + """ + Handler for response from DD regarding its version. + + @param message: version response message from DD.\n + + @return: None if not successful, the version string if unpacked successfully + """ + major = struct.unpack(' 0 for each in [major, minor, micro, build, compatibility]]): + self.dd_version = f"v{major[0]}.{minor[0]}.{micro[0]}-{build[0]}.{compatibility[0]}" + self.logger.debug(f"DD VERSION: {self.dd_version}") + + if all([len(each) > 0 for each in [fpga_id, fpga_major, fpga_minor, fpga_lab]]): + self.dd_fpga_version = f"v{fpga_id[0]}.{fpga_major[0]}.{fpga_minor[0]}-{fpga_lab[0]}" + self.logger.debug(f"DD FPGA VERSION: {self.dd_fpga_version}") + + self.dd_version_response_timestamp = timestamp + def cmd_log_in_to_dd(self, resend: bool = False) -> int: """ Constructs and sends a login command via CAN bus. Login required before \n @@ -268,3 +301,37 @@ self.dd_set_logged_in_status(False) + def cmd_dd_safety_shutdown_override(self, active: int, reset: int = NO_RESET) -> int: + """ + Constructs and sends an DD safety shutdown override command via CAN bus. + Constraints: + Must be logged into DD. + + @param active: int - True to activate safety shutdown, False to deactivate + @param reset: integer - 1 to reset a previous override, 0 to override + @return: 1 if successful, zero otherwise + + """ + + rst = integer_to_bytearray(reset) + saf = integer_to_bytearray(active) + payload = rst + saf + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, + message_id=MsgIds.MSG_ID_DD_SAFETY_SHUTDOWN_OVERRIDE_REQUEST.value, + payload=payload) + + self.logger.debug("overriding FP safety shutdown") + + # Send message + received_message = self.can_interface.send(message) + + if received_message is not None: + if received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] == 1: + self.logger.debug("Safety shutdown signal overridden") + else: + self.logger.debug("Safety shutdown signal override failed.") + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False \ No newline at end of file