Index: HD_DialOutFlow.py =================================================================== diff -u --- HD_DialOutFlow.py (revision 0) +++ HD_DialOutFlow.py (revision 6124a4264e27660239a0a01436dee04d0c63dac6) @@ -0,0 +1,86 @@ +from enum import Enum +from DialityCoreCanProtocol import DenaliMessage +from DialityCoreCanProtocol import DenaliChannels +import sys + + +class DialOutStates(Enum): + STOP = 0 + RUN = 1 + PAUSE = 2 + + +class HD_DialOut: + """ + :class HD_Dialout + + Encapsulates command for testing dialout flow module. + """ + can = None + + MSG_ID_SET_DIALOUT_FLOW_STATE = 0x8016 + MSG_ID_SET_DIALOUT_FLOW_RX = 0X8018 + + DIALOUT_STATES = list(DialOutStates) + + def __init__(self, hd_object): + """ + Constructor for the HD_Dialout class + + :param HD: reference to an HD parent object + """ + self.__can_interface = hd_object.can_interface + + def setUFState(self, new_state): + """ + setUFState function sets the new states to STOP, RUN or PAUSE + :param new_state: from DialOutStates.STOP, DialOutStates.RUN or DialoutStates.PAUSE + :return: TRUE if confirmed, FALSE if HD had error or None for time out or incorrect parameters + """ + return_value = None + received_msg = None + + if new_state in self.DIALOUT_STATES: + payload = [new_state.value] + msg = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_SET_DIALOUT_FLOW_STATE, + payload=payload) + received_msg = self.__can_interface.send(msg) + else: + print("Argument to setUFState method are incorrect", file=sys.stderr) + + if received_msg is not None: + return_value = True if DenaliMessage.getPayload(received_msg)[0] == 1 else False + + return return_value + + def setUFRx(self, rx_total_volume_ml, rx_time_min, rx_flow_rate): + """ + setUFRx function sets prescription for UF. Total Volume, time in minutes and flow rate + :param rx_total_volume_ml (integer) is total volume in ml + :param rx_time_min (integer) is rx time + :param rx_flow_rate (integer) is described flow rate + :return: TRUE if confirmed, FALSE if HD had error or None for time out or incorrect parameters + """ + return_value = None + received_msg = None + + if isinstance(rx_total_volume_ml, int) and isinstance(rx_time_min, int) and \ + isinstance(rx_flow_rate, int): + + payload = list(rx_total_volume_ml.to_bytes(2, DenaliMessage.BYTE_ORDER)) + payload += list(rx_time_min.to_bytes(2, DenaliMessage.BYTE_ORDER)) + payload += list(rx_flow_rate.to_bytes(2, DenaliMessage.BYTE_ORDER)) + + msg = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_SET_DIALOUT_FLOW_RX, + payload=payload) + received_msg = self.__can_interface.send(msg) + else: + print("Arguments to setUFRx are incorrect", file=sys.stderr) + + if received_msg is not None: + return_value = True if DenaliMessage.getPayload(received_msg)[0] == 1 else False + + return return_value +