Index: leahi_dialin/td/modules/alarms.py =================================================================== diff -u -rfa670938681e25a1314c56aafc630e9dc2f13a4a -reed88866e3e27bc4278b467534708c16fc7907bc --- leahi_dialin/td/modules/alarms.py (.../alarms.py) (revision fa670938681e25a1314c56aafc630e9dc2f13a4a) +++ leahi_dialin/td/modules/alarms.py (.../alarms.py) (revision eed88866e3e27bc4278b467534708c16fc7907bc) @@ -15,6 +15,7 @@ ############################################################################ # Module imports +from functools import partial from logging import Logger import struct from enum import unique @@ -105,12 +106,17 @@ self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, message_id = MsgIds.MSG_ID_TD_ACTIVE_ALARMS_LIST_REQUEST_RESPONSE.value, function = self._handler_alarm_list_response) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.td_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_TD_ALARM_PROPERTIES_RESPONSE.value, + function = self._handler_alarm_table_response) self.td_alarm_status_timestamp = 0.0 #: The timestamp of the last Alarm Status message self.td_alarm_triggered_timestamp = 0.0 #: The timestamp of the last Alarm Triggered message self.td_alarm_cleared_timestamp = 0.0 #: The timestamp of the last Alarm Cleared message self.td_alarm_clr_condition_timestamp = 0.0 #: The timestamp of the last Alarm Clear Condition message self.td_alarm_information_timestamp = 0.0 #: The timestamp of the last Alarm Information message + self.alarm_table_timestamp = 0.0 #: The timestamp of the last Alarm Table Properties message + # composite alarm status based on latest TD alarm status broadcast message self.alarms_priority_state = 0 #: The current Top Alarm's priority value self.alarm_top = 0 #: The current Top Alarm's value @@ -145,6 +151,9 @@ self.ui_alarm_list = [] #: The UI Alarm List content self.ui_alarm_list_timestamp = 0.0 #: The timestamp of the last Alarm List + # Alarm Table Properties + self.alarm_table = {} #: The Alarm Table with Alarm Property details + def clear_dialin_alarms(self): """ @@ -296,59 +305,21 @@ decoder_list = sensor_list, message = message, start_from_byte = len(msg_list) * DataTypes.U32.size()) - """ - vol = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) - ach = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])) - acl = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3])) - bac = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4])) - saf = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5])) - acp = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6])) - trs = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.START_POS_FIELD_7+1])) - trb = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7+1:MsgFieldPositions.START_POS_FIELD_7+2])) - tet = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7+2:MsgFieldPositions.START_POS_FIELD_7+3])) - srs = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7+3:MsgFieldPositions.START_POS_FIELD_7+4])) - srb = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7+4:MsgFieldPositions.START_POS_FIELD_7+5])) - set = struct.unpack('B', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7+5:MsgFieldPositions.START_POS_FIELD_7+6])) - self.alarm_volume = vol[0] - self.alarm_audio_curr_hg = ach[0] - self.alarm_audio_curr_lg = acl[0] - self.alarm_backup_audio_curr = bac[0] - self.safety_shutdown_active = True if saf[0] == 1 else False - self.ac_power_lost = True if acp[0] == 1 else False - self.alarm_table_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_RESUME.value] = True if trs[0] == 1 else False - self.alarm_table_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_RINSEBACK.value] = True if trb[0] else False - self.alarm_table_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_END_TREATMENT.value] = True if tet[0] else False - self.alarm_state_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_RESUME.value] = True if srs[0] else False - self.alarm_state_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_RINSEBACK.value] = True if srb[0] else False - self.alarm_state_button_blockers[self.AlarmResponseButtons.TD_ALARM_RESPONSE_BUTTON_END_TREATMENT.value] = True if set[0] else False - """ self.td_alarm_information_timestamp = timestamp @publish(["msg_id_td_active_alarms_list_request_response", "accepted", "rejection_reason", "active_alarm_list"]) def _handler_alarm_list_response(self, message, timestamp=0.0): """ - Handles published TD alarm clear alarm condition messages. + Handles published TD alarm list response message. - @param message: published TD alarm clear alarm condition message + @param message: published TD alarm list response message @return: none """ self.ui_alarm_list_accepted = struct.unpack(DataTypes.U32.unpack_attrib(), bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] self.ui_alarm_list_reject_reason = struct.unpack(DataTypes.U32.unpack_attrib(), bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - + i = 3 for _ in range(0,10): start_pos = eval(f'MsgFieldPositions.START_POS_FIELD_{i}') @@ -359,6 +330,47 @@ self.ui_alarm_list_timestamp = timestamp + @publish(["msg_id_td_active_alarms_properties_response", "active_table", "alarm_table_timestamp"]) + def _handler_alarm_table_response(self, message, timestamp=0.0): + """ + Handles published TD alarm table properties messages. + + @param message: published TD alarm table properties message + @return: none + """ + properties_list = [] + properties_list.append(('Priority', DataTypes.U32)) + properties_list.append(('Rank', DataTypes.U32)) + properties_list.append(('Source', DataTypes.U32)) + properties_list.append(('System_Fault', DataTypes.BOOL)) + properties_list.append(('DD_Fault', DataTypes.BOOL)) + properties_list.append(('Stops', DataTypes.BOOL)) + properties_list.append(('Clear_Immediately', DataTypes.BOOL)) + properties_list.append(('No_Clear', DataTypes.BOOL)) + properties_list.append(('No_Resume', DataTypes.BOOL)) + properties_list.append(('No_Rinseback', DataTypes.BOOL)) + properties_list.append(('No_End_Treatment', DataTypes.BOOL)) + properties_list.append(('Not_in_Rinseback', DataTypes.BOOL)) + properties_list.append(('Not_in_Post_Treatment', DataTypes.BOOL)) + properties_list.append(('No_Blood_Recirc', DataTypes.BOOL)) + properties_list.append(('Auto_Resume', DataTypes.BOOL)) + properties_list.append(('Clear_Alarm_Only', DataTypes.BOOL)) + properties_list.append(('Treatment_Log', DataTypes.BOOL)) + properties_list.append(('Alarm_Id', DataTypes.U32)) + + result = self.process_into_vars(decoder_list = properties_list, + message = message) + + # Save the result in the table + for prop in result: + if result['Alarm_Id'] not in self.alarm_table: + self.alarm_table[result['Alarm_Id']] = {} + if prop != 'Alarm_Id': + self.alarm_table[result['Alarm_Id']][prop] = result[prop] + + self.alarm_table_timestamp = timestamp + + def cmd_alarm_status_broadcast_interval_override(self, ms: int = 250, reset: int = NO_RESET): """ Constructs and sends the alarm status broadcast interval override command @@ -645,22 +657,28 @@ @return: 1 if successful, zero otherwise """ response = 1 + execute_list = [] for alarm_enum in AlarmList: - retry = 3 - attempt = 0 - while attempt < retry: - resp = self.cmd_request_alarm_details_for_id(alarm_enum.value) + execute_list.append(partial(self.cmd_request_alarm_details_for_alarm(alarm_enum.value))) + + # Execute the stored functions one by one + # Remove the ones that got 1 (successfully recieved) as response + # Retry the ones that are failed 2 more times + retry = 0 + while execute_list != [] and retry < 3: + failed = [] + for func in execute_list: + resp = func() if resp == 1: - attempt += retry - attempt += 1 - # If at least one request didn't go through, set sent response to 0 - if retry < attempt: - response = 0 + failed.append(func) + execute_list = failed + retry += 1 + response = 1 if failed == [] else 0 return response - def cmd_request_alarm_details_for_id(self, alarm_id: int) -> int: + def cmd_request_alarm_details_for_alarm(self, alarm_id: int) -> int: """ Constructs and sends the Alarm details request for selected alarm. Constraints: