Index: dialin/common/msg_defs.py =================================================================== diff -u -r87cf0bc784212d2608c58d1388b37396aa0a4656 -r58ebcc0edb2e2aae8166630eb5d5d984d9ad3817 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision 58ebcc0edb2e2aae8166630eb5d5d984d9ad3817) @@ -15,7 +15,6 @@ ############################################################################ import enum - class MsgIds(enum.Enum): MSG_ID_UNUSED = 0 # Zero is an undefined (un-used) message ID) MSG_ID_OFF_BUTTON_PRESS = 1 # HD/UI off button interactions @@ -75,6 +74,11 @@ MSG_ID_DG_HEAT_DISINFECT_DATA = 0x37 # DG heat disinfection publish data MSG_ID_UI_START_TREATMENT = 0x38 # UI user request to initiate a treatment MSG_ID_HD_START_TREATMENT_RESPONSE = 0x39 # HD response to user request to initiate a treatment + MSG_ID_HD_VALVES_DATA = 0x3A # HD broadcast of valves data + MSG_ID_UI_USER_CONFIRM_TREATMENT_PARAMS = 0x3B # UI user confirmation of treatment parameters + MSG_ID_UI_TREATMENT_END_REQUEST = 0x3C # UI user treatment end request + MSG_ID_HD_TREATMENT_END_RESPONSE = 0x3D # HD response to user request to end treatment + MSG_ID_HD_AIR_TRAP_DATA = 0x003E # HD broadcast of air trap data MSG_ID_CAN_ERROR_COUNT = 0x999 # test code in support of EMC testing @@ -126,6 +130,14 @@ MSG_ID_HD_ACCEL_SET_CALIBRATION = 0x802A # HD accelerometer set calibration factors request MSG_ID_HD_BLOOD_FLOW_SET_CALIBRATION = 0x802B # Blood flow set calibration factors request MSG_ID_HD_DIALYSATE_FLOW_SET_CALIBRATION = 0x802C # Dialysate flow set calibration factors request + MSG_ID_HD_SET_PARAMETER_TREATMENT_PARAMETER = 0x802D # Set a treatment parameter (will change actual setting, not an override) + MSG_ID_HD_VALVES_HOME = 0x802E # Home an HD Valve + MSG_ID_HD_VALVES_POSITION_OVERRIDE = 0x802F # Set an HD valve to a position in counts + MSG_ID_HD_VALVES_SET_AIR_TRAP_VALVE = 0x8030 # Set the HD blood trap valve status + MSG_ID_HD_VALVES_SET_PWM_OVERRIDE = 0x8031 # Set an HD valve PWM + MSG_ID_DG_AIR_TRAP_DATA_BROADCAST_INTERVAL_OVERRIDE = 0x8032 # HD air trap data broadcast interval override request + MSG_ID_DG_AIR_TRAP_LEVEL_SENSOR_OVERRIDE = 0x8033 # HD air trap level sensor override request + MSG_ID_HD_SOFTWARE_RESET_REQUEST = 0x8034 # HD reset request MSG_ID_FIRST_DG_TESTER_MESSAGE = 0xA000 # First DG test message ID MSG_ID_DG_TESTER_LOGIN_REQUEST = MSG_ID_FIRST_DG_TESTER_MESSAGE # DG tester log-in @@ -161,11 +173,8 @@ MSG_ID_HEAT_DISINFECT_RSRVR2_TO_RSRVR1_DURATION_MINS = 0xA01F # Heat disinfection reservoir 2 to reservoir 1 duration in minutes MSG_ID_HEAT_DISINFECT_NO_OF_CYCLES_TO_RUN = 0xA020 # Heat disinfection number of cycles to run MSG_ID_HEAT_DISINFECT_PUBLISH_INTERVAL_OVERRIDE = 0xA021 # Heat disinfection data publish interval override request - MSG_ID_HD_VALVES_DATA = 0x3A # HD valves data publish - MSG_ID_HD_VALVES_HOME = 0x802E # HD valves home command + MSG_ID_DG_SOFTWARE_RESET_REQUEST = 0xA022 # DG reset request MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE = 0x8030 # HD valves set blood trap valve state - MSG_ID_HD_VALVES_POSITION_OVERRIDE = 0x802F # HD valves position override command - MSG_ID_HD_VALVES_SET_PWM_OVERRIDE = 0x8031 # HD valves PWM override command MSG_ID_HD_DEBUG_EVENT = 0xFFF1 # HD debug event text to be logged in event log MSG_ID_DG_DEBUG_EVENT = 0xFFF2 # DG debug event text to be logged in event log Index: dialin/hd/hemodialysis_device.py =================================================================== diff -u -r87cf0bc784212d2608c58d1388b37396aa0a4656 -r58ebcc0edb2e2aae8166630eb5d5d984d9ad3817 --- dialin/hd/hemodialysis_device.py (.../hemodialysis_device.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) +++ dialin/hd/hemodialysis_device.py (.../hemodialysis_device.py) (revision 58ebcc0edb2e2aae8166630eb5d5d984d9ad3817) @@ -14,6 +14,8 @@ # ############################################################################ import struct +from .accelerometer import HDAccelerometer +from .air_trap import HDAirTrap from .alarms import HDAlarms from .buttons import HDButtons from .ui_proxy import HDUIProxy @@ -28,8 +30,10 @@ from ..protocols.CAN import (DenaliMessage, DenaliCanMessenger, DenaliChannels) +from ..utils.conversions import integer_to_bytearray from ..utils.base import _AbstractSubSystem, _publish, _LogManager from .constants import NO_RESET +from ..common.msg_defs import MsgIds class HD(_AbstractSubSystem): @@ -38,12 +42,6 @@ the HD firmware. """ - # HD message IDs - MSG_ID_HD_OPERATION_MODE_BROADCAST = 0x0025 - MSG_ID_LOGIN_TO_HD = 0x8000 - MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE = 0x8026 - MSG_ID_POWEROFF_NOTIFY = 0x0020 - # broadcast message field positions START_POS_HD_OP_MODE = DenaliMessage.PAYLOAD_START_INDEX END_POS_HD_OP_MODE = START_POS_HD_OP_MODE + 4 @@ -92,7 +90,7 @@ # register handler for HD operation mode broadcast messages if self.can_interface is not None: channel_id = DenaliChannels.hd_sync_broadcast_ch_id - msg_id = self.MSG_ID_HD_OPERATION_MODE_BROADCAST + msg_id = MsgIds.MSG_ID_HD_OP_MODE.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_hd_op_mode_sync) @@ -101,6 +99,8 @@ self.hd_operation_sub_mode = 0 # Create command groups + self.accel = HDAccelerometer(self.can_interface, self.logger) + self.air_trap = HDAirTrap(self.can_interface, self.logger) self.alarms = HDAlarms(self.can_interface, self.logger) self.buttons = HDButtons(self.can_interface, self.logger) self.ui = HDUIProxy(self.can_interface, self.logger) @@ -147,7 +147,7 @@ """ message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_LOGIN_TO_HD, + message_id=MsgIds.MSG_ID_TESTER_LOGIN_REQUEST.value, payload=list(map(int, map(ord, self.HD_LOGIN_PASSWORD)))) self.logger.debug("Logging in...") @@ -188,7 +188,7 @@ payload = rst + saf message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE, + message_id=MsgIds.MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE.value, payload=payload) self.logger.debug("overriding HD safety shutdown") @@ -205,3 +205,33 @@ else: self.logger.debug("Timeout!!!!") return False + + def cmd_hd_software_reset_request(self): + """ + Constructs and sends an HD software reset request via CAN bus. + Constraints: + Must be logged into HD. + + \returns response message if received, False if no response received + + @return: 1 if successful, zero otherwise + + """ + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_HD_SOFTWARE_RESET_REQUEST.value) + + self.logger.debug("requesting HD software reset") + + # 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("HD is resetting...") + else: + self.logger.debug("HD reset request failed.") + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False