Index: dialin/dg/service_record.py =================================================================== diff -u -rd384151f5e4718f092f9cafbf537fbca34b44e07 -re949b0efaf7f65be389116f4c905b50cbae60b7d --- dialin/dg/service_record.py (.../service_record.py) (revision d384151f5e4718f092f9cafbf537fbca34b44e07) +++ dialin/dg/service_record.py (.../service_record.py) (revision e949b0efaf7f65be389116f4c905b50cbae60b7d) @@ -28,8 +28,12 @@ _DEFAULT_TIME_VALUE = 0 _DEFAULT_CRC_VALUE = 0 + # Maximum allowed bytes to be written to RTC RAM _RTC_RAM_MAX_BYTES_TO_WRITE = 64 + + # Delay in between each payload transfer _PAYLOAD_TRANSFER_DELAY = 0.2 + _DIALIN_RECORD_UPDATE_DELAY_S = 0.2 def __init__(self, can_interface, logger: Logger): """ @@ -46,8 +50,9 @@ self.received_msg_length = 0 self.service_data = 0 self._is_getting_service_in_progress = False - self.raw_service_record = [] - self.utilities = NVOpsUtils() + self._write_fw_data_to_excel = True + self._raw_service_record = [] + self._utilities = NVOpsUtils() # Service main record self.dg_service_record = OrderedDict() @@ -68,7 +73,7 @@ if self._is_getting_service_in_progress is not True: self._is_getting_service_in_progress = True # Clear the list for the next call - self.raw_service_record.clear() + self._raw_service_record.clear() # Run the firmware commands to get the record self._request_dg_fw_service_record() @@ -124,14 +129,55 @@ # 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_service_record += (message['message'][self._RECORD_START_INDEX + - self._RECORD_SPECS_BYTES:end_of_data_index]) + self._raw_service_record += (message['message'][self._RECORD_START_INDEX + + self._RECORD_SPECS_BYTES:end_of_data_index]) if self.current_message == self.total_messages: # Done with receiving the messages self._is_getting_service_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.dg_service_record, self.raw_service_record) + self._utilities.process_received_record_from_fw(self.dg_service_record, self._raw_service_record, + write_to_excel=self._write_fw_data_to_excel) + def set_dg_service_record(self): + """ + Handles updating the DG service record and sends it to FW. + + @return: none + """ + # Read the data from firmware but do not update the excel document + # At this step, another read from firmware is requested internally to update the dictionary. + # The values in the dictionary is compared against the excel report and if they are different, it automatically + # sets the calibration time and calculates the CRC for that group. By default once a read from firmware is + # requested, the excel report is updated automatically. + self._write_fw_data_to_excel = False + self.get_dg_service_record() + # Wait until reading calibration record from firmware is updated + while self._utilities.get_reading_record_status() is not True: + time.sleep(self._DIALIN_RECORD_UPDATE_DELAY_S) + record_packets = self._utilities.prepare_record_to_send_to_fw(self.dg_service_record) + + self.logger.debug('Setting DG service 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) + + # Convert the list packet to a bytearray + payload = b''.join(packet) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DG_SET_SERVICE_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 + def _prepare_dg_service_record(self): """ Handles assembling the sub dictionaries of each group to make the main HD service record. @@ -152,10 +198,10 @@ record_crc = OrderedDict({'crc': [' max_len: # Since the received_msg_length is greater than maximum, enable wrap text active_sheet[cell_name].alignment = Alignment(vertical='center', horizontal=horizontal, wrap_text=True) # Calculate what the row height should be when the cell is extended row_height = math.ceil(length_of_data / max_len) * self.ROW_DEFAULT_HEIGHT active_sheet.column_dimensions[column_letter].width = max_len - # If the received_msg_length of the data provided is already less than the received_msg_length of cell, do nothing + # If the received_msg_length of the data provided is already less than the received_msg_length of cell, + # do nothing elif column_width < length_of_data: active_sheet.column_dimensions[column_letter].width = length_of_data + self.COLUMN_WIDTH_TOLERANCE row_height = self.ROW_DEFAULT_HEIGHT Index: dialin/utils/nv_ops_utils.py =================================================================== diff -u -r72335b185c277c008b114da7ad97bdc2978b3d76 -re949b0efaf7f65be389116f4c905b50cbae60b7d --- dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision 72335b185c277c008b114da7ad97bdc2978b3d76) +++ dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision e949b0efaf7f65be389116f4c905b50cbae60b7d) @@ -390,7 +390,12 @@ for ch in current_value: # Unpack the values to be written to the dictionary raw = struct.unpack(data_type, fw_raw_records_bytes[read_start_index:read_start_index + value_bytes])[0] - data += raw.decode("utf-8") + # Check if the the values is a character first, otherwise it can be received as a byte that was not a + # character from firmware + try: + data += raw.decode("utf-8") + except: + data += 'X' read_start_index += value_bytes else: # Unpack the values to be written to the dictionary Index: tests/test_dg_records.py =================================================================== diff -u -rf9549f885d852f0b9607e9d198af5384cea7d6c7 -re949b0efaf7f65be389116f4c905b50cbae60b7d --- tests/test_dg_records.py (.../test_dg_records.py) (revision f9549f885d852f0b9607e9d198af5384cea7d6c7) +++ tests/test_dg_records.py (.../test_dg_records.py) (revision e949b0efaf7f65be389116f4c905b50cbae60b7d) @@ -46,7 +46,28 @@ except KeyboardInterrupt: pass +def process_service_record(read=False): + sys = dg.service_record + print(sys.dg_service_record) + + try: + if read: + sys.get_dg_service_record() + while True: + sleep(0.5) + if sys.is_reading_record_done(): + if sys.is_reading_record_done(): + break + else: + sys.set_dg_service_record() + + print(sys.dg_service_record) + + except KeyboardInterrupt: + pass + + if __name__ == "__main__": # Create an instance of the DG Class dg = DG(log_level='DEBUG') @@ -55,10 +76,10 @@ exit(1) sleep(2) - #srvc = dg.service_record - #schrun = dg.scheduled_runs_record + #process_calibration_record(read=False) + #process_system_record(read=True) + process_service_record(read=True) - process_calibration_record(read=False)