Index: dialin/common/msg_defs.py =================================================================== diff -u -r3fb7646b2d2a5346ac5b6eecbcee97ccc643d8be -r2fb3be9a2925e440db33f993d5964d0439c4bd42 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 3fb7646b2d2a5346ac5b6eecbcee97ccc643d8be) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision 2fb3be9a2925e440db33f993d5964d0439c4bd42) @@ -144,6 +144,7 @@ MSG_ID_HD_VOLTAGES_DATA = 0x7B # HD voltages data publish MSG_ID_HD_ALARM_AUDIO_VOLUME_SET_RESPONSE = 0x7C # HD response to UI set alarm audio volume request MSG_ID_HD_ALARM_INFORMATION = 0x7D # HD alarm information broadcast message + MSG_ID_DG_VOLTAGES_DATA = 0x86 # DG voltages data publish MSG_ID_CAN_ERROR_COUNT = 0x999 # test code in support of EMC testing @@ -261,8 +262,8 @@ MSG_ID_DG_ACCEL_OVERRIDE = 0xA017 # DG accelerometer sensor override request MSG_ID_DG_ACCEL_MAX_OVERRIDE = 0xA018 # DG accelerometer sensor max. override request MSG_ID_DG_ACCEL_SEND_INTERVAL_OVERRIDE = 0xA019 # DG accelerometer data broadcast interval override request - MSG_ID___AVAILABLE_11 = 0xA01A # This msg ID is available for use - MSG_ID_RO_PUMP_SET_PWM = 0xA01B # RO pump set PWM for open loop + MSG_ID_DG_MONITORED_VOLTAGES_SEND_INTERVAL_OVERRIDE = 0xA01A # DG monitored voltages publish interval override request + MSG_ID_DG_MONITORED_VOLTAGES_OVERRIDE = 0xA01B # DG monitored voltage override request MSG_ID_DRAIN_PUMP_SET_DELTA_PRESSURE_OVERRIDE = 0xA01C # Drain pump set delta pressure override MSG_ID_HEAT_DISINFECT_RECIRC_PATH_DURATION_MINS = 0xA01D # Heat disinfection recirculation path duration in minutes MSG_ID_HEAT_DISINFECT_RSRVR1_TO_RSRVR2_DURATION_MINS = 0xA01E # Heat disinfection reservoir 1 to reservoir 2 duration in minutes Index: dialin/dg/voltages.py =================================================================== diff -u --- dialin/dg/voltages.py (revision 0) +++ dialin/dg/voltages.py (revision 2fb3be9a2925e440db33f993d5964d0439c4bd42) @@ -0,0 +1,211 @@ +########################################################################### +# +# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +# +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# +# @file voltages.py +# +# @author (last) Sean Nash +# @date (last) 22-Apr-2021 +# @author (original) Sean Nash +# @date (original) 22-Apr-2021 +# +############################################################################ +import struct +from enum import unique +from ..utils.base import DialinEnum +from ..protocols.CAN import (DenaliMessage, + DenaliChannels) +from ..utils.conversions import integer_to_bytearray, float_to_bytearray +from .constants import RESET, NO_RESET +from ..utils.base import _AbstractSubSystem, _publish +from ..common.msg_defs import MsgIds, MsgFieldPositions +from logging import Logger + + +# Monitored voltages +@unique +class DGMonitoredVoltages(DialinEnum): + MONITORED_LINE_24V_MAIN = 0 # Main voltage (24V) + MONITORED_LINE_1_8V_FPGA = 1 # FPGA logic voltage (1.8V) + MONITORED_LINE_1V_FPGA = 2 # FPGA reference voltage (1V) + MONITORED_LINE_3_3V_SENSORS = 3 # Sensors voltage (3.3V) + MONITORED_LINE_1_8V_PROC = 4 # Processor voltage (1.8V) + MONITORED_LINE_5V_SENSORS = 5 # Sensors voltage (5V) + MONITORED_LINE_5V_LOGIC = 6 # Logic voltage (5V) + MONITORED_LINE_3_3V = 7 # Logic voltage (3.3V) + MONITORED_LINE_1_2V_PROC = 8 # Processor voltage (1.2V) + MONITORED_LINE_V_REF = 9 # Reference voltage (3V) + MONITORED_LINE_EXT_ADC_1_REF_V = 10 # External ADC 1 reference voltage (3V) + MONITORED_LINE_EXT_ADC_2_REF_V = 11 # External ADC 2 reference voltage (3V) + MONITORED_LINE_24V_PRIM_HTR_V = 12 # Primary heater voltage (24V) + MONITORED_LINE_24V_TRIM_HTR_V = 13 # Trimmer heater voltage (24V) + NUM_OF_MONITORED_LINES = 14 # Number of monitored voltages + + +class DGVoltages(_AbstractSubSystem): + """ + Hemodialysis Delivery (DG) Dialin API sub-class for voltage monitor related commands and data. + """ + + def __init__(self, can_interface, logger: Logger): + """ + DGVoltages constructor + + """ + super().__init__() + self.can_interface = can_interface + self.logger = logger + + if self.can_interface is not None: + channel_id = DenaliChannels.hd_sync_broadcast_ch_id + msg_id = MsgIds.MSG_ID_DG_VOLTAGES_DATA.value + self.can_interface.register_receiving_publication_function(channel_id, msg_id, + self._handler_monitored_voltages_sync) + self.monitored_voltages = [0.0] * DGMonitoredVoltages.NUM_OF_MONITORED_VOLTAGE_LINES.value + + def get_monitored_voltages(self): + """ + Gets all DG monitored voltages + + @return: List of voltages of size NUM_OF_MONITORED_VOLTAGE_LINES + """ + return self.monitored_voltages + + @_publish([ + "monitored_voltages" + ]) + def _handler_monitored_voltages_sync(self, message): + """ + Handles published DG monitored voltages data messages. Voltage data are captured + for reference. + + @param message: published monitored voltages data message + @return: none + """ + + v1 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) + v12 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])) + v18p = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3])) + v18f = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4])) + v3r = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5])) + ve1 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6])) + ve2 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7])) + v33 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_8:MsgFieldPositions.END_POS_FIELD_8])) + v33s = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_9:MsgFieldPositions.END_POS_FIELD_9])) + v5l = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_10:MsgFieldPositions.END_POS_FIELD_10])) + v5s = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_11:MsgFieldPositions.END_POS_FIELD_11])) + v24 = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_12:MsgFieldPositions.END_POS_FIELD_12])) + v24p = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_13:MsgFieldPositions.END_POS_FIELD_13])) + v24t = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_14:MsgFieldPositions.END_POS_FIELD_14])) + + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_1V_FPGA.value] = v1[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_1_2V_PROC.value] = v12[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_1_8V_PROC.value] = v18p[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_1_8V_FPGA.value] = v18f[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_V_REF.value] = v3r[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_EXT_ADC_1_REF_V.value] = ve1[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_EXT_ADC_2_REF_V.value] = ve2[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_3_3V.value] = v33[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_3_3V_SENSORS.value] = v33s[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_5V_LOGIC.value] = v5l[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_5V_SENSORS.value] = v5s[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_24V_MAIN.value] = v24[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_24V_PRIM_HTR_V.value] = v24p[0] + self.monitored_voltages[DGMonitoredVoltages.MONITORED_LINE_24V_TRIM_HTR_V.value] = v24t[0] + + def cmd_monitored_voltage_override(self, signal:int=0, volts:float=0.0, reset:int=NO_RESET): + """ + Constructs and sends the DG monitored voltage override command + Constraints: + Must be logged into DG. + Given signal must be valid member of DGMonitoredVoltages enum + + @param signal: integer - ID of signal to override + @param volts: float - value (in volts) to override signal with + @param reset: integer - 1 to reset a previous override, 0 to override + @return: 1 if successful, zero otherwise + """ + + rst = integer_to_bytearray(reset) + vlt = float_to_bytearray(volts) + idx = integer_to_bytearray(signal) + payload = rst + vlt + idx + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_DG_MONITORED_VOLTAGES_OVERRIDE.value, + payload=payload) + + self.logger.debug("override monitored DG voltage for signal " + str(signal)) + + # Send message + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + if reset == RESET: + str_res = "reset back to normal. " + else: + str_res = str(volts) + " V. " + self.logger.debug("Monitored DG voltage overridden to " + str_res + + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + + def cmd_monitored_voltages_broadcast_interval_override(self, ms:int=1000, reset:int=NO_RESET): + """ + Constructs and sends the monitored DG voltages broadcast interval override command + Constraints: + Must be logged into DG. + Given interval must be non-zero and a multiple of the DG general task interval (50 ms). + + @param ms: integer - interval (in ms) to override with + @param reset: integer - 1 to reset a previous override, 0 to override + @return: 1 if successful, zero otherwise + """ + + rst = integer_to_bytearray(reset) + mis = integer_to_bytearray(ms) + payload = rst + mis + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_DG_MONITORED_VOLTAGES_SEND_INTERVAL_OVERRIDE.value, + payload=payload) + + self.logger.debug("override monitored DG voltages broadcast interval") + + # Send message + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + if reset == RESET: + str_res = "reset back to normal: " + else: + str_res = str(ms) + " ms: " + self.logger.debug("DG monitored voltages broadcast interval overridden to " + str_res + + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False Index: dialin/hd/ui_proxy.py =================================================================== diff -u -rd54312249b9f790e834849917cb107bae2774222 -r2fb3be9a2925e440db33f993d5964d0439c4bd42 --- dialin/hd/ui_proxy.py (.../ui_proxy.py) (revision d54312249b9f790e834849917cb107bae2774222) +++ dialin/hd/ui_proxy.py (.../ui_proxy.py) (revision 2fb3be9a2925e440db33f993d5964d0439c4bd42) @@ -1271,21 +1271,21 @@ def cmd_set_treatment_parameters(self, bld_flow: int = 100, dia_flow: int = 100, - duration: int = 60, - hep_rate: float = 0.1, - hep_bol : float = 0.1, - hep_stop: int = 1, + duration: int = 240, + hep_rate: float = 0.0, + hep_bol : float = 0.0, + hep_stop: int = 0, sal_bol : int = 100, acid : int = 0, bicarb : int = 0, dialyzer: int = 0, - dia_temp: float = 35, + dia_temp: float = 37.0, art_low : int = -300, - art_high: int = -200, - ven_low : int = -100, - ven_high: int = 100, - bp_intvl: int = 15, - rb_flow : int = 50): + art_high: int = 0, + ven_low : int = 20, + ven_high: int = 400, + bp_intvl: int = 30, + rb_flow : int = 75): """ Constructs and sends a ui set treatment parameters message Constraints: Index: dialin/hd/voltages.py =================================================================== diff -u -r4ff3b2874eb12aee034d1f85ae32c161d05efc00 -r2fb3be9a2925e440db33f993d5964d0439c4bd42 --- dialin/hd/voltages.py (.../voltages.py) (revision 4ff3b2874eb12aee034d1f85ae32c161d05efc00) +++ dialin/hd/voltages.py (.../voltages.py) (revision 2fb3be9a2925e440db33f993d5964d0439c4bd42) @@ -62,7 +62,7 @@ def get_monitored_voltages(self): """ - Gets all monitored voltages + Gets all HD monitored voltages @return: List of voltages of size NUM_OF_MONITORED_VOLTAGE_LINES """ @@ -73,7 +73,7 @@ ]) def _handler_monitored_voltages_sync(self, message): """ - Handles published monitored voltages data messages. Voltage data are captured + Handles published HD monitored voltages data messages. Voltage data are captured for reference. @param message: published monitored voltages data message @@ -108,7 +108,7 @@ def cmd_monitored_voltage_override(self, signal:int=0, volts:float=0.0, reset:int=NO_RESET): """ - Constructs and sends the monitored voltage override command + Constructs and sends the HD monitored voltage override command Constraints: Must be logged into HD. Given signal must be valid member of HDMonitoredVoltages enum @@ -128,7 +128,7 @@ message_id=MsgIds.MSG_ID_HD_MONITORED_VOLTAGES_OVERRIDE.value, payload=payload) - self.logger.debug("override monitored voltage for signal " + str(signal)) + self.logger.debug("override monitored HD voltage for signal " + str(signal)) # Send message received_message = self.can_interface.send(message) @@ -139,7 +139,7 @@ str_res = "reset back to normal. " else: str_res = str(volts) + " V. " - self.logger.debug("Monitored voltage overridden to " + str_res + + self.logger.debug("Monitored HD voltage overridden to " + str_res + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] @@ -149,7 +149,7 @@ def cmd_monitored_voltages_broadcast_interval_override(self, ms:int=1000, reset:int=NO_RESET): """ - Constructs and sends the monitored voltages broadcast interval override command + Constructs and sends the monitored HD voltages broadcast interval override command Constraints: Must be logged into HD. Given interval must be non-zero and a multiple of the HD general task interval (50 ms).