Index: leahi_dialin/fp/modules/events.py =================================================================== diff -u -r75c97894e28b7cc684fcaf8f7ffba3f8c1bb61d8 -r27cd8e0e7b47617083e8c12f73306f0ba648e687 --- leahi_dialin/fp/modules/events.py (.../events.py) (revision 75c97894e28b7cc684fcaf8f7ffba3f8c1bb61d8) +++ leahi_dialin/fp/modules/events.py (.../events.py) (revision 27cd8e0e7b47617083e8c12f73306f0ba648e687) @@ -19,7 +19,7 @@ from datetime import datetime from time import time -from leahi_dialin.common import fp_enum_repository +from leahi_dialin.common import dd_enum_repository, fp_enum_repository from leahi_dialin.common.generic_defs import DataTypes from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols.CAN import DenaliCanMessenger, DenaliChannels, DenaliCanMessenger @@ -151,10 +151,11 @@ event_id = struct.unpack(DataTypes.U32.unpack_attrib(), bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] # Convert the event ID to enum - event_enum = fp_enum_repository.FPEventList(event_id) + compensated_event_id = event_id - dd_enum_repository.DDEventList.NUM_OF_DD_EVENT_IDS.value + event_enum = fp_enum_repository.FPEventList(compensated_event_id) current_timestamp = datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S.%f') - if event_id == fp_enum_repository.FPEventList.FP_EVENT_OPERATION_STATUS.value: + if event_enum is fp_enum_repository.FPEventList.FP_EVENT_OPERATION_STATUS: # Get the data type - irrelevant event_data_type_1 = struct.unpack(DataTypes.U32.unpack_attrib(), bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] @@ -195,24 +196,23 @@ event_tuple = (current_timestamp, event_enum.name, event_data_1, event_data_2) # Check if the event state name is sub mode change. - elif event_enum is fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE: + elif event_enum is fp_enum_repository.FPEventList.FP_EVENT_SUB_MODE_CHANGE: # Get the length of the list of the op mode list op_list_len = len(self._fp_event_dictionary[fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE.name]) # Get the last tuple of the op mode # It is a list of tuples that each tuple is (timestamp, event type, prev op mode, current op mode) if op_list_len != 0: - last_op_tuple = self._fp_event_dictionary[fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE.name][op_list_len - 1] - + last_op_tuple = self._fp_event_dictionary[fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE.name][-1] else: # No op mode event has been received before the submode event was received. Use broadcast messages to # determine current op mode. Previous mode can not be known last_op_tuple = (current_timestamp, - fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE.name, FPEvents.UNKNOWN_STATE, + fp_enum_repository.FPEventList.FP_EVENT_OP_MODE_CHANGE.name, self.UNKNOWN_STATE, fp_enum_repository.FPOpModes(self.fp_event_op_mode).name) # 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) - current_op_mode = last_op_tuple[len(last_op_tuple) - 1] - current_op_mode_timestamp = datetime.strptime(last_op_tuple[0], '%Y-%m-%d %H:%M:%S.%f') + prev_op_mode_name = last_op_tuple[-1] + prev_op_mode_timestamp = datetime.strptime(last_op_tuple[0], '%Y-%m-%d %H:%M:%S.%f') sub_mode_list_len = len(self._fp_event_dictionary[fp_enum_repository.FPEventList.FP_EVENT_SUB_MODE_CHANGE.name]) @@ -226,25 +226,25 @@ current_sub_mode_timestamp = 0 # Get the class of the states enums of the current operation mode that is running - current_sub_mode_enum_class = self._fp_op_mode_2_sub_mode[current_op_mode] + current_sub_mode_enum_class = self._fp_op_mode_2_sub_mode[prev_op_mode_name] # 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 current_sub_mode_timestamp != 0: - if current_op_mode_timestamp <= current_sub_mode_timestamp: + if prev_op_mode_timestamp <= current_sub_mode_timestamp: event_data_1 = current_sub_mode_enum_class(event_data_1).name event_data_2 = current_sub_mode_enum_class(event_data_2).name - elif current_op_mode_timestamp > current_sub_mode_timestamp: + elif prev_op_mode_timestamp > current_sub_mode_timestamp: # If the previous and current of the last two tuples do not match, then an operation mode transition # has occurred 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_op_mode = last_op_tuple[len(last_op_tuple) - 2] + previous_op_mode = last_op_tuple[-2] if previous_op_mode != FPEvents.UNKNOWN_STATE: previous_sub_mode_enum_class = self._fp_op_mode_2_sub_mode[previous_op_mode] event_data_1 = previous_sub_mode_enum_class(event_data_1).name @@ -253,7 +253,6 @@ event_data_1 = str(event_data_1) event_data_2 = current_sub_mode_enum_class(event_data_2).name else: - if event_data_2 != 0: event_data_1 = current_sub_mode_enum_class(event_data_1).name event_data_2 = current_sub_mode_enum_class(event_data_2).name