Index: dialin/common/msg_ids.py =================================================================== diff -u -ra1d640c70267e6e5e2ad81fc23bc5ca91847b61d -r54b1635a7fe67dc09bfa294c4978d0739cb169d4 --- dialin/common/msg_ids.py (.../msg_ids.py) (revision a1d640c70267e6e5e2ad81fc23bc5ca91847b61d) +++ dialin/common/msg_ids.py (.../msg_ids.py) (revision 54b1635a7fe67dc09bfa294c4978d0739cb169d4) @@ -484,6 +484,7 @@ MSG_ID_DG_GET_LOAD_CELLS_TARE_VALUES = 0xA06B MSG_ID_DG_SET_LOAD_CELLS_TARE_VALUES = 0xA06C MSG_ID_DG_SEND_LOAD_CELLS_TARE_VALUES_TO_DIALIN = 0xA06D + MSG_ID_DG_SET_COND_SENSOR_CAL_TABLE = 0xA06E MSG_ID_HD_DEBUG_EVENT = 0xFFF1 MSG_ID_DG_DEBUG_EVENT = 0xFFF2 Index: dialin/dg/conductivity_sensors.py =================================================================== diff -u -r9bc00e997e91dab8b404aa877b02ae3d4100d417 -r54b1635a7fe67dc09bfa294c4978d0739cb169d4 --- dialin/dg/conductivity_sensors.py (.../conductivity_sensors.py) (revision 9bc00e997e91dab8b404aa877b02ae3d4100d417) +++ dialin/dg/conductivity_sensors.py (.../conductivity_sensors.py) (revision 54b1635a7fe67dc09bfa294c4978d0739cb169d4) @@ -15,6 +15,7 @@ ############################################################################ import struct from logging import Logger +from enum import unique from .constants import RESET, NO_RESET from ..common.msg_defs import MsgIds, MsgFieldPositions @@ -24,13 +25,26 @@ from ..utils.conversions import integer_to_bytearray, float_to_bytearray +@unique class ConductivitySensorsEnum(DialinEnum): CPI = 0 CPO = 1 CD1 = 2 CD2 = 3 + NUM_OF_CONDUCTIVITY_SENSORS = 4 +@unique +class ConductivitySensorsCalTableName(DialinEnum): + CAL_DATA_CPI_COND_SENSOR = 0 # CPi conductivity sensor. + CAL_DATA_CPO_COND_SENSOR = 1 # CPo conductivity sensor. + CAL_DATA_CD1_COND_SENSOR = 2 # CD1 conductivity sensor. + CAL_DATA_CD2_COND_SENSOR = 3 # CD2 conductivity sensor. + CAL_DATA_CD2_COND_SENSOR_CHEM_DISINFECT = 4 # CD2 chemical disinfect conductivity sensor. + CAL_DATA_CD2_COND_SENSOR_FILL_BICARB_TEST = 5 # CD2 conductivity sensor fill bicarb test. + NUM_OF_CAL_DATA_COND_SENSORS = 6 # Number of conductivity sensors. + + class ConductivitySensors(AbstractSubSystem): """ ConductivitySensors @@ -219,3 +233,48 @@ else: self.logger.error("Timeout!!!!") return False + + def cmd_set_conductivity_sensor_cal_table(self, sensor_id: int, cal_table_id: int): + """ + Constructs and sends the conductivity sensor calibration table command + + @param sensor_id: unsigned_int - sensor ID + @param cal_table_id: unsigned_int - calibration table value to pick + @return: 1 if successful, zero otherwise + + Conductivity sensor IDs: \n + 0 = CPI \n + 1 = CPO \n + 2 = CD1 \n + 3 = CD2 \n + + Conductivity sensor calibration table IDs: \n + 0 = CAL_DATA_CPI_COND_SENSOR \n + 1 = CAL_DATA_CPO_COND_SENSOR \n + 2 = CAL_DATA_CD1_COND_SENSOR \n + 3 = CAL_DATA_CD2_COND_SENSOR \n + 4 = CAL_DATA_CD2_COND_SENSOR_CHEM_DISINFECT \n + 5 = CAL_DATA_CD2_COND_SENSOR_FILL_BICARB_TEST \n + """ + + sensor_byte_array = integer_to_bytearray(sensor_id) + cal_table_byte_array = integer_to_bytearray(cal_table_id) + payload = sensor_byte_array + cal_table_byte_array + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DG_SET_COND_SENSOR_CAL_TABLE.value, + payload=payload) + + self.logger.debug("Setting Sensor {} calibration table to {}".format(ConductivitySensorsEnum(sensor_id).name, + ConductivitySensorsCalTableName(cal_table_id).name)) + + # Send message + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.error("Timeout!!!!") + return False Index: tests/tx_test_config_tests.py =================================================================== diff -u -r2dbb3b03c9e63d2cda582facc6cef28710252a8a -r54b1635a7fe67dc09bfa294c4978d0739cb169d4 --- tests/tx_test_config_tests.py (.../tx_test_config_tests.py) (revision 2dbb3b03c9e63d2cda582facc6cef28710252a8a) +++ tests/tx_test_config_tests.py (.../tx_test_config_tests.py) (revision 54b1635a7fe67dc09bfa294c4978d0739cb169d4) @@ -5,7 +5,6 @@ from dialin.hd.hemodialysis_device import HD from dialin.dg.load_cells import DGLoadCellNames from dialin.hd.switches import HDSwitchesNames, HDSwitchStatus -from dialin.hd.ui_proxy import TreatmentParameters from dialin.hd.constants import RESET, NO_RESET from dialin.ui.hd_simulator import HDSimulator from dialin.common.dg_defs import DGHeatDisinfectStates, DGHeatDisinfectUIStates @@ -46,105 +45,139 @@ sys.path.append("..") +def check_status(delay_counter, sleep_time, target_delay, state_counter): + + if delay_counter > (target_delay / sleep_time): + state_counter += 1 + delay_counter = 0 + else: + delay_counter += 1 + + return state_counter, delay_counter + + def expedite_pretreatment(): + sleep_time = 0.1 counter = 1 - #dg.load_cells.cmd_get_load_cells_tare_values() + delay_counter = 0 + target_delay = 1 - # For testing only. Use the get function to get the actual tare values during the development of this script and - # the procedure for this - dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_1_PRIMARY.name] = 1726.822998046875 - dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_1_BACKUP.name] = 1716.2781982421875 - dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_2_PRIMARY.name] = 1716.46484375 - dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_2_BACKUP.name] = 1712.1719970703125 - while True: - if counter == 1 and \ + if counter == 1: + if delay_counter == 0: + # dg.load_cells.cmd_get_load_cells_tare_values() + + # For testing only. Use the get function to get the actual tare values during the development of this + # script and the procedure for this + dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_1_PRIMARY.name] = 1726.822998046875 + dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_1_BACKUP.name] = 1716.2781982421875 + dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_2_PRIMARY.name] = 1716.46484375 + dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_2_BACKUP.name] = 1712.1719970703125 + + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + elif counter == 2 and \ dg.load_cells.load_cells_tare_values[DGLoadCellNames.LOAD_CELL_RESERVOIR_1_PRIMARY.name] != 0.0: - # Received the load cells tare values from DG. Reset both stacks - dg.cmd_dg_software_reset_request() - hd.cmd_hd_software_reset_request() - sleep(1) - counter += 1 + if delay_counter == 0: + # Received the load cells tare values from DG. Reset both stacks + dg.cmd_dg_software_reset_request() + hd.cmd_hd_software_reset_request() - if counter == 2 and dg.dg_operation_mode == 3: - # After reset log in again - dg.cmd_log_in_to_dg() - # Wait to make sure the log in really happened - sleep(1) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) - if counter == 3: - dg.load_cells.cmd_set_load_cells_tare_values() - counter += 1 + elif counter == 3 and dg.dg_operation_mode == 3: + if delay_counter == 0: + # After reset log in again + dg.cmd_log_in_to_dg() - if counter == 4 and hd.hd_operation_mode == 3: - hd.cmd_log_in_to_hd() - # Wait to make sure the log in really happened - sleep(1) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) - if counter == 5: - # Set the operation mode is pre-treatment before commanding the start DG - hd.cmd_hd_set_operation_mode(4) - counter += 1 + elif counter == 4: + if delay_counter == 0: + dg.load_cells.cmd_set_load_cells_tare_values() - if counter == 6 and hd.hd_operation_mode == 4: - # Start DG cannot be when HD is in standby - dg.hd_proxy.cmd_start_stop_dg() - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, 0, counter) - if counter == 7 and dg.dg_operation_mode == 5 and dg.dg_operation_sub_mode == 1: - # This section is for testing only to make sure we always have fluid in the reservoir. This part is not - # needed in the actual test procedure - dg.hd_proxy.cmd_fill(1600) - sleep(1) - counter += 1 + elif counter == 5 and hd.hd_operation_mode == 3: + if delay_counter == 0: + hd.cmd_log_in_to_hd() - if counter == 8 and dg.dg_operation_mode == 5 and dg.dg_operation_sub_mode == 1: - hd.test_configs.cmd_set_test_config(HDTestConfigOptions.TEST_CONFIG_EXPEDITE_PRE_TREATMENT.value) - sleep(1) - hd.test_configs.cmd_set_test_config(HDTestConfigOptions.TEST_CONFIG_SKIP_BLOOD_PRIME.value) - sleep(0.5) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) - if counter == 9: - hd.ui.cmd_set_treatment_parameters() - sleep(1) - counter += 1 + elif counter == 6: + if delay_counter == 0: + # Set the operation mode is pre-treatment before commanding the start DG + hd.cmd_hd_set_operation_mode(4) - if counter == 10: - hd.ui.cmd_ui_confirm_treatment_parameters(1) - sleep(1) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, 0, counter) - if counter == 11: - hd.ui.cmd_ui_uf_volume_set(0.0) - sleep(1) - counter += 1 + elif counter == 7 and hd.hd_operation_mode == 4: + if delay_counter == 0: + # Start DG cannot be when HD is in standby + dg.hd_proxy.cmd_start_stop_dg() - if counter == 12: - hd.switches.cmd_hd_switch_status_override(HDSwitchesNames.FRONT_DOOR.value, HDSwitchStatus.OPEN.value) - sleep(2) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, 0, counter) - if counter == 13: - hd.switches.cmd_hd_switch_status_override(HDSwitchesNames.FRONT_DOOR.value, HDSwitchStatus.OPEN.value, RESET) - sleep(0.5) - counter += 1 + elif counter == 8 and dg.dg_operation_mode == 5 and dg.dg_operation_sub_mode == 1: + if delay_counter == 0: + # This section is for testing only to make sure we always have fluid in the reservoir. This part is not + # needed in the actual test procedure + dg.hd_proxy.cmd_fill(1600) - if counter == 14: - hd.ui.cmd_ui_patient_connection_confirm() - sleep(0.5) - counter += 1 + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + elif counter == 9 and dg.dg_operation_mode == 5 and dg.dg_operation_sub_mode == 1: + if delay_counter == 0: + hd.test_configs.cmd_set_test_config(HDTestConfigOptions.TEST_CONFIG_EXPEDITE_PRE_TREATMENT.value) + + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + elif counter == 10: + if delay_counter == 0: + hd.ui.cmd_set_treatment_parameters() + + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + elif counter == 11: + if delay_counter == 0: + hd.ui.cmd_ui_confirm_treatment_parameters(1) + + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + elif counter == 12: + if delay_counter == 0: + hd.ui.cmd_ui_uf_volume_set(0.0) + + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + elif counter == 13: + if delay_counter == 0: + hd.switches.cmd_hd_switch_status_override(HDSwitchesNames.FRONT_DOOR.value, HDSwitchStatus.OPEN.value) + + counter, delay_counter = check_status(delay_counter, sleep_time, 2, counter) + + elif counter == 14: + if delay_counter == 0: + hd.switches.cmd_hd_switch_status_override(HDSwitchesNames.FRONT_DOOR.value, HDSwitchStatus.OPEN.value, + RESET) + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + if counter == 15: - hd.ui.cmd_ui_start_treatment_request() - counter += 1 + if delay_counter == 0: + hd.ui.cmd_ui_patient_connection_confirm() - sleep(0.5) + counter, delay_counter = check_status(delay_counter, sleep_time, 2, counter) + if counter == 16: + if delay_counter == 0: + hd.ui.cmd_ui_start_treatment_request() + counter, delay_counter = check_status(delay_counter, sleep_time, target_delay, counter) + + sleep(sleep_time) + + if __name__ == "__main__": dg = DG(log_level='DEBUG') dg.cmd_log_in_to_dg()