Index: dialin/dg/calibration_record.py =================================================================== diff -u -r7cd740bfb30cafa48847843cd09c3ee346b882a4 -rf9549f885d852f0b9607e9d198af5384cea7d6c7 --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision 7cd740bfb30cafa48847843cd09c3ee346b882a4) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision f9549f885d852f0b9607e9d198af5384cea7d6c7) @@ -32,6 +32,7 @@ _EEPROM_MAX_BYTES_TO_WRITE = 16 _PAYLOAD_TRANSFER_DELAY = 0.2 + _DIALIN_RECORD_UPDATE_DELAY = 0.2 def __init__(self, can_interface, logger: Logger): """ @@ -150,12 +151,17 @@ @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_calibration_record() - + # Wait until reading calibration record from firmware is updated while self._utilities.get_reading_record_status() is not True: - time.sleep(0.2) + time.sleep(self._DIALIN_RECORD_UPDATE_DELAY) + # Write the excel record self._utilities.write_excel_record_to_dialin_record(self.dg_calibration_record) record_packets = self._utilities.prepare_record_to_send_to_fw(self.dg_calibration_record) Index: dialin/dg/dialysate_generator.py =================================================================== diff -u -rdf4353089f674167fa92bebb1447d2278b9b30d9 -rf9549f885d852f0b9607e9d198af5384cea7d6c7 --- dialin/dg/dialysate_generator.py (.../dialysate_generator.py) (revision df4353089f674167fa92bebb1447d2278b9b30d9) +++ dialin/dg/dialysate_generator.py (.../dialysate_generator.py) (revision f9549f885d852f0b9607e9d198af5384cea7d6c7) @@ -33,7 +33,7 @@ from .concentrate_pumps import ConcentratePumps from .calibration_record import DGCalibration from .system_record import DGSystemRecord -from .service_record import DGService +from .service_record import DGServiceRecord from .scheduled_runs_record import DGScheduledRunsRecord from ..utils.conversions import integer_to_bytearray from ..protocols.CAN import (DenaliCanMessenger, DenaliMessage, DenaliChannels) @@ -154,7 +154,7 @@ self.uv_reactors = UVReactors(self.can_interface, self.logger) self.calibration_record = DGCalibration(self.can_interface, self.logger) self.system_record = DGSystemRecord(self.can_interface, self.logger) - self.service_record = DGService(self.can_interface, self.logger) + self.service_record = DGServiceRecord(self.can_interface, self.logger) self.scheduled_runs_record = DGScheduledRunsRecord(self.can_interface, self.logger) def get_version(self): Index: dialin/dg/service_record.py =================================================================== diff -u -r5fe81152c836440fe3c41308ebcc02cfbedce2cd -rf9549f885d852f0b9607e9d198af5384cea7d6c7 --- dialin/dg/service_record.py (.../service_record.py) (revision 5fe81152c836440fe3c41308ebcc02cfbedce2cd) +++ dialin/dg/service_record.py (.../service_record.py) (revision f9549f885d852f0b9607e9d198af5384cea7d6c7) @@ -16,7 +16,7 @@ SERVICE_LOCATION_FIELD = 1 -class DGService(_AbstractSubSystem): +class DGServiceRecord(_AbstractSubSystem): """ Hemodialysis Device (HD) Dialin API sub-class for service record commands. Index: dialin/utils/nv_ops_utils.py =================================================================== diff -u -r7cd740bfb30cafa48847843cd09c3ee346b882a4 -rf9549f885d852f0b9607e9d198af5384cea7d6c7 --- dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision 7cd740bfb30cafa48847843cd09c3ee346b882a4) +++ dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision f9549f885d852f0b9607e9d198af5384cea7d6c7) @@ -1,6 +1,7 @@ import struct import datetime +import time import math import os import shutil @@ -95,7 +96,6 @@ def write_fw_record_to_excel(self, dialin_record): row = 1 - for group in dialin_record.keys(): start_row = row @@ -145,15 +145,15 @@ @return True if reading to firmware records to excel is done otherwise False """ + temp_buffer = [] + is_value_different = False row = 1 - for group in dialin_record.keys(): col = 1 cell_value = self.excel_ops.get_cell_value(self._excel_workbook, self._record_name, row, col) if cell_value == group: - print(cell_value) if isinstance(dialin_record[group], dict): for hardware in dialin_record[group].keys(): @@ -162,19 +162,46 @@ for spec in dialin_record[group][hardware]: cell_value = self.excel_ops.get_cell_value(self._excel_workbook, self._record_name, row, col) - dialin_record[group][hardware][spec][1] = cell_value + if 'crc' not in spec and 'time' not in spec: + temp_buffer.append(struct.pack(dialin_record[group][hardware][spec][0], cell_value)) + if dialin_record[group][hardware][spec][1] != cell_value: + print('{}, {}, {}'.format(spec, dialin_record[group][hardware][spec][1], cell_value)) + is_value_different = True + dialin_record[group][hardware][spec][1] = cell_value + + if is_value_different and 'time' in spec: + epoch_time = self.get_current_time_in_epoch() + print(hardware, spec, epoch_time) + dialin_record[group][hardware][spec][1] = epoch_time + temp_buffer.append(struct.pack(dialin_record[group][hardware][spec][0], epoch_time)) + date_time = self.get_current_date_time(epoch_time) + self.excel_ops.write_to_excel(self._excel_workbook, self._record_name, row, col, + date_time) + elif 'time' in spec and isinstance(cell_value, str): + epoch_time = self.get_date_time_in_epoch(cell_value) + dialin_record[group][hardware][spec][1] = epoch_time + print(epoch_time) + + if is_value_different and 'crc' in spec: + # Convert the data in the temp buffer to bytes and calculate its crc. + data = b''.join(temp_buffer) + crc_value = crc_16(data) + # Clear the temp buffer for the next round of data + is_value_different = False + dialin_record[group][hardware][spec][1] = crc_value col += 2 else: col = 3 for spec in dialin_record[group][hardware]: cell_value = self.excel_ops.get_cell_value(self._excel_workbook, self._record_name, row, col) dialin_record[group][hardware][1] = cell_value - + temp_buffer.clear() row += 1 - row += 1 + self.excel_ops.save_report(self._excel_workbook, self._workspace_dir, self._firmware_stack) + def get_writing_to_excel_status(self): """ Publicly accessible function to get the reading status @@ -217,6 +244,25 @@ """ return int(datetime.datetime.now().timestamp()) + @staticmethod + def get_current_date_time(epoch): + """ + Returns the current date and time from an epoch time + + @return: data and time in string + """ + return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epoch)) + + @staticmethod + def get_date_time_in_epoch(data_time): + """ + Returns the date time in epoch + + @return: data and time in epoch + """ + time_struct = time.strptime(data_time, '%Y-%m-%d %H:%M:%S') + return int(time.mktime(time_struct)) + def process_received_record_from_fw(self, dialin_record, fw_raw_records_bytes, write_to_excel=True): """ Handles processing the received record from firmware @@ -247,7 +293,7 @@ data = struct.unpack(data_type, fw_raw_records_bytes[raw_payload_temp_start_index: raw_payload_temp_start_index + value_bytes])[0] # Convert the crc to hex - dialin_record[group][self._DATA_VALUE_INDEX] = hex(data) + dialin_record[group][self._DATA_VALUE_INDEX] = data elif group == 'padding': # Get the data type data_type = dialin_record[group][self._DATA_TYPE_INDEX] @@ -293,7 +339,7 @@ @param key: key of the dialin record dictionary @param read_start_index: index to read the next set of byte(s) from fw raw records @param inner_key: the key to an inner dictionary that is the value of the provided key (i.e. pressure: {ppi : - [0,1}) + [0,1]}) @return: dialin record dictionary that is updated and read start index as a tuple """ @@ -312,23 +358,19 @@ if data_type == '