Index: dialin/common/msg_defs.py =================================================================== diff -u -r1b2e845397cd3f595eaaf743567f09742c737a6d -r6d387cadbda3027d23510126942eaa9f6317d357 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 1b2e845397cd3f595eaaf743567f09742c737a6d) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision 6d387cadbda3027d23510126942eaa9f6317d357) @@ -217,6 +217,8 @@ MSG_ID_DG_RO_PUMP_TARGET_FLOW_OVERRIDE = 0xA031 # DG RO pump target flow rate override MSG_ID_DG_RO_PUMP_TARGET_PRESSURE_OVERRIDE = 0xA032 # DG RO pump target pressure override MSG_ID_DG_SET_CALIBRATION_DATA = 0xA033 # DG set calibration data + MSG_ID_DG_GET_CALIBRATION_DATA = 0xA034 # DG get calibration data + MSG_ID_DG_SEND_CALIBRATION_DATA = 0xA035 # DG send calibration data MSG_ID_HD_DEBUG_EVENT = 0xFFF1 # HD debug event text to be logged in event log MSG_ID_DG_DEBUG_EVENT = 0xFFF2 # DG debug event text to be logged in event log Index: dialin/dg/calibration.py =================================================================== diff -u -r1b2e845397cd3f595eaaf743567f09742c737a6d -r6d387cadbda3027d23510126942eaa9f6317d357 --- dialin/dg/calibration.py (.../calibration.py) (revision 1b2e845397cd3f595eaaf743567f09742c737a6d) +++ dialin/dg/calibration.py (.../calibration.py) (revision 6d387cadbda3027d23510126942eaa9f6317d357) @@ -1,18 +1,20 @@ import struct -from ..common.msg_defs import MsgIds +from ..utils.conversions import integer_to_bytearray +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import _AbstractSubSystem, _publish from logging import Logger class DGCalibration(_AbstractSubSystem): - """ Dialysate Generator (DG) Dialin API sub-class for calibration commands. """ + CALIBRATION_RECORD_START_INDEX = 6 + def __init__(self, can_interface, logger: Logger): """ @@ -23,17 +25,62 @@ self.can_interface = can_interface self.logger = logger + self.current_message = 0 + self.total_messages = 0 + self.length = 0 + self.cal_data = 0 + self.raw_cal_record = [] if self.can_interface is not None: channel_id = DenaliChannels.dg_sync_broadcast_ch_id - msg_id = MsgIds.MSG_ID_DG_CALIBRATION_DATA.value + msg_id = MsgIds.MSG_ID_DG_SEND_CALIBRATION_DATA.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_dg_calibration_sync) + @_publish(["current_message", "total_messages", "length", "cal_data"]) def _handler_dg_calibration_sync(self, message): - pass + """ + Handles published ro pump data messages. RO pump data are captured + for reference. + @param message: published RO pump data message + + @return: None + """ + curr = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] + total = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] + length = struct.unpack('i', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] + + self.current_message = curr + self.total_messages = total + self.length = length + self.cal_data = message['message'][self.CALIBRATION_RECORD_START_INDEX:] + + def get_dg_calibration_data(self): + """ + Handles getting DG calibration record from firmware. + + @return: None + """ + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DG_GET_CALIBRATION_DATA.value) + + self.logger.debug('Getting DG calibration record') + + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + def set_dg_calibration_data(self, data): #test = {'sensors': {'ppi': {'gain': ['