Index: .gitignore =================================================================== diff -u -r93f8f5fb2b59848ab6cdaeb3344ecfbd9fdccef3 -rb93c9ea734481269f9c7423d15d42d6bf8e2f85a --- .gitignore (.../.gitignore) (revision 93f8f5fb2b59848ab6cdaeb3344ecfbd9fdccef3) +++ .gitignore (.../.gitignore) (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -9,3 +9,4 @@ tags.* +*.log Index: DialityCoreCanProtocol.py =================================================================== diff -u -rf1a95e42324e7f6da895039e4863db6af49bf0d2 -rb93c9ea734481269f9c7423d15d42d6bf8e2f85a --- DialityCoreCanProtocol.py (.../DialityCoreCanProtocol.py) (revision f1a95e42324e7f6da895039e4863db6af49bf0d2) +++ DialityCoreCanProtocol.py (.../DialityCoreCanProtocol.py) (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -22,6 +22,7 @@ from time import sleep import sys import argparse +from argparse import RawTextHelpFormatter import logging @@ -341,7 +342,7 @@ START_BYTE = DenaliMessage.START_BYTE DIALIN_MSG_RESP_TO = 0.1 # number of seconds to wait for a response to a sent command - def __init__(self, can_interface='can0', log_level="debug"): + def __init__(self, can_interface='can0', log_level="error"): """ DenaliCanMessenger constructor @@ -368,7 +369,7 @@ self.run = False self.sync_response_dictionary = {} - numeric_level = getattr(logging, log_level.upper(), None) + numeric_level = getattr(logging, log_level.upper(), logging.ERROR) logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', filename="DialIn.log", datefmt='%m-%d-%Y:%H:%M:%S', @@ -424,7 +425,8 @@ channel_id = message.arbitration_id message_length = can_data[DenaliMessage.PAYLOAD_LENGTH_INDEX] - print_and_log(str(time.time()) + " " + str(channel_id) + " " + str(can_data), log_level="info") + print_and_log(str(time.time()) + " " + str(channel_id) + " " + str(can_data), + log_level=logging.INFO) # if we are building a long message, then proceed to push it to the channel dictionary if channel_id in self.long_msg_channel_id_set: @@ -548,8 +550,7 @@ data=packet, is_extended_id=False) - self.logger.debug(packet) - # input("Press enter to send...") + print_and_log(packet) self.bus.send(packet, 0) # 0.1) # Sending @@ -576,16 +577,19 @@ return self.command_response_message -def print_and_log(message, log_level="debug"): +def print_and_log(message, log_level=logging.DEBUG): """ - Prints and logs a message + Prints a message if its severity is >= the current log level. + Also logs the message. \param message: The message to print and log \param log_level: The logging level, indicates the severity of the message \returns: None """ - print(message) + if logging.getLogger().getEffectiveLevel() <= log_level: + print(message) + if log_level == "debug": logging.debug(message) elif log_level == "info": @@ -597,53 +601,52 @@ elif log_level == "critical": logging.critical(message) - -def tst_print_received_packet(message, sync=False): +def test_print_received_packet(self, message, sync=False): channel_id = message[0] message[0] = DenaliMessage.START_BYTE introduction = "Received: " if sync: introduction = "Sync " + introduction - print_and_log(introduction, message, " in channel: ", channel_id) + print_and_log("{0} {1} in channel: {3}".format(introduction, message, channel_id)) -def tst_print_to_screen(message): +def test_print_to_screen(message): if message is None: print_and_log("Timeout!!!") else: - tst_print_received_packet(message) + test_print_received_packet(message) -def tst_function_for_sync(message): - tst_print_received_packet(message, sync=True) +def test_function_for_sync(message): + test_print_received_packet(message, sync=True) -def tst_print_sending_dg_board(message): - print_and_log("Sending to board: ", message['message'], " in channel: ", message['channel_id']) +def test_print_sending_dg_board(message): + print_and_log("Sending to board: {0} on channel: {1}".format(message['message'], message['channel_id'])) -def tst_print_sending_dg_sim(message): - print_and_log("Sending to DG simulator: ", message['message'], " in channel", message['channel_id'], end=" ---> ") +def test_print_sending_dg_sim(message): + print_and_log("Sending to DG simulator: {0} on channel {1}".format(message["message"], message["channel_id"])) -def tst_dg(log_level): +def test_dg(log_level): test_messenger = DenaliCanMessenger(log_level=log_level) test_received_channel_id = DenaliChannels.hd_to_ui_ch_id test_received_message_id = 0x100 test_messenger.register_receiving_publication_function(test_received_channel_id, test_received_message_id, - tst_function_for_sync) + test_function_for_sync) test_dg_simulator_received_channel_id = DenaliChannels.dialin_to_dg_ch_id test_dg_simulator_sync_msg_id = 0x05 test_dg_simulator_msg_id = 0x03 test_messenger.register_receiving_publication_function(test_dg_simulator_received_channel_id, test_dg_simulator_sync_msg_id, - tst_function_for_sync) + test_function_for_sync) test_messenger.start() @@ -655,39 +658,42 @@ payload=[]) sleep(3.0) - tst_print_sending_dg_board(test_msg) + test_print_sending_dg_board(test_msg) test_response = test_messenger.send(test_msg) - tst_print_to_screen(test_response) + test_print_to_screen(test_response) sleep(3.0) - tst_print_sending_dg_board(test_msg) + test_print_sending_dg_board(test_msg) test_response = test_messenger.send(test_msg) - tst_print_to_screen(test_response) + test_print_to_screen(test_response) sleep(3.0) - tst_print_sending_dg_sim(test_dg_msg) + test_print_sending_dg_sim(test_dg_msg) test_response = test_messenger.send(test_dg_msg) - tst_print_to_screen(test_response) + test_print_to_screen(test_response) sleep(3.0) - tst_print_sending_dg_sim(test_dg_msg) + test_print_sending_dg_sim(test_dg_msg) test_response = test_messenger.send(test_dg_msg) - tst_print_to_screen(test_response) + test_print_to_screen(test_response) -def tst_can(): +def test_can(self): test_messenger = DenaliCanMessenger() test_messenger.start() if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Dial-In Core Can Protocol") + parser = argparse.ArgumentParser(description="Dial-In Core Can Protocol \n" + "\tExample: \n" + "\tpython3 DialityCoreCanProtocol.py --test-dg --log-level=\"debug\"", + formatter_class=RawTextHelpFormatter) parser.add_argument("--test-dg", action="store_true") - parser.add_argument("--log-level", default="debug") + parser.add_argument("--log-level", default="error") args = parser.parse_args() if args.test_dg: - tst_dg(args.log_level) + test_dg(args.log_level) if len(sys.argv) < 2: parser.print_help() Index: DialysateGenerator.py =================================================================== diff -u -rf1a95e42324e7f6da895039e4863db6af49bf0d2 -rb93c9ea734481269f9c7423d15d42d6bf8e2f85a --- DialysateGenerator.py (.../DialysateGenerator.py) (revision f1a95e42324e7f6da895039e4863db6af49bf0d2) +++ DialysateGenerator.py (.../DialysateGenerator.py) (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -61,7 +61,7 @@ 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))) + lambda message: print(".", end='', flush=True))) self.can_interface.start() def fill(self, start_or_stop='start'): @@ -113,7 +113,7 @@ # If there is content... if received_message is not None: - #print(received_message) + # print(received_message) if reset == HD.RESET: str_res = "reset back to normal" else: @@ -266,5 +266,6 @@ success = dg.fill('stop') self.assertTrue(success) + if __name__ == '__main__': unittest.main(verbosity=2) Index: HemodialysisDevice.py =================================================================== diff -u -rf1a95e42324e7f6da895039e4863db6af49bf0d2 -rb93c9ea734481269f9c7423d15d42d6bf8e2f85a --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision f1a95e42324e7f6da895039e4863db6af49bf0d2) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -48,7 +48,7 @@ self.can_interface = DenaliCanMessenger(can_interface=can__interface) self.can_interface.start() # Create command groups - self._Basics = HD.HD__Basics(self) + self.Basics = HD.HD__Basics(self) self.Alarms = HD.HD_Alarms(self, self.can_interface) self.BloodFlow = HD.HD_BloodFlow(self, self.can_interface) self.Buttons = HD.HD_Buttons(self) Fisheye: Tag b93c9ea734481269f9c7423d15d42d6bf8e2f85a refers to a dead (removed) revision in file `Miscellaneous/DG_Firmware_Simulator.py'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b93c9ea734481269f9c7423d15d42d6bf8e2f85a refers to a dead (removed) revision in file `Miscellaneous/HD_TestScript.py'. Fisheye: No comparison available. Pass `N' to diff? Index: Scripts/DG_Firmware_Simulator.py =================================================================== diff -u --- Scripts/DG_Firmware_Simulator.py (revision 0) +++ Scripts/DG_Firmware_Simulator.py (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -0,0 +1,39 @@ +from DialityCoreCanProtocol import * +from time import sleep + +dialin_messenger = DenaliCanMessenger() + +# Building response message + +response_msg = DenaliMessage.build_message(channel_id=DenaliChannels.dg_to_hd_ch_id, + message_id=1000, + payload=[1]) + +# Building Publication message +publication_msg = DenaliMessage.build_message(channel_id=DenaliChannels.dg_sync_broadcast_ch_id, + message_id=0x7100, + payload=[1, 2, 3, 4, 5]) + +print("") +print("o -> response to fill command") +print(". -> publication message") +print("") + + +def respondToCommand(message): + dialin_messenger.send(response_msg) + print("o", end='', flush=True) + + +# Register response command for the DG +dialin_messenger.register_receiving_publication_function(channel_id=DenaliChannels.ui_to_hd_ch_id, + message_id=1000, + function=respondToCommand) + +dialin_messenger.start() + +# This is the main loop +while True: + dialin_messenger.send(publication_msg) + print(".", end='', flush=True) + sleep(1) Index: Scripts/HD_TestScript.py =================================================================== diff -u --- Scripts/HD_TestScript.py (revision 0) +++ Scripts/HD_TestScript.py (revision b93c9ea734481269f9c7423d15d42d6bf8e2f85a) @@ -0,0 +1,59 @@ +########################################################################### +# +# Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. +# +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# +# @file HD_TestScript.py +# +# @date 19-Nov-2019 +# @author S. Nash +# +# @brief This is an example test script for the HD. +# +############################################################################ + +from HemodialysisDevice import HD +from time import sleep + +if __name__ == "__main__": + hd = HD() + sleep(2) + + if hd.Basics.CmdLogInToHD() == 0: + exit(1) + + hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.RESET, 0) + + sleep(2) + print("Blood Flow Target = " + str(hd.BloodFlow.TargetBloodFlowRate)) + print("Blood Pump Current= " + str(hd.BloodFlow.MeasuredBloodPumpMCCurrent)) + sleep(5) + print("Blood Pump Current= " + str(hd.BloodFlow.MeasuredBloodPumpMCCurrent)) + + hd.BloodFlow.CmdBloodPumpMeasuredCurrentOverride(hd.NO_RESET, 140) + + sleep(1) + print("Blood Pump Current= " + str(hd.BloodFlow.MeasuredBloodPumpMCCurrent)) + sleep(5) + hd.BloodFlow.CmdBloodPumpMeasuredCurrentOverride(hd.RESET, 0) + + while True: + sleep(0.5) + print("Measured Flow = " + str(hd.BloodFlow.MeasuredBloodFlowRate) + " mL/min") + tgtRate = 0 + hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.NO_RESET, 2000) + + while True: + if hd.BloodFlow.TargetBloodFlowRate == 0: + if tgtRate != 0: + hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.NO_RESET, 2000) + tgtRate = 0 + else: + if tgtRate == 0: + hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.NO_RESET, 200) + tgtRate = hd.BloodFlow.TargetBloodFlowRate + +# hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.RESET,0) +