Index: dialin/dg/__init__.py =================================================================== diff -u -r8ea13ae6dd10732bfcc456798f4785c4d88c95d3 -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/__init__.py (.../__init__.py) (revision 8ea13ae6dd10732bfcc456798f4785c4d88c95d3) +++ dialin/dg/__init__.py (.../__init__.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -13,8 +13,8 @@ # @date (original) 02-Apr-2020 # ############################################################################ -from .dialysate_generator import DG from .constants import RESET, NO_RESET +from .dialysate_generator import DG from .drain_pump import DGDrainPump from .hd_proxy import DGHDProxy from .heaters import Heaters Index: dialin/dg/accelerometer.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/accelerometer.py (.../accelerometer.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/accelerometer.py (.../accelerometer.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,15 +14,16 @@ # ############################################################################ import struct -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) -from ..utils.conversions import integer_to_bytearray, float_to_bytearray +from logging import Logger + from .constants import RESET, NO_RESET -from ..utils.base import AbstractSubSystem, publish from ..common.msg_defs import MsgIds, MsgFieldPositions +from ..protocols.CAN import DenaliMessage, DenaliChannels +from ..utils.base import AbstractSubSystem, publish from ..utils.checks import check_broadcast_interval_override_ms -from logging import Logger +from ..utils.conversions import integer_to_bytearray, float_to_bytearray + class DGAccelerometer(AbstractSubSystem): """ Hemodialysis Delivery (DG) Dialin API sub-class for accelerometer related commands. @@ -107,25 +108,25 @@ message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])) z = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3])) - self.vector = self.AccelerometerVector( x[0], y[0], z[0] ) + self.vector = self.AccelerometerVector(x[0], y[0], z[0]) x = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4])) y = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5])) z = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6])) - self.vector_max = self.AccelerometerVector( x[0], y[0], z[0] ) + self.vector_max = self.AccelerometerVector(x[0], y[0], z[0]) x = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7])) y = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_8:MsgFieldPositions.END_POS_FIELD_8])) z = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_9:MsgFieldPositions.END_POS_FIELD_9])) - self.tilts = self.AccelerometerVector( x[0], y[0], z[0] ) + self.tilts = self.AccelerometerVector(x[0], y[0], z[0]) - def cmd_accel_vector_override(self, axis: int, mag: int, reset: int = NO_RESET) -> int: + def cmd_accel_vector_override(self, axis: int, mag: int, reset: int = NO_RESET) -> int: """ Constructs and sends the accelerometer vector override command Constraints: @@ -158,7 +159,7 @@ else: str_res = str(mag) + " g. " self.logger.debug("Accelerometer axis " + str(axis) + " overridden to " + str_res + - str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: @@ -198,7 +199,7 @@ else: str_res = str(mag) + " g. " self.logger.debug("Accelerometer max. axis " + str(axis) + " overridden to " + str_res + - str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: @@ -240,7 +241,7 @@ else: str_res = str(ms) + " ms: " self.logger.debug("Accelerometer broadcast interval overridden to " + str_res + - str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: Index: dialin/dg/alarms.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/alarms.py (.../alarms.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/alarms.py (.../alarms.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -13,16 +13,15 @@ # @date (original) 02-Sep-2020 # ############################################################################ -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) -from ..utils.conversions import integer_to_bytearray -from ..utils.base import AbstractSubSystem, publish -from .constants import RESET, NO_RESET -from collections import OrderedDict import struct from logging import Logger -from ..common.alarm_defs import AlarmList + +from .constants import RESET, NO_RESET from ..common.msg_defs import MsgIds +from ..protocols.CAN import (DenaliMessage, + DenaliChannels) +from ..utils.base import AbstractSubSystem, publish +from ..utils.conversions import integer_to_bytearray class DGAlarms(AbstractSubSystem): @@ -127,8 +126,7 @@ else: str_res = ("active" if state != 0 else "inactive") self.logger.debug("Alarm " + str(alarm) + " " + str_res + ": " + str( - received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return 1 == received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] return False - Index: dialin/dg/calibration_record.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,12 +1,12 @@ - import struct import time from collections import OrderedDict +from logging import Logger + from ..common.msg_defs import MsgIds, MsgFieldPositions -from ..protocols.CAN import (DenaliMessage, DenaliChannels) +from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem, publish from ..utils.nv_ops_utils import NVOpsUtils -from logging import Logger class DGCalibrationNVRecord(AbstractSubSystem): @@ -57,7 +57,6 @@ self.dg_calibration_record = self._prepare_dg_calibration_record() if self.can_interface is not None: - channel_id = DenaliChannels.dg_to_dialin_ch_id msg_id = MsgIds.MSG_ID_DG_SEND_CALIBRATION_RECORD.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, @@ -251,7 +250,6 @@ hardware = OrderedDict() for i in hardware_names: - hardware[i] = {'fourth_order': [' None: + def _handler_flush_sync(self, message: dict) -> None: """ Handles published flush message @@ -70,4 +67,3 @@ self.overall_elapsed_time = int(elapsed_time / 1000) self.state_elapsed_time = int(state_elapsed_time / 1000) self.flush_drain_line_volume_l = drain_line_volume - Index: dialin/dg/hd_proxy.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/hd_proxy.py (.../hd_proxy.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/hd_proxy.py (.../hd_proxy.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -13,14 +13,14 @@ # @date (original) 15-Apr-2020 # ############################################################################ -from ..utils.conversions import integer_to_bytearray -from ..common.msg_defs import MsgIds -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) -from ..utils.base import AbstractSubSystem, publish from logging import Logger +from ..common.msg_defs import MsgIds +from ..protocols.CAN import DenaliMessage, DenaliChannels +from ..utils.base import AbstractSubSystem +from ..utils.conversions import integer_to_bytearray + class DGHDProxy(AbstractSubSystem): """ Dialysate Generator (DG) Dialin API sub-class for HD proxy commands. @@ -39,22 +39,22 @@ self.can_interface = can_interface self.logger = logger - def cmd_switch_reservoirs(self, reservoirID=RESERVOIR1): + def cmd_switch_reservoirs(self, reservoir_id: int = RESERVOIR1) -> int: """ Constructs and sends the switch reservoirs command. Constraints: DG must be in re-circulate mode. Given reservoirID must be in the reservoir list below. - @param reservoirID: unsigned int - reservoir to set as active (HD will draw from this reservoir). + @param reservoir_id: unsigned int - reservoir to set as active (HD will draw from this reservoir). @return: 1 if successful, zero otherwise - \details Reservoir IDs: \n + @details Reservoir IDs: \n 0 = RESERVOIR 1 \n 1 = RESERVOIR 2 \n """ - res = integer_to_bytearray(reservoirID) + res = integer_to_bytearray(reservoir_id) payload = res message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, @@ -105,7 +105,7 @@ self.logger.debug("Timeout!!!!") return False - def cmd_drain(self, volume:int=0, tare_load_cell:bool=False) -> int: + def cmd_drain(self, volume: int = 0, tare_load_cell: bool = False) -> int: """ Constructs and sends the drain command. Constraints: @@ -151,17 +151,17 @@ if start: cmd = 1 - str = "start " + cmd_str = "start " else: cmd = 0 - str = "stop" + cmd_str = "stop " payload = integer_to_bytearray(cmd) message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_STARTING_STOPPING_TREATMENT_CMD.value, payload=payload) - self.logger.debug(str+" DG cmd sent to DG") + self.logger.debug(cmd_str + "DG cmd sent to DG") # Send message received_message = self.can_interface.send(message) @@ -184,17 +184,17 @@ if start: cmd = 1 - str = "start " + cmd_str = "start " else: cmd = 0 - str = "stop" + cmd_str = "stop " payload = integer_to_bytearray(cmd) message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_DG_START_STOP_TRIMMER_HEATER_CMD.value, payload=payload) - self.logger.debug(str+"DG trimmer heater cmd sent to DG") + self.logger.debug(cmd_str + "DG trimmer heater cmd sent to DG") # Send message received_message = self.can_interface.send(message) @@ -235,7 +235,7 @@ self.logger.debug("Sending sample water command") self.can_interface.send(message, 0) - def cmd_start_stop_heat_disinfect(self, start:bool=True) -> int: + def cmd_start_stop_heat_disinfect(self, start: bool = True) -> int: """ Constructs and sends the start/stop DG heat disinfect command @@ -245,16 +245,16 @@ # 1 is to start if start: cmd = 1 - str = "Starting" + cmd_str = "Starting" else: cmd = 0 - str = "Stopping" + cmd_str = "Stopping" payload = integer_to_bytearray(cmd) message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_DG_START_STOP_HEAT_DISINFECT.value, payload=payload) - self.logger.debug(str + " DG heat disinfect") + self.logger.debug(cmd_str + " DG heat disinfect") received_message = self.can_interface.send(message) @@ -266,7 +266,7 @@ self.logger.debug("Timeout!!!!") return False - def cmd_start_stop_dg_flush(self, start:bool=True) -> int: + def cmd_start_stop_dg_flush(self, start: bool = True) -> int: """ Constructs and sends the start/stop DG flush command @@ -276,16 +276,16 @@ # 1 is to start if start: cmd = 1 - str = "Starting" + cmd_str = "Starting" else: cmd = 0 - str = "Stopping" + cmd_str = "Stopping" payload = integer_to_bytearray(cmd) message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_DG_START_STOP_FLUSH.value, payload=payload) - self.logger.debug(str + " DG flush") + self.logger.debug(cmd_str + " DG flush") received_message = self.can_interface.send(message) @@ -326,4 +326,4 @@ return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Timeout!!!!") - return False \ No newline at end of file + return False Index: dialin/dg/heat_disinfect.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/heat_disinfect.py (.../heat_disinfect.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/heat_disinfect.py (.../heat_disinfect.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,15 +1,41 @@ - import struct +from enum import unique +from logging import Logger + from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique @unique -class HeatCancellationModes(DialinEnum): +class HeatDisinfectStates(DialinEnum): + DG_HEAT_DISINFECT_STATE_START = 0 + DG_HEAT_DISINFECT_STATE_DRAIN_R1 = 1 + DG_HEAT_DISINFECT_STATE_DRAIN_R2 = 2 + DG_HEAT_DISINFECT_STATE_FLUSH_DRAIN = 3 + DG_HEAT_DISINFECT_STATE_FLUSH_CIRCULATION = 4 + DG_HEAT_DISINFECT_STATE_FLUSH_R1_AND_R2 = 5 + DG_HEAT_DISINFECT_STATE_FLUSH_R2_AND_DRAIN_R1 = 6 + DG_HEAT_DISINFECT_STATE_FLUSH_DRAIN_R2 = 7 + DG_HEAT_DISINFECT_STATE_FLUSH_DRAIN_R1 = 8 + DG_HEAT_DISINFECT_STATE_FILL_WITH_WATER = 9 + DG_HEAT_DISINFECT_STATE_DISINFECT_R1_TO_R2 = 10 + DG_HEAT_DISINFECT_STATE_FILL_R2_WITH_HOT_WATER = 11 + DG_HEAT_DISINFECT_STATE_DISINFECT_R2_TO_R1 = 12 + DG_HEAT_DISINFECT_STATE_COOL_DOWN_HEATERS = 13 + DG_HEAT_DISINFECT_STATE_COOL_DOWN_RO_FILTER = 14 + DG_HEAT_DISINFECT_STATE_MIX_DRAIN_R1 = 15 + DG_HEAT_DISINFECT_STATE_MIX_DRAIN_R2 = 16 + DG_HEAT_DISINFECT_STATE_RINSE_R1_TO_R2 = 17 + DG_HEAT_DISINFECT_STATE_RINSE_R2_TO_R1_AND_DRAIN_R1 = 18 + DG_HEAT_DISINFECT_STATE_RINSE_CIRCULATION = 19 + DG_HEAT_DISINFECT_STATE_CANCEL_BASIC_PATH = 20 + DG_HEAT_DISINFECT_STATE_CANCEL_WATER_PATH = 21 + DG_HEAT_DISINFECT_STATE_COMPLETE = 22 + +@unique +class HeatCancellationModes(DialinEnum): CANCELLATION_MODE_NONE = 0 CANCELLATION_MODE_BASIC = 1 CANCELLATION_MODE_HOT = 2 @@ -18,13 +44,10 @@ class HeatDisinfect(AbstractSubSystem): """ - \class HeatDisinfect - - \brief Heat disinfect class with APIs to set the timing of each of the stages. + Heat Disinfection class with APIs to set the timing of each of the stages. """ def __init__(self, can_interface, logger: Logger): - super().__init__() self.can_interface = can_interface @@ -68,7 +91,7 @@ self.heat_disinfect_count_down_time = disinfect_count_down_time @publish(["heat_disinfect_state", "overall_elapsed_time", "state_elapsed_time", "cancellation_mode", "r1_level", - "r2_level", "heat_disinfect_ui_state"]) + "r2_level", "heat_disinfect_ui_state"]) def _handler_heat_disinfect_sync(self, message): """ Handles published heat disinfect message Index: dialin/dg/heaters.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/heaters.py (.../heaters.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/heaters.py (.../heaters.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -15,20 +15,19 @@ ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray -from ..utils.conversions import float_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms -from ..common.msg_defs import MsgIds, MsgFieldPositions +from enum import unique +from logging import Logger + from .constants import NO_RESET +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray, float_to_bytearray @unique class HeatersStartStop(DialinEnum): - STOP = 0 START = 1 @@ -102,7 +101,7 @@ return self.trimmer_heater_target_temperature @publish(["main_primary_heater_duty_cycle", "small_primary_heater_duty_cycle", "trimmer_heater_duty_cycle", - "primary_heaters_target_temperature", "trimmer_heater_target_temperature"]) + "primary_heaters_target_temperature", "trimmer_heater_target_temperature"]) def _handler_heaters_sync(self, message): """ Handles published heaters message @@ -207,9 +206,9 @@ if not check_broadcast_interval_override_ms(ms): return False - resetValue = integer_to_bytearray(reset) - intervalValue = integer_to_bytearray(ms) - payload = resetValue + intervalValue + reset_value = integer_to_bytearray(reset) + 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=MsgIds.MSG_ID_HEATERS_PUBLISH_INTERVAL_ORVERRIDE.value, @@ -226,3 +225,4 @@ else: self.logger.debug("Timeout!!!!") return False + Index: dialin/dg/load_cells.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/load_cells.py (.../load_cells.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/load_cells.py (.../load_cells.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,14 +14,14 @@ # ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray, float_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms +from logging import Logger + +from .constants import RESET, NO_RESET from ..common.msg_defs import MsgIds, MsgFieldPositions -from .constants import RESET,NO_RESET -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) +from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem, publish -from logging import Logger +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray, float_to_bytearray class DGLoadCells(AbstractSubSystem): @@ -164,10 +164,9 @@ else: str_res = str(ms) + " ms: " self.logger.debug("Load cell data broadcast interval overridden to " + str_res + - str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) # response payload is OK or not OK return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Timeout!!!!") return False - Index: dialin/dg/pressures.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/pressures.py (.../pressures.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/pressures.py (.../pressures.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,14 +14,14 @@ # ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray, float_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms -from ..common.msg_defs import MsgIds, MsgFieldPositions +from logging import Logger + from .constants import NO_RESET -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) +from ..common.msg_defs import MsgIds, MsgFieldPositions +from ..protocols.CAN import DenaliMessage, DenaliChannels from ..utils.base import AbstractSubSystem, publish -from logging import Logger +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray, float_to_bytearray class DGPressures(AbstractSubSystem): Index: dialin/dg/reservoirs.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/reservoirs.py (.../reservoirs.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/reservoirs.py (.../reservoirs.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -15,10 +15,10 @@ ############################################################################ import struct from logging import Logger -from ..protocols.CAN import (DenaliMessage, - DenaliChannels) -from ..utils.base import AbstractSubSystem, publish + from ..common.msg_defs import MsgIds, MsgFieldPositions +from ..protocols.CAN import DenaliMessage, DenaliChannels +from ..utils.base import AbstractSubSystem, publish from ..utils.conversions import integer_to_bytearray @@ -102,7 +102,7 @@ "active_reservoir", "fill_to_vol_ml", "drain_to_vol_ml" - ]) + ]) def _handler_reservoirs_sync(self, message): """ Handles published reservoir data messages. Reservoir data are captured @@ -122,4 +122,3 @@ self.active_reservoir = res[0] self.fill_to_vol_ml = fil[0] self.drain_to_vol_ml = dra[0] - Index: dialin/dg/ro_pump.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/ro_pump.py (.../ro_pump.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/ro_pump.py (.../ro_pump.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,14 +14,15 @@ # ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray, float_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms -from ..common.msg_defs import MsgIds, MsgFieldPositions +from enum import unique +from logging import Logger + from .constants import RESET, NO_RESET +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray, float_to_bytearray @unique @@ -39,6 +40,7 @@ Dialysate Generator (DG) Dialin API sub-class for RO pump related commands. """ + def __init__(self, can_interface, logger: Logger): """ DGROPump constructor @@ -168,7 +170,7 @@ @param duty: integer - 1 percentage for duty cycle between 0 and 100 @return: 1 if successful, zero otherwise """ - dc = float_to_bytearray(duty/100) + dc = float_to_bytearray(duty / 100) payload = dc message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, @@ -275,4 +277,3 @@ else: self.logger.debug("Timeout!!!!") return False - Index: dialin/dg/samplewater.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/samplewater.py (.../samplewater.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/samplewater.py (.../samplewater.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,11 +14,12 @@ # ############################################################################ import struct +from logging import Logger + +from .constants import NO_RESET +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import DenaliChannels from ..utils.base import AbstractSubSystem, publish -from ..common.msg_defs import MsgIds, MsgFieldPositions -from .constants import NO_RESET -from logging import Logger class DGSampleWater(AbstractSubSystem): Index: dialin/dg/service_record.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/service_record.py (.../service_record.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/service_record.py (.../service_record.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,12 +1,13 @@ import struct import time from collections import OrderedDict +from enum import unique +from logging import Logger + from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, DialinEnum, publish from ..utils.nv_ops_utils import NVOpsUtils -from logging import Logger -from enum import unique @unique @@ -234,4 +235,3 @@ groups_byte_size += self._utilities.calculate_group_byte_size(service_records[record]) return service_records, groups_byte_size - Index: dialin/dg/system_record.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/system_record.py (.../system_record.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/system_record.py (.../system_record.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,13 +1,13 @@ - import struct import time from collections import OrderedDict +from enum import unique +from logging import Logger + from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, DialinEnum, publish from ..utils.nv_ops_utils import NVOpsUtils -from logging import Logger -from enum import unique @unique @@ -238,4 +238,3 @@ groups_byte_size += self._utilities.calculate_group_byte_size(system_records[record]) return system_records, groups_byte_size - Index: dialin/dg/temperature_sensors.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/temperature_sensors.py (.../temperature_sensors.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/temperature_sensors.py (.../temperature_sensors.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -14,19 +14,19 @@ # ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray -from ..utils.conversions import float_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms -from ..common.msg_defs import MsgIds, MsgFieldPositions +from enum import unique +from logging import Logger + from .constants import NO_RESET +from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray, float_to_bytearray + @unique class TemperatureSensorsNames(DialinEnum): - INLET_PRIMARY_HEATER = 0 OUTLET_PRIMARY_HEATER = 1 CONDUCTIVITY_SENSOR_1 = 2 @@ -98,7 +98,7 @@ return self.temperature_sensors[sensor] @publish(["temperature_sensors", "primary_raw_thermo_couple", "primary_raw_cold_junc", - "trimmer_raw_thermo_couple", "trimmer_raw_cold_junc", "conductivity_1_raw", "conductivity_2_raw"]) + "trimmer_raw_thermo_couple", "trimmer_raw_cold_junc", "conductivity_1_raw", "conductivity_2_raw"]) def _handler_temperature_sensors_sync(self, message): """ Handles published temperature sensors message @@ -220,9 +220,10 @@ 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=MsgIds.MSG_ID_TEMPERATURE_SENSORS_PUBLISH_INTERVAL_OVERRIDE.value, - payload=payload) + message = DenaliMessage.build_message( + channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_TEMPERATURE_SENSORS_PUBLISH_INTERVAL_OVERRIDE.value, + payload=payload) self.logger.debug("Sending {} ms publish interval to the Temperature Sensors module".format(ms)) # Send message @@ -236,7 +237,8 @@ self.logger.debug("Timeout!!!!") return False - def cmd_temperature_sensors_override_value(self, sensor_index: int, sensor_value: float, reset: int = NO_RESET) -> int: + def cmd_temperature_sensors_override_value(self, sensor_index: int, + sensor_value: float, reset: int = NO_RESET) -> int: """ Constructs and sends the value override of a temperature sensor. Constraints: @@ -248,7 +250,7 @@ @param reset: (int) whether to reset the override value. The default is NO_RESET @returns 1 if successful, zero otherwise - \details temperature sensor indexes: \n + @details temperature sensor indexes: \n 0 = Primary Heater Inlet 1 = Primary Heater Outlet 2 = Conductivity Sensor 1 @@ -290,4 +292,3 @@ else: self.logger.debug("Timeout!!!!") return False - Index: dialin/dg/thermistors.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/thermistors.py (.../thermistors.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/thermistors.py (.../thermistors.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,17 +1,17 @@ - import struct +from enum import unique +from logging import Logger + +from .constants import RESET, NO_RESET from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from ..utils.conversions import integer_to_bytearray, float_to_bytearray from ..utils.checks import check_broadcast_interval_override_ms -from .constants import RESET, NO_RESET -from logging import Logger -from enum import unique +from ..utils.conversions import integer_to_bytearray, float_to_bytearray + @unique class ThermistorsNames(DialinEnum): - THERMISTOR_ONBOARD_NTC = 0 THERMISTOR_POWER_SUPPLY_1 = 1 THERMISTOR_POWER_SUPPLY_2 = 2 @@ -119,8 +119,8 @@ mis = integer_to_bytearray(ms) payload = rst + mis - id = MsgIds.MSG_ID_DG_THERMISTORS_DATA_PUBLISH_INTERVAL_OVERRIDE.value - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=id, + msg_id = MsgIds.MSG_ID_DG_THERMISTORS_DATA_PUBLISH_INTERVAL_OVERRIDE.value + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=msg_id, payload=payload) self.logger.debug("Overriding themistors broadcast interval") @@ -142,4 +142,4 @@ return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] else: self.logger.debug("Timeout!!!!") - return False \ No newline at end of file + return False Index: dialin/dg/uv_reactors.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/uv_reactors.py (.../uv_reactors.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/uv_reactors.py (.../uv_reactors.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -1,25 +1,23 @@ - import struct -from ..utils.conversions import integer_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms +from enum import unique +from logging import Logger + from .constants import NO_RESET, RESET from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray @unique class ReactorsNames(DialinEnum): - INLET_UV_REACTOR = 0 OUTLET_UV_REACTOR = 1 @unique class ReactorsStates(DialinEnum): - UV_REACTOR_STATE_OFF = 0 UV_REACTOR_STATE_ON = 1 @@ -93,8 +91,8 @@ return self.outlet_uv_reactor_state @publish(['inlet_uv_reactor_health', 'outlet_uv_reactor_health', 'inlet_uv_reactor_state', - 'outlet_uv_reactor_state']) - def _handler_uv_reactors_sync(self, message:dict) -> None: + 'outlet_uv_reactor_state']) + def _handler_uv_reactors_sync(self, message: dict) -> None: """ Handles published thermistors message. Index: dialin/dg/valves.py =================================================================== diff -u -rebf0a72a1a1a52f3cfe20975de4857201275888c -rf06c062512981820509a86a07a54b7070adbf3d1 --- dialin/dg/valves.py (.../valves.py) (revision ebf0a72a1a1a52f3cfe20975de4857201275888c) +++ dialin/dg/valves.py (.../valves.py) (revision f06c062512981820509a86a07a54b7070adbf3d1) @@ -15,14 +15,15 @@ ############################################################################ import struct -from ..utils.conversions import integer_to_bytearray -from ..utils.checks import check_broadcast_interval_override_ms -from ..common.msg_defs import MsgIds +from enum import unique +from logging import Logger + from .constants import NO_RESET +from ..common.msg_defs import MsgIds from ..protocols.CAN import (DenaliMessage, DenaliChannels) from ..utils.base import AbstractSubSystem, publish, DialinEnum -from logging import Logger -from enum import unique +from ..utils.checks import check_broadcast_interval_override_ms +from ..utils.conversions import integer_to_bytearray # Valve states ENERGIZED = True @@ -31,42 +32,36 @@ @unique class VPiVSPVBfVRD1VRD2States(DialinEnum): - VALVE_STATE_CLOSED = 0 VALVE_STATE_OPEN = 1 @unique class VPdStates(DialinEnum): - VALVE_STATE_DRAIN_C_TO_NO = 0 VALVE_STATE_OPEN_C_TO_NC = 1 @unique class VPoStates(DialinEnum): - VALVE_STATE_NOFILL_C_TO_NO = 0 VALVE_STATE_FILL_C_TO_NC = 1 @unique class VDrVRcStates(DialinEnum): - VALVE_STATE_DRAIN_C_TO_NO = 0 VALVE_STATE_RECIRC_C_TO_NC = 1 @unique class VRoVRiStates(DialinEnum): - VALVE_STATE_R1_C_TO_NO = 0 VALVE_STATE_R2_C_TO_NC = 1 @unique class VRdVRfStates(DialinEnum): - VALVE_STATE_R2_C_TO_NO = 0 VALVE_STATE_R1_C_TO_NC = 1 @@ -78,7 +73,7 @@ # Valves states publish message field positions START_POS_VALVES_STATES = DenaliMessage.PAYLOAD_START_INDEX - END_POS_VALVES_STATES = START_POS_VALVES_STATES + 2 # Valves States come in as a U16 value (2 bytes) + END_POS_VALVES_STATES = START_POS_VALVES_STATES + 2 # Valves States come in as a U16 value (2 bytes) # Valve IDs VALVE_RESERVOIR_FILL = 0 # VRF @@ -126,7 +121,7 @@ self.valve_state_VRD2 = {"id": self.VALVE_RESERVOIR_DRAIN_2, "state": DEENERGIZED} self.valve_state_VPD = {"id": self.VALVE_PRODUCTION_DRAIN, "state": DEENERGIZED} - self.valve_states_enum = [0 for i in range(self.NUM_OF_VALVES)] + self.valve_states_enum = [0 for _ in range(self.NUM_OF_VALVES)] def get_valve_states(self): """ @@ -163,7 +158,7 @@ self.valve_state_VRD1.get("state", None), self.valve_state_VRD2.get("state", None), self.valve_state_VPD.get("state", None) - ] + ] @staticmethod def sort_by_id(observation): @@ -172,8 +167,8 @@ of tuples. For example: - >>> hd = DG() - >>> observation = {'datetime': datetime.datetime(2020, 7, 13, 10, 43, 27, 433357), + hd = DG() + observation = {'datetime': datetime.datetime(2020, 7, 13, 10, 43, 27, 433357), 'valve_state_VBF': {'id': 5, 'state': True}, 'valve_state_VDR': {'id': 7, 'state': True}, @@ -189,7 +184,7 @@ 'valve_state_VRO': {'id': 3, 'state': True}, 'valve_state_VSP': {'id': 9, 'state': True}, 'valve_states_all': 8191} - >>> self.logger.debug(hd.valves.sort_by_id(observation)) + self.logger.debug(hd.valves.sort_by_id(observation)) ('valve_state_VRF', 0, True) ('valve_state_VRI', 1, True) @@ -217,7 +212,8 @@ result = sorted(result, key=lambda each: each[1]) return result - def _binary_to_valve_state(self, binary): + @staticmethod + def _binary_to_valve_state(binary) -> bool: """ @param binary: binary value @return: 1 = energized, otherwise de-energized @@ -244,7 +240,7 @@ "valve_state_VRD2", "valve_state_VPD", "valve_states_enum" - ]) + ]) def _handler_valves_sync(self, message): """ Handles published valves states message.