Index: DialysateGenerator.py =================================================================== diff -u -r76a013b309517d69b64ec4b74778715595a046bc -rf1a95e42324e7f6da895039e4863db6af49bf0d2 --- DialysateGenerator.py (.../DialysateGenerator.py) (revision 76a013b309517d69b64ec4b74778715595a046bc) +++ DialysateGenerator.py (.../DialysateGenerator.py) (revision f1a95e42324e7f6da895039e4863db6af49bf0d2) @@ -16,6 +16,7 @@ from DialityCoreCanProtocol import * from time import sleep +import unittest """ \mainpage Dialin API @@ -42,68 +43,68 @@ MSG_ID_LOAD_CELL_B1_OVERRIDE = 0xA007 MSG_ID_LOAD_CELL_B2_OVERRIDE = 0xA008 - def __init__(self, can__interface="can0"): + def __init__(self, can_interface="can0"): """ - DG constructor using can bus + DG constructor using can bus - \param can__interface: string with can bus name, e.g. "can0" + \param can_interface: string with can bus name, e.g. "can0" + \returns DG object that allows communication with board via port - \returns DG object that allows communication with board via port + \details For example: - \details For example: + dg_object = DG(can_interface='can0') or + dg_object = DG('can0') - dg_object = DG(can__interface='can0') or - dg_object = DG('can0') """ # Create listener - self.__can_interface = DenaliCanMessenger(can_interface=can__interface) - self.__can_interface.registerReceivingPublicationFunction(channel_id=DenaliChannels.dg_sync_broadcast_ch_id, - message_id=self.DG_MSG_ID_BROADCAST, - function=( + self.can_interface = DenaliCanMessenger(can_interface=can_interface) + self.can_interface.register_receiving_publication_function(channel_id=DenaliChannels.dg_sync_broadcast_ch_id, + message_id=self.DG_MSG_ID_BROADCAST, + function=( lambda message: print(".", end='', flush=True))) - self.__can_interface.start() + self.can_interface.start() def fill(self, start_or_stop='start'): """ - request the DG board to 'start' or to 'stop' fill + Request the DG board to 'start' or to 'stop' fill - \param start_or_stop is a string indicating which action to take, e.g., 'start' or 'stop' + \param start_or_stop is a string indicating which action to take, e.g., 'start' or 'stop' - \returns True if ran the command, False otherwise, returns None if timeout + \returns True if ran the command, False otherwise, returns None if timeout """ payload = [1] if start_or_stop == 'start' else [0] - msg = DenaliMessage.buildMessage(channel_id=DenaliChannels.hd_to_dg_ch_id, - message_id=self.DG_MSG_ID_FILL_COMMAND, - payload=payload) + msg = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_dg_ch_id, + message_id=self.DG_MSG_ID_FILL_COMMAND, + payload=payload) # Send message - received_msg = self.__can_interface.send(msg) - returnValue = None + received_msg = self.can_interface.send(msg) + return_value = None if received_msg is not None: - returnValue = True if DenaliMessage.getPayload(received_msg)[0] == 1 else False + return_value = True if DenaliMessage.get_payload(received_msg)[0] == 1 else False - return returnValue + return return_value def CmdLoadCellA1Override(self, reset, adc_raw): """ - Constructs and sends the load cell A1 override command + Constructs and sends the load cell A1 override command - \param reset: integer - 1 to reset a previous override, 0 to override - \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 - \returns 1 if successful, zero otherwise + \param reset: integer - 1 to reset a previous override, 0 to override + \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 + \returns 1 if successful, zero otherwise - TODO: This is built based on HD but needs more infrastructure made for DG before being operational + TODO: This is built based on HD but needs more infrastructure made for DG before being operational """ rst = self.outer_instance.integer2ByteArray(reset) cur = self.outer_instance.float2ByteArray(adc_raw) payload = rst + cur - message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_LOAD_CELL_A1_OVERRIDE, - payload=payload) + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_LOAD_CELL_A1_OVERRIDE, + payload=payload) print("override load cell A1 raw adc value") @@ -128,22 +129,22 @@ def CmdLoadCellA2Override(self, reset, adc_raw): """ - Constructs and sends the load cell A2 override command + Constructs and sends the load cell A2 override command - \param reset: integer - 1 to reset a previous override, 0 to override - \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 - \returns 1 if successful, zero otherwise + \param reset: integer - 1 to reset a previous override, 0 to override + \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 + \returns 1 if successful, zero otherwise - TODO: This is built based on HD but needs more infrastructure made for DG before being operational + TODO: This is built based on HD but needs more infrastructure made for DG before being operational """ rst = self.outer_instance.integer2ByteArray(reset) cur = self.outer_instance.float2ByteArray(adc_raw) payload = rst + cur - message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_LOAD_CELL_A2_OVERRIDE, - payload=payload) + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_LOAD_CELL_A2_OVERRIDE, + payload=payload) print("override load cell A2 raw adc value") @@ -168,22 +169,22 @@ def CmdLoadCellB1Override(self, reset, adc_raw): """ - Constructs and sends the load cell B1 override command + Constructs and sends the load cell B1 override command - \param reset: integer - 1 to reset a previous override, 0 to override - \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 - \returns 1 if successful, zero otherwise + \param reset: integer - 1 to reset a previous override, 0 to override + \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 + \returns 1 if successful, zero otherwise - TODO: This is built based on HD but needs more infrastructure made for DG before being operational + TODO: This is built based on HD but needs more infrastructure made for DG before being operational """ rst = self.outer_instance.integer2ByteArray(reset) cur = self.outer_instance.float2ByteArray(adc_raw) payload = rst + cur - message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_LOAD_CELL_B1_OVERRIDE, - payload=payload) + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_LOAD_CELL_B1_OVERRIDE, + payload=payload) print("override load cell B1 raw adc value") @@ -208,22 +209,22 @@ def CmdLoadCellB2Override(self, reset, adc_raw): """ - Constructs and sends the load cell B2 override command + Constructs and sends the load cell B2 override command - \param reset: integer - 1 to reset a previous override, 0 to override - \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 - \returns 1 if successful, zero otherwise + \param reset: integer - 1 to reset a previous override, 0 to override + \param adc_raw: unsigned int - raw adc value. 0.0894 per gram. 1000 ml = 11,186 + \returns 1 if successful, zero otherwise - TODO: This is built based on HD but needs more infrastructure made for DG before being operational + TODO: This is built based on HD but needs more infrastructure made for DG before being operational """ rst = self.outer_instance.integer2ByteArray(reset) cur = self.outer_instance.float2ByteArray(adc_raw) payload = rst + cur - message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_LOAD_CELL_B2_OVERRIDE, - payload=payload) + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_LOAD_CELL_B2_OVERRIDE, + payload=payload) print("override load cell B2 raw adc value") @@ -246,27 +247,24 @@ return False -def test_dg_start(): - dg = DG() - sleep(2) - resp = dg.fill('start') - test_passed = isinstance(resp, bool) +class Test(unittest.TestCase): - if test_passed: - print("DG started and DG response is {}".format(test_passed)) + # @unittest.skip("Skipping dg_start.") + def test_dg_start(self): + dg = DG() + sleep(2) + success = dg.fill("start") + self.assertTrue(success) - assert test_passed + # @unittest.skip("Skipping dg_start_stop.") + def test_dg_start_stop(self): + dg = DG() + sleep(2) + success = dg.fill("start") + self.assertTrue(success) + sleep(2) + success = dg.fill('stop') + self.assertTrue(success) - -def test_dg_stop(): - dg = DG() - sleep(1) - dg.fill('start') - sleep(2) - resp = dg.fill('stop') - test_passed = isinstance(resp, bool) - - if test_passed: - print("DG started/stopped and DG response is {}".format(test_passed)) - - assert test_passed +if __name__ == '__main__': + unittest.main(verbosity=2)