Index: dialin/dg/calibration_record.py =================================================================== diff -u -re36d87e663d95c79214f66b5db9aa6d6e8b47adf -ra26b886c2bbe75c1292afa150a63d1d9b8026b3b --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision e36d87e663d95c79214f66b5db9aa6d6e8b47adf) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision a26b886c2bbe75c1292afa150a63d1d9b8026b3b) @@ -8,6 +8,7 @@ from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import _AbstractSubSystem, _publish +from ..utils.utils import Utils from logging import Logger @@ -17,18 +18,18 @@ Dialysate Generator (DG) Dialin API sub-class for calibration commands. """ - CALIBRATION_RECORD_START_INDEX = 6 - CALIBRATION_RECORD_SPECS_BYTES = 12 + _RECORD_START_INDEX = 6 + _RECORD_SPECS_BYTES = 12 CALIBRATION_RECORDS_SPECS_BYTE_ARRAY = 3 - DEFAULT_GAIN_VALUE = 1 - DEFAULT_OFFSET_VALUE = 0 + _DEFAULT_GAIN_VALUE = 1 + _DEFAULT_OFFSET_VALUE = 0 DEFAULT_RATIO_VALUE = 1 DEFAULT_VOLUME_VALUE = 0 DEFAULT_CONCENTRATE_VALUE = 1 DEFAULT_BICARB_VALUE = 1 - DEFAULT_CALIBRATION_VALUE = 1 - DEFAULT_CAL_TIME_VALUE = 0 - DEFAULT_CAL_CRC_VALUE = 0 + _DEFAULT_CALIBRATION_VALUE = 1 + _DEFAULT_TIME_VALUE = 0 + _DEFAULT_CRC_VALUE = 0 CURRENT_MESSAGE_NUM_INDEX = 0 TOTAL_MESSAGES_NUM_INDEX = 4 @@ -41,15 +42,13 @@ TARGET_BYTES_TO_SEND_TO_FW = 150 MIN_PAYLOAD_BYTES_SPACE = 4 - EEPROM_MAX_BYTES_TO_WRITE = 16 + _EEPROM_MAX_BYTES_TO_WRITE = 16 PAYLOAD_CURRENT_MSG_INDEX = 0 PAYLOAD_TOTAL_MSG_INDEX = 1 PAYLOAD_CAL_BYTES_INDEX = 2 + _PAYLOAD_TRANSFER_DELAY = 0.2 - # DG calibration main record - DG_CALIBRATION_RECORD = OrderedDict() - def __init__(self, can_interface, logger: Logger): """ @@ -65,6 +64,9 @@ self.length = 0 self.cal_data = 0 self.raw_cal_record = [] + self.utilities = Utils() + # DG calibration main record + self.dg_calibration_record = OrderedDict() if self.can_interface is not None: @@ -129,76 +131,20 @@ self.length = length # The end of calibration record payload is from the start index + 12 bytes for the current message + total # messages + the length of calibration. The rest is the CAN messaging CRC that is not needed to be kept - end_of_data_index = self.CALIBRATION_RECORD_START_INDEX + self.CALIBRATION_RECORD_SPECS_BYTES + self.length + end_of_data_index = self._RECORD_START_INDEX + self._RECORD_SPECS_BYTES + self.length # Get the calibration data only - self.cal_data = message['message'][self.CALIBRATION_RECORD_START_INDEX:end_of_data_index] + self.cal_data = message['message'][self._RECORD_START_INDEX:end_of_data_index] # Continue getting calibration records until the all the calibration messages are received. Concatenate the # calibration records to each other if self.current_message <= self.total_messages: - self.raw_cal_record += (message['message'][self.CALIBRATION_RECORD_START_INDEX + - self.CALIBRATION_RECORD_SPECS_BYTES:end_of_data_index]) + self.raw_cal_record += (message['message'][self._RECORD_START_INDEX + + self._RECORD_SPECS_BYTES:end_of_data_index]) if self.current_message == self.total_messages: # If all the messages have been received, call another function to process the raw data - self._update_dg_calibration_record_from_fw() + self.utilities.process_received_record_from_fw(self.dg_calibration_record, self.raw_cal_record) - def _update_dg_calibration_record_from_fw(self): - """ - Handles parsing the calibration messages that were received from DG firmware. - - @return: None - """ - raw_payload_temp_start_index = 0 - # Convert the concatenated raw data into a byte array since the struct library requires byte arrays. - self.raw_cal_record = bytearray(self.raw_cal_record) - - # Loop through the keys for the main calibration dictionary - # DG_Calibration : {pressure_sensors : { ppi : { gain: [' 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: - - current_payload_length += data_type_bytes - # Insert a 4-byte 0 to the index of the total messages. This is a place holder and it will - # be updated with the right value later. - temp_buffer[self.PAYLOAD_TOTAL_MSG_INDEX] = struct.pack(' self._MIN_PAYLOAD_BYTES_SPACE: - current_payload_length += data_type_bytes - # Insert a 4-byte 0 to the index of the total messages. This is a place holder and it will - # be updated with the right value later. - temp_buffer[self._PAYLOAD_TOTAL_MSG_INDEX] = struct.pack(' self._MIN_PAYLOAD_BYTES_SPACE: + current_payload_length += data_type_bytes + # Insert a 4-byte 0 to the index of the total messages. This is a place holder and it will + # be updated with the right value later. + temp_buffer[self._PAYLOAD_TOTAL_MSG_INDEX] = struct.pack('