Index: leahi_dialin/fp/modules/events.py =================================================================== diff -u -r34b64ff2d8a64f4b7b60b80bb7cf4c36845e5943 -r75c97894e28b7cc684fcaf8f7ffba3f8c1bb61d8 --- leahi_dialin/fp/modules/events.py (.../events.py) (revision 34b64ff2d8a64f4b7b60b80bb7cf4c36845e5943) +++ leahi_dialin/fp/modules/events.py (.../events.py) (revision 75c97894e28b7cc684fcaf8f7ffba3f8c1bb61d8) @@ -67,32 +67,13 @@ fp_enum_repository.FPOpModes.MODE_DEGP.name: fp_enum_repository.FPGenPermeateDefStates, fp_enum_repository.FPOpModes.MODE_NLEG.name: fp_enum_repository.FPNotLegalStates} - # Define the dictionaries - self._fp_event_dictionary = dict() - self._fp_event_data_type = dict() - # Loop through the list of the FP events enums and initial the event dictionary. Each event is a key in the # dictionary and the value is a list. + self._fp_event_dictionary = dict() for event in fp_enum_repository.FPEventList: self._fp_event_dictionary[fp_enum_repository.FPEventList(event).name] = [] - # Loop through the list of the event data type enum and update the dictionary - for data_type in fp_enum_repository.DataTypes: - event_data_type = fp_enum_repository.DataTypes(data_type).name - struct_unpack_type = None - # If U32 is in the data type enum (i.e. EVENT_DATA_TYPE_U32), then the key is the enum and the value is - # the corresponding format in the python struct - if 'U32' in event_data_type or 'BOOL' in event_data_type: - struct_unpack_type = 'I' - elif 'S32' in event_data_type: - struct_unpack_type = 'i' - elif 'F32' in event_data_type: - struct_unpack_type = 'f' - - self._fp_event_data_type[event_data_type] = struct_unpack_type - - def get_fp_nth_event(self, event_id, event_number=0): """ Returns the nth requested FP event @@ -167,55 +148,54 @@ sub_state = 0 current_sub_tuple = [] - event_id = struct.unpack('i', bytearray( + 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) + 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: - # Get the data type - event_data_type_1 = struct.unpack('i', bytearray( + # 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] - struct_data_type = self._fp_event_data_type[fp_enum_repository.DataTypes(event_data_type_1).name] - op_mode = struct.unpack('