Index: dialin/common/msg_defs.py =================================================================== diff -u -r65277463eda63686c6132b6716aaa997b6df1861 -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 65277463eda63686c6132b6716aaa997b6df1861) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -1,6 +1,21 @@ +########################################################################### +# +# 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 msg_defs.py +# +# @author (last) Peter Lucia +# @date (last) 07-Aug-2020 +# @author (original) Peter Lucia +# @date (original) 07-Aug-2020 +# +############################################################################ import enum -from ..protocols.CAN import DenaliMessage + class MsgIds(enum.Enum): MSG_ID_UNUSED = 0 # Zero is an undefined (un-used) message ID) MSG_ID_OFF_BUTTON_PRESS = 1 # HD/UI off button interactions @@ -60,13 +75,9 @@ MSG_ID_DG_HEAT_DISINFECT_DATA = 0x37 # DG heat disinfection publish data MSG_ID_UI_START_TREATMENT = 0x38 # UI user request to initiate a treatment MSG_ID_HD_START_TREATMENT_RESPONSE = 0x39 # HD response to user request to initiate a treatment - MSG_ID_HD_VALVES_DATA = 0x3A # HD broadcast of valves data - MSG_ID_UI_USER_CONFIRM_TREATMENT_PARAMS = 0x3B # UI user confirmation of treatment parameters - MSG_ID_UI_TREATMENT_END_REQUEST = 0x3C # UI user treatment end request - MSG_ID_HD_TREATMENT_END_RESPONSE = 0x3D # HD response to user request to end treatment - MSG_ID_HD_AIR_TRAP_DATA = 0x3E # HD broadcast of air trap data - MSG_ID_USER_UF_PAUSE_RESUME_RESPONSE = 0x3F # HD response to user request to pause or resume UF + MSG_ID_CAN_ERROR_COUNT = 0x999 # test code in support of EMC testing + # service/test CAN messages MSG_ID_FIRST_TESTER_MESSAGE = 0x8000 # First HD test message ID MSG_ID_TESTER_LOGIN_REQUEST = MSG_ID_FIRST_TESTER_MESSAGE # HD tester log-in @@ -150,6 +161,11 @@ MSG_ID_HEAT_DISINFECT_RSRVR2_TO_RSRVR1_DURATION_MINS = 0xA01F # Heat disinfection reservoir 2 to reservoir 1 duration in minutes MSG_ID_HEAT_DISINFECT_NO_OF_CYCLES_TO_RUN = 0xA020 # Heat disinfection number of cycles to run MSG_ID_HEAT_DISINFECT_PUBLISH_INTERVAL_OVERRIDE = 0xA021 # Heat disinfection data publish interval override request + MSG_ID_HD_VALVES_DATA = 0x3A # HD valves data publish + MSG_ID_HD_VALVES_HOME = 0x802E # HD valves home command + MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE = 0x8030 # HD valves set blood trap valve state + MSG_ID_HD_VALVES_POSITION_OVERRIDE = 0x802F # HD valves position override command + MSG_ID_HD_VALVES_SET_PWM_OVERRIDE = 0x8031 # HD valves PWM override command MSG_ID_HD_DEBUG_EVENT = 0xFFF1 # HD debug event text to be logged in event log MSG_ID_DG_DEBUG_EVENT = 0xFFF2 # DG debug event text to be logged in event log @@ -176,53 +192,4 @@ REQUEST_REJECT_REASON_UF_NOT_IN_PROGESS = 14 REQUEST_REJECT_REASON_UF_NOT_PAUSED = 15 REQUEST_REJECT_REASON_SALINE_BOLUS_IN_PROGRESS = 16 - REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE = 17 - REQUEST_REJECT_REASON_HEPARIN_PRESTOP_EXCEEDS_DURATION = 18 - REQUEST_REJECT_REASON_ARTERIAL_PRESSURE_LOW_VS_HIGH = 19 - REQUEST_REJECT_REASON_VENOUS_PRESSURE_LOW_VS_HIGH = 20 - REQUEST_REJECT_REASON_SALINE_MAX_VOLUME_REACHED = 21 - REQUEST_REJECT_REASON_SALINE_BOLUS_NOT_IN_PROGRESS = 22 - NUM_OF_REQUEST_REJECT_REASONS = 23 - -class MsgFldPositions(): - # Generic response msg field byte positions (where 32-bit data fields are used) - START_POS_FIELD_1 = DenaliMessage.PAYLOAD_START_INDEX - END_POS_FIELD_1 = START_POS_FIELD_1 + 4 - START_POS_FIELD_2 = END_POS_FIELD_1 - END_POS_FIELD_2 = START_POS_FIELD_2 + 4 - START_POS_FIELD_3 = END_POS_FIELD_2 - END_POS_FIELD_3 = START_POS_FIELD_3 + 4 - START_POS_FIELD_4 = END_POS_FIELD_3 - END_POS_FIELD_4 = START_POS_FIELD_4 + 4 - START_POS_FIELD_5 = END_POS_FIELD_4 - END_POS_FIELD_5 = START_POS_FIELD_5 + 4 - START_POS_FIELD_6 = END_POS_FIELD_5 - END_POS_FIELD_6 = START_POS_FIELD_6 + 4 - START_POS_FIELD_7 = END_POS_FIELD_6 - END_POS_FIELD_7 = START_POS_FIELD_7 + 4 - START_POS_FIELD_8 = END_POS_FIELD_7 - END_POS_FIELD_8 = START_POS_FIELD_8 + 4 - START_POS_FIELD_9 = END_POS_FIELD_8 - END_POS_FIELD_9 = START_POS_FIELD_9 + 4 - START_POS_FIELD_10 = END_POS_FIELD_9 - END_POS_FIELD_10 = START_POS_FIELD_10 + 4 - START_POS_FIELD_11 = END_POS_FIELD_10 - END_POS_FIELD_11 = START_POS_FIELD_11 + 4 - START_POS_FIELD_12 = END_POS_FIELD_11 - END_POS_FIELD_12 = START_POS_FIELD_12 + 4 - START_POS_FIELD_13 = END_POS_FIELD_12 - END_POS_FIELD_13 = START_POS_FIELD_13 + 4 - START_POS_FIELD_14 = END_POS_FIELD_13 - END_POS_FIELD_14 = START_POS_FIELD_14 + 4 - START_POS_FIELD_15 = END_POS_FIELD_14 - END_POS_FIELD_15 = START_POS_FIELD_15 + 4 - START_POS_FIELD_16 = END_POS_FIELD_15 - END_POS_FIELD_16 = START_POS_FIELD_16 + 4 - START_POS_FIELD_17 = END_POS_FIELD_16 - END_POS_FIELD_17 = START_POS_FIELD_17 + 4 - START_POS_FIELD_18 = END_POS_FIELD_17 - END_POS_FIELD_18 = START_POS_FIELD_18 + 4 - START_POS_FIELD_19 = END_POS_FIELD_18 - END_POS_FIELD_19 = START_POS_FIELD_19 + 4 - START_POS_FIELD_20 = END_POS_FIELD_19 - END_POS_FIELD_20 = START_POS_FIELD_20 + 4 + NUM_OF_REQUEST_REJECT_REASONS = 17 Index: dialin/dg/temperature_sensors.py =================================================================== diff -u -r4bdb012848d1b59be5edc31d677b77b9d95f6190 -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/dg/temperature_sensors.py (.../temperature_sensors.py) (revision 4bdb012848d1b59be5edc31d677b77b9d95f6190) +++ dialin/dg/temperature_sensors.py (.../temperature_sensors.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -7,8 +7,8 @@ # # @file temperature_sensors.py # -# @author (last) Dara Navaei -# @date (last) 07-Jul-2020 +# @author (last) Peter Lucia +# @date (last) 26-Aug-2020 # @author (original) Dara Navaei # @date (original) 02-Jun-2020 # @@ -19,7 +19,25 @@ from .constants import NO_RESET from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import _AbstractSubSystem, _publish +from logging import Logger +import enum + +class TemperatureSensorsEnum(enum.Enum): + PRIMARY_HEATER_INLET = 0 + PRIMARY_HEATER_OUTLET = 1 + CONDUCTIVITY_SENSOR_1 = 2 + CONDUCTIVITY_SENSOR_2 = 3 + DIALYSATE_REDUNDANT = 4 + DIALYSATE = 5 + PRIMARY_HEATER_THERMOCOUPLE = 6 + TRIMMER_HEATER_THERMOCOUPLE = 7 + PRIMARY_HEATER_COLD_JUNCTION = 8 + TRIMMER_HEATER_COLD_JUNCTION = 9 + PRIMARY_HEATER_INTERNAL = 10 + TRIMMER_HEATER_INTERNAL = 11 + + class TemperatureSensors(_AbstractSubSystem): MSG_ID_DG_TEMPERATURE_DATA = 0x2D @@ -63,12 +81,12 @@ START_POS_TRI_INTERNAL_TEMP = END_POS_PRI_INTERNAL_TEMP END_POS_TRI_INTERNAL_TEMP = START_POS_TRI_INTERNAL_TEMP + 4 - def __init__(self, can_interface=None): + def __init__(self, can_interface, logger: Logger): super().__init__() self.can_interface = can_interface - + self.logger = logger self.inlet_primary = 0.0 self.outlet_primary = 0.0 self.cd1 = 0.0 @@ -85,7 +103,8 @@ if self.can_interface is not None: channel_id = DenaliChannels.dg_sync_broadcast_ch_id msg_id = self.MSG_ID_DG_TEMPERATURE_DATA - self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_temperature_sensors_sync) + self.can_interface.register_receiving_publication_function(channel_id, msg_id, + self._handler_temperature_sensors_sync) @_publish(["inlet_primary", "outlet_primary", "cd1", "cd2","outlet_redundancy", "inlet_dialysate", "primary_tc", "trimmer_tc", "primary_cj", "trimmer_cj", "primary_internal", "trimmer_internal"]) @@ -146,7 +165,10 @@ def cmd_temperature_sensors_broadcast_interval_override(self, ms, reset=NO_RESET): """ - Constructs and sends broadcast time interval + Constructs and sends broadcast time interval. + Constraints: + Must be logged into DG. + Given interval must be non-zero and a multiple of the DG priority task interval (10 ms). @param ms: Publish time interval in ms @param reset: integer - 1 to reset a previous override, 0 to override @@ -160,7 +182,7 @@ message_id=self.MSG_ID_TEMPERATURE_SENSORS_PUBLISH_INTERVAL_OVERRIDE, payload=payload) - print("Sending {} ms publish interval to the Temperature Sensors module".format(ms)) + self.logger.debug("Sending {} ms publish interval to the Temperature Sensors module".format(ms)) # Send message received_message = self.can_interface.send(message) @@ -169,16 +191,33 @@ # Response payload is OK or not return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Timeout!!!!") + self.logger.debug("Timeout!!!!") return False def cmd_temperature_sensors_override_value(self, sensor_index, sensor_value, reset=NO_RESET): """ - Constructs and sends the value override of a temperature sensor + Constructs and sends the value override of a temperature sensor. + Constraints: + Must be logged into DG. + Given sensor_index must be one of the sensors listed below. @param sensor_index : Index of the sensor - @param sensor_value: Value of the sensor to be overriden + @param sensor_value: Value of the sensor to override @returns 1 if successful, zero otherwise + + \details temperature sensor indexes: \n + 0 = Primary Heater Inlet + 1 = Primary Heater Outlet + 2 = Conductivity Sensor 1 + 3 = Conductivity Sensor 2 + 4 = Dialysate (Redundant) + 5 = Dialysate + 6 = Primary Heater Thermocouple + 7 = Trimmer Heater Thermocouple + 8 = Primary Heater Cold Junction + 9 = Trimmer Heater Cold Junction + 10= Primary Heater Internal + 11= Trimmer Heater Internal """ rst = integer_to_bytearray(reset) value = float_to_bytearray(sensor_value) @@ -190,7 +229,7 @@ message_id=self.MSG_ID_TEMPERATURE_SENSORS_VALUE_OVERRIDE, payload=payload) - print("Setting sensor {} to {} C".format(sensor_index, sensor_value)) + self.logger.debug("Setting sensor {} to {} C".format(sensor_index, sensor_value)) # Send message received_message = self.can_interface.send(message) @@ -200,6 +239,6 @@ # Response payload is OK or not return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Timeout!!!!") + self.logger.debug("Timeout!!!!") return False Index: dialin/hd/hemodialysis_device.py =================================================================== diff -u -r2c016f17a5468be8add2a467c989c19f69d501df -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/hd/hemodialysis_device.py (.../hemodialysis_device.py) (revision 2c016f17a5468be8add2a467c989c19f69d501df) +++ dialin/hd/hemodialysis_device.py (.../hemodialysis_device.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -8,7 +8,7 @@ # @file hemodialysis_device.py # # @author (last) Peter Lucia -# @date (last) 20-Jul-2020 +# @date (last) 26-Aug-2020 # @author (original) Peter Lucia # @date (original) 02-Apr-2020 # @@ -28,7 +28,8 @@ from ..protocols.CAN import (DenaliMessage, DenaliCanMessenger, DenaliChannels) -from ..utils.base import _AbstractSubSystem, _publish +from ..utils.base import _AbstractSubSystem, _publish, _LogManager +from .constants import NO_RESET class HD(_AbstractSubSystem): @@ -41,6 +42,7 @@ MSG_ID_HD_OPERATION_MODE_BROADCAST = 0x0025 MSG_ID_LOGIN_TO_HD = 0x8000 MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE = 0x8026 + MSG_ID_POWEROFF_NOTIFY = 0x0020 # broadcast message field positions START_POS_HD_OP_MODE = DenaliMessage.PAYLOAD_START_INDEX @@ -64,19 +66,27 @@ def __init__(self, can_interface="can0", log_level=None): """ - HD constructor using can bus + HD object provides test/service commands for the HD sub-system. + >> hd_object = HD('can0') + >> hd_object = HD(can_interface='can0', log_level="DEBUG") + + Possible log levels: + ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "CAN_ONLY", "PRINT_ONLY"] + @param can_interface: (str) CANBus interface name, e.g. "can0" - @return: HD object provides test/service commands for the HD sub-system. + @param log_level: (str) Logging level, defaults to None - >> hd_object = HD(can_interface='can0') - >> hd_object = HD('can0') """ super().__init__() + self._log_manager = _LogManager(log_level=log_level, log_filepath=self.__class__.__name__+".log") + self.logger = self._log_manager.logger # Create listener - self.can_interface = DenaliCanMessenger(can_interface=can_interface, log_level=log_level) + self.can_interface = DenaliCanMessenger(can_interface=can_interface, + logger=self.logger, + log_can=self._log_manager.log_level == "CAN_ONLY") self.can_interface.start() # register handler for HD operation mode broadcast messages @@ -91,17 +101,17 @@ self.hd_operation_sub_mode = 0 # Create command groups - self.alarms = HDAlarms(self.can_interface) - self.buttons = HDButtons(self.can_interface) - self.ui = HDUIProxy(self.can_interface) - self.rtc = HDRTC(self.can_interface) - self.watchdog = HDWatchdog(self.can_interface) - self.bloodflow = HDBloodFlow(self.can_interface) - self.dialysate_inlet_flow = HDDialysateInletFlow(self.can_interface) - self.dialysate_outlet_flow = HDDialysateOutletFlow(self.can_interface) - self.treatment = HDTreatment(self.can_interface) - self.pressure_occlusion = HDPressureOcclusion(self.can_interface) - self.valves = HDValves(self.can_interface) + self.alarms = HDAlarms(self.can_interface, self.logger) + self.buttons = HDButtons(self.can_interface, self.logger) + self.ui = HDUIProxy(self.can_interface, self.logger) + self.rtc = HDRTC(self.can_interface, self.logger) + self.watchdog = HDWatchdog(self.can_interface, self.logger) + self.bloodflow = HDBloodFlow(self.can_interface, self.logger) + self.dialysate_inlet_flow = HDDialysateInletFlow(self.can_interface, self.logger) + self.dialysate_outlet_flow = HDDialysateOutletFlow(self.can_interface, self.logger) + self.treatment = HDTreatment(self.can_interface, self.logger) + self.pressure_occlusion = HDPressureOcclusion(self.can_interface, self.logger) + self.valves = HDValves(self.can_interface, self.logger) def get_operation_mode(self): """ @@ -140,47 +150,58 @@ message_id=self.MSG_ID_LOGIN_TO_HD, payload=list(map(int, map(ord, self.HD_LOGIN_PASSWORD)))) - print("Logging in...") + self.logger.debug("Logging in...") # Send message received_message = self.can_interface.send(message) if received_message is not None: if received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] == 1: - print("Success: Logged In") + self.logger.debug("Success: Logged In") else: - print("Failure: Log In Failed.") + self.logger.debug("Failure: Log In Failed.") return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Login Timeout!!!!") + self.logger.debug("Login Timeout!!!!") return False - def cmd_hd_safety_shutdown_override(self): + def cmd_hd_safety_shutdown_override(self, active=True, reset=NO_RESET): """ Constructs and sends an HD safety shutdown override command via CAN bus. + Constraints: + Must be logged into HD. \returns response message if received, False if no response received - @param msg: byte array - properly formatted HD message to insert - + @param active: boolean - True to activate safety shutdown, False to deactivate + @param reset: integer - 1 to reset a previous override, 0 to override @return: 1 if successful, zero otherwise """ + if active: + sft=1 + else: + sft=0 + rst = integer_to_bytearray(reset) + saf = integer_to_bytearray(sft) + payload = rst + saf + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE) + message_id=self.MSG_ID_HD_SAFETY_SHUTDOWN_OVERRIDE, + payload=payload) - print("overriding HD safety shutdown") + self.logger.debug("overriding HD safety shutdown") # Send message received_message = self.can_interface.send(message) if received_message is not None: if received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] == 1: - print("Safety shutdown signal overridden") + self.logger.debug("Safety shutdown signal overridden") else: - print("Safety shutdown signal override failed.") + self.logger.debug("Safety shutdown signal override failed.") return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Timeout!!!!") + self.logger.debug("Timeout!!!!") return False Index: dialin/hd/valves.py =================================================================== diff -u -r34b6c910e5c691b6bf661283f28bc87c9be20220 -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/hd/valves.py (.../valves.py) (revision 34b6c910e5c691b6bf661283f28bc87c9be20220) +++ dialin/hd/valves.py (.../valves.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -5,22 +5,41 @@ from .constants import NO_RESET from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import _AbstractSubSystem, _publish +from ..common import MsgIds +from logging import Logger +import enum +class ValvesEnum(enum.Enum): + VDI = 0 + VDO = 1 + VBA = 2 + VBV = 3 + +class ValvesPositions(enum.Enum): + VALVE_POSITION_NOT_IN_POSITION = 0 + VALVE_POSITION_A_INSERT_EJECT = 1 + VALVE_POSITION_B_OPEN = 2 + VALVE_POSITION_C_CLOSE = 3 + +class ValvesStates(enum.Enum): + VALVE_STATE_WAIT_FOR_POST = 0 + VALVE_STATE_HOMING_NOT_STARTED = 1 + VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE = 2 + VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE = 3 + VALVE_STATE_IDLE = 4 + VALVE_STATE_IN_TRANSITION = 5 + VALVE_STATE_IN_BYPASS_MODE = 6 + +class AirTrapState(enum.Enum): + STATE_CLOSED = 0 + STATE_OPEN = 1 + class HDValves(_AbstractSubSystem): """ \class HDValves \brief Hemodialysis Device (HD) Dialin API sub-class for valves related commands. """ - - # Valve state message IDs - MSG_ID_HD_VALVES_DATA = 0x3A - MSG_ID_HD_VALVES_HOME = 0x802E - MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE = 0x8030 - MSG_ID_HD_VALVES_POSITION_OVERRIDE = 0x802F - MSG_ID_HD_VALVES_SET_PWM_OVERRIDE = 0x8031 - MSG_ID_VALVES_STATES_PUBLISH_INTERVAL_OVERRIDE = 0xA00F - MSG_ID_TEMP_FAST_HD_VALVES_REMOVE_LATER = 0x6D # TODO Remove # Valves states publish message field positions @@ -66,48 +85,32 @@ END_FAST_VALVES_CMD = START_FAST_VALVES_CMD + 2 # TODO Fast publish REMOVE LATER - def __init__(self, can_interface=None): + def __init__(self, can_interface, logger: Logger): """ DGDrainPump constructor \param outer_instance: reference to the DG (outer) class. """ super().__init__() self.can_interface = can_interface + self.logger = logger if self.can_interface is not None: channel_id = DenaliChannels.hd_sync_broadcast_ch_id - msg_id = self.MSG_ID_HD_VALVES_DATA + msg_id = MsgIds.MSG_ID_HD_VALVES_DATA.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, - self.handler_hd_valves_sync) + self._handler_hd_valves_sync) # TODO remove msg_id2 = self.MSG_ID_TEMP_FAST_HD_VALVES_REMOVE_LATER self.can_interface.register_receiving_publication_function(channel_id, msg_id2, self.handler_hd_valves_fast_temp_sync) # TODO remove - self.states = ["VALVE_STATE_WAIT_FOR_POST", "VALVE_STATE_HOMING_NOT_STARTED", - "VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE", "VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE", - "VALVE_STATE_IDLE", "VALVE_STATE_IN_TRANSITION", "VALVE_STATE_IN_BYPASS_MODE"] + # A dictionary of the valves with the status + self.valves_status = {ValvesEnum.VDI.name:{}, ValvesEnum.VDO.name:{}, ValvesEnum.VBA.name:{}, + ValvesEnum.VBV.name:{}} - self.positions = ["VALVE_POSITION_NOT_IN_POSITION", "VALVE_POSITION_A_INSERT_EJECT", - "VALVE_POSITION_B_OPEN", "VALVE_POSITION_C_CLOSE"] - - self.valves = ["VDI", "VDO", "VBA", "VBV"] - - self.air_trap_states = ["Open", "Close"] - - self.hd_valve_ID = 0 - self.hd_valve_state = 0 - self.hd_valve_curr_pos_ID = 0 - self.hd_valve_curr_pos_cnt = 0 - self.hd_valve_next_pos_cnt = 0 - self.hd_valve_current = 0 - self.hd_valves_pos_c = 0 - self.hd_valves_pos_a = 0 - self.hd_valves_pos_b = 0 - self.hd_valves_pwm = 0 self.hd_air_trap_status = 0 #TODO Remove these later @@ -116,7 +119,7 @@ self.hd_valves_fast_cmd = 0 #TODO Remove these later - def cmd_temperature_sensors_broadcast_interval_override(self, ms, reset=NO_RESET): + def cmd_hd_valves_broadcast_interval_override(self, ms, reset=NO_RESET): """ Constructs and sends broadcast time interval @@ -128,11 +131,11 @@ interval_value = integer_to_bytearray(ms) payload = reset_value + interval_value - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, - message_id=self.MSG_ID_VALVES_STATES_PUBLISH_INTERVAL_OVERRIDE, + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=MsgIds.MSG_ID_VALVES_STATES_PUBLISH_INTERVAL_OVERRIDE.value, payload=payload) - print("Sending {} ms publish interval to the HD valves module".format(ms)) + self.logger.debug("Sending {} ms publish interval to the HD valves module".format(ms)) # Send message received_message = self.can_interface.send(message) @@ -141,7 +144,7 @@ # Response payload is OK or not return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Timeout!!!!") + self.logger.debug("Timeout!!!!") return False def cmd_set_hd_valve_position(self, valve, position, reset=NO_RESET): @@ -165,7 +168,7 @@ payload = reset_value + pos + vlv message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_VALVES_POSITION_OVERRIDE, + message_id=MsgIds.MSG_ID_HD_VALVES_POSITION_OVERRIDE.value, payload=payload) # Send message received_message = self.can_interface.send(message) @@ -175,12 +178,12 @@ # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("HD cmd_valve_override Timeout!!!") + self.logger.debug("HD cmd_valve_override Timeout!!!") return False def cmd_set_hd_valve_pwm(self, valve, pwm, direction, reset=NO_RESET): """ - Constructs and sends the HD valves home command + Constructs and sends the HD valves PWM command \param valve: integer - Valve number: VDI = 0 @@ -199,7 +202,7 @@ payload = reset_value + vlv + pwm + dir message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_VALVES_SET_PWM_OVERRIDE, + message_id=MsgIds.MSG_ID_HD_VALVES_SET_PWM_OVERRIDE.value, payload=payload) # Send message received_message = self.can_interface.send(message) @@ -209,7 +212,7 @@ # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("HD cmd_valve_override Timeout!!!") + self.logger.debug("HD cmd_valve_override Timeout!!!") return False def cmd_home_hd_valve(self, valve): @@ -226,7 +229,7 @@ payload = integer_to_bytearray(valve) message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_VALVES_HOME, + message_id=MsgIds.MSG_ID_HD_VALVES_HOME.value, payload=payload) # Send message received_message = self.can_interface.send(message) @@ -236,58 +239,37 @@ # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("HD Homing Valve Timeout!!!") + self.logger.debug("HD Homing Valve Timeout!!!") return False - def cmd_open_hd_air_trap_valve(self): + def cmd_set_hd_air_trap_valve(self, valve_state=AirTrapState.STATE_CLOSED.name): """ - Constructs and sends an open command to the HD air trap valve + Constructs and sends an open/close command to the HD air trap valve \returns 1 if successful, zero otherwise """ - payload = integer_to_bytearray(1) - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE, - payload=payload) - # Send message - received_message = self.can_interface.send(message) - - # If there is content... - if received_message is not None: - print("Opening air trap valve") - # response payload is OK or not OK - return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + if valve_state == AirTrapState.STATE_OPEN: + payload = integer_to_bytearray(1) else: - print("Opening air trap valve timeout!!") - return False + payload = integer_to_bytearray(0) - def cmd_close_hd_air_trap_valve(self): - """ - Constructs and sends a stop command to the HD air trap valve - - \returns 1 if successful, zero otherwise - """ - payload = integer_to_bytearray(0) - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_hd_ch_id, - message_id=self.MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE, + message_id=MsgIds.MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE.value, payload=payload) # Send message received_message = self.can_interface.send(message) # If there is content... if received_message is not None: - print("Closing air trap valve") + self.logger.debug("Opening air trap valve") # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: - print("Closing air trap valve timeout!!") + self.logger.debug("Opening air trap valve timeout!!") return False - @_publish(["hd_valve_ID", "hd_valve_state", "hd_valve_curr_pos_ID", "hd_valve_curr_pos_cnt", - "hd_valve_next_pos_cnt", "hd_valve_current", "hd_valves_pos_c", "hd_valves_pos_a", - "hd_valves_pos_b", "hd_valves_pwm", "hd_air_trap_status"]) + @_publish(["valves_status"]) def _handler_hd_valves_sync(self, message): """ Handles published HD valves data messages. HD valves data are captured @@ -297,41 +279,44 @@ \returns none """ vlv_ID = struct.unpack('i', bytearray( - message['message'][self.START_POS_VALVES_ID:self.END_POS_VALVES_ID])) + message['message'][self.START_POS_VALVES_ID:self.END_POS_VALVES_ID]))[0] state_ID = struct.unpack('i', bytearray( - message['message'][self.START_VALVES_STATE:self.END_VALVES_STATE])) + message['message'][self.START_VALVES_STATE:self.END_VALVES_STATE]))[0] pos_ID = struct.unpack('i', bytearray( - message['message'][self.START_POS_VALVES_CURR_POS:self.END_POS_VALVES_CURR_POS])) + message['message'][self.START_POS_VALVES_CURR_POS:self.END_POS_VALVES_CURR_POS]))[0] pos_cnt = struct.unpack('h', bytearray( - message['message'][self.START_POS_VALVES_CURR_POS_CNT:self.END_POS_VALVES_CURR_POS_CNT])) + message['message'][self.START_POS_VALVES_CURR_POS_CNT:self.END_POS_VALVES_CURR_POS_CNT]))[0] next_pos = struct.unpack('h', bytearray( - message['message'][self.START_POS_VALVES_NEXT_POS_CNT:self.END_POS_VALVES_NEXT_POS_CNT])) + message['message'][self.START_POS_VALVES_NEXT_POS_CNT:self.END_POS_VALVES_NEXT_POS_CNT]))[0] current = struct.unpack('f', bytearray( - message['message'][self.START_POS_VALVES_CURRENT:self.END_POS_VALVES_CURRENT])) + message['message'][self.START_POS_VALVES_CURRENT:self.END_POS_VALVES_CURRENT]))[0] pos_c = struct.unpack('h', bytearray( - message['message'][self.START_VALVES_POS_C:self.END_VALVES_POS_C])) + message['message'][self.START_VALVES_POS_C:self.END_VALVES_POS_C]))[0] pos_a = struct.unpack('h', bytearray( - message['message'][self.START_VALVES_POS_A:self.END_VALVES_POS_A])) + message['message'][self.START_VALVES_POS_A:self.END_VALVES_POS_A]))[0] pos_b = struct.unpack('h', bytearray( - message['message'][self.START_VALVES_POS_B:self.END_VALVES_POS_B])) + message['message'][self.START_VALVES_POS_B:self.END_VALVES_POS_B]))[0] pwm = struct.unpack('i', bytearray( - message['message'][self.START_VALVES_PWM:self.END_VALVES_PWM])) + message['message'][self.START_VALVES_PWM:self.END_VALVES_PWM]))[0] air_trap = struct.unpack('i', bytearray( - message['message'][self.START_AIR_TRAP_VALVE_STATUS:self.END_AIR_TRAP_VALVE_STATUS])) + message['message'][self.START_AIR_TRAP_VALVE_STATUS:self.END_AIR_TRAP_VALVE_STATUS]))[0] - self.hd_valve_ID = self.valves[vlv_ID[0]] if vlv_ID[0] < len(self.valves) else 'Valve Unknown' - self.hd_valve_state = self.states[state_ID[0]] if state_ID[0] < len(self.states) else 'State Unknown' - self.hd_valve_curr_pos_ID = self.positions[pos_ID[0]] if pos_ID[0] < len(self.positions) else 'Position Unknown' - self.hd_valve_curr_pos_cnt = pos_cnt[0] - self.hd_valve_next_pos_cnt = next_pos[0] - self.hd_valve_current = current[0] - self.hd_valves_pos_c = pos_c[0] - self.hd_valves_pos_a = pos_a[0] - self.hd_valves_pos_b = pos_b[0] - self.hd_valves_pwm = pwm[0] - self.hd_air_trap_status = self.air_trap_states[air_trap[0]] if air_trap[0] < len(self.air_trap_states) else \ - 'Status Unknwon' + # To make sure the valve number is not out of range + try: + # Get the valve name + vlv_name = ValvesEnum(vlv_ID).name + # Update the valves dictionary + self.valves_status[vlv_name] = {'Valve': vlv_name, 'PosID': ValvesPositions(pos_ID).name, 'PosCnt': pos_cnt, + 'Cmd': next_pos, 'State': ValvesStates(state_ID).name, 'Current': current, + 'PosA': pos_a, 'PosB': pos_b, 'PosC': pos_c, 'PWM': pwm} + except: + self.logger.debug('Invalid ID Selected') + try: + self.hd_air_trap_status = AirTrapState(air_trap).name + except: + self.hd_air_trap_status = 'Valve Status Unknown' + #TODO REMOVE THIS FUNCTION def handler_hd_valves_fast_temp_sync(self, message): Index: dialin/squish/denaliMessages.py =================================================================== diff -u -r27357f8b363431d4bbb9f15960b24c7036fdc76c -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/squish/denaliMessages.py (.../denaliMessages.py) (revision 27357f8b363431d4bbb9f15960b24c7036fdc76c) +++ dialin/squish/denaliMessages.py (.../denaliMessages.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ########################################################################### # # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. @@ -14,17 +13,6 @@ # @date (original) 09-Jul-2020 # ############################################################################ -## -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. -# copyright -# 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 denaliMessages.py -# date 2020/04/08 -# author Behrouz NematiPour -# import time import subprocess @@ -33,137 +21,152 @@ from dialin.squish import messageBuilder - class EResponse: Rejected = 0 Accepted = 1 class GuiActionType: - Unknown = 0 - PowerOff = 1 - KeepAlive = 7 - BloodFlow = 5 - DialysateInletFlow = 8 - DialysateOutletFlow = 11 - TreatmentTime = 13 - PowerOffBroadcast = 14 + Unknown = 0 + PowerOff = 1 + KeepAlive = 7 + BloodFlow = 5 + DialysateInletFlow = 8 + DialysateOutletFlow = 11 + TreatmentTime = 13 + PowerOffBroadcast = 14 - AlarmStatus = 2 - AlarmTriggered = 3 - AlarmCleared = 4 + AlarmStatus = 2 + AlarmTriggered = 3 + AlarmCleared = 4 - PressureOcclusion = 9 + PressureOcclusion = 9 - DGDrainPumpData = 36 - DGHeatersData = 44 - LoadCellReadings = 12 - DGPressuresData = 32 - TemperatureSensors = 45 - - CanBUSFaultCount = 2457 - HDDebugText = 0xFFF1 - DGDebugText = 0xFFF2 + DGDrainPumpData = 36 + DGHeatersData = 44 + LoadCellReadings = 12 + DGPressuresData = 32 + TemperatureSensors = 45 - AdjustBloodDialysateReq = 23 - AdjustBloodDialysateRsp = 24 + CanBUSFaultCount = 2457 + HDDebugText = 0xFFF1 + DGDebugText = 0xFFF2 - AdjustDurationReq = 22 - AdjustDurationRsp = 27 + AdjustBloodDialysateReq = 23 + AdjustBloodDialysateRsp = 24 - AdjustUltrafiltrationStateReq = 16 # Req and Rsp are the same in this specific message + AdjustDurationReq = 22 + AdjustDurationRsp = 27 - AdjustUltrafiltrationEditReq = 17 - AdjustUltrafiltrationEditRsp = 19 + AdjustUltrafiltrationStateReq = 16 # Req and Rsp are the same in this specific message + AdjustUltrafiltrationEditReq = 17 + AdjustUltrafiltrationEditRsp = 19 + AdjustUltrafiltrationConfirmReq = 21 AdjustUltrafiltrationConfirmRsp = 46 - - TreatmentRanges = 26 + TreatmentRanges = 26 - String = 65279 + String = 65279 - Acknow = 65535 + Acknow = 65535 - AcknowGeneric = 0 # Generic Acknowledgment is not a unique message ID and inherits its Id from the actual message. Zero is a placeholder + AcknowGeneric = 0 # Generic Acknowledgment is not a unique message ID and inherits its Id from the actual message. Zero is a placeholder def send_acknowledge_HD(): subprocess.call(['cansend', 'can0', '020#A5.01.00.FF.FF.00.19.00']) + def send_acknowledge_UI(): subprocess.call(['cansend', 'can0', '100#A5.01.00.FF.FF.00.19.00']) + def send_CheckIn_DG(): subprocess.call(['cansend', 'can0', '010#A5.01.00.06.00.00.76.00']) - + + def show_PowerOffDialog(): subprocess.call(['cansend', 'can0', '020#A5.01.00.01.00.01.00.38']) + def hide_PowerOffDialog(): subprocess.call(['cansend', 'can0', '020#A5.01.00.01.00.01.01.09']) + def show_PowerOffNotificationDialog(): subprocess.call(['cansend', 'can0', '040#A5.01.00.0E.00.00.24.00']) + def show_PowerOffRejectionDialog(): subprocess.call(['cansend', 'can0', '020#A5.01.00.01.00.01.02.5A']) + ################################################################################################## -# After each multi-frame message put a 100ms sleep, time.sleep(0.1) # +# After each multi-frame message put a 100ms sleep, time.sleep(0.1) # # it seems it's needed otherwise the test will check a value which has not been received yet. # ################################################################################################## def waitForMessageToBeSent(): - time.sleep(0.050) # 50ms + time.sleep(0.050) # 50ms + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildHDDebugText(vText): len = 40 - txt = messageBuilder.textToByte(vText, len) # + 1 null term - msg = messageBuilder.buildMessage( GuiActionType.HDDebugText, 1 * (len + 1), False, txt) + txt = messageBuilder.textToByte(vText, len) # + 1 null term + msg = messageBuilder.buildMessage(GuiActionType.HDDebugText, 1 * (len + 1), False, txt) return messageBuilder.toFrames(msg) + + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setHDDebugText (vText): +def setHDDebugText(vText): frames = buildHDDebugText(vText) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGDebugText(vText): len = 40 - txt = messageBuilder.textToByte(vText, len) # + 1 null term - msg = messageBuilder.buildMessage( GuiActionType.DGDebugText, 1 * (len + 1), False, txt) + txt = messageBuilder.textToByte(vText, len) # + 1 null term + msg = messageBuilder.buildMessage(GuiActionType.DGDebugText, 1 * (len + 1), False, txt) return messageBuilder.toFrames(msg) + + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setDGDebugText (vText): +def setDGDebugText(vText): frames = buildDGDebugText(vText) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '070#{}'.format(frame)]) waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate): +def buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, + vMinDialysateFlowRate, vMaxDialysateFlowRate): msg = messageBuilder.buildMessage(GuiActionType.TreatmentRanges, 4 * 6, True, - utils.toI32(vMinTreatmentDuration), - utils.toI32(vMaxTreatmentDuration), - utils.toF32(vMinUFVolume ), - utils.toF32(vMaxUFVolume ), - utils.toI32(vMinDialysateFlowRate), - utils.toI32(vMaxDialysateFlowRate) - ) + utils.toI32(vMinTreatmentDuration), + utils.toI32(vMaxTreatmentDuration), + utils.toF32(vMinUFVolume), + utils.toF32(vMaxUFVolume), + utils.toI32(vMinDialysateFlowRate), + utils.toI32(vMaxDialysateFlowRate) + ) return messageBuilder.toFrames(msg) -def setTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate): - frames = buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate) +def setTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, + vMinDialysateFlowRate, vMaxDialysateFlowRate): + frames = buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, + vMinDialysateFlowRate, vMaxDialysateFlowRate) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) @@ -172,14 +175,14 @@ def buildSetTreatmentBloodFlowRate(vFlowSetPt, vMeasFlow, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM): msg = messageBuilder.buildMessage(GuiActionType.BloodFlow, 4 * 7, False, - utils.toI32(vFlowSetPt ), - utils.toF32(vMeasFlow ), - utils.toF32(vRotSpd ), - utils.toF32(vMotSpd ), - utils.toF32(vMCSpd ), - utils.toF32(vMCCurr ), - utils.toF32(vPWM ) - ) + utils.toI32(vFlowSetPt), + utils.toF32(vMeasFlow), + utils.toF32(vRotSpd), + utils.toF32(vMotSpd), + utils.toF32(vMCSpd), + utils.toF32(vMCCurr), + utils.toF32(vPWM) + ) return messageBuilder.toFrames(msg) @@ -189,18 +192,18 @@ for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) waitForMessageToBeSent() - + def buildSetTreatmentDialysateFlowRate(vFlowSetPt, vMeasFlow, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM): msg = messageBuilder.buildMessage(GuiActionType.DialysateInletFlow, 4 * 7, False, - utils.toI32(vFlowSetPt), - utils.toF32(vMeasFlow), - utils.toF32(vRotSpd), - utils.toF32(vMotSpd), - utils.toF32(vMCSpd), - utils.toF32(vMCCurr), - utils.toF32(vPWM) - ) + utils.toI32(vFlowSetPt), + utils.toF32(vMeasFlow), + utils.toF32(vRotSpd), + utils.toF32(vMotSpd), + utils.toF32(vMCSpd), + utils.toF32(vMCCurr), + utils.toF32(vPWM) + ) return messageBuilder.toFrames(msg) @@ -211,14 +214,14 @@ subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) waitForMessageToBeSent() - + def buildTreatmentAdjustBloodDialysateResponse(vAccepted, vReason, vBloodRate, vDialysate): msg = messageBuilder.buildMessage(GuiActionType.AdjustBloodDialysateRsp, 4 * 4, True, - utils.toI32(vAccepted), - utils.toI32(vReason), - utils.toI32(vBloodRate), - utils.toI32(vDialysate) - ) + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toI32(vBloodRate), + utils.toI32(vDialysate) + ) return messageBuilder.toFrames(msg) @@ -232,11 +235,11 @@ def buildTreatmentAdjustDurationResponse(vAccepted, vReason, vDuration, vUltrafiltration): msg = messageBuilder.buildMessage(GuiActionType.AdjustDurationRsp, 4 * 4, True, - utils.toI32(vAccepted), - utils.toI32(vReason), - utils.toI32(vDuration), - utils.toF32(vUltrafiltration) - ) + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toI32(vDuration), + utils.toF32(vUltrafiltration) + ) return messageBuilder.toFrames(msg) @@ -249,9 +252,9 @@ def buildTreatmentAdjustUltrafiltrationStateResponse(vState): - msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationStateReq, 1 * 4 , False, - utils.toI32(vState) - ) + msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationStateReq, 1 * 4, False, + utils.toI32(vState) + ) return messageBuilder.toFrames(msg) @@ -264,29 +267,32 @@ def setTreatmentAdjustUltrafiltrationAccepted(): - setTreatmentAdjustUltrafiltrationStateResponse( EResponse.Accepted ) + setTreatmentAdjustUltrafiltrationStateResponse(EResponse.Accepted) def setTreatmentAdjustUltrafiltrationRejected(): - setTreatmentAdjustUltrafiltrationStateResponse( EResponse.Rejected ) + setTreatmentAdjustUltrafiltrationStateResponse(EResponse.Rejected) -def buildTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, vRate, vRateDiff, vRateOld): - msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationEditRsp, 8 * 4 , True, - utils.toI32(vAccepted), - utils.toI32(vReason), - utils.toF32(vVolume), - utils.toI32(vDuration), - utils.toI32(vDurationDiff), - utils.toF32(vRate), - utils.toF32(vRateDiff), - utils.toF32(vRateOld) - ) +def buildTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, vRate, + vRateDiff, vRateOld): + msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationEditRsp, 8 * 4, True, + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toF32(vVolume), + utils.toI32(vDuration), + utils.toI32(vDurationDiff), + utils.toF32(vRate), + utils.toF32(vRateDiff), + utils.toF32(vRateOld) + ) return messageBuilder.toFrames(msg) -def setTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, vRate, vRateDiff, vRateOld): - frames = buildTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, vRate, vRateDiff, vRateOld) +def setTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, vRate, + vRateDiff, vRateOld): + frames = buildTreatmentAdjustUltrafiltrationEditResponse(vAccepted, vReason, vVolume, vDuration, vDurationDiff, + vRate, vRateDiff, vRateOld) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) @@ -302,25 +308,25 @@ def buildTreatmentAdjustUltrafiltrationConfirmResponse(vAccepted, vReason, vVolume, vDuration, vRate): - msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationConfirmRsp, 5 * 4 , True, - utils.toI32(vAccepted), - utils.toI32(vReason), - utils.toF32(vVolume), - utils.toI32(vDuration), - utils.toF32(vRate) - ) + msg = messageBuilder.buildMessage(GuiActionType.AdjustUltrafiltrationConfirmRsp, 5 * 4, True, + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toF32(vVolume), + utils.toI32(vDuration), + utils.toF32(vRate) + ) return messageBuilder.toFrames(msg) -def setTreatmentAdjustUltrafiltrationConfirmResponse (vAccepted, vReason, vVolume, vDuration, vRate): +def setTreatmentAdjustUltrafiltrationConfirmResponse(vAccepted, vReason, vVolume, vDuration, vRate): frames = buildTreatmentAdjustUltrafiltrationConfirmResponse(vAccepted, vReason, vVolume, vDuration, vRate) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) waitForMessageToBeSent() -def setTreatmentAdjustUltrafiltrationConfirmRejected ( vReason ): +def setTreatmentAdjustUltrafiltrationConfirmRejected(vReason): frames = buildTreatmentAdjustUltrafiltrationConfirmResponse(0, vReason, 0, 0, 0) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: @@ -330,14 +336,14 @@ def buildTreatmentTime(vSecsTotal, vSecsElap, vSecsRem): msg = messageBuilder.buildMessage(GuiActionType.TreatmentTime, 3 * 4, False, - utils.toI32(vSecsTotal), - utils.toI32(vSecsElap), - utils.toI32(vSecsRem) - ) + utils.toI32(vSecsTotal), + utils.toI32(vSecsElap), + utils.toI32(vSecsRem) + ) return messageBuilder.toFrames(msg) -def setTreatmentTime(vSecsTotal, vSecsElap, vSecsRem = None): +def setTreatmentTime(vSecsTotal, vSecsElap, vSecsRem=None): if vSecsRem == None: vSecsRem = vSecsTotal - vSecsElap frames = buildTreatmentTime(vSecsTotal, vSecsElap, vSecsRem) @@ -346,62 +352,65 @@ subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) waitForMessageToBeSent() - + def buildSetTreatmentUltrafiltration(vRefUFVol, vMeasUFVol, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM): msg = messageBuilder.buildMessage(GuiActionType.DialysateOutletFlow, 4 * 7, False, - utils.toF32(vRefUFVol), - utils.toF32(vMeasUFVol), - utils.toF32(vRotSpd), - utils.toF32(vMotSpd), - utils.toF32(vMCSpd), - utils.toF32(vMCCurr), - utils.toF32(vPWM) - ) + utils.toF32(vRefUFVol), + utils.toF32(vMeasUFVol), + utils.toF32(vRotSpd), + utils.toF32(vMotSpd), + utils.toF32(vMCSpd), + utils.toF32(vMCCurr), + utils.toF32(vPWM) + ) return messageBuilder.toFrames(msg) def setTreatmentUltrafiltration(vRefUFVol, vMeasUFVol, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM): - frames = buildSetTreatmentUltrafiltration(vRefUFVol, vMeasUFVol, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM ) + frames = buildSetTreatmentUltrafiltration(vRefUFVol, vMeasUFVol, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) waitForMessageToBeSent() - -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0009,040,N,HD,All,PressureOcclusionData,(F32)^ArterialPressure,(F32)^VenousPressure,(F32)^BloodPumpOcclusion,(F32)^DialysateInletPumpOcclusion,(F32)^DialysateOutletPumpOcclusion -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def buildPressureOcclusionData(vArterialPressure, vVenousPressure, vBloodPumpOcclusion, vDialysateInletPumpOcclusion, vDialysateOutletPumpOcclusion): - msg = messageBuilder.buildMessage( 0x0009, 4+4+4+4+4, False, - utils.toF32(vArterialPressure ), - utils.toF32(vVenousPressure ), - utils.toF32(vBloodPumpOcclusion ), - utils.toF32(vDialysateInletPumpOcclusion ), - utils.toF32(vDialysateOutletPumpOcclusion)) + +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0009,040,N,HD,All,PressureOcclusionData,(F32)^ArterialPressure,(F32)^VenousPressure,(F32)^BloodPumpOcclusion,(F32)^DialysateInletPumpOcclusion,(F32)^DialysateOutletPumpOcclusion +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def buildPressureOcclusionData(vArterialPressure, vVenousPressure, vBloodPumpOcclusion, vDialysateInletPumpOcclusion, + vDialysateOutletPumpOcclusion): + msg = messageBuilder.buildMessage(0x0009, 4 + 4 + 4 + 4 + 4, False, + utils.toF32(vArterialPressure), + utils.toF32(vVenousPressure), + utils.toF32(vBloodPumpOcclusion), + utils.toF32(vDialysateInletPumpOcclusion), + utils.toF32(vDialysateOutletPumpOcclusion)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setPressureOcclusionData (vArterialPressure, vVenousPressure, vBloodPumpOcclusion, vDialysateInletPumpOcclusion, vDialysateOutletPumpOcclusion): - frames = buildPressureOcclusionData(vArterialPressure, vVenousPressure, vBloodPumpOcclusion, vDialysateInletPumpOcclusion, vDialysateOutletPumpOcclusion) +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def setPressureOcclusionData(vArterialPressure, vVenousPressure, vBloodPumpOcclusion, vDialysateInletPumpOcclusion, + vDialysateOutletPumpOcclusion): + frames = buildPressureOcclusionData(vArterialPressure, vVenousPressure, vBloodPumpOcclusion, + vDialysateInletPumpOcclusion, vDialysateOutletPumpOcclusion) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) waitForMessageToBeSent() - -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x001F,080,N,DG,All,DGROPumpData,(U32)^SetPtPressure,(F32)^FlowRate,(F32)^PWM -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x001F,080,N,DG,All,DGROPumpData,(U32)^SetPtPressure,(F32)^FlowRate,(F32)^PWM +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGROPumpData(vSetPtPressure, vFlowRate, vPWM): - msg = messageBuilder.buildMessage( 0x001F, 4+4+4, False, - utils.toI32(vSetPtPressure), - utils.toF32(vFlowRate ), - utils.toF32(vPWM )) + msg = messageBuilder.buildMessage(0x001F, 4 + 4 + 4, False, + utils.toI32(vSetPtPressure), + utils.toF32(vFlowRate), + utils.toF32(vPWM)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGROPumpData(vSetPtPressure, vFlowRate, vPWM): frames = buildDGROPumpData(vSetPtPressure, vFlowRate, vPWM) frames = messageBuilder.toCandumpFormat(frames) @@ -410,19 +419,19 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0020,080,N,DG,All,DGPressuresData,(F32)^ROInletPSI,(F32)^ROOutletPSI,(F32)^DrainInletPSI,(F32)^DrainOutletPSI -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0020,080,N,DG,All,DGPressuresData,(F32)^ROInletPSI,(F32)^ROOutletPSI,(F32)^DrainInletPSI,(F32)^DrainOutletPSI +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGPressuresData(vROInletPSI, vROOutletPSI, vDrainInletPSI, vDrainOutletPSI): - msg = messageBuilder.buildMessage( 0x0020, 4+4+4+4, False, - utils.toF32(vROInletPSI ), - utils.toF32(vROOutletPSI ), - utils.toF32(vDrainInletPSI ), - utils.toF32(vDrainOutletPSI)) + msg = messageBuilder.buildMessage(0x0020, 4 + 4 + 4 + 4, False, + utils.toF32(vROInletPSI), + utils.toF32(vROOutletPSI), + utils.toF32(vDrainInletPSI), + utils.toF32(vDrainOutletPSI)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGPressuresData(vROInletPSI, vROOutletPSI, vDrainInletPSI, vDrainOutletPSI): frames = buildDGPressuresData(vROInletPSI, vROOutletPSI, vDrainInletPSI, vDrainOutletPSI) frames = messageBuilder.toCandumpFormat(frames) @@ -431,17 +440,17 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0024,080,N,DG,All,DGDrainPumpData,(U32)^SetPtRPM,(U32)^DACValue -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0024,080,N,DG,All,DGDrainPumpData,(U32)^SetPtRPM,(U32)^DACValue +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGDrainPumpData(vSetPtRPM, vDACValue): - msg = messageBuilder.buildMessage( 0x0024, 4+4, False, - utils.toI32(vSetPtRPM), - utils.toI32(vDACValue)) + msg = messageBuilder.buildMessage(0x0024, 4 + 4, False, + utils.toI32(vSetPtRPM), + utils.toI32(vDACValue)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGDrainPumpData(vSetPtRPM, vDACValue): frames = buildDGDrainPumpData(vSetPtRPM, vDACValue) frames = messageBuilder.toCandumpFormat(frames) @@ -450,16 +459,16 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0027,080,N,DG,All,DGOperationMode,(U32)^DGOpMode -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0027,080,N,DG,All,DGOperationMode,(U32)^DGOpMode +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGOperationMode(vDGOpMode): - msg = messageBuilder.buildMessage( 0x0027, 4, False, - utils.toI32(vDGOpMode)) + msg = messageBuilder.buildMessage(0x0027, 4, False, + utils.toI32(vDGOpMode)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGOperationMode(vDGOpMode): frames = buildDGOperationMode(vDGOpMode) frames = messageBuilder.toCandumpFormat(frames) @@ -468,18 +477,18 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0028,080,N,DG,All,DGReservoirData,(U32)^ActiveReservoir,(U32)^FillToVolML,(U32)^DrainToVolML -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0028,080,N,DG,All,DGReservoirData,(U32)^ActiveReservoir,(U32)^FillToVolML,(U32)^DrainToVolML +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGReservoirData(vActiveReservoir, vFillToVolML, vDrainToVolML): - msg = messageBuilder.buildMessage( 0x0028, 4+4+4, False, - utils.toI32(vActiveReservoir), - utils.toI32(vFillToVolML ), - utils.toI32(vDrainToVolML )) + msg = messageBuilder.buildMessage(0x0028, 4 + 4 + 4, False, + utils.toI32(vActiveReservoir), + utils.toI32(vFillToVolML), + utils.toI32(vDrainToVolML)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGReservoirData(vActiveReservoir, vFillToVolML, vDrainToVolML): frames = buildDGReservoirData(vActiveReservoir, vFillToVolML, vDrainToVolML) frames = messageBuilder.toCandumpFormat(frames) @@ -488,16 +497,16 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x002A,080,N,DG,All,DGValvesStates,(U16)^ValvesStates -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x002A,080,N,DG,All,DGValvesStates,(U16)^ValvesStates +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGValvesStates(vValvesStates): - msg = messageBuilder.buildMessage( 0x002A, 2, False, - utils.toI16(vValvesStates)) + msg = messageBuilder.buildMessage(0x002A, 2, False, + utils.toI16(vValvesStates)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGValvesStates(vValvesStates): frames = buildDGValvesStates(vValvesStates) frames = messageBuilder.toCandumpFormat(frames) @@ -506,18 +515,18 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x002C,080,N,DG,All,DGHeatersData,(U32)^MainPriMaryDC,(U32)^SmallPrimaryDC,(U32)^TrimmerDC -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x002C,080,N,DG,All,DGHeatersData,(U32)^MainPriMaryDC,(U32)^SmallPrimaryDC,(U32)^TrimmerDC +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGHeatersData(vMainPriMaryDC, vSmallPrimaryDC, vTrimmerDC): - msg = messageBuilder.buildMessage( 0x002C, 4+4+4, False, - utils.toI32(vMainPriMaryDC ), - utils.toI32(vSmallPrimaryDC), - utils.toI32(vTrimmerDC )) + msg = messageBuilder.buildMessage(0x002C, 4 + 4 + 4, False, + utils.toI32(vMainPriMaryDC), + utils.toI32(vSmallPrimaryDC), + utils.toI32(vTrimmerDC)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGHeatersData(vMainPriMaryDC, vSmallPrimaryDC, vTrimmerDC): frames = buildDGHeatersData(vMainPriMaryDC, vSmallPrimaryDC, vTrimmerDC) frames = messageBuilder.toCandumpFormat(frames) @@ -526,19 +535,19 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x000C,080,N,DG,All,DGLoadCellReadingsData,(F32)^Rs1Prim,(F32)^Rs1Bkup,(F32)^Rs2Prim,(F32)^Rs2Bkup -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x000C,080,N,DG,All,DGLoadCellReadingsData,(F32)^Rs1Prim,(F32)^Rs1Bkup,(F32)^Rs2Prim,(F32)^Rs2Bkup +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildDGLoadCellReadingsData(vRs1Prim, vRs1Bkup, vRs2Prim, vRs2Bkup): - msg = messageBuilder.buildMessage( 0x000C, 4+4+4+4, False, - utils.toF32(vRs1Prim), - utils.toF32(vRs1Bkup), - utils.toF32(vRs2Prim), - utils.toF32(vRs2Bkup)) + msg = messageBuilder.buildMessage(0x000C, 4 + 4 + 4 + 4, False, + utils.toF32(vRs1Prim), + utils.toF32(vRs1Bkup), + utils.toF32(vRs2Prim), + utils.toF32(vRs2Bkup)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setDGLoadCellReadingsData(vRs1Prim, vRs1Bkup, vRs2Prim, vRs2Bkup): frames = buildDGLoadCellReadingsData(vRs1Prim, vRs1Bkup, vRs2Prim, vRs2Bkup) frames = messageBuilder.toCandumpFormat(frames) @@ -547,47 +556,57 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x002D,080,N,DG,All,DGTemperaturesData,(F32)^InletPrimaryHeater,(F32)^OutletPrimaryHeater,(F32)^ConductivitySensor1,(F32)^ConductivitySensor2,(F32)^OutletRedundancy,(F32)^InletDialysate,(F32)^PrimaryHeaterThermocouple,(F32)^TrimmerHeaterThermocouple,(F32)^PrimaryHeaterColdJunction,(F32)^TrimmerHeaterColdJunction,(F32)^PrimaryHeaterInternalTemperature,(F32)^TrimmerHeaterInternalTemperature -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def buildDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, vConductivitySensor2, vOutletRedundancy, vInletDialysate, vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, vPrimaryHeaterColdJunction, vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, vTrimmerHeaterInternalTemperature): - msg = messageBuilder.buildMessage( 0x002D, 4+4+4+4+4+4+4+4+4+4+4+4, False, - utils.toF32(vInletPrimaryHeater ), - utils.toF32(vOutletPrimaryHeater ), - utils.toF32(vConductivitySensor1 ), - utils.toF32(vConductivitySensor2 ), - utils.toF32(vOutletRedundancy ), - utils.toF32(vInletDialysate ), - utils.toF32(vPrimaryHeaterThermocouple ), - utils.toF32(vTrimmerHeaterThermocouple ), - utils.toF32(vPrimaryHeaterColdJunction ), - utils.toF32(vTrimmerHeaterColdJunction ), - utils.toF32(vPrimaryHeaterInternalTemperature), - utils.toF32(vTrimmerHeaterInternalTemperature)) +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x002D,080,N,DG,All,DGTemperaturesData,(F32)^InletPrimaryHeater,(F32)^OutletPrimaryHeater,(F32)^ConductivitySensor1,(F32)^ConductivitySensor2,(F32)^OutletRedundancy,(F32)^InletDialysate,(F32)^PrimaryHeaterThermocouple,(F32)^TrimmerHeaterThermocouple,(F32)^PrimaryHeaterColdJunction,(F32)^TrimmerHeaterColdJunction,(F32)^PrimaryHeaterInternalTemperature,(F32)^TrimmerHeaterInternalTemperature +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def buildDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, vConductivitySensor2, + vOutletRedundancy, vInletDialysate, vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, + vPrimaryHeaterColdJunction, vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, + vTrimmerHeaterInternalTemperature): + msg = messageBuilder.buildMessage(0x002D, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4, False, + utils.toF32(vInletPrimaryHeater), + utils.toF32(vOutletPrimaryHeater), + utils.toF32(vConductivitySensor1), + utils.toF32(vConductivitySensor2), + utils.toF32(vOutletRedundancy), + utils.toF32(vInletDialysate), + utils.toF32(vPrimaryHeaterThermocouple), + utils.toF32(vTrimmerHeaterThermocouple), + utils.toF32(vPrimaryHeaterColdJunction), + utils.toF32(vTrimmerHeaterColdJunction), + utils.toF32(vPrimaryHeaterInternalTemperature), + utils.toF32(vTrimmerHeaterInternalTemperature)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, vConductivitySensor2, vOutletRedundancy, vInletDialysate, vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, vPrimaryHeaterColdJunction, vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, vTrimmerHeaterInternalTemperature): - frames = buildDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, vConductivitySensor2, vOutletRedundancy, vInletDialysate, vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, vPrimaryHeaterColdJunction, vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, vTrimmerHeaterInternalTemperature) +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def setDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, vConductivitySensor2, + vOutletRedundancy, vInletDialysate, vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, + vPrimaryHeaterColdJunction, vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, + vTrimmerHeaterInternalTemperature): + frames = buildDGTemperaturesData(vInletPrimaryHeater, vOutletPrimaryHeater, vConductivitySensor1, + vConductivitySensor2, vOutletRedundancy, vInletDialysate, + vPrimaryHeaterThermocouple, vTrimmerHeaterThermocouple, vPrimaryHeaterColdJunction, + vTrimmerHeaterColdJunction, vPrimaryHeaterInternalTemperature, + vTrimmerHeaterInternalTemperature) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '080#{}'.format(frame)]) waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x000F,040,N,HD,All,TreatmentStatesData,(U32)^SubMode,(U32)^UFState,(U32)^SalineState -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x000F,040,N,HD,All,TreatmentStatesData,(U32)^SubMode,(U32)^UFState,(U32)^SalineState +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildTreatmentStatesData(vSubMode, vUFState, vSalineState): - msg = messageBuilder.buildMessage( 0x000F, 4+4+4, False, - utils.toI32(vSubMode ), - utils.toI32(vUFState ), - utils.toI32(vSalineState)) + msg = messageBuilder.buildMessage(0x000F, 4 + 4 + 4, False, + utils.toI32(vSubMode), + utils.toI32(vUFState), + utils.toI32(vSalineState)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setTreatmentStatesData(vSubMode, vUFState, vSalineState): frames = buildTreatmentStatesData(vSubMode, vUFState, vSalineState) frames = messageBuilder.toCandumpFormat(frames) @@ -596,16 +615,16 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0025,040,N,HD,All,HDOperationModeData,(U32)^OpMode -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0025,040,N,HD,All,HDOperationModeData,(U32)^OpMode +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildHDOperationModeData(vOpMode): - msg = messageBuilder.buildMessage( 0x0025, 4, False, - utils.toI32(vOpMode)) + msg = messageBuilder.buildMessage(0x0025, 4, False, + utils.toI32(vOpMode)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setHDOperationModeData(vOpMode): frames = buildHDOperationModeData(vOpMode) frames = messageBuilder.toCandumpFormat(frames) @@ -614,18 +633,18 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x002F,040,N,HD,All,TreatmentSalineBolusData,(U32)^Target,(F32)^Cumulitive,(F32)^Delivered -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x002F,040,N,HD,All,TreatmentSalineBolusData,(U32)^Target,(F32)^Cumulitive,(F32)^Delivered +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildTreatmentSalineBolusData(vTarget, vCumulitive, vDelivered): - msg = messageBuilder.buildMessage( 0x002F, 4+4+4, False, - utils.toI32(vTarget ), - utils.toF32(vCumulitive), - utils.toF32(vDelivered )) + msg = messageBuilder.buildMessage(0x002F, 4 + 4 + 4, False, + utils.toI32(vTarget), + utils.toF32(vCumulitive), + utils.toF32(vDelivered)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setTreatmentSalineBolusData(vTarget, vCumulitive, vDelivered): frames = buildTreatmentSalineBolusData(vTarget, vCumulitive, vDelivered) frames = messageBuilder.toCandumpFormat(frames) @@ -634,18 +653,18 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0014,020,Y,HD,UI,SalineBolusResponse,(U32)^Accepted,(U32)^Reason,(U32)^Target -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0014,020,Y,HD,UI,SalineBolusResponse,(U32)^Accepted,(U32)^Reason,(U32)^Target +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildSalineBolusResponse(vAccepted, vReason, vTarget): - msg = messageBuilder.buildMessage( 0x0014, 4+4+4, True, - utils.toI32(vAccepted), - utils.toI32(vReason ), - utils.toI32(vTarget )) + msg = messageBuilder.buildMessage(0x0014, 4 + 4 + 4, True, + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toI32(vTarget)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setSalineBolusResponse(vAccepted, vReason, vTarget): frames = buildSalineBolusResponse(vAccepted, vReason, vTarget) frames = messageBuilder.toCandumpFormat(frames) @@ -656,8 +675,8 @@ def buildCanBUSFaultCount(vCount): msg = messageBuilder.buildMessage(GuiActionType.CanBUSFaultCount, 4 * 1, False, - utils.toI32(vCount) - ) + utils.toI32(vCount) + ) return messageBuilder.toFrames(msg) @@ -693,38 +712,39 @@ def clear_all_alarms(): setAlarmStatus(0, 0, 0, 0, 0) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0002,001,N,HD,All,AlarmStatus,(U32)^State,(U32)^Top,(U32)^EscalatesIn,(U32)^MuteTimeout,(U16)^Flags -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0002,001,N,HD,All,AlarmStatus,(U32)^State,(U32)^Top,(U32)^EscalatesIn,(U32)^MuteTimeout,(U16)^Flags +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildAlarmStatus(vState, vTop, vEscalatesIn, vMuteTimeout, vFlags): - msg = messageBuilder.buildMessage( 0x0002, 4+4+4+4+2, False, - utils.toI32(vState ), - utils.toI32(vTop ), - utils.toI32(vEscalatesIn), - utils.toI32(vMuteTimeout), - utils.toI16(vFlags )) + msg = messageBuilder.buildMessage(0x0002, 4 + 4 + 4 + 4 + 2, False, + utils.toI32(vState), + utils.toI32(vTop), + utils.toI32(vEscalatesIn), + utils.toI32(vMuteTimeout), + utils.toI16(vFlags)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setAlarmStatus (vState, vTop, vEscalatesIn, vMuteTimeout, vFlags): +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def setAlarmStatus(vState, vTop, vEscalatesIn, vMuteTimeout, vFlags): frames = buildAlarmStatus(vState, vTop, vEscalatesIn, vMuteTimeout, vFlags) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '001#{}'.format(frame)]) waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0003,001,Y,HD,All,AlarmTriggered,(U32)^AlarmID -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0003,001,Y,HD,All,AlarmTriggered,(U32)^AlarmID +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildAlarmTriggered(vAlarmID): - msg = messageBuilder.buildMessage( 0x0003, 4, True, - utils.toI32(vAlarmID)) + msg = messageBuilder.buildMessage(0x0003, 4, True, + utils.toI32(vAlarmID)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setAlarmTriggered(vAlarmID): frames = buildAlarmTriggered(vAlarmID) frames = messageBuilder.toCandumpFormat(frames) @@ -733,20 +753,19 @@ waitForMessageToBeSent() -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -## 0x0004,001,Y,HD,All,AlarmCleared,(U32)^AlarmID -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## 0x0004,001,Y,HD,All,AlarmCleared,(U32)^AlarmID +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildAlarmCleared(vAlarmID): - msg = messageBuilder.buildMessage( 0x0004, 4, True, - utils.toI32(vAlarmID)) + msg = messageBuilder.buildMessage(0x0004, 4, True, + utils.toI32(vAlarmID)) return messageBuilder.toFrames(msg) -## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setAlarmCleared(vAlarmID): frames = buildAlarmCleared(vAlarmID) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '001#{}'.format(frame)]) waitForMessageToBeSent() - Index: dialin/squish/messageBuilder.py =================================================================== diff -u -rc3cc81dada72714b9675594cc0c6a79975e8991d -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/squish/messageBuilder.py (.../messageBuilder.py) (revision c3cc81dada72714b9675594cc0c6a79975e8991d) +++ dialin/squish/messageBuilder.py (.../messageBuilder.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ########################################################################### # # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. @@ -14,17 +13,6 @@ # @date (original) 09-Jul-2020 # ############################################################################ -## -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. -# copyright -# 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 messageBuilder.py -# date 2020/04/08 -# author Behrouz NematiPour -# from dialin.squish import utils from dialin.squish import crc @@ -99,5 +87,3 @@ msg += arg msg += crc.calcCRC8(msg) return syncByte + msg - - Index: dialin/squish/unittests.py =================================================================== diff -u -r2c016f17a5468be8add2a467c989c19f69d501df -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/squish/unittests.py (.../unittests.py) (revision 2c016f17a5468be8add2a467c989c19f69d501df) +++ dialin/squish/unittests.py (.../unittests.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -16,12 +16,17 @@ import test import sys -from .crc import calcCRC8 +from subprocess import check_output +from dialin.squish import crc +MICRO = [8, 9] + + def test_python_version(): - test.compare(sys.version_info.major,3) - test.compare(sys.version_info.minor,6) - test.compare(sys.version_info.micro in [8,9], True) + test.compare(sys.version_info.major, 3) + test.compare(sys.version_info.minor, 6) + + test.compare(sys.version_info.micro in MICRO, True) def test_crc8(): strByte1 = ( "4B 43 09 00 14 00 00" @@ -46,7 +51,19 @@ "00 00" #7F ) - test.compare(calcCRC8(strByte1, ' '), '9D') - test.compare(calcCRC8(strByte2, ' '), '55') - test.compare(calcCRC8(strByte3, ' '), '4F') - test.compare(calcCRC8(strByte4, ' '), '7F') + test.compare(crc.calcCRC8(strByte1, ' '), '9D') + test.compare(crc.calcCRC8(strByte2, ' '), '55') + test.compare(crc.calcCRC8(strByte3, ' '), '4F') + test.compare(crc.calcCRC8(strByte4, ' '), '7F') + +def test_can0(): + canid = "can0" + ipa = "ip a" + ipa = check_output(ipa, shell=True) + loc = str(ipa).find(canid) + fnd = loc >= 0 + if (fnd): + msg = "can device '{}' found".format(canid) + else: + msg = "No can device registered as '{}'".format(canid) + test.compare(loc >= 0, True, msg) Index: dialin/squish/utils.py =================================================================== diff -u -rb919e9cba87e4b3b8747227113fc5ae3df6fa6a6 -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- dialin/squish/utils.py (.../utils.py) (revision b919e9cba87e4b3b8747227113fc5ae3df6fa6a6) +++ dialin/squish/utils.py (.../utils.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ########################################################################### # # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. @@ -14,17 +13,6 @@ # @date (original) 09-Jul-2020 # ############################################################################ -## -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. -# copyright -# 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 utils.py -# date 2019/11/21 -# author Behrouz NematiPour -# import time import struct Index: tests/hd_valves_test.py =================================================================== diff -u -r34b6c910e5c691b6bf661283f28bc87c9be20220 -r87cf0bc784212d2608c58d1388b37396aa0a4656 --- tests/hd_valves_test.py (.../hd_valves_test.py) (revision 34b6c910e5c691b6bf661283f28bc87c9be20220) +++ tests/hd_valves_test.py (.../hd_valves_test.py) (revision 87cf0bc784212d2608c58d1388b37396aa0a4656) @@ -2,28 +2,28 @@ sys.path.append("..") from dialin.hd.constants import RESET, NO_RESET from dialin.hd.hemodialysis_device import HD +from dialin.hd.valves import ValvesEnum +from dialin.hd.valves import AirTrapState from time import sleep if __name__ == "__main__": # Create an instance of the DG Class - hd = HD() + hd = HD(log_level='DEBUG') if hd.cmd_log_in_to_hd() == 0: exit(1) valves = hd.valves - #valves.cmd_open_hd_air_trap_valve() + #valves.cmd_open_hd_air_trap_valve(AirTrapState.STATE_OPEN) #sleep(2) - #valves.cmd_close_hd_air_trap_valve() - #sleep(2) #valves.cmd_home_hd_valve(2) #sleep(4) counter = 0 overall_counter = 0 sleep_time = 0.01 - overall_time_seconds = 3 + overall_time_seconds = 1 """ while overall_counter < (overall_time_seconds/sleep_time): @@ -67,6 +67,15 @@ #valves.cmd_home_hd_valve(2) #sleep(2) + #valves.cmd_hd_valves_broadcast_interval_override(10, reset=RESET) + #sleep(3) + + #valves.cmd_home_hd_valve(2) + #sleep(3) + + valves.cmd_hd_valves_broadcast_interval_override(10) + sleep(3) + valves.cmd_set_hd_valve_position(2, 2) while overall_counter < (overall_time_seconds/sleep_time): @@ -78,20 +87,20 @@ # valves.hd_valve_curr_pos_cnt, valves.hd_valve_next_pos_cnt, valves.hd_valve_current, # valves.hd_valves_pos_c, valves.hd_valves_pos_a, valves.hd_valves_pos_b)) counter = 0 + print(valves.valves_status[ValvesEnum.VBA.name]) + #print("Valve, {}, Pos, {}, Cmd, {}, Curr, {}, PosA, {}, PosB, {}, PosC, {}, State, {}, PWM, {}".format( + # valves.hd_valve_ID, valves.hd_valve_fast_pos, + # valves.hd_valves_fast_cmd, valves.hd_valve_fast_current, + # valves.hd_valves_pos_a, valves.hd_valves_pos_b, + # valves.hd_valves_pos_c, valves.hd_valve_state, + # valves.hd_valves_pwm)) - print("Valve, {}, Pos, {}, Cmd, {}, Curr, {}, PosA, {}, PosB, {}, PosC, {}, State, {}, PWM, {}".format( - valves.hd_valve_ID, valves.hd_valve_fast_pos, - valves.hd_valves_fast_cmd, valves.hd_valve_fast_current, - valves.hd_valves_pos_a, valves.hd_valves_pos_b, - valves.hd_valves_pos_c, valves.hd_valve_state, - valves.hd_valves_pwm)) - counter = counter + 1 overall_counter = overall_counter + 1 sleep(sleep_time) - """" + """ valves.cmd_set_hd_valve_pwm(2, 0, 0, reset=RESET) print("Reset")