#!/bin/python3 from utils import singleton from utils import conversions from protocols import CAN from common import msg_ids @singleton class TD_Messaging: def __init__(self): self.can_enabled: bool=False self.can_Channel: str = "can0" self.can_interface = CAN.DenaliCanMessenger(can_interface=self.can_Channel) self.can_interface.start() if self.can_interface is not None: self.can_enabled = True def cmd_send_hd_operation_mode(self, op_mode: int, sub_mode: int = 0): """ Broadcasts the current HD operation mode @param op_mode: hd operation mode @param sub_mode: hd operation sub-mode @return: None """ if not self.can_enabled: raise ValueError("CAN Interface is not enabled") payload = conversions.integer_to_bytearray(op_mode ) payload += conversions.integer_to_bytearray(sub_mode) message = CAN.DenaliMessage.build_message( channel_id=CAN.DenaliChannels.td_sync_broadcast_ch_id, message_id=msg_ids.MsgIds.MSG_ID_TD_OP_MODE_DATA.value, payload=payload) self.can_interface.send(message, 0)