Index: dialin/dg/sw_config.py =================================================================== diff -u -rd832b9ec145bf0c8bf3bf0bdc4844d146a60e600 -r6286da1bcfac5f1d43659196fb1baf27af50d746 --- dialin/dg/sw_config.py (.../sw_config.py) (revision d832b9ec145bf0c8bf3bf0bdc4844d146a60e600) +++ dialin/dg/sw_config.py (.../sw_config.py) (revision 6286da1bcfac5f1d43659196fb1baf27af50d746) @@ -14,7 +14,7 @@ @unique -class SWConfigs(DialinEnum): +class DGSWConfigs(DialinEnum): # NOTE: NUM_OF enum has been removed because it should be a part of the software configuration # structure since the members of this class is for looped to create the dictionary automatically SW_CONFIG_DISABLE_HEATERS_MONITOR = 0 @@ -208,7 +208,7 @@ def _prepare_dg_sw_configs_record(self) -> OrderedDict: """ - Handles assembling the sub dictionaries of each group to make a blank dg software configuration record. + Handles assembling the sub dictionaries of each group to make a blank DG software configuration record. @return: (OrderedDict) the assembled dg software configuration record """ @@ -252,8 +252,8 @@ # Create an ordered dictionary sw_configs = OrderedDict({name: {}}) - # Loop through the members of the SWConfigs enum class - for config in SWConfigs.__members__: + # Loop through the members of the DGSWConfigs enum class + for config in DGSWConfigs.__members__: # Insert the enum name into the dictionary with the default software config. Each config is one byte sw_configs[name].update({config: [' bool: + """ + Handles resetting HD software configuration record. + + @return: True if successful, False otherwise + """ + # Get the default software configuration dictionary + self.hd_sw_config_record = self._prepare_hd_sw_configs_record() + # Calculate the CRC for reset software configuration record + #self._utilities.reset_fw_system_service_record(self.hd_sw_config_record) + status = self._cmd_set_hd_sw_config_record() + + return status + + def _cmd_request_hd_sw_config_record(self) -> int: + """ + Handles getting HD software config record from firmware. + + @return: 1 upon success, False otherwise + """ + if self._is_getting_sw_config_in_progress is not True: + self._is_getting_sw_config_in_progress = True + # Clear the list for the next call + self._raw_sw_config_record.clear() + # Run the firmware commands to get the record + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_HD_GET_SW_CONFIG_RECORD.value) + + self.logger.debug('Getting HD software configuration record') + + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + self.logger.debug("Received FW ACK after requesting DG software configuration record.") + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + + self.logger.debug("Request cancelled: an existing request is in progress.") + return False + + def _handler_hd_sw_config_sync(self, message): + """ + Handles published HD software configuration record messages. HD software configuration records are captured for + processing and updating the HD software configuration record. + + @param message: published HD software configuration record data message + + @return: None + """ + curr = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] + total = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] + length = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] + + self._current_message = curr + self._total_messages = total + self._received_msg_length = length + # The end of calibration_record record payload is from the start index + 12 bytes for the current message +total + # messages + the length of calibration_record. The rest is the CAN messaging CRC that is not needed + # to be kept + end_of_data_index = MsgFieldPositions.START_POS_FIELD_1 + self._RECORD_SPECS_BYTES + self._received_msg_length + + # Get the data only and not specs of it (i.e current message number) + self._sw_config_data = message['message'][MsgFieldPositions.START_POS_FIELD_1:end_of_data_index] + + # Continue getting calibration_record records until the all the calibration_record messages are received. + # Concatenate the calibration_record records to each other + if self._current_message <= self._total_messages: + self._raw_sw_config_record += (message['message'][MsgFieldPositions.START_POS_FIELD_1 + + self._RECORD_SPECS_BYTES:end_of_data_index]) + if self._current_message == self._total_messages: + # Done with receiving the messages + self._is_getting_sw_config_in_progress = False + # If all the messages have been received, call another function to process the raw data + self._utilities.process_received_record_from_fw(self.hd_sw_config_record, self._raw_sw_config_record) + self._handler_received_complete_hd_sw_config_record() + + @publish(["hd_sw_config_record"]) + def _handler_received_complete_hd_sw_config_record(self): + """ + Publishes the received software configuration record + + @return: None + """ + self.logger.debug("Received a complete HD software configuration record.") + + def cmd_update_hd_sw_config_record(self, excel_report_path: str): + """ + Handles preparing the HD software configuration from the provided excel report + + @param excel_report_path: (str) the directory in which the excel report of the software configuration is located + @return: none + """ + # 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) + # The excel document was successfully read initiate a write command + if status: + self._cmd_set_hd_sw_config_record() + else: + self.logger.debug('Could not find the software configurations file') + + def _cmd_set_hd_sw_config_record(self) -> bool: + """ + Handles updating the HD software configuration record and sends it to FW. + + @return: True upon success, False otherwise + """ + record_packets = self._utilities.prepare_record_to_send_to_fw(self.hd_sw_config_record) + + self.logger.debug('Setting HD sw config record') + + # Update all the data packets with the last message count since is the number of messages that firmware + # should receive + for packet in record_packets: + # Sleep to let the firmware receive and process the data + time.sleep(self._PAYLOAD_TRANSFER_DELAY_S) + + # Convert the list packet to a bytearray + payload = b''.join(packet) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_HD_SET_SW_CONFIG_RECORD.value, + payload=payload) + + received_message = self.can_interface.send(message) + + # If there is no content... + if received_message is None: + self.logger.debug("Timeout!!!!") + return False + + self.logger.debug("Finished sending HD software configuration record.") + return True + + def _prepare_hd_sw_configs_record(self) -> OrderedDict: + """ + Handles assembling the sub dictionaries of each group to make a blank HD software configuration record. + + @return: (OrderedDict) the assembled dg software configuration record + """ + record = OrderedDict() + + groups_byte_size = 0 + # create a list of the functions of the sub dictionaries + functions = [self._prepare_sw_configs_record()] + + for function in functions: + # Update the groups bytes size so far to be used for padding later + groups_byte_size += function[1] + # Update the calibration record + record.update(function[0]) + + # Build the CRC of the main calibration_record record + record_crc = OrderedDict({'crc': [' tuple: + """ + Handles creating the software configuration record dictionary. + + @return: software configuration record dictionary and the byte size of this group + """ + groups_byte_size = 0 + name = 'sw_configs' + # Create an ordered dictionary + sw_configs = OrderedDict({name: {}}) + + # Loop through the members of the HDSWConfigs enum class + for config in HDSWConfigs.__members__: + # Insert the enum name into the dictionary with the default software config. Each config is one byte + sw_configs[name].update({config: [' 4: + break + + timer += 1 + + print(var) + f.write(var) + sleep(1) + + counter += 1 + """ + + Index: tests/hd_valves_test.py =================================================================== diff -u -radae506afce35a0063c6c2baf7e8580986f3bee7 -r6286da1bcfac5f1d43659196fb1baf27af50d746 --- tests/hd_valves_test.py (.../hd_valves_test.py) (revision adae506afce35a0063c6c2baf7e8580986f3bee7) +++ tests/hd_valves_test.py (.../hd_valves_test.py) (revision 6286da1bcfac5f1d43659196fb1baf27af50d746) @@ -20,6 +20,8 @@ from dialin.hd.valves import ValvesEnum from dialin.hd.valves import AirTrapState from dialin.hd.valves import ValvesPositions +from dialin.common.alarm_defs import AlarmList +from dialin.common.hd_defs import HDOpModes from time import sleep @@ -114,6 +116,36 @@ sleep(1) +def fail_homing(): + + i = 0 + while i < 5: + status = False + hd.cmd_hd_software_reset_request() + sleep(1) + + hd.alarms.clear_dialin_alarms() + + while True: + if hd.hd_operation_mode == HDOpModes.MODE_STAN.value and status is not True: + hd.cmd_log_in_to_hd() + sleep(1) + + hd.valves.cmd_home_hd_valve(0) + #sleep(2) + hd.valves.cmd_set_hd_valve_position_count_override(0, 8000) + status = True + + print(i, hd.alarms.get_alarm_state(AlarmList.ALARM_ID_HD_VALVE_HOMING_FAILED.value), hd.alarms.alarm_top) #, hd.valves.valves_status[ValvesEnum.VDI.name]) + sleep(0.1) + + if hd.alarms.get_alarm_state(AlarmList.ALARM_ID_HD_VALVE_HOMING_FAILED.value): + i += 1 + sleep(1) + break + + + if __name__ == "__main__": # Create an instance of the DG Class hd = HD(log_level='DEBUG') @@ -124,5 +156,5 @@ valves = hd.valves #cycle_valves() - change_valves_position() - + #change_valves_position() + fail_homing() Index: tests/peter/set_RTCs.py =================================================================== diff -u -radae506afce35a0063c6c2baf7e8580986f3bee7 -r6286da1bcfac5f1d43659196fb1baf27af50d746 --- tests/peter/set_RTCs.py (.../set_RTCs.py) (revision adae506afce35a0063c6c2baf7e8580986f3bee7) +++ tests/peter/set_RTCs.py (.../set_RTCs.py) (revision 6286da1bcfac5f1d43659196fb1baf27af50d746) @@ -39,11 +39,11 @@ current_time.tm_year) print("Successfully set HD rtc") - if dg.cmd_log_in_to_dg(): - dg.rtc.cmd_set_rtc_time_and_date(current_time.tm_sec, - current_time.tm_min, - current_time.tm_hour, - current_time.tm_mday, - current_time.tm_mon, - current_time.tm_year) - print("Successfully set DG rtc") + #if dg.cmd_log_in_to_dg(): + # dg.rtc.cmd_set_rtc_time_and_date(current_time.tm_sec, + # current_time.tm_min, + # current_time.tm_hour, + # current_time.tm_mday, + # current_time.tm_mon, + # current_time.tm_year) + # print("Successfully set DG rtc") Index: tests/peter/test_dg_records.py =================================================================== diff -u -r3e92417e035803f1401d5818f0117859ee049d9e -r6286da1bcfac5f1d43659196fb1baf27af50d746 --- tests/peter/test_dg_records.py (.../test_dg_records.py) (revision 3e92417e035803f1401d5818f0117859ee049d9e) +++ tests/peter/test_dg_records.py (.../test_dg_records.py) (revision 6286da1bcfac5f1d43659196fb1baf27af50d746) @@ -24,7 +24,7 @@ sys.path.append("../../") from dialin.dg.dialysate_generator import DG from dialin.utils.nv_ops_utils import NVOpsUtils -from dialin.dg.sw_config import SWConfigs +from dialin.dg.sw_config import DGSWConfigs from time import sleep """ @@ -189,7 +189,7 @@ while not observer.received: sleep(0.2) """ - #dg.sw_configs.dg_sw_config_record['sw_configs'][SWConfigs.SW_CONFIG_DISABLE_HEATERS_MONITOR.name][1] = 1 + #dg.sw_configs.dg_sw_config_record['sw_configs'][DGSWConfigs.SW_CONFIG_DISABLE_HEATERS_MONITOR.name][1] = 1 #print(dg.sw_configs.dg_sw_config_record) #dg.sw_configs.cmd_set_dg_sw_config_record(dg.sw_configs.dg_sw_config_record) @@ -257,7 +257,7 @@ #sleep(0.25) #print(dg.calibration_record.dg_calibration_record) - #dg.scheduled_runs_record.cmd_reset_dg_calibration_record() + dg.calibration_record.cmd_reset_dg_calibration_record() #sleep(0.25) dg.system_record.cmd_reset_dg_system_record() sleep(0.25) Index: tests/peter/test_hd_records.py =================================================================== diff -u -r4df4ba2027fd95dbdd6601cd3ec14861ce9fb6e7 -r6286da1bcfac5f1d43659196fb1baf27af50d746 --- tests/peter/test_hd_records.py (.../test_hd_records.py) (revision 4df4ba2027fd95dbdd6601cd3ec14861ce9fb6e7) +++ tests/peter/test_hd_records.py (.../test_hd_records.py) (revision 6286da1bcfac5f1d43659196fb1baf27af50d746) @@ -97,9 +97,10 @@ if hd.cmd_log_in_to_hd(resend=False): hd.calibration_record.cmd_reset_hd_calibration_record() - print(hd.calibration_record.hd_calibration_record) + #print(hd.calibration_record.hd_calibration_record) #hd.system_record.cmd_reset_hd_system_record() #hd.service_record.cmd_reset_hd_service_record() + #print(hd.service_record.hd_service_record) def test_hd_system_record(): @@ -125,10 +126,36 @@ hd.system_record.cmd_set_hd_system_record(hd.system_record.hd_system_record) +def test_hd_sw_config_record(): + hd = HD(log_level="DEBUG") + if hd.cmd_log_in_to_hd(): + + #print(dg.cmd_ui_request_dg_version()) + #dg.sw_configs.cmd_reset_dg_sw_config_record() + #hd.sw_configs.cmd_reset_hd_sw_config_record() + #sleep(2) + + #hd.sw_configs.cmd_get_hd_sw_config_record('/home/fw/') + hd.sw_configs.cmd_update_hd_sw_config_record('/home/fw/projects/HD_NV_Records/2022-01-26-SW-CONFIGS-Record.xlsx') + #dg.sw_configs.cmd_set_dg_sw_config_record('/home/fw/DG_NV_Records/2022-01-22-SW-CONFIGS-Record.xlsx') + + """ + observer = Observer("dg_sw_config_record") + dg.sw_configs.attach(observer) + while not observer.received: + sleep(0.2) + """ + #dg.sw_configs.dg_sw_config_record['sw_configs'][DGSWConfigs.SW_CONFIG_DISABLE_HEATERS_MONITOR.name][1] = 1 + #print(dg.sw_configs.dg_sw_config_record) + + #dg.sw_configs.cmd_set_dg_sw_config_record(dg.sw_configs.dg_sw_config_record) + + if __name__ == "__main__": test_hd_reset_record_record() + #test_hd_sw_config_record() #test_hd_calibration_record() # test_hd_service_record() #test_hd_reset_system_record()