Index: dialin/common/msg_ids.py =================================================================== diff -u -re8f9ead3fe058b688c0b42c599886375e1730008 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- dialin/common/msg_ids.py (.../msg_ids.py) (revision e8f9ead3fe058b688c0b42c599886375e1730008) +++ dialin/common/msg_ids.py (.../msg_ids.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -471,6 +471,9 @@ MSG_ID_DG_NELSON_DISINFECT_SUPPORT = 0xA064 MSG_ID_DG_SET_DIALYSATE_MIXING_RATIOS = 0xA065 MSG_ID_DG_SET_TEST_CONFIGURATION = 0xA066 + MSG_ID_DG_GET_TEST_CONFIGURATION = 0xA067 + MSG_ID_DG_SEND_TEST_CONFIGURATION = 0xA068 + MSG_ID_DG_RESET_ALL_TEST_CONFIGURATIONS = 0xA069 MSG_ID_HD_DEBUG_EVENT = 0xFFF1 MSG_ID_DG_DEBUG_EVENT = 0xFFF2 Index: dialin/common/test_config_defs.py =================================================================== diff -u -re8f9ead3fe058b688c0b42c599886375e1730008 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- dialin/common/test_config_defs.py (.../test_config_defs.py) (revision e8f9ead3fe058b688c0b42c599886375e1730008) +++ dialin/common/test_config_defs.py (.../test_config_defs.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -4,7 +4,7 @@ @unique -class DGTestConfigEnums(DialinEnum): +class DGTestConfigOptions(DialinEnum): # NOTE: This enum has been commented out because two enums cannot have the same value but the firmware is assigned # to the enum number. TEST_CONFIG_ENABLE_MIXING_WITH_WATER = 0 # Test configuration enable mixing with water. @@ -13,6 +13,6 @@ @unique -class HDTestConfigEnums(DialinEnum): +class HDTestConfigOptions(DialinEnum): pass # TODo update Index: dialin/dg/dg_test_configs.py =================================================================== diff -u -re8f9ead3fe058b688c0b42c599886375e1730008 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- dialin/dg/dg_test_configs.py (.../dg_test_configs.py) (revision e8f9ead3fe058b688c0b42c599886375e1730008) +++ dialin/dg/dg_test_configs.py (.../dg_test_configs.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -1,16 +1,11 @@ -import struct -import time -from enum import unique from logging import Logger -from time import sleep - from ..common.msg_defs import MsgIds, MsgFieldPositions -from ..common.test_config_defs import DGTestConfigEnums +from ..common.test_config_defs import DGTestConfigOptions from ..protocols.CAN import DenaliMessage, DenaliChannels -from .constants import NO_RESET, RESET -from ..utils.conversions import integer_to_bytearray -from ..utils.base import AbstractSubSystem, DialinEnum +from .constants import NO_RESET +from ..utils.conversions import integer_to_bytearray, bytearray_to_integer +from ..utils.base import AbstractSubSystem, publish class DGTestConfig(AbstractSubSystem): @@ -29,19 +24,24 @@ self.can_interface = can_interface self.logger = logger self.dg_test_configs = dict() + self.dg_test_configs_response_timestamp = 0.0 - for config in DGTestConfigEnums.__members__: - if 'NUM_OF_TEST_CONFIGS' not in config: - self.dg_test_configs[config] = 0 + self._reset_test_configs_record() + if self.can_interface is not None: + channel_id = DenaliChannels.dg_to_dialin_ch_id + msg_id = MsgIds.MSG_ID_DG_SEND_TEST_CONFIGURATION.value + self.can_interface.register_receiving_publication_function(channel_id, msg_id, + self._handler_dg_test_config_sync) + def cmd_get_test_config_status(self, config: int): """ Returns the status of a test config @param config: (int) Test config to set @return: the status of a test config """ - return self.dg_test_configs[DGTestConfigEnums(config).name] + return self.dg_test_configs[DGTestConfigOptions(config).name] def cmd_set_test_config(self, config: int, reset: int = NO_RESET): """ @@ -62,9 +62,9 @@ payload=payload) if reset == NO_RESET: - self.logger.debug("Setting {}".format(DGTestConfigEnums(config).name)) + self.logger.debug("Setting {}".format(DGTestConfigOptions(config).name)) else: - self.logger.debug("Resetting {}".format(DGTestConfigEnums(config).name)) + self.logger.debug("Resetting {}".format(DGTestConfigOptions(config).name)) # Send message received_message = self.can_interface.send(message) @@ -77,4 +77,81 @@ self.logger.debug("Timeout!!!!") return False + def cmd_request_test_config_status_from_fw(self): + """ + Constructs and sends the DG test configs request + Constraints: + Must be logged into DG. + @return: 1 if successful, zero otherwise + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DG_GET_TEST_CONFIGURATION.value) + + self.logger.debug('Getting DG test configuration record') + + received_message = self.can_interface.send(message) + + self._reset_test_configs_record() + + # If there is content... + if received_message is not None: + self.logger.debug("Received FW ACK after requesting DG test configuration record.") + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + + def cmd_reset_all_test_configs(self): + """ + Constructs and sends the DG test configs reset all + Constraints: + Must be logged into DG. + + @return: 1 if successful, zero otherwise + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DG_RESET_ALL_TEST_CONFIGURATIONS.value) + + self.logger.debug("Resetting all DG test configurations") + + # Send message + received_message = self.can_interface.send(message) + + # If there is no 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.debug("Timeout!!!!") + return False + + @publish(['dg_test_configs']) + def _handler_dg_test_config_sync(self, message, timestamp=0.0): + """ + Handles published test configuration status messages. + + @param message: published DG test configurations message + @return: None + """ + payload = message['message'] + index = MsgFieldPositions.START_POS_FIELD_1 + + for config in DGTestConfigOptions.__members__: + if 'NUM_OF_TEST_CONFIGS' not in config: + config_value, index = bytearray_to_integer(payload, index, False) + self.dg_test_configs[config] = config_value + + self.dg_test_configs_response_timestamp = timestamp + + def _reset_test_configs_record(self): + """ + Resets the test configuration dictionary + + @return: None + """ + for config in DGTestConfigOptions.__members__: + # Loop through the list of the test configuration and set the values to 0xFFFFFFFF + if 'NUM_OF_TEST_CONFIGS' not in config: + self.dg_test_configs[config] = 0xFFFFFFFF Index: dialin/dg/dialysate_generator.py =================================================================== diff -u -r9bc00e997e91dab8b404aa877b02ae3d4100d417 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- dialin/dg/dialysate_generator.py (.../dialysate_generator.py) (revision 9bc00e997e91dab8b404aa877b02ae3d4100d417) +++ dialin/dg/dialysate_generator.py (.../dialysate_generator.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -54,6 +54,7 @@ from .events import DGEvents from .sw_configs import DGSoftwareConfigs from .usage_info_record import DGUsageNVRecord +from .dg_test_configs import DGTestConfig from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import DenaliCanMessenger, DenaliMessage, DenaliChannels from ..utils import * @@ -201,6 +202,7 @@ self.events = DGEvents(self.can_interface, self.logger) self.sw_configs = DGSoftwareConfigs(self.can_interface, self.logger) self.usage_record = DGUsageNVRecord(self.can_interface, self.logger) + self.test_configs = DGTestConfig(self.can_interface, self.logger) def get_version(self): """ Index: dialin/hd/sw_configs.py =================================================================== diff -u -r9bc00e997e91dab8b404aa877b02ae3d4100d417 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- dialin/hd/sw_configs.py (.../sw_configs.py) (revision 9bc00e997e91dab8b404aa877b02ae3d4100d417) +++ dialin/hd/sw_configs.py (.../sw_configs.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -77,6 +77,7 @@ SW_CONFIG_DISABLE_SERVICE_AND_DISINFECT_CHECK = 42 SW_CONFIG_DISABLE_AIR_PUMP = 43 + class HDSoftwareConfigs(AbstractSubSystem): """ @brief Hemodialysis Device (HD) Dialin API sub-class for HD software configurations related commands. Index: tests/dg_nvm_scripts.py =================================================================== diff -u -r6eb7388c7884a276c3c8b93aa8060feaab38081b -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- tests/dg_nvm_scripts.py (.../dg_nvm_scripts.py) (revision 6eb7388c7884a276c3c8b93aa8060feaab38081b) +++ tests/dg_nvm_scripts.py (.../dg_nvm_scripts.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -27,12 +27,12 @@ # It creates a folder called DG_NV_Records in the destination that is called # If no address is provided, the default location is one folder above the dialin folder wherever it is installed # in your computer. - #dg.sw_configs.cmd_get_dg_sw_config_record() + dg.sw_configs.cmd_get_dg_sw_config_record() # Use cmd_set_dg_sw_config_record() set the changes back to firmware # This function requires an address for the excel report. Use the absolute address of your excel report like the # example below - dg.sw_configs.cmd_update_dg_sw_config_record('/home/fw/projects/DG_NV_Records/2023-04-17-DG-SW-CONFIGS-Record.xlsx') + #dg.sw_configs.cmd_update_dg_sw_config_record('/home/fw/projects/DG_NV_Records/2023-04-25-DG-SW-CONFIGS-Record.xlsx') # Use this function to reset the configuration records to all be 0 #dg.sw_configs.cmd_reset_dg_sw_config_record() Index: tests/dg_tests.py =================================================================== diff -u -re8f9ead3fe058b688c0b42c599886375e1730008 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- tests/dg_tests.py (.../dg_tests.py) (revision e8f9ead3fe058b688c0b42c599886375e1730008) +++ tests/dg_tests.py (.../dg_tests.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -48,6 +48,7 @@ from dialin.hd.voltages import HDMonitoredVoltages from dialin.hd.pretreatment import PreTreatmentRsrvrState from dialin.common.dg_defs import DGFlushStates, DGHeatDisinfectActiveCoolStates +from dialin.common.test_config_defs import DGTestConfigOptions, HDTestConfigOptions from time import sleep from datetime import datetime import sys @@ -151,9 +152,9 @@ def get_hd_occlusion_pressures_info(): - info = ('Art_pres, {:5.3f}, Venous_pres, {:5.3f}, Blood_pump_pres, {:5.3f}, DialIn_pres, {}, DialOut_pres, {}, ' + info = ('Art_pres, {:5.3f}, Venous_pres, {:5.3f}, Blood_pump_pres, {:5.3f}, DialOut_pres, {}, ' .format(hd.pressure_occlusion.arterial_pressure, hd.pressure_occlusion.venous_pressure, - hd.pressure_occlusion.blood_pump_occlusion, hd.pressure_occlusion.dialysate_inlet_pump_occlusion, + hd.pressure_occlusion.blood_pump_occlusion, hd.pressure_occlusion.dialysate_outlet_pump_occlusion)) return info @@ -522,7 +523,7 @@ f = open(address, "w") #dg.heaters.cmd_heaters_broadcast_interval_override(50) #sleep(1) - #dg.hd_proxy.cmd_start_stop_dg_heat_disinfect() + dg.hd_proxy.cmd_start_stop_dg_heat_disinfect() #dg.hd_proxy.cmd_start_stop_dg_heat_disinfect_active_cool() try: @@ -671,9 +672,22 @@ hd = HD(log_level='DEBUG') hd.cmd_log_in_to_hd() sleep(1) + """ + print(dg.test_configs.dg_test_configs) + print(hex(dg.test_configs.cmd_get_test_config_status(DGTestConfigOptions.TEST_CONFIG_ENABLE_MIXING_WITH_WATER.value))) - run_heat_disinfect() + dg.test_configs.cmd_set_test_config(DGTestConfigOptions.TEST_CONFIG_ENABLE_MIXING_WITH_WATER.value, reset=0) + sleep(1) + dg.test_configs.cmd_request_test_config_status_from_fw() + + while True: + print(hex(dg.test_configs.cmd_get_test_config_status( + DGTestConfigOptions.TEST_CONFIG_ENABLE_MIXING_WITH_WATER.value))) + sleep(1) + """ + #run_heat_disinfect() + #run_flush_mode() #run_chemical_disinfect() @@ -684,7 +698,7 @@ # cmd_set_disinfect_ui_screen() - #collect_treatment_data() + collect_treatment_data() #collect_hd_treatment() Index: tests/test_hd_valves.py =================================================================== diff -u -racd09d02879e8add4cf7f694f5db8e423a76c341 -r386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf --- tests/test_hd_valves.py (.../test_hd_valves.py) (revision acd09d02879e8add4cf7f694f5db8e423a76c341) +++ tests/test_hd_valves.py (.../test_hd_valves.py) (revision 386b48cd9e28d3a3d30ddd3d87fe5da686eb5dbf) @@ -19,19 +19,28 @@ from dialin.hd.hemodialysis_device import HD from dialin.hd.valves import ValvesEnum from time import sleep +import os if __name__ == "__main__": # create an HD object called hd hd = HD() hd.cmd_log_in_to_hd() + address = os.path.join(os.getcwd(), "DVT-006-valves.log") + f = open(address, "w") + hd.valves.cmd_hd_valves_broadcast_interval_override(50) sleep(1) #hd.valves.cmd_home_hd_valve(ValvesEnum.VDI.value) + #hd.cmd_hd_set_operation_mode(2) + #sleep(1) + while True: - print(hd.valves.valves_status, hd.alarms.alarm_top) - sleep(0.05) + var = str(hd.valves.valves_status) + '\r' + print(var) + f.write(var) + sleep(0.5) """