Index: dialin/dg/events.py =================================================================== diff -u -r5a413e437f8a341c9e9b77342df6e634c1563add -r35c62a4a697d9741b93ca2dfbd7afba33988a953 --- dialin/dg/events.py (.../events.py) (revision 5a413e437f8a341c9e9b77342df6e634c1563add) +++ dialin/dg/events.py (.../events.py) (revision 35c62a4a697d9741b93ca2dfbd7afba33988a953) @@ -1,8 +1,7 @@ import struct from logging import Logger - -from ..common import DGEventList, DGEventDataType +from ..common import * from ..common.msg_defs import MsgIds, MsgFieldPositions from ..protocols.CAN import DenaliChannels from ..utils.base import AbstractSubSystem, publish @@ -33,6 +32,15 @@ self._dg_event_dictionary = dict() self._dg_event_data_type = dict() + # Dictionary of the the mode as key and the sub mode states enum class as the value + self._dg_op_mode_2_sub_mode = {DGOpModes.DG_MODE_STAN.name: DGStandByModeStates, + DGOpModes.DG_MODE_CIRC.name: DGRecircModeStates, + DGOpModes.DG_MODE_FILL.name: DGFillModeStates, + DGOpModes.DG_MODE_DRAI.name: DGDrainModeStates, + DGOpModes.DG_MODE_FLUS.name: DGFlushStates, + DGOpModes.DG_MODE_HEAT.name: DGHeatDisinfectStates, + DGOpModes.DG_MODE_CHEM.name: DGChemicalDisinfectStates} + # Loop through the list of the DG events enums and initial the event dictionary. Each event is a key in the # dictionary and the value is a list. for event in DGEventList: @@ -129,6 +137,51 @@ # Convert the event ID to enum event_state_name = DGEventList(event_id).name + # Check if the event state name is operation mode change. If it is, get the name of the operation modes + # from the op modes enum class + if event_state_name == DGEventList.DG_EVENT_OP_MODE_CHANGE.name: + event_data_1 = DGOpModes(event_data_1).name + event_data_2 = DGOpModes(event_data_2).name + # Check if the event state name is sub mode change. + elif event_state_name == DGEventList.DG_EVENT_SUB_MODE_CHANGE.name: + # Get the length of the list of the sub mode list + event_list_len = len(self._dg_event_dictionary[DGEventList.DG_EVENT_OP_MODE_CHANGE.name]) + # Get the last tuple of the sub mode + # It is a list of tuples that each tuple is (timestamp, event type, prev op mode, current op mode) + last_op_mode = self._dg_event_dictionary[DGEventList.DG_EVENT_OP_MODE_CHANGE.name][event_list_len - 1] + # Get the current and previous operation modes of the last tuple in the list of the sub modes + # i.e. (timestamp, event type, prev, current) + last_current = last_op_mode[len(last_op_mode) - 1] + last_previous = last_op_mode[len(last_op_mode) - 2] + + # Get the tuple prior to the last tuple and get its previous and current operation modes + prev_to_last_op = self._dg_event_dictionary[DGEventList.DG_EVENT_OP_MODE_CHANGE.name][event_list_len - 2] + prev_current = prev_to_last_op[len(prev_to_last_op) - 1] + prev_previous = prev_to_last_op[len(prev_to_last_op) - 2] + + # Get the class of the states enums of the current operation mode that is running + current_sub_mode_enum_class = self._dg_op_mode_2_sub_mode[last_current] + + # Check if the operation modes of the two tuples match + # i.e. last = (timestamp, event type, prev, current) and one before = (timestamp, event type, prev, current) + # If the prev and current match respectively, it means the current operation mode has not changed so the + # operation mode states can be converted from the current sub mode enum class + if last_current == prev_current and last_previous == prev_previous: + + event_data_1 = current_sub_mode_enum_class(event_data_1).name + event_data_2 = current_sub_mode_enum_class(event_data_2).name + + else: + # If the previous and current of the last two tuples do not match, then an operation modes transition + # has occurred and and the previous state is converted from the previous class and the current op mode + # is converted from current operation states enum class. + # i.e last = (timestamp, event type, 3, 8) and one before = (timestamp, event type, 8, 3) + # previous and current do not match so in the last type (timestamp, event type, 8, 3) the prev state + # should be from op mode 8 and the current state should be from op mode 3 + previous_sub_mode_enum_class = self._dg_op_mode_2_sub_mode[last_previous] + event_data_1 = previous_sub_mode_enum_class(event_data_1).name + event_data_2 = current_sub_mode_enum_class(event_data_2).name + # Get the current timestamp and create a tuple of the current events event_tuple = (str(datetime.now()), event_state_name, event_data_1, event_data_2) Index: tests/dg_heat_and_chemical_disinfect_test.py =================================================================== diff -u -r5a413e437f8a341c9e9b77342df6e634c1563add -r35c62a4a697d9741b93ca2dfbd7afba33988a953 --- tests/dg_heat_and_chemical_disinfect_test.py (.../dg_heat_and_chemical_disinfect_test.py) (revision 5a413e437f8a341c9e9b77342df6e634c1563add) +++ tests/dg_heat_and_chemical_disinfect_test.py (.../dg_heat_and_chemical_disinfect_test.py) (revision 35c62a4a697d9741b93ca2dfbd7afba33988a953) @@ -17,9 +17,9 @@ from dialin.dg.dialysate_generator import DG from dialin.hd.hemodialysis_device import HD -from dialin.common.dg_defs import HeatDisinfectStates, HeatDisinfectUIStates +from dialin.common.dg_defs import DGHeatDisinfectStates, DGHeatDisinfectUIStates from dialin.dg.heat_disinfect import HeatCancellationModes -from dialin.common.dg_defs import ChemicalDisinfectStates, ChemDisinfectUIStates +from dialin.common.dg_defs import DGChemicalDisinfectStates, DGChemDisinfectUIStates from dialin.dg.chemical_disinfect import ChemCancellationModes from dialin.dg.drain_pump import DrainPumpStates from dialin.dg.thermistors import ThermistorsNames @@ -38,13 +38,13 @@ info = ('State, {}, Overall_elapsed_time, {}, State_elapsed_time, {}, Disinfect_elapsed_time, {}, ' 'Cancellation_mode, {}, R1_level, {:5.3f}, R2_level, {:5.3f}, Current_rinse_count, {}, ' 'Total_rinse_count, {}, UI_state, {}, ' - .format(ChemicalDisinfectStates(dg.chemical_disinfect.chemical_disinfect_state).name, + .format(DGChemicalDisinfectStates(dg.chemical_disinfect.chemical_disinfect_state).name, dg.chemical_disinfect.overall_elapsed_time, dg.chemical_disinfect.state_elapsed_time, dg.chemical_disinfect.chemical_disinfect_elapsed_time, ChemCancellationModes(dg.chemical_disinfect.cancellation_mode).name, dg.chemical_disinfect.r1_level, dg.chemical_disinfect.r2_level, dg.chemical_disinfect.current_post_rinse_count, dg.chemical_disinfect.target_post_rinse_count, - ChemDisinfectUIStates(dg.chemical_disinfect.chemical_disinfect_ui_state).name)) + DGChemDisinfectUIStates(dg.chemical_disinfect.chemical_disinfect_ui_state).name)) return info @@ -62,11 +62,11 @@ info = ('State, {}, Overall_elapsed_time, {}, State_elapsed_time, {}, Disinfect_elapsed_time, {}, ' 'R1_level, {:5.3f}, R2_level, {:5.3f}, Top_alarm, {}, UI_state, {} ' - .format(HeatDisinfectStates(dg.heat_disinfect.heat_disinfect_state).name, + .format(DGHeatDisinfectStates(dg.heat_disinfect.heat_disinfect_state).name, dg.heat_disinfect.overall_elapsed_time, dg.heat_disinfect.state_elapsed_time, dg.heat_disinfect.heat_disinfect_count_down_time, dg.heat_disinfect.r1_level, dg.heat_disinfect.r2_level, hd.alarms.alarm_top, - HeatDisinfectUIStates(dg.chemical_disinfect.chemical_disinfect_ui_state).name)) + DGHeatDisinfectUIStates(dg.chemical_disinfect.chemical_disinfect_ui_state).name)) return info @@ -542,7 +542,7 @@ hd.cmd_log_in_to_hd() sleep(1) - #run_heat_disinfect() + run_heat_disinfect() #run_chemical_disinfect()