Index: tests/test_gen_requirements.py =================================================================== diff -u --- tests/test_gen_requirements.py (revision 0) +++ tests/test_gen_requirements.py (revision 878d608b5b6e1974f14e3da2956ac8063e30bf14) @@ -0,0 +1,130 @@ +########################################################################### +# +# 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 test_demo.py +# +# @date 15-May-2020 +# @author P. Lucia +# +# @brief This is a demo script to exercise the HD and DG. +# +############################################################################ +import sys +sys.path.append("..") +from dialin.dg.dialysate_generator import DG +from dialin.hd.hemodialysis_device import HD +from dialin.hd.constants import RESET, NO_RESET, BUTTON_PRESSED, BUTTON_RELEASED +import time +import pprint + + +def test_dg_version(): + """ + Prints the DG version. + + @return: None + """ + dg = DG() + if dg.cmd_log_in_to_dg(): + dg.cmd_ui_request_dg_version() + time.sleep(0.5) + print(dg.dg_version) + + +def gen_publish_requirements(modules): + result = {} + + for module in modules: + for attr in dir(module): + if not callable(getattr(module, attr)) and \ + not attr.startswith("MSG") and \ + not attr.startswith("START") and \ + not attr.startswith("END") and \ + not attr == "can_interface" and \ + not attr.startswith("_") and \ + not attr.isupper(): + result[module.__class__.__name__] = result.get(module.__class__.__name__, []) + [attr] + + # pp = pprint.PrettyPrinter(indent=4) + # pp.pprint(result) + + for module, attrs in result.items(): + print("\n{0} \n ".format(module)) + for attr in attrs: + print("The Dialin API shall publish the {0} to all observers upon HD messaging.".format(attr.replace("_", " "))) + + return result + +def gen_cmd_requirements(modules): + + result = {} + + for module in modules: + for attr in dir(module): + if callable(getattr(module, attr)) and attr.startswith("cmd"): + result[module.__class__.__name__] = result.get(module.__class__.__name__, []) + [attr] + + # pp = pprint.PrettyPrinter(indent=4) + # pp.pprint(result) + + for module, attrs in result.items(): + print("\n{0} \n ".format(module)) + for attr in attrs: + print("The Dialin API shall provide a command that constructs and sends the {0} command.".format(attr + .replace("_", " ") + .replace("cmd ", "") + .replace("uf", "UF") + .replace("ui", "UI") + )) + + return result + + +def gen_dg_requirements(): + pass + + + +if __name__ == '__main__': + hd = HD() + + result = {} + + modules = [ + hd.alarms, + hd.buttons, + hd.ui, + hd.rtc, + hd.watchdog, + hd.bloodflow, + hd.dialysate_inlet_flow, + hd.dialysate_outlet_flow, + hd.treatment, + hd.pressure_occlusion, + hd.buttons + ] + gen_publish_requirements(modules) + gen_cmd_requirements(modules) + + dg = DG() + + result = {} + + modules = [ + dg.hd_proxy, + dg.load_cells, + dg.pressures, + dg.reservoirs, + dg.valves, + dg.ro_pump, + dg.drain_pump, + # dg.heaters, + # dg.temperature_sensors + ] + + gen_publish_requirements(modules) + gen_cmd_requirements(modules)