Index: dialin/dg/service_record.py =================================================================== diff -u -rf0cb1f298e3960769e0133172769deb9afe5a393 -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- dialin/dg/service_record.py (.../service_record.py) (revision f0cb1f298e3960769e0133172769deb9afe5a393) +++ dialin/dg/service_record.py (.../service_record.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -18,11 +18,12 @@ from collections import OrderedDict from enum import unique 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, DialinEnum, publish -from ..utils.nv_ops_utils import NVOpsUtils +from ..utils.nv_ops_utils import NVOpsUtils, NVUtilsObserver @unique @@ -43,10 +44,10 @@ _DEFAULT_SERVICE_LOCATION = ServiceLocation.SERVICE_LOCATION_FACTORY.value _DEFAULT_TIME_VALUE = 0 _DEFAULT_CRC_VALUE = 0 + _FIRMWARE_STACK_NAME = 'DG' # Maximum allowed bytes to be written to RTC RAM _RTC_RAM_MAX_BYTES_TO_WRITE = 64 - _PAYLOAD_TRANSFER_DELAY_S = 0.2 def __init__(self, can_interface, logger: Logger): @@ -250,3 +251,52 @@ groups_byte_size += self._utilities.calculate_group_byte_size(service_records[record]) return service_records, groups_byte_size + + def cmd_set_dg_service_record_excel_to_fw(self, report_address: str): + """ + Handles setting the service record data that is in an excel report to the firmware. + + @param report_address: (str) the address in which its data must be written from excel + + @return: none + """ + + # Request the DG service record and set and observer class to callback when the record is read back + self.cmd_request_dg_service_record() + observer = NVUtilsObserver("dg_usage_info_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.dg_service_record, report_address, + self._utilities.SERVICE_RECORD_TAB_NAME) + + self.cmd_set_dg_service_record(self.dg_service_record) + + def cmd_get_dg_service_record(self, report_address: str = None): + """ + Publicly accessible function to request the DG service record and write the record to excel. + + @param report_address: the address that the report needs to be written to. The default is None so it picks an + address and writes the excel report. + + @return: none + """ + + # Create the excel report + self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._utilities.USAGE_INFO_RECORD_TAB_NAME, + report_address, protect_sheet=True) + + # Create an object of the observer class to observe the dictionary + observer = NVUtilsObserver("dg_service_record") + # Attach the observer to the list + self.attach(observer) + + # Request the latest software configuration record from firmware + self.cmd_request_dg_service_record() + # Wait until data has been received from firmware + while not observer.received: + sleep(0.1) + print(self.dg_service_record) + # Write the updated values from excel to firmware + self._utilities.write_fw_record_to_excel(self.dg_service_record) Index: dialin/dg/usage_info_record.py =================================================================== diff -u -r7ea4b936cef531b2cde9053ae58b7119a3bf0e6c -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- dialin/dg/usage_info_record.py (.../usage_info_record.py) (revision 7ea4b936cef531b2cde9053ae58b7119a3bf0e6c) +++ dialin/dg/usage_info_record.py (.../usage_info_record.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -32,7 +32,7 @@ Dialysate Generator (DG) Dialin API sub-class for setting and getting the usage information record. """ - _DEFAULT_USAGE_INFO_VALUE = 0 + _DEFAULT_USAGE_INFO_VALUE = 0.0 _DEFAULT_CRC_VALUE = 0 _RECORD_SPECS_BYTES = 12 # Maximum allowed bytes to be written to RTC RAM @@ -231,10 +231,16 @@ groups_byte_size = 0 usage_info_records = OrderedDict( {'usage_info_record': - {'ro_total_liters': [' bool: + """ + Handles resetting DG usage info record. + + @return: True if successful, False otherwise + """ + self.dg_usage_info_record = self._prepare_dg_usage_info_record() + self.dg_usage_info_record = self._utilities.reset_fw_record(self.dg_usage_info_record) + status = self._cmd_set_dg_usage_info_record(self.dg_usage_info_record) + + return status + + def cmd_set_dg_usage_info_excel_to_fw(self, report_address: str): + """ + Handles setting the usage info data that is in an excel report to the firmware. + + @param report_address: (str) the address in which its data must be written from excel + + @return: none + """ + + # Request the DG usage record and set and observer class to callback when the record is read back + self._cmd_request_dg_usage_info_record() + observer = NVUtilsObserver("dg_usage_info_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.dg_usage_info_record, report_address, + self._utilities.USAGE_INFO_RECORD_TAB_NAME) + + self._cmd_set_dg_usage_info_record(self.dg_usage_info_record) Index: dialin/hd/service_record.py =================================================================== diff -u -rf0cb1f298e3960769e0133172769deb9afe5a393 -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- dialin/hd/service_record.py (.../service_record.py) (revision f0cb1f298e3960769e0133172769deb9afe5a393) +++ dialin/hd/service_record.py (.../service_record.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -18,11 +18,12 @@ from collections import OrderedDict from enum import unique 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, DialinEnum -from ..utils.nv_ops_utils import NVOpsUtils +from ..utils.nv_ops_utils import NVOpsUtils, NVUtilsObserver @unique @@ -43,6 +44,7 @@ _DEFAULT_SERVICE_LOCATION = ServiceLocation.SERVICE_LOCATION_FACTORY.value _DEFAULT_TIME_VALUE = 0 _DEFAULT_CRC_VALUE = 0 + _FIRMWARE_STACK_NAME = 'HD' # Maximum allowed bytes to be written to RTC RAM _RTC_RAM_MAX_BYTES_TO_WRITE = 64 @@ -252,3 +254,52 @@ groups_byte_size += self._utilities.calculate_group_byte_size(service_records[record]) return service_records, groups_byte_size + + def cmd_set_dg_service_record_excel_to_fw(self, report_address: str): + """ + Handles setting the service record data that is in an excel report to the firmware. + + @param report_address: (str) the address in which its data must be written from excel + + @return: none + """ + + # Request the DG service record and set and observer class to callback when the record is read back + self.cmd_request_hd_service_record() + observer = NVUtilsObserver("hd_service_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_service_record, report_address, + self._utilities.SERVICE_RECORD_TAB_NAME) + + self.cmd_set_hd_service_record(self.hd_service_record) + + def cmd_get_hd_service_record(self, report_address: str = None): + """ + Publicly accessible function to request the HD service record and write the record to excel. + + @param report_address: the address that the report needs to be written to. The default is None so it picks an + address and writes the excel report. + + @return: none + """ + + # Create the excel report + self._utilities.prepare_excel_report(self._FIRMWARE_STACK_NAME, self._utilities.USAGE_INFO_RECORD_TAB_NAME, + report_address, protect_sheet=True) + + # Create an object of the observer class to observe the dictionary + observer = NVUtilsObserver("hd_service_record") + # Attach the observer to the list + self.attach(observer) + + # Request the latest software configuration record from firmware + self.cmd_request_hd_service_record() + # Wait until data has been received from firmware + while not observer.received: + sleep(0.1) + print(self.hd_service_record) + # Write the updated values from excel to firmware + self._utilities.write_fw_record_to_excel(self.hd_service_record) Index: dialin/hd/usage_info_record.py =================================================================== diff -u -r7ea4b936cef531b2cde9053ae58b7119a3bf0e6c -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- dialin/hd/usage_info_record.py (.../usage_info_record.py) (revision 7ea4b936cef531b2cde9053ae58b7119a3bf0e6c) +++ dialin/hd/usage_info_record.py (.../usage_info_record.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -141,7 +141,7 @@ """ self.logger.debug("Received a complete HD usage information record.") - def cmd_update_dg_usage_info_record(self, excel_report_path: str): + def cmd_update_hd_usage_info_record(self, excel_report_path: str): """ Handles preparing the HD usage information from the provided excel report @@ -233,7 +233,8 @@ {'usage_info_record': {'tx_total_time_hours': [' bool: + """ + Handles resetting HD usage info record. + + @return: True if successful, False otherwise + """ + self.hd_usage_info_record = self._prepare_hd_usage_info_record() + self.hd_usage_info_record = self._utilities.reset_fw_record(self.hd_usage_info_record) + status = self._cmd_set_hd_usage_info_record(self.hd_usage_info_record) + + return status + + def cmd_set_dg_usage_info_excel_to_fw(self, report_address: str): + """ + Handles setting the usage info data that is in an excel report to the firmware. + + @param report_address: (str) the address in which its data must be written from excel + + @return: none + """ + + # Request the DG usage record and set and observer class to callback when the calibration record is read + # back + self._cmd_request_hd_usage_info_record() + observer = NVUtilsObserver("hd_usage_info_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_usage_info_record, report_address, + self._utilities.USAGE_INFO_RECORD_TAB_NAME) + + self._cmd_set_hd_usage_info_record(self.hd_usage_info_record) + Index: dialin/utils/nv_ops_utils.py =================================================================== diff -u -ra3008f2085dca1d8de69c242414b91429bc188e9 -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision a3008f2085dca1d8de69c242414b91429bc188e9) +++ dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -90,6 +90,8 @@ NON_VOLATILE_RECORD_NAME = 'SW_Config_Report' USAGE_INFO_RECORD_TAB_NAME = 'Usage_Info_Report' SYSTEM_RECORD_TAB_NAME = 'System_Record' + SERVICE_RECORD_TAB_NAME = 'Service_Record' + DEFAULT_EPOCH_VALUE = 0 _RECORD_START_INDEX = 6 _RECORD_SPECS_BYTES = 12 Index: tests/dg_nvm_scripts.py =================================================================== diff -u -r3ebf82ed05a35a2ee9f38f0f0dc1541aeaa09e04 -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- tests/dg_nvm_scripts.py (.../dg_nvm_scripts.py) (revision 3ebf82ed05a35a2ee9f38f0f0dc1541aeaa09e04) +++ tests/dg_nvm_scripts.py (.../dg_nvm_scripts.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -54,21 +54,20 @@ # Use cmd_set_dg_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 - #dg.calibration_record.cmd_set_dg_calibration_excel_to_fw('/home/fw/projects/DG_NV_Records/2022-10-06-DG-Record_betadvt2.xlsx') + dg.calibration_record.cmd_set_dg_calibration_excel_to_fw('/home/fw/projects/DG_NV_Records/2022-10-06-DG-Record_betadvt2.xlsx') # For resetting the calibration record to benign values, use the function below #dg.calibration_record.cmd_reset_dg_calibration_record() def run_system_commands(): - # 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_system_record_report() to get the system record in an excel # This function gets an address to locate the report there (i.e. /home/fw/projects/) # 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 you computer. + # in your computer. #dg.system_record.cmd_get_dg_system_record_report() dg.system_record.cmd_set_dg_system_record_excel_to_fw('/home/fw/projects/DG_NV_Records/2022-09-26-DG-Record.xlsx') @@ -77,6 +76,36 @@ #dg.system_record.cmd_reset_dg_system_record() +def run_usage_info_commands(): + # 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_system_record_report() to get the system record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # 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.usage_record.cmd_get_dg_usage_info_record() + + dg.usage_record.cmd_set_dg_usage_info_excel_to_fw('/home/fw/projects/DG_NV_Records/2022-09-26-DG-Record.xlsx') + + dg.usage_record.cmd_reset_dg_usage_info_record() + + +def run_service_commands(): + # 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_system_record_report() to get the system record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # 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.service_record.cmd_get_dg_service_record() + + dg.service_record.cmd_set_dg_service_record_excel_to_fw('/home/fw/projects/DG_NV_Records/2022-09-26-DG-Record.xlsx') + + dg.service_record.cmd_reset_dg_service_record() + + if __name__ == "__main__": dg = DG(log_level="DEBUG") @@ -89,6 +118,7 @@ #run_system_commands() - #dg.usage_record.cmd_get_dg_usage_info_record() - #dg.usage_record.cmd_update_dg_usage_info_record('/home/fw/projects/DG_NV_Records/2022-04-22-DG-Record.xlsx') + #run_usage_info_commands() + #run_service_commands() + Index: tests/hd_nvm_scripts.py =================================================================== diff -u -r3ebf82ed05a35a2ee9f38f0f0dc1541aeaa09e04 -rcd79d9df6686d5aa1f71ad4789a7c372ddcff370 --- tests/hd_nvm_scripts.py (.../hd_nvm_scripts.py) (revision 3ebf82ed05a35a2ee9f38f0f0dc1541aeaa09e04) +++ tests/hd_nvm_scripts.py (.../hd_nvm_scripts.py) (revision cd79d9df6686d5aa1f71ad4789a7c372ddcff370) @@ -68,7 +68,7 @@ # This function gets an address to locate the report there (i.e. /home/fw/projects/) # 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 you computer. + # in your computer. #hd.system_record.cmd_get_hd_system_record_report() hd.system_record.cmd_set_hd_system_record_excel_to_fw('/home/fw/projects/HD_NV_Records/2022-09-26-HD-Record.xlsx') @@ -77,6 +77,36 @@ #hd.system_record.cmd_reset_hd_system_record() +def run_usage_info_commands(): + # 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_system_record_report() to get the system record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # 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. + hd.usage_record.cmd_get_hd_usage_info_record() + + hd.usage_record.cmd_set_dg_usage_info_excel_to_fw('/home/fw/projects/HD_NV_Records/2022-09-26-HD-Record.xlsx') + + hd.usage_record.cmd_reset_hd_usage_info_record() + + +def run_service_commands(): + # 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_system_record_report() to get the system record in an excel + # This function gets an address to locate the report there (i.e. /home/fw/projects/) + # 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. + hd.service_record.cmd_get_hd_service_record() + + hd.service_record.cmd_set_dg_service_record_excel_to_fw('/home/fw/projects/HD_NV_Records/2022-09-26-HD-Record.xlsx') + + hd.service_record.cmd_reset_hd_service_record() + + if __name__ == "__main__": hd = HD(log_level="DEBUG") @@ -91,3 +121,7 @@ #run_system_commands() + #run_usage_info_commands() + + #run_service_commands() +