Index: dialin/dg/service_record.py =================================================================== diff -u -rdd42e4d9cfe821b0a755ccc86cc1a4a2a3dd2f37 -rb9a0dd1c65e089b0e7a7ddb83cf2b2669ef3049a --- dialin/dg/service_record.py (.../service_record.py) (revision dd42e4d9cfe821b0a755ccc86cc1a4a2a3dd2f37) +++ dialin/dg/service_record.py (.../service_record.py) (revision b9a0dd1c65e089b0e7a7ddb83cf2b2669ef3049a) @@ -31,7 +31,7 @@ # 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_S = 0.2 _DIALIN_RECORD_UPDATE_DELAY_S = 0.2 @@ -165,6 +165,8 @@ # 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) + + self._utilities.write_excel_record_to_dialin_record(self.dg_service_record) record_packets = self._utilities.prepare_record_to_send_to_fw(self.dg_service_record) self.logger.debug('Setting DG service record') Index: dialin/hd/service_record.py =================================================================== diff -u -rdd42e4d9cfe821b0a755ccc86cc1a4a2a3dd2f37 -rb9a0dd1c65e089b0e7a7ddb83cf2b2669ef3049a --- dialin/hd/service_record.py (.../service_record.py) (revision dd42e4d9cfe821b0a755ccc86cc1a4a2a3dd2f37) +++ dialin/hd/service_record.py (.../service_record.py) (revision b9a0dd1c65e089b0e7a7ddb83cf2b2669ef3049a) @@ -28,9 +28,13 @@ _DEFAULT_TIME_VALUE = 0 _DEFAULT_CRC_VALUE = 0 + # Maximum allowed bytes to be written to RTC RAM _RTC_RAM_MAX_BYTES_TO_WRITE = 64 - _PAYLOAD_TRANSFER_DELAY = 0.2 + # Delay in between each payload transfer + _PAYLOAD_TRANSFER_DELAY_S = 0.2 + _DIALIN_RECORD_UPDATE_DELAY_S = 0.2 + def __init__(self, can_interface, logger: Logger): """ @@ -45,9 +49,10 @@ self.total_messages = 0 self.received_msg_length = 0 self._is_getting_service_in_progress = False + self._write_fw_data_to_excel = True self.service_data = 0 - self.raw_service_record = [] - self.utilities = NVOpsUtils() + self._raw_service_record = [] + self._utilities = NVOpsUtils() # Service main record self.hd_service_record = OrderedDict() @@ -59,6 +64,17 @@ # Prepare the service record by putting sub-dictionaries together self._prepare_hd_service_record() + # Prepare the excel report and workspace + self._utilities.prepare_excel_report('HD', 'Service') + + def is_reading_record_done(self): + """ + Handles getting the status of reading record + + @return: True if reading is done otherwise False + """ + return self._utilities.get_writing_to_excel_status() + def get_hd_service_record(self): """ Handles getting HD service record from firmware. @@ -68,7 +84,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_hd_fw_service_record() @@ -93,7 +109,7 @@ self.logger.debug("Timeout!!!!") return False - @_publish(["current_message", "total_messages", "length", "service_data"]) + @_publish(["current_message", "total_messages", "received_msg_length", "service_data"]) def _handler_hd_service_sync(self, message): """ Handles published HD system record messages. HD system records are captured for @@ -124,14 +140,57 @@ # 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.hd_service_record, self.raw_service_record) + self._utilities.process_received_record_from_fw(self.hd_service_record, self._raw_service_record, + write_to_excel=self._write_fw_data_to_excel) + def set_hd_service_record(self): + """ + Handles updating the HD system 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_hd_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) + + self._utilities.write_excel_record_to_dialin_record(self.hd_service_record) + record_packets = self._utilities.prepare_record_to_send_to_fw(self.hd_service_record) + + self.logger.debug('Setting HD 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_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_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_hd_service_record(self): """ Handles assembling the sub dictionaries of each group to make the main HD service record. @@ -152,10 +211,10 @@ record_crc = OrderedDict({'crc': ['