Index: leahi_dialin/dd/modules/drybicart.py =================================================================== diff -u -r3f4937e339925dde0b95f08e49969f8983c5cba4 -reca9e15bc984af2b7f59eb38f3836ca354ee1251 --- leahi_dialin/dd/modules/drybicart.py (.../drybicart.py) (revision 3f4937e339925dde0b95f08e49969f8983c5cba4) +++ leahi_dialin/dd/modules/drybicart.py (.../drybicart.py) (revision eca9e15bc984af2b7f59eb38f3836ca354ee1251) @@ -16,17 +16,19 @@ # Module imports from logging import Logger +from typing import Union # Project imports from leahi_dialin.common.constants import NO_RESET , RESET +from leahi_dialin.common.dd_defs import DDBicarbChFillExecStates, DDDryBicartDrainExecStates, DDDryBicartFillExecStates +from leahi_dialin.common.disp_defs import BicarbTypes from leahi_dialin.common.generic_defs import DataTypes from leahi_dialin.common.msg_ids import MsgIds from leahi_dialin.common.override_templates import cmd_generic_broadcast_interval_override, cmd_generic_override -from dataclasses import dataclass from leahi_dialin.protocols.CAN import CanMessenger, CanChannels from leahi_dialin.utils.abstract_classes import AbstractSubSystem from leahi_dialin.utils.base import publish -from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray +from leahi_dialin.utils.conversions import integer_to_bytearray class DDDryBicart(AbstractSubSystem): @@ -52,26 +54,184 @@ function = self._handler_dry_bicart_sync) self.dd_dry_bicart_timestamp = 0.0 #: The timestamp of the last message - self.dd_dry_bicart_fill_execution_state = 0 #: The Dry Bicart fill execution state - self.dd_bicarb_chamber_fill_execution_state = 0 #: The Bicarb chamber fill execution state - self.dd_dry_bicart_drain_execution_state = 0 #: The Dry Bicart drain execution state - self.dd_dry_bicart_fill_cycle_counter = 0 #: The Dry Bicart fill cycle counter - self.dd_dry_bicart_max_fill_cycle_count = 0 #: The Dry Bicart max fill cycle state - self.dd_dry_bicart_fill_request = 0 #: Is fill requested for Dry Bicart or not - self.dd_bicarb_chamber_fill_request = 0 #: Is fill requested for Bicarb Chamber or not - self.dd_dry_bicart_drain_request = 0 #: Is drain requested for Dry Bicart or not - self.dd_dry_bicart_last_fill_time = 0 #: The Dry Bicart last fill time - self.dd_dry_bicart_current_fill_time = 0 #: The Dry Bicart current fill time - self.dd_dryBiCartType = 0 #: The Dry Bicart concentrate option index - self.dd_dryBiCartDrainTimePeriod = 0 #: The Dry Bicart drain time period in sec - self.dd_dry_bicart_timestamp = 0 #: The timestamp of the last message + self.dd_dry_bicart_fill_execution_state = DDDryBicartFillExecStates.NUM_OF_DRY_BICART_FILL_EXEC_STATES + self.dd_bicarb_chamber_fill_execution_state = DDBicarbChFillExecStates.NUM_OF_BICARB_CHAMBER_FILL_EXEC_STATES + self.dd_dry_bicart_drain_execution_state = DDDryBicartDrainExecStates.NUM_OF_DRY_BICART_DRAIN_EXEC_STATES + self.dd_dry_bicart_fill_cycle_counter = 0 + self.dd_dry_bicart_max_fill_cycle_count = 0 + self.dd_dry_bicart_fill_request = False + self.dd_dry_bicart_drain_request = False + self.dd_bicarb_chamber_fill_request = False + self.dd_dry_bicart_last_fill_time = 0 + self.dd_dry_bicart_current_fill_time = 0 + self.dry_bicart_type = BicarbTypes.NUM_OF_BICARB_TYPES + self.dry_bicart_drain_time_period = 0 + +# ============================================================ Properties ============================================================ + @property + def dd_dry_bicart_fill_execution_state(self) -> DDDryBicartFillExecStates: + """ + The Dry Bicart fill execution state + """ + return self._dry_bicart_fill_execution_state + + @dd_dry_bicart_fill_execution_state.setter + def dd_dry_bicart_fill_execution_state(self, value: Union[int, DDDryBicartFillExecStates]): + if isinstance(value, int): + self._dry_bicart_fill_execution_state = DDDryBicartFillExecStates(value) + else: + self._dry_bicart_fill_execution_state = value + + + @property + def dd_dry_bicart_drain_execution_state(self) -> DDDryBicartDrainExecStates: + """ + The Dry Bicart drain execution state + """ + return self._dry_bicart_drain_execution_state + + @dd_dry_bicart_drain_execution_state.setter + def dd_dry_bicart_drain_execution_state(self, value: Union[int, DDDryBicartDrainExecStates]): + if isinstance(value, int): + self._dry_bicart_drain_execution_state = DDDryBicartDrainExecStates(value) + else: + self._dry_bicart_drain_execution_state = value + + + @property + def dd_bicarb_chamber_fill_execution_state(self) -> DDBicarbChFillExecStates: + """ + The Bicarb chamber F fill execution state + """ + return self._bicarb_chamber_fill_execution_state + + @dd_bicarb_chamber_fill_execution_state.setter + def dd_bicarb_chamber_fill_execution_state(self, value: Union[int, DDBicarbChFillExecStates]): + if isinstance(value, int): + self._bicarb_chamber_fill_execution_state = DDBicarbChFillExecStates(value) + else: + self._bicarb_chamber_fill_execution_state = value + + + @property + def dd_dry_bicart_fill_cycle_counter(self) -> int: + """ + The Dry Bicart fill cycle counter + """ + return self._dry_bicart_fill_cycle_counter + + @dd_dry_bicart_fill_cycle_counter.setter + def dd_dry_bicart_fill_cycle_counter(self, value): + self._dry_bicart_fill_cycle_counter = value + + + @property + def dd_dry_bicart_max_fill_cycle_count(self) -> int: + """ + The Dry Bicart max fill cycle state + """ + return self._dry_bicart_max_fill_cycle_count + + @dd_dry_bicart_max_fill_cycle_count.setter + def dd_dry_bicart_max_fill_cycle_count(self, value): + self._dry_bicart_max_fill_cycle_count = value + + + @property + def dd_dry_bicart_fill_request(self) -> bool: + """ + Is fill requested for Dry Bicart or not + """ + return self._dry_bicart_fill_request + + @dd_dry_bicart_fill_request.setter + def dd_dry_bicart_fill_request(self, value): + self._dry_bicart_fill_request = value + + + @property + def dd_dry_bicart_drain_request(self) -> bool: + """ + Is drain requested for Dry Bicart or not + """ + return self._dry_bicart_drain_request + + @dd_dry_bicart_drain_request.setter + def dd_dry_bicart_drain_request(self, value): + self._dry_bicart_drain_request = value + + + @property + def dd_bicarb_chamber_fill_request(self) -> bool: + """ + Is fill requested for Bicarb Chamber or not + """ + return self._bicarb_chamber_fill_request + + @dd_bicarb_chamber_fill_request.setter + def dd_bicarb_chamber_fill_request(self, value): + self._bicarb_chamber_fill_request = value + + + @property + def dd_dry_bicart_last_fill_time(self) -> int: + """ + The Dry Bicart last fill time + """ + return self._dry_bicart_last_fill_time + + @dd_dry_bicart_last_fill_time.setter + def dd_dry_bicart_last_fill_time(self, value): + self._dry_bicart_last_fill_time = value + + + @property + def dd_dry_bicart_current_fill_time(self) -> int: + """ + The Dry Bicart current fill time + """ + return self._dry_bicart_current_fill_time + + @dd_dry_bicart_current_fill_time.setter + def dd_dry_bicart_current_fill_time(self, value): + self._dry_bicart_current_fill_time = value + + + @property + def dry_bicart_type(self) -> BicarbTypes: + """ + The Dry Bicart concentrate option + """ + return self._dry_bicart_type + + @dry_bicart_type.setter + def dry_bicart_type(self, value: Union[int, BicarbTypes]): + if isinstance(value, int): + self._dry_bicart_type = BicarbTypes(value) + else: + self._dry_bicart_type = value + + + @property + def dry_bicart_drain_time_period(self) -> int: + """ + The Dry Bicart drain time period in sec + """ + return self._dry_bicart_drain_time_period + + @dry_bicart_drain_time_period.setter + def dry_bicart_drain_time_period(self, value): + self._dry_bicart_drain_time_period = value + + +# ============================================================ Handlers ============================================================ @publish(["msg_id_dd_dry_bicart_data", "dd_dry_bicart_fill_execution_state", "dd_bicarb_chamber_fill_execution_state", "dd_dry_bicart_drain_execution_state", "dd_dry_bicart_fill_cycle_counter", "dd_dry_bicart_max_fill_cycle_count", "dd_dry_bicart_fill_request", "dry_bicarb_chamber_fill_request", "dd_dry_bicart_drain_request", - "dd_dry_bicart_last_fill_time", "dd_dry_bicart_current_fill_time", "dd_dryBiCartType", "dd_dryBiCartDrainTimePeriod", + "dd_dry_bicart_last_fill_time", "dd_dry_bicart_current_fill_time", "dry_bicart_type", "dry_bicart_drain_time_period", "dd_dry_bicart_timestamp"]) def _handler_dry_bicart_sync(self, message, timestamp=0.0): """ @@ -81,25 +241,25 @@ @return: None """ msg_list = [] - msg_list.append(('self.dd_dry_bicart_fill_execution_state', DataTypes.U32)) - msg_list.append(('self.dd_bicarb_chamber_fill_execution_state', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_drain_execution_state', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_fill_cycle_counter', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_max_fill_cycle_count', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_fill_request', DataTypes.U32)) - msg_list.append(('self.dd_bicarb_chamber_fill_request', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_drain_request', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_last_fill_time', DataTypes.U32)) - msg_list.append(('self.dd_dry_bicart_current_fill_time', DataTypes.U32)) - msg_list.append(('self.dd_dryBiCartType', DataTypes.U32)) - msg_list.append(('self.dd_dryBiCartDrainTimePeriod', DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_fill_execution_state, DataTypes.U32)) + msg_list.append((type(self).dd_bicarb_chamber_fill_execution_state, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_drain_execution_state, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_fill_cycle_counter, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_max_fill_cycle_count, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_fill_request, DataTypes.U32)) + msg_list.append((type(self).dd_bicarb_chamber_fill_request, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_drain_request, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_last_fill_time, DataTypes.U32)) + msg_list.append((type(self).dd_dry_bicart_current_fill_time, DataTypes.U32)) + msg_list.append((type(self).dry_bicart_type, DataTypes.U32)) + msg_list.append((type(self).dry_bicart_drain_time_period, DataTypes.U32)) - self.process_into_vars(decoder_list = msg_list, - message = message) - + self.process_into_vars(decoder_list = msg_list, message = message) self.dd_dry_bicart_timestamp = timestamp + +# ============================================================ Overrides and Requests ============================================================ def cmd_dry_bicart_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the dry bicart data broadcast interval override command