Index: tests/DebugMsgCatcher.py =================================================================== diff -u --- tests/DebugMsgCatcher.py (revision 0) +++ tests/DebugMsgCatcher.py (revision 220df56bd614175c8786b69811edce333eb146a1) @@ -0,0 +1,89 @@ +########################################################################### +# +# Copyright (c) 2020-2022 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 DebugMsgCatcher.py +# +# @author (last) Darren Cox +# @date (last) 08-Jul-2022 +# @author (original) Darren Cox +# @date (original) 01-Aug-2022 +# +############################################################################ + +from dialin.hd.hemodialysis_device import HD +from dialin import HD +from logging import Logger +import sys +import csv +import datetime +import time +import threading +from dialin.hd.hemodialysis_device import HD +from dialin.dg.dialysate_generator import DG +from dialin.common.msg_defs import MsgIds, MsgFieldPositions +from dialin.protocols.CAN import DenaliCanMessenger, DenaliMessage, DenaliChannels +from dialin.utils.base import AbstractSubSystem, publish, LogManager +from dialin.utils.checks import check_broadcast_interval_override_ms +from dialin.utils.conversions import integer_to_bytearray, float_to_bytearray + +def _handler_debug_msg_catch(filename, message): + """ + + @param + """ + print("_handler_debug_msg_catch") + # new timestamp in first 2 columns + timestamp = f"timestamp, {datetime.datetime.now()}, " + # Add message to csv row + text = timestamp + message + print(text) + with open(filename, 'a') as file: + csvwriter = csv.writer(file, delimiter=',') + csvwriter.writerow(text.split(',')) + + +if __name__ == "__main__": + dtnow = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") + filename = f"DebugMsg_" + dtnow + ".csv" + #debugmsgs = DebugMsgCatcher(filename) + #threading.Thread(target=DebugMsgCatcher, args=(filename,)).start() + + dg = DG(log_level='DEBUG') + dg.cmd_log_in_to_dg() + time.sleep(1) + hd = HD(log_level='DEBUG') + hd.cmd_log_in_to_hd() + time.sleep(1) + + # Wait for user to start + # input("Press ENTER key to start.") + + # Time in seconds to run + total_time = 60 * 60 + text = "Waiting for Debug messages: " + filename + print(text) + + last_debug_index = hd.hd_debug_event_index + + time_start = 0 + while time_start <= total_time: + # wait for Debug messages + #print(last_debug_index) + #print(hd.hd_debug_event_index) + while last_debug_index != hd.hd_debug_event_index: + print(hd.hd_debug_events[last_debug_index]) + _handler_debug_msg_catch(filename, hd.hd_debug_events[last_debug_index]) + last_debug_index += 1 + if last_debug_index >= 10: + last_debug_index = 0 + time.sleep(1) + time_start += 1 + if 0 == time_start % 300: + text = "Time remaining: " + str((total_time - time_start)/60) + "min" + print(text) + + print("Time Expired: Exiting")