Index: README.md =================================================================== diff -u -ra89308cbb06b9d2052fe3d1b4ed210a03036a021 -r82e32ae00355b2245a2660569935de152a883799 --- README.md (.../README.md) (revision a89308cbb06b9d2052fe3d1b4ed210a03036a021) +++ README.md (.../README.md) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -47,7 +47,7 @@ All release versions will eventually be placed on their own separate branch to facilitate backwards compatibility and a fully accessible and testable API version history. -How to install from the master branch, which contains the latest in-development changes (Available!) +How to install from the master branch ``` #!/bin/bash @@ -57,14 +57,14 @@ pip3 install git+ssh://git@dvm-linux02:7999/vv/dialin.git ``` -How to install a specific release version (Not yet available) +How to install a build from a specific branch. To change the branch, replace staging with the desired branch ``` #!/bin/bash virtualenv --python=python3 venv source venv/bin/activate -branch="0.0.1" # update the branch_name here +branch="staging" pip3 install git+ssh://git@dvm-linux02:7999/vv/dialin.git@$branch ``` @@ -75,48 +75,15 @@ virtualenv --python=python3 venv source venv/bin/activate -pip3 install dialin-0.0.1-py3-none-any.whl +pip3 install dialin--py3-none-any.whl ``` ### Modules -- See the tests directory for examples of how to use this API -- Also consult the Dialin API documentation which can be generated using the `tools/document.sh` script. +- Consult the Dialin API documentation which can be generated using the `tools/document.sh` script. +- See the tests directory for example usages of the API. -``` -from dialin.hd.alarms import HDAlarms -from dialin.hd.blood_flow import HDBloodFlow -from dialin.hd.buttons import HDButtons -from dialin.hd.constants import RESET, NO_RESET -from dialin.hd.dialysate_inlet_flow import HDDialysateInletFlow -from dialin.hd.dialysate_outlet_flow import HDDialysateOutletFlow -from dialin.hd.hemodialysis_device import HD -from dialin.hd.pressure_occlusion import HDPressureOcclusion -from dialin.hd.rtc import HDRTC -from dialin.hd.treatment import HDTreatment -from dialin.hd.ui_proxy import HDUIProxy -from dialin.hd.watchdog import HDWatchdog - - -from dialin.dg.dialysate_generator import DG - - -from dialin.protocols.CAN import (DenaliCanMessenger, - DenaliMessage, - DenaliChannels, - LongDenaliMessageBuilder) - - -from dialin.utils.conversions import (integer_to_bytearray, - float_to_bytearray) - - - -``` - - - ## Dialin API Internal Development Environment ### Linux @@ -131,33 +98,18 @@ ### Windows -Note that windows support for the python-can library has not been validated. -As a result, this API is not functional on windows and windows support may have to be removed -in the future. +Due to a limitation in the underlying python-can library, Dialin does not currently support Windows. -For a brand new setup, after cloning this repository: -``` -> setup_environment_windows.bat - -``` - -If the windows environment has been previously set up: - -``` -> activate_environment_windows.bat -``` - - ## Unit Testing -All internal tests of the dialin API can be found in the tests directory at the root of -this git repository: +All unit tests of the Dialin API can be found in tests/unit_tests. To run them: ``` -(venv) $ cd tests -(venv) $ python3 dialin_unit_test_example.py +$ cd tools +$ ./run_unit_tests.sh 127 ↵ ``` +If there is a failure, the script will indicate what failed. No output means all tests have passed. ## Building the Dialin package Index: dialin/__init__.py =================================================================== diff -u -rc864e886bc1b52d3a43f03c507425248c44a913f -r82e32ae00355b2245a2660569935de152a883799 --- dialin/__init__.py (.../__init__.py) (revision c864e886bc1b52d3a43f03c507425248c44a913f) +++ dialin/__init__.py (.../__init__.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -1,6 +1,7 @@ from .version import VERSION -from .hd.hemodialysis_device import HD -from .dg.dialysate_generator import DG -from .ui.hd_simulator import HDSimulator +from .hd import * +from .dg import * +from .ui import * +from .utils import * -__version__= VERSION \ No newline at end of file +__version__ = VERSION \ No newline at end of file Index: dialin/common/msg_defs.py =================================================================== diff -u -r96006d22aa13f0287e2697a7cac7604201633263 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 96006d22aa13f0287e2697a7cac7604201633263) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -106,6 +106,10 @@ MSG_ID_HD_BLOOD_PRIME_PROGRESS = 0x59 # HD broadcast of blood prime progress MSG_ID_UI_TX_END_CMD = 0x57 # UI end treatment sub-mode user request MSG_ID_HD_TX_END_CMD_RESPONSE = 0x58 # HD end treatment sub-mode user request response + MSG_ID_UI_HD_SET_RTC_REQUEST = 0x6D # UI to DG Request to set RTC Request + MSG_ID_HD_UI_SET_RTC_RESPONSE = 0x6E # DG to UI set RTC Response + MSG_ID_UI_DG_SET_RTC_REQUEST = 0x6F # UI to HD request to set RTC Request + MSG_ID_DG_UI_SET_RTC_RESPONSE = 0x70 # HD to UI Set RTC Response MSG_ID_CAN_ERROR_COUNT = 0x999 # test code in support of EMC testing Index: dialin/hd/accelerometer.py =================================================================== diff -u -r812bbf1e5b3b2f1c4f5cfbef1264787e18afb5c3 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/hd/accelerometer.py (.../accelerometer.py) (revision 812bbf1e5b3b2f1c4f5cfbef1264787e18afb5c3) +++ dialin/hd/accelerometer.py (.../accelerometer.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -38,6 +38,9 @@ self.y = y self.z = z + def __repr__(self): + return "{0}: ({1},{2},{3})".format(self.__class__.__name__, self.x, self.y, self.z) + # Vector axes VECTOR_AXIS_X = 0 VECTOR_AXIS_Y = 1 Index: dialin/protocols/CAN.py =================================================================== diff -u -rcdf1c02e39d16c42fcb04a93f7ff180a8533d491 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/protocols/CAN.py (.../CAN.py) (revision cdf1c02e39d16c42fcb04a93f7ff180a8533d491) +++ dialin/protocols/CAN.py (.../CAN.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -368,6 +368,7 @@ dg_to_ui_ch_id = 0x070 dg_sync_broadcast_ch_id = 0x080 ui_to_hd_ch_id = 0x100 + ui_to_dg_ch_id = 0x110 ui_sync_broadcast_ch_id = 0x200 dialin_to_hd_ch_id = 0x400 hd_to_dialin_ch_id = 0x401 Index: dialin/ui/__init__.py =================================================================== diff -u -rf7cd7cb24f34bc40f718ecd8824c600ee1565134 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/ui/__init__.py (.../__init__.py) (revision f7cd7cb24f34bc40f718ecd8824c600ee1565134) +++ dialin/ui/__init__.py (.../__init__.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -1,2 +1,6 @@ -from .hd_simulator import HDSimulator, TXStates, EResponse, TreatmentParameterRejections -from .hd_simulator_alarms import HDAlarmsSimulator +from .hd_simulator import (HDSimulator, + TXStates, + EResponse, + TreatmentParameterRejections) +from .dg_simulator import DGSimulator +from .hd_simulator_alarms import HDAlarmsSimulator \ No newline at end of file Fisheye: Tag c2751410695697044b014189eb6e0ff69bb949d4 refers to a dead (removed) revision in file `dialin/ui/dg_simulator.py'. Fisheye: No comparison available. Pass `N' to diff? Index: dialin/ui/hd_simulator.py =================================================================== diff -u -r142b14d3bf4eeac8ca011978e1c32766256fb8b1 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 142b14d3bf4eeac8ca011978e1c32766256fb8b1) +++ dialin/ui/hd_simulator.py (.../hd_simulator.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -29,10 +29,8 @@ DenaliChannels) from ..utils.base import _AbstractSubSystem, _LogManager from ..utils.conversions import integer_to_bytearray, float_to_bytearray, byte_to_bytearray, short_to_bytearray +from ..utils import YES -YES = 1 -NO = 0 - class TreatmentParameterRejections: def __init__(self): self.param_request_valid = RequestRejectReasons.REQUEST_REJECT_REASON_NONE @@ -198,6 +196,13 @@ instanceCount = 0 def __init__(self, can_interface="can0", log_level=None, console_out=False): + """ + The HDSimulator constructor + + @param can_interface: (str) the can interface name + @param log_level: (str) or (None) if not set, contains the logging level + @param console_out: (bool) If True, write each dialin message to the console. + """ super().__init__() HDSimulator.instanceCount = HDSimulator.instanceCount + 1 @@ -227,13 +232,56 @@ self.can_interface.register_receiving_publication_function(channel_id, MsgIds.MSG_ID_UI_TREATMENT_END_REQUEST.value, self._handler_ui_end_treatment) + self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_UI_HD_SET_RTC_REQUEST.value, + self._handler_set_rtc_request) self.alarms_simulator = HDAlarmsSimulator(self.can_interface, self.logger) self.treatment_parameter_rejections = TreatmentParameterRejections() - def alarm(self) : + def alarm(self) -> HDAlarmsSimulator: + """ + Gets the alarm simulator object + @return: (HDAlarmsSimulator) the alarms simulator + """ return self.alarms_simulator + def _handler_set_rtc_request(self, message: dict) -> None: + """ + Handles a UI request to set the HD RTC + @param message: (dict) the message containing the request + @return: None + """ + + START_POS = DenaliMessage.PAYLOAD_START_INDEX + END_POS = START_POS + 4 + + epoch = struct.unpack('i', bytearray( + message['message'][START_POS:END_POS]))[0] + + self.logger.debug("Request to set the HD epoch to {0}".format(epoch)) + + self.cmd_send_set_rtc_response(YES, 0) + + def cmd_send_set_rtc_response(self, response, reason): + """ + Sends a set RTC response message + + @param response: (int) 0=NO, 1=YES + @return: None + """ + self.logger.debug("HD: Sending response {0} reason {1}".format(response, reason)) + + payload = integer_to_bytearray(response) + payload += integer_to_bytearray(reason) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.hd_to_ui_ch_id, + message_id=MsgIds.MSG_ID_HD_UI_SET_RTC_RESPONSE.value, + payload=payload) + + self.can_interface.send(message, 0) + + def cmd_send_treatment_parameter_validation_response(self, rejections: List[RequestRejectReasons]): """ Sends a treatment parameter validation response Index: dialin/utils/__init__.py =================================================================== diff -u -r703231f83070516744deb638547eda07aa9d02a7 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/utils/__init__.py (.../__init__.py) (revision 703231f83070516744deb638547eda07aa9d02a7) +++ dialin/utils/__init__.py (.../__init__.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -1 +1,3 @@ -from .base import DialinEnum \ No newline at end of file +from .base import * +YES = 1 +NO = 0 \ No newline at end of file Index: dialin/utils/base.py =================================================================== diff -u -r8a4783c11ec826a2b84480ffb6b033edcac12954 -r82e32ae00355b2245a2660569935de152a883799 --- dialin/utils/base.py (.../base.py) (revision 8a4783c11ec826a2b84480ffb6b033edcac12954) +++ dialin/utils/base.py (.../base.py) (revision 82e32ae00355b2245a2660569935de152a883799) @@ -494,6 +494,7 @@ def has_value(cls, value): return value in cls._value2member_map_ + class AlarmEnum(Enum): def __init__(self, *args): cls = self.__class__ Fisheye: Tag 82e32ae00355b2245a2660569935de152a883799 refers to a dead (removed) revision in file `tests/test_alarm_2.py'. Fisheye: No comparison available. Pass `N' to diff? Index: tests/test_hd_dg_simulators.py =================================================================== diff -u --- tests/test_hd_dg_simulators.py (revision 0) +++ tests/test_hd_dg_simulators.py (revision 82e32ae00355b2245a2660569935de152a883799) @@ -0,0 +1,39 @@ +########################################################################### +# +# Copyright (c) 2019-2020 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_saline_bolus.py +# +# @author (last) Peter Lucia +# @date (last) 15-Mar-2021 +# @author (original) Peter Lucia +# @date (original) 15-Mar-2021 +# +############################################################################ +import sys +from time import sleep + +sys.path.append("..") +from dialin import HDSimulator, DGSimulator, AbstractObserver + + +class Observer(AbstractObserver): + + def update(self, result): + print(result) + + +hd_sim = HDSimulator(log_level="DEBUG") +dg_sim = DGSimulator(log_level="DEBUG") +observer = Observer() + +hd_sim.attach(observer) +dg_sim.attach(observer) + +while True: + sleep(1) + + Index: tools/run_reset_hd.sh =================================================================== diff -u --- tools/run_reset_hd.sh (revision 0) +++ tools/run_reset_hd.sh (revision 82e32ae00355b2245a2660569935de152a883799) @@ -0,0 +1,5 @@ +#!/bin/bash + +cansend can0 "400#A5.00.00.00.80.03.31.32" +cansend can0 "400#33.49.00.00.00.00.00.00" +cansend can0 "400#A5.00.00.34.80.00.D7.00"