Index: DialysateGenerator.py =================================================================== diff -u -rdcef300220f44f1bdc68e35dcee7bba1fc6e2a08 -rf2b88894a458d9e03a9cb005af02ef16fd5e6f32 --- DialysateGenerator.py (.../DialysateGenerator.py) (revision dcef300220f44f1bdc68e35dcee7bba1fc6e2a08) +++ DialysateGenerator.py (.../DialysateGenerator.py) (revision f2b88894a458d9e03a9cb005af02ef16fd5e6f32) @@ -14,24 +14,27 @@ # ############################################################################ -from DialityCoreCanProtocol import DialityCanMessenger -from DialityCoreCanProtocol import DialityPacket +from DialityCoreCanProtocol import * from time import sleep - -""" \mainpage Dialin API +""" :mainpage Dialin API Dialin API is comprised primarily by 3 classes: - - \ref DialysateGenerator.DG - - \ref HemodialysisDevice.HD + - :ref DialysateGenerator.DG + - :ref HemodialysisDevice.HD """ + +def PublicationReceiverHandler(message): + print(".", end='', flush=True) + + class DG: """ - \class DG + :class DG - \brief Dialysate Generator (DG) Dialin object API. It provides the basic interface to communicate with + Dialysate Generator (DG) Dialin object API. It provides the basic interface to communicate with the DG board """ @@ -40,71 +43,60 @@ """ DG constructor using can bus - \param bus: can bus, e.g. "can0" + :param can__interface: can bus, 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') """ # Create listener - self.__can_interface = DialityCanMessenger(can_interface=can__interface) + self.__can_interface = DialinCanMessenger(can_interface=can__interface) + self.__can_interface.registerReceivingPublicationFunction(channel_id=DialinChannels.dg_sync_broadcast_ch_id, + message_id=0x7100, + function=PublicationReceiverHandler) self.__can_interface.start() - def fill(self, startOrStop='start'): + def fill(self, start_or_stop='start'): """ - \brief request the DG board to fill + request the DG board to fill - \returns True if ran the command, False otherwise + :returns True if ran the command, False otherwise, returns None if timeout """ - channel_id = 0x100 - msgID = 1000 + payload = [1] if start_or_stop == 'start' else [0] - if startOrStop == 'start': - cargo=[1] - else: - cargo=[0] + msg = DialinMessage.buildMessage(channel_id=DialinChannels.hd_to_dg_ch_id, + message_id=0x7000, + payload=payload) - packet = DialityPacket.buildPacket(request_id=msgID, cargo=cargo) - - # Send message - received_packet = self.__can_interface.send(channel_id, packet) + received_msg = self.__can_interface.send(msg) + returnValue = None - if received_packet is not None: + if received_msg is not None: + returnValue = True if DialinMessage.getPayload(received_msg)[0] == 1 else False - return received_packet[4] - else: - return False + return returnValue - def registerSyncReceiver(self, channel_id, request_id, method): - self.__can_interface.registerSyncFunction(channel_id, request_id, method) - -def test_sync_function(packet): - print("s", end="", flush=True) - - -def test_fill_print(packet): - - if packet is not False: - print("f") +def test_fill_print(msg): + if msg is not None: + print("f", end='', flush=True) else: - print("t") + print("t", end='', flush=True) if __name__ == "__main__": - test_dg = DG() sleep(2) test_packet = test_dg.fill('start') test_fill_print(test_packet) - sleep(20) + sleep(2) test_packet = test_dg.fill('stop') test_fill_print(test_packet)