Index: DialityCoreCanProtocol.py =================================================================== diff -u -r764c3cdf3d1cf32337d28dd5355daad28e9d9d91 -rc172ebf4d713b654fb5a75113c96bf7f5ef5d858 --- DialityCoreCanProtocol.py (.../DialityCoreCanProtocol.py) (revision 764c3cdf3d1cf32337d28dd5355daad28e9d9d91) +++ DialityCoreCanProtocol.py (.../DialityCoreCanProtocol.py) (revision c172ebf4d713b654fb5a75113c96bf7f5ef5d858) @@ -118,8 +118,6 @@ message = DenaliMessage.__padMessageWithZeros(message) - print (message) - return DenaliMessage.buildBasicMessage(channel_id=channel_id, message=message) @staticmethod Index: HD_DialOutFlow.py =================================================================== diff -u -r6124a4264e27660239a0a01436dee04d0c63dac6 -rc172ebf4d713b654fb5a75113c96bf7f5ef5d858 --- HD_DialOutFlow.py (.../HD_DialOutFlow.py) (revision 6124a4264e27660239a0a01436dee04d0c63dac6) +++ HD_DialOutFlow.py (.../HD_DialOutFlow.py) (revision c172ebf4d713b654fb5a75113c96bf7f5ef5d858) @@ -18,18 +18,31 @@ """ can = None - MSG_ID_SET_DIALOUT_FLOW_STATE = 0x8016 - MSG_ID_SET_DIALOUT_FLOW_RX = 0X8018 + # Command message ID + MSG_ID_SET_DIALOUT_FLOW_STATE = 0x8017 + MSG_ID_SET_DIALOUT_FLOW_RX = 0x8018 + # Broadcast message ID + MSG_ID_DIALYSATE_UF_DATA = 0x0009 + DIALOUT_STATES = list(DialOutStates) - def __init__(self, hd_object): + # variable storing information received by Handler + + def __init__(self, can_interface): """ Constructor for the HD_Dialout class - :param HD: reference to an HD parent object + :param can_interface: reference to DenaliMessenger """ - self.__can_interface = hd_object.can_interface + self.__can_interface = can_interface + self.__can_interface.registerReceivingPublicationFunction(channel_id=DenaliChannels.hd_sync_broadcast_ch_id, + message_id=self.MSG_ID_DIALYSATE_UF_DATA, + function=self.receiveDialysateUFDataHandler) + self.DialOutBroadcast = {'state': 'None', + 'target_volume': 0, + 'measured_volume': 0, + 'pwm': 0} def setUFState(self, new_state): """ @@ -65,8 +78,8 @@ 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): + 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)) @@ -84,3 +97,15 @@ return return_value + def receiveDialysateUFDataHandler(self, message): + + payload = DenaliMessage.getPayload(message) + + state_num = int.from_bytes(bytearray(payload[0:2]), byteorder=DenaliMessage.BYTE_ORDER, signed=True) + self.DialOutBroadcast['state'] = DialOutStates(state_num).name + self.DialOutBroadcast['target_volume'] = int.from_bytes(bytearray(payload[2:4]), + byteorder=DenaliMessage.BYTE_ORDER, signed=True) + self.DialOutBroadcast['measured_volume'] = int.from_bytes(bytearray(payload[4:6]), + byteorder=DenaliMessage.BYTE_ORDER, signed=True) + self.DialOutBroadcast['pwm'] = int.from_bytes(bytearray(payload[6:8]), + byteorder=DenaliMessage.BYTE_ORDER, signed=True) Index: HemodialysisDevice.py =================================================================== diff -u -r8735608b72c44913ad2623ee0bb8883f6e2bfa92 -rc172ebf4d713b654fb5a75113c96bf7f5ef5d858 --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 8735608b72c44913ad2623ee0bb8883f6e2bfa92) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision c172ebf4d713b654fb5a75113c96bf7f5ef5d858) @@ -20,6 +20,8 @@ from DialityCoreCanProtocol import DenaliChannels from time import sleep from binascii import unhexlify +from HD_DialOutFlow import HD_DialOut +from HD_DialOutFlow import DialOutStates import struct @@ -50,6 +52,7 @@ self.Buttons = HD.HD_Buttons(self) self.BloodFlow = HD.HD_BloodFlow(self, self.can_interface) self.Watchdog = HD.HD_Watchdog(self) + self.DialOut = HD_DialOut(self.can_interface) class HD__Basics: """ @@ -874,6 +877,40 @@ # t2 = message_id +def test_HD_DialOutFlow(): + """ + test_HD_DialOutFlow is a pytest function to test the HD_DialOutFlow states + + :return: True if test passed, False, otherwise + """ + # create an HD object called hd + hd_obj = HD() + + # wait 2 seconds and then login to HD as a tester + sleep(2) + hd_obj._Basics.CmdLogInToHD() + + sleep(5) + hd_obj.DialOut.setUFState(DialOutStates.RUN) + sleep(2) + state_run = hd_obj.DialOut.DialOutBroadcast['state'] + print(hd_obj.DialOut.DialOutBroadcast) + + sleep(5) + hd_obj.DialOut.setUFState(DialOutStates.PAUSE) + sleep(2) + state_pause = hd_obj.DialOut.DialOutBroadcast['state'] + print(hd_obj.DialOut.DialOutBroadcast) + + sleep(3) + hd_obj.DialOut.setUFState(DialOutStates.STOP) + sleep(2) + state_stop = hd_obj.DialOut.DialOutBroadcast['state'] + print(hd_obj.DialOut.DialOutBroadcast) + + assert(state_run == 'RUN' and state_stop == 'STOP' and state_pause == 'PAUSE') + + if __name__ == "__main__": # create an HD object called hd hd = HD()