#!/bin/python3 from leahi_dialin.ui.utils import singleton_threadsafe from leahi_dialin.utils import conversions from leahi_dialin.protocols import CAN from leahi_dialin.common import msg_ids from leahi_dialin.common.alarm_priorities import AlarmPriority @singleton_threadsafe class TD_Messaging_Alarms(): def __init__(self): self.can_enabled: bool=False self.can_Channel: str = "can0" class fakeLogger(): def __init__(self): pass def error(a1, a2): pass def info(a1, a2): pass self.can_interface = CAN.DenaliCanMessenger(can_interface=self.can_Channel, logger=fakeLogger() ) self.can_interface.start() if self.can_interface is not None: self.can_enabled = True def cmd_activate_alarm_id(self, state: int = AlarmPriority.ALARM_HIGH, alarm: int = 0, escalates_in: int = 0, silence_expires: int = 0, flags: int = 0): """ Activates the specified alarm @param state: (int) Alarm priority @param alarm: (int) the alarm id @param escalates_in: (int) how long until the alarm escalates @param silence_expires: (int) seconds until silence expires @param flags: (int) See 'cmd_make_alarm_flags' @return: None """ state = conversions.integer_to_bytearray(state) top = conversions.integer_to_bytearray(alarm) escalates_in = conversions.integer_to_bytearray(escalates_in) silence_expires = conversions.integer_to_bytearray(silence_expires) flags = conversions.integer_to_bytearray(flags) payload = state + top + escalates_in + silence_expires + flags message = CAN.DenaliMessage.build_message( channel_id=CAN.DenaliChannels.td_alarm_broadcast_ch_id, message_id=CAN.MsgIds.MSG_ID_ALARM_STATUS_DATA.value, payload=payload) self.can_interface.send(message, 0) def cmd_send_general_response(self, message_id: int, accepted: int, reason: int, is_pure_data: bool = False, has_parameters: bool = False, parameters_payload: any = 0x00, channel_id=CAN.DenaliChannels.td_to_ui_ch_id) -> None: """ a general method to send any standard response message, by it's id and list of parameters. @param message_id: the id of the message @param accepted: the standard accepted parameter of any response message @param reason: the standard rejection reason parameter of any response message @param is_pure_data: The message only has data @param has_parameters: if the message has parameter this needs to be true. @param parameters_payload: the list of parameters pre-converted and ready to be concatenated to the payload. @param channel_id: (int) indicates the channel @return: None """ payload = "" if not is_pure_data: payload = conversions.integer_to_bytearray(accepted) payload += conversions.integer_to_bytearray(reason ) if has_parameters: payload = parameters_payload message = CAN.DenaliMessage.build_message( channel_id, message_id, payload ) self.can_interface.send(message, 0)