Index: dialin/dg/calibration_record.py =================================================================== diff -u -r7c47b3d1b3c4b685999c0f0a8b402b692391d633 -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision 7c47b3d1b3c4b685999c0f0a8b402b692391d633) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -57,7 +57,6 @@ _DIALIN_RECORD_UPDATE_DELAY_S = 0.2 _FIRMWARE_STACK_NAME = 'DG' - _CAL_RECORD_TAB_NAME = 'Calibration Record' def __init__(self, can_interface, logger: Logger): """ @@ -105,7 +104,7 @@ @return: none """ # Prepare the excel report - self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._CAL_RECORD_TAB_NAME, + self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._utilities.CAL_RECORD_TAB_NAME, report_destination, protect_sheet=True) # Request the DG calibration record and set and observer class to callback when the calibration record is read # back @@ -213,7 +212,7 @@ while not observer.received: sleep(0.1) self._utilities.write_excel_record_to_fw_record(self.dg_calibration_record, report_address, - self._CAL_RECORD_TAB_NAME) + self._utilities.CAL_RECORD_TAB_NAME) self.cmd_set_dg_calibration_record(self.dg_calibration_record) Index: dialin/hd/calibration_record.py =================================================================== diff -u -rdc3b97933c58b8854781f2984083a2f8eccd3217 -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- dialin/hd/calibration_record.py (.../calibration_record.py) (revision dc3b97933c58b8854781f2984083a2f8eccd3217) +++ dialin/hd/calibration_record.py (.../calibration_record.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -17,11 +17,12 @@ import time from collections import OrderedDict from logging import Logger +from time import sleep from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem, publish -from ..utils.nv_ops_utils import NVOpsUtils +from ..utils.nv_ops_utils import NVOpsUtils, Observer class HDCalibrationNVRecord(AbstractSubSystem): @@ -50,6 +51,8 @@ _PAYLOAD_TRANSFER_DELAY_S = 0.2 _DIALIN_RECORD_UPDATE_DELAY_S = 0.2 + _FIRMWARE_STACK_NAME = 'HD' + def __init__(self, can_interface, logger: Logger): """ @@ -64,7 +67,6 @@ self.total_messages = 0 self.received_msg_length = 0 self._is_getting_cal_in_progress = False - self._write_fw_data_to_excel = True self.cal_data = 0 self._raw_cal_record = [] self._utilities = NVOpsUtils(logger=self.logger) @@ -89,6 +91,28 @@ return status + def cmd_get_hd_calibration_record_report(self, report_destination: str = None): + """ + Handles getting HD calibration_record record from firmware and writing it to excel. + + @param report_destination: (str) the destination that the report should be written to + + @return: none + """ + # Prepare the excel report + self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._utilities.CAL_RECORD_TAB_NAME, + report_destination, protect_sheet=True) + # Request the HD calibration record and set and observer class to callback when the calibration record is read + # back + self.cmd_request_hd_calibration_record() + observer = Observer("hd_calibration_record") + # Attach the observer to the list + self.attach(observer) + while not observer.received: + sleep(0.1) + # Pass the HD calibration record to the function to write the excel + self._utilities.write_fw_record_to_excel(self.hd_calibration_record) + def cmd_request_hd_calibration_record(self) -> int: """ Handles getting HD calibration_record record from firmware. @@ -166,12 +190,34 @@ """ self.logger.debug("Received a complete hd calibration record.") + def cmd_set_hd_calibration_excel_to_fw(self, report_address: str): + """ + Handles setting the calibration data that is in an excel report to the firmware. + + @param report_address: (str) the address in which its data must be written to excel + + @return: none + """ + + # Request the HD calibration record and set and observer class to callback when the calibration record is read + # back + self.cmd_request_hd_calibration_record() + observer = Observer("hd_calibration_record") + # Attach the observer to the list + self.attach(observer) + while not observer.received: + sleep(0.1) + self._utilities.write_excel_record_to_fw_record(self.hd_calibration_record, report_address, + self._utilities.CAL_RECORD_TAB_NAME) + + self.cmd_set_hd_calibration_record(self.hd_calibration_record) + def cmd_set_hd_calibration_record(self, hd_calibration_record: OrderedDict) -> bool: """ Handles updating the HD calibration_record record with the newest calibration_record data of a hardware and sends it to FW. - @param hd_calibration_record: (OrderedDict) the hd calibration record to be send + @param hd_calibration_record: (OrderedDict) the hd calibration record to be sent @return: none """ record_packets = self._utilities.prepare_record_to_send_to_fw(hd_calibration_record) Index: dialin/hd/sw_config.py =================================================================== diff -u -r159ebdd205a50c66a870f3fa5b592a6177603960 -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- dialin/hd/sw_config.py (.../sw_config.py) (revision 159ebdd205a50c66a870f3fa5b592a6177603960) +++ dialin/hd/sw_config.py (.../sw_config.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -71,7 +71,6 @@ _RTC_RAM_MAX_BYTES_TO_WRITE = 64 _PAYLOAD_TRANSFER_DELAY_S = 0.2 _FIRMWARE_STACK_NAME = 'HD' - _NON_VOLATILE_RECORD_NAME = 'SW_Config_Report' def __init__(self, can_interface, logger: Logger): """ @@ -198,7 +197,7 @@ """ # Pass the software configuration record dictionary to be updated with the excel document status = self._utilities.get_sw_configs_from_excel(self.hd_sw_config_record, excel_report_path, - self._NON_VOLATILE_RECORD_NAME) + self._utilities.NON_VOLATILE_RECORD_NAME) # The excel document was successfully read initiate a write command if status: self._cmd_set_hd_sw_config_record() @@ -304,8 +303,8 @@ @return: none """ # Create the excel report - self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._NON_VOLATILE_RECORD_NAME, report_address, - protect_sheet=True) + self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._utilities.NON_VOLATILE_RECORD_NAME, + report_address, protect_sheet=True) # Request the latest software configuration record from firmware self._cmd_request_hd_sw_config_record() # Create ab object of the observer class to observe the dictionary Index: dialin/utils/excel_ops.py =================================================================== diff -u -rddf8a289ffc27f86d69a60922ce71d1681b668ce -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- dialin/utils/excel_ops.py (.../excel_ops.py) (revision ddf8a289ffc27f86d69a60922ce71d1681b668ce) +++ dialin/utils/excel_ops.py (.../excel_ops.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -210,12 +210,11 @@ @param excel_workbook: Excel workbook object @param save_dir: Saving directory - @param record_name: Type of recored being saved (i.e. calibration, software configuration) + @param record_name: Type of record being saved (i.e. calibration, software configuration) @param stack_name: Name of the software stack name (i.e. HD) default none @returns none """ - address = '' # Get the current date current_date = str(datetime.datetime.now().date()) # Some of the records might want to add the name of the stack. For instance, software configurations might want to Index: dialin/utils/nv_ops_utils.py =================================================================== diff -u -rddf8a289ffc27f86d69a60922ce71d1681b668ce -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision ddf8a289ffc27f86d69a60922ce71d1681b668ce) +++ dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -84,7 +84,11 @@ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 ) + # Public defines DEFAULT_CHAR_VALUE = ' ' + CAL_RECORD_TAB_NAME = 'Calibration Record' + NON_VOLATILE_RECORD_NAME = 'SW_Config_Report' + _RECORD_START_INDEX = 6 _RECORD_SPECS_BYTES = 12 _RECORD_SPECS_BYTE_ARRAY = 3 @@ -194,12 +198,22 @@ # Check if the firmware stack (i.e. DG) is in the file and name of the file # does not have lock in it. When the file is open, there is a hidden lock file # in there and it is ignored - if self._firmware_stack in str(file) and 'lock' not in str(file): - # Create the file path and exit the loop - path = os.path.join(self._workspace_dir, file) - is_report_found = True - break + file = str(file) + if self._firmware_stack in file and 'lock' not in file: + if self._SW_CONFIGS_REPORT_NAME in file and self._SW_CONFIGS_REPORT_NAME == record_name and \ + str(datetime.datetime.now().date()) in file: + # Create the file path and exit the loop + path = os.path.join(self._workspace_dir, file) + is_report_found = True + break + if self._SW_CONFIGS_REPORT_NAME in file and self._SW_CONFIGS_REPORT_NAME == record_name and \ + str(datetime.datetime.now().date()) in file: + # Create the file path and exit the loop + path = os.path.join(self._workspace_dir, file) + is_report_found = True + break + if is_report_found: # Load the excel workbook self._excel_workbook = load_excel_report(path) Index: tests/dg_tests.py =================================================================== diff -u -ra7f6b7938acc3b1e5e8dd9b8d5f8237a3b298e6b -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- tests/dg_tests.py (.../dg_tests.py) (revision a7f6b7938acc3b1e5e8dd9b8d5f8237a3b298e6b) +++ tests/dg_tests.py (.../dg_tests.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -73,6 +73,7 @@ hd.dialysate_outlet_flow.measured_dialysate_outlet_uf_volume)) return info + def get_hd_occlusion_pressures_info(): info = ('Art_pres, {:5.3f}, Venous_pres, {:5.3f}, Blood_pump_pres, {}, DialIn_pres, {}, DialOut_pres, {}, ' .format(hd.pressure_occlusion.arterial_pressure, hd.pressure_occlusion.venous_pressure, @@ -154,9 +155,11 @@ def get_ro_info(): info = ('RO, {}, PPi, {:5.3f}, PPo, {:5.3f}, PWM, {:5.3f}, Flow, {:5.3f}, Tgt_flow, {:5.3f}, Dia_flow, {:5.3f}, ' + 'Feedback_PWM, {:5.3f}, ' .format(dg.ro_pump.ro_pump_state, dg.pressures.ro_pump_inlet_pressure, dg.pressures.ro_pump_outlet_pressure, dg.ro_pump.pwm_duty_cycle_pct, - dg.ro_pump.measured_flow_rate_lpm, dg.ro_pump.target_flow_lpm, dg.dialysate_flow_sensor.flow_rate)) + dg.ro_pump.measured_flow_rate_lpm, dg.ro_pump.target_flow_lpm, dg.dialysate_flow_sensor.flow_rate, + dg.ro_pump.feedback_duty_cycle_pct)) return info @@ -562,7 +565,7 @@ hd.cmd_log_in_to_hd() sleep(1) - # run_heat_disinfect() + run_heat_disinfect() # run_chemical_disinfect() @@ -578,6 +581,3 @@ # test_dg_fans_alarms() - while True: - print(get_hd_occlusion_pressures_info(), get_hd_fans_info()) - sleep(1) Index: tests/hd_nvm_scripts.py =================================================================== diff -u -rddf8a289ffc27f86d69a60922ce71d1681b668ce -r6d6c2318a81c130b7875bfad31424e56fd8f59f2 --- tests/hd_nvm_scripts.py (.../hd_nvm_scripts.py) (revision ddf8a289ffc27f86d69a60922ce71d1681b668ce) +++ tests/hd_nvm_scripts.py (.../hd_nvm_scripts.py) (revision 6d6c2318a81c130b7875bfad31424e56fd8f59f2) @@ -1,28 +1,58 @@ from dialin import HD -if __name__ == "__main__": - hd = HD(log_level="DEBUG") +def run_sw_configs_commands(): + # NOTE: For further details, please refer to 'Instructions to Change the Software Configurations Dynamically' in + # the development section of the DevOps OneNote file - if hd.cmd_log_in_to_hd(): + # Comment and un-comment any of the functions that you would like to use or you can use your own scripts. - # NOTE: For further details, please refer to 'Instructions to Change the Software Configurations Dynamically' in - # the development section of the DevOps OneNote file + # Use cmd_get_hd_sw_config_record() to get the software configurations record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # It creates a folder called HD_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. + hd.sw_configs.cmd_get_hd_sw_config_record() - # Comment and un-comment any of the functions that you would like to use or you can use your own scripts. + # Use cmd_update_hd_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 + #hd.sw_configs.cmd_update_hd_sw_config_record('/home/fw/projects/HD_NV_Records/2022-02-14-HD-SW-CONFIGS-Record.xlsx') - # Use cmd_get_hd_sw_config_record() to get the software configurations record in an excel - # This function gets an address to locate the report there (i.e. /home/fw/projects/) - # It creates a folder called HD_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 you computer. - #hd.sw_configs.cmd_get_hd_sw_config_record() + # Use this function to reset the configuration records to all be 0 + # hd.sw_configs.cmd_reset_hd_sw_config_record() - # Use cmd_update_hd_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 - hd.sw_configs.cmd_update_hd_sw_config_record('/home/fw/projects/HD_NV_Records/2022-02-14-HD-SW-CONFIGS-Record.xlsx') - # Use this function to reset the configuration records to all be 0 - #hd.sw_configs.cmd_reset_hd_sw_config_record() +def run_calibration_commands(): + # NOTE: For further details, please refer to 'Instructions to Calibrate a Device Using the Calibration Report' + # in the development section of the DevOps OneNote file + # Comment and un-comment any of the functions that you would like to use or you can use your own scripts. + + # Use cmd_get_dg_calibration_record_report() to get the calibration record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # It creates a folder called HD_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. + hd.calibration_record.cmd_get_hd_calibration_record_report() + + # Use cmd_set_hd_calibration_excel_to_fw() 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 + #hd.calibration_record.cmd_set_hd_calibration_excel_to_fw('/home/fw/projects/HD_NV_Records/2022-02-21-HD-Record.xlsx') + + # For resetting the calibration record to benign values, use the function below + #hd.calibration_record.cmd_reset_hd_calibration_record() + + +if __name__ == "__main__": + + hd = HD(log_level="DEBUG") + + if hd.cmd_log_in_to_hd(): + + # Comment this function if not needed + run_sw_configs_commands() + + # Comment this function if not needed + #run_calibration_commands()