Index: dialin/dg/calibration_record.py =================================================================== diff -u -rf7927c4086e16a080e6ba1552e10f6d776c84e17 -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision f7927c4086e16a080e6ba1552e10f6d776c84e17) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -61,16 +61,28 @@ self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_dg_calibration_sync) + def cmd_reset_dg_calibration_record(self) -> bool: + """ + Handles resetting DG calibration record. + + @return: True if successful, False otherwise + """ + self._prepare_dg_calibration_record() + self.dg_calibration_record = self._utilities.reset_fw_record(self.dg_calibration_record) + status = self.cmd_set_dg_calibration_record(self.dg_calibration_record) + + return status + def cmd_request_dg_calibration_record(self) -> bool: """ Handles getting DG calibration_record record from firmware. @return: True if successful, False otherwise """ - self.logger.debug("Requesting a dg calibration record...") if not self._is_getting_cal_in_progress: + self._is_getting_cal_in_progress = True self._raw_cal_record.clear() @@ -123,14 +135,11 @@ self._RECORD_SPECS_BYTES:end_of_data_index]) if self.current_message == self.total_messages: - # Done with getting all the calibration data. + # Check if the requested read was just for comparing the results before writing to firmware back self._is_getting_cal_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_calibration_record, self._raw_cal_record) self._handler_received_complete_dg_calibration_record() - # TODO remove - print(self.dg_calibration_record) - # TODO remove @_publish(["dg_calibration_record"]) def _handler_received_complete_dg_calibration_record(self): @@ -141,17 +150,16 @@ """ self.logger.debug("Received a complete dg calibration record.") - def cmd_set_dg_calibration_record(self, dg_calibration_record: OrderedDict) -> bool: + def cmd_set_dg_calibration_record(self, previous_record: OrderedDict) -> bool: """ Handles updating the DG calibration record with the newest calibration_record data of a hardware and sends it to FW. - @param dg_calibration_record: (OrderedDict) the dg calibration record to be sent + @param previous_record: (OrderedDict) the dg calibration record to be sent @return: True upon success, False otherwise """ - - record_packets = self._utilities.prepare_record_to_send_to_fw(dg_calibration_record) - + # Pass the new changes as well as the previous calibration record + record_packets = self._utilities.prepare_record_to_send_to_fw(self.dg_calibration_record) self.logger.debug('Setting DG calibration started') # Update all the data packets with the last message count since is the number of messages that firmware @@ -190,11 +198,11 @@ # ordered dictionaries to maintain the order in which they are inserted. The results are a tuple, the first # element is the dictionary that was built and the second element is the byte size of the dictionary. records_with_sizes = [self._prepare_pressure_sensors_cal_record(), self._prepare_flow_sensors_cal_record(), - self._prepare_load_cells_record(), self._prepare_temperature_sensors_record(), - self._prepare_conductivity_sensors_record(), self._prepare_pumps_record(), - self._prepare_volume_record(), self._prepare_acid_concentrates_record(), - self._prepare_bicarb_concentrates_record(), self._prepare_filters_record(), - self._prepare_fans_record(), self._prepare_accelerometer_sensor_record()] + self._prepare_load_cells_record(), self._prepare_temperature_sensors_record(), + self._prepare_conductivity_sensors_record(), self._prepare_pumps_record(), + self._prepare_volume_record(), self._prepare_acid_concentrates_record(), + self._prepare_bicarb_concentrates_record(), self._prepare_filters_record(), + self._prepare_fans_record(), self._prepare_accelerometer_sensor_record()] for record, byte_size in records_with_sizes: # Update the groups bytes size so far to be use to padding later Index: dialin/dg/hd_proxy.py =================================================================== diff -u -rf7927c4086e16a080e6ba1552e10f6d776c84e17 -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/dg/hd_proxy.py (.../hd_proxy.py) (revision f7927c4086e16a080e6ba1552e10f6d776c84e17) +++ dialin/dg/hd_proxy.py (.../hd_proxy.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -113,7 +113,7 @@ Given drain to volume must be between 0 and 1950 mL. @param volume: unsigned int - volume (in mL) to drain the inactive reservoir to. - @param tareLoadCell: bool - flag indicates to tare loadcell. + @param tare_load_cell: bool - flag indicates to tare loadcell. @return: 1 if successful, zero otherwise """ Index: dialin/dg/service_record.py =================================================================== diff -u -r8a13a85045edfcf69bf0e728d294f04b924d732c -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/dg/service_record.py (.../service_record.py) (revision 8a13a85045edfcf69bf0e728d294f04b924d732c) +++ dialin/dg/service_record.py (.../service_record.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -21,6 +21,8 @@ Hemodialysis Device (HD) Dialin API sub-class for service record commands. """ + # The default service time interval is 6 months in seconds + _DEFAULT_SERVICE_INTERVAL_S = 15768000 _RECORD_SPECS_BYTES = 12 _DEFAULT_SERVICE_LOCATION = ServiceLocation.SERVICE_LOCATION_FACTORY.value _DEFAULT_TIME_VALUE = 0 @@ -56,6 +58,18 @@ self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_dg_service_sync) + def cmd_reset_dg_service_record(self) -> bool: + """ + Handles resetting DG service record. + + @return: True if successful, False otherwise + """ + self._prepare_dg_service_record() + self.dg_service_record = self._utilities.reset_fw_record(self.dg_service_record) + status = self.cmd_set_dg_service_record(self.dg_service_record) + + return status + def cmd_request_dg_service_record(self) -> int: """ Handles getting DG service record from firmware. @@ -212,7 +226,8 @@ groups_byte_size = 0 service_records = OrderedDict({'service_record': {'service_location': [' bool: + """ + Handles resetting DG system record. + + @return: True if successful, False otherwise + """ + self._prepare_dg_system_record() + self.dg_system_record = self._utilities.reset_fw_system_service_record(self.dg_system_record) + status = self.cmd_set_dg_system_record(self.dg_system_record) + + return status + def cmd_request_dg_system_record(self) -> int: """ Handles getting DG system record from firmware. Index: dialin/hd/calibration_record.py =================================================================== diff -u -r6e20f4690ce887c351d8c65546f93311e5df6ad1 -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/hd/calibration_record.py (.../calibration_record.py) (revision 6e20f4690ce887c351d8c65546f93311e5df6ad1) +++ dialin/hd/calibration_record.py (.../calibration_record.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -52,7 +52,7 @@ self._raw_cal_record = [] self._utilities = NVOpsUtils(logger=self.logger) # HD Calibration main record - self.hd_calibration_record = self._setup_base_calibration_record() + self.hd_calibration_record = self.setup_base_calibration_record() if self.can_interface is not None: @@ -173,7 +173,7 @@ self.logger.debug("Finished sending HD calibration record.") return True - def _setup_base_calibration_record(self): + def setup_base_calibration_record(self): """ Handles assembling the sub dictionaries of each hardware group to make the main HD calibration_record record. @@ -247,7 +247,7 @@ hardware_names = ['vbv', 'vba', 'vdi', 'vdo'] group_byte_size = 0 - group_name = 'vales' + group_name = 'valves' hardware_group = OrderedDict({group_name: OrderedDict()}) hardware = OrderedDict() Index: dialin/hd/system_record.py =================================================================== diff -u -r2e392c92d55178f457a67423ba8c503a86dcf3c8 -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/hd/system_record.py (.../system_record.py) (revision 2e392c92d55178f457a67423ba8c503a86dcf3c8) +++ dialin/hd/system_record.py (.../system_record.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -23,7 +23,7 @@ """ _RECORD_SPECS_BYTES = 12 - _DEFAULT_CHAR_VALUE = 'X' + _DEFAULT_CHAR_VALUE = '-' _DEFAULT_MFG_LOCATION = MFGLocation.MFG_LOCATION_FACTORY.value _MAX_PN_BYTES = 10 _MAX_SN_BYTES = 15 @@ -57,7 +57,7 @@ self._raw_system_record = [] self._utilities = NVOpsUtils(logger=self.logger) # System main record - self.hd_system_record = self._prepare_hd_system_record() + self.hd_system_record = self.prepare_hd_system_record() if self.can_interface is not None: channel_id = DenaliChannels.hd_to_dialin_ch_id @@ -175,7 +175,7 @@ self.logger.debug("Finished sending HD system record.") return True - def _prepare_hd_system_record(self): + def prepare_hd_system_record(self): """ Handles assembling the sub dictionaries of each group to make the main HD system record. Index: dialin/utils/nv_ops_utils.py =================================================================== diff -u -r691a604eec8e3d0dd7d4b5e217ee5ee143e8e27e -r89f9210ef5bf37a6812c4dc06aaa636dd47b9d72 --- dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision 691a604eec8e3d0dd7d4b5e217ee5ee143e8e27e) +++ dialin/utils/nv_ops_utils.py (.../nv_ops_utils.py) (revision 89f9210ef5bf37a6812c4dc06aaa636dd47b9d72) @@ -3,7 +3,6 @@ from logging import Logger from typing import List from collections import OrderedDict - from .excel_ops import * @@ -98,7 +97,6 @@ @param directory: (str) the directory in which to write the excel doc @return none """ - path = '' is_report_found = False @@ -181,7 +179,6 @@ row += 1 - save_report(self._excel_workbook, self._workspace_dir, self._firmware_stack) # Signal reading is done self._is_writing_to_excel_done = True @@ -211,10 +208,9 @@ if isinstance(calibration_record[group][hardware], dict): col = 4 for spec in calibration_record[group][hardware]: - cell_value = get_cell_value(self._excel_workbook, self._record_name, row, - col) - # Check if the cell value is not none. If it is none, it cannot be converted to a number - # like float or integer + cell_value = get_cell_value(self._excel_workbook, self._record_name, row, col) + # Check if the cell value is not none. If it is none, it cannot be converted to a + # number like float or integer is_cell_value_valid = True if cell_value is not None else False if 'crc' not in spec and 'time' not in spec and is_cell_value_valid: temp_buffer.append(struct.pack(calibration_record[group][hardware][spec][0], cell_value)) @@ -276,10 +272,92 @@ Gets the reading record status @return: True if done, false otherwise """ - return self._is_read_done @staticmethod + def get_processed_characters(record: list) -> bytearray: + """ + Gets the list of the characters and makes sure their length is to the define length + + @param record: (list) the list that contains the characters, data type and the target character length + @return characters (bytearray) that are converted to bytearrays + """ + data_type = record[0] + char = record[1] + char_len = record[2] + temp = bytearray() + + if len(char) > char_len: + char = char[:char_len] + elif len(char) < char_len: + for i in range(len(char), char_len): + char += '-' + + for ch in char: + temp += struct.pack(data_type, ch.encode('ascii')) + + return temp + + @staticmethod + def reset_fw_record(record: OrderedDict) -> OrderedDict: + """ + Gets a record and updated the calibration date and crc + + @param record: (dict) the record to calculate the calibration time and crc + @return record (OrderedDict) the record with updated calibration time and crc + """ + + for key, value in record.items(): + if isinstance(value, dict): + for sub_key, sub_value in value.items(): + if sub_key == 'cal_time': + sub_value['cal_time'][1] = NVOpsUtils.get_current_time_in_epoch() + crc = NVOpsUtils.get_group_record_crc(sub_value) + sub_value['crc'][1] = crc + + return record + + @staticmethod + def reset_fw_system_service_record(record: OrderedDict) -> OrderedDict: + """ + Gets a record and updated the calibration date and crc + + @param record: (dict) the record to calculate the calibration time and crc + @return record (OrderedDict) the record with updated calibration time and crc + """ + for key, value in record.items(): + if isinstance(value, dict): + crc = NVOpsUtils.get_group_record_crc(value) + value['crc'][1] = crc + + return record + + @staticmethod + def get_group_record_crc(group_record: dict) -> int: + """ + Gets a group record and calculates the crc for the group + + @param group_record: (dict) the record to calculate the crc + @return crc (int) the calculated crc + """ + value_in_bytes = b'' + temp = [] + print(group_record) + for key, value in group_record.items(): + if key is not 'crc': + data_type = value[0] + value = value[1] + if data_type == ' self._MIN_PAYLOAD_BYTES_SPACE: current_payload_length += data_type_bytes temp_buffer[self._PAYLOAD_TOTAL_MSG_INDEX] = struct.pack(' self._MIN_PAYLOAD_BYTES_SPACE: @@ -613,8 +694,7 @@ # If the data type is a