Source code for uds.can.extended_addressing_information

"""Implementation of Extended Addressing Information handler."""

__all__ = ["ExtendedCanAddressingInformation"]

from typing import Optional

from uds.utilities import InconsistentArgumentsError, UnusedArgumentError, validate_raw_byte
from uds.transmission_attributes import AddressingType
from .addressing_format import CanAddressingFormat
from .frame_fields import CanIdHandler
from .abstract_addressing_information import AbstractCanAddressingInformation, PacketAIParamsAlias


[docs] class ExtendedCanAddressingInformation(AbstractCanAddressingInformation): """Addressing Information of CAN Entity (either server or client) that uses Extended Addressing format.""" AI_DATA_BYTES_NUMBER: int = 1 """Number of CAN Frame data bytes that are used to carry Addressing Information.""" @property def addressing_format(self) -> CanAddressingFormat: """CAN Addressing format used.""" return CanAddressingFormat.EXTENDED_ADDRESSING
[docs] @classmethod def validate_packet_ai(cls, addressing_type: AddressingType, can_id: Optional[int] = None, target_address: Optional[int] = None, source_address: Optional[int] = None, address_extension: Optional[int] = None) -> PacketAIParamsAlias: """ Validate Addressing Information parameters of a CAN packet that uses Extended Addressing format. :param addressing_type: Addressing type to validate. :param can_id: CAN Identifier value to validate. :param target_address: Target Address value to validate. :param source_address: Source Address value to validate. :param address_extension: Address Extension value to validate. :raise InconsistentArgumentsError: Provided CAN ID value is incompatible with Extended Addressing format. :raise UnusedArgumentError: Provided parameter is not supported by this Addressing format. :return: Normalized dictionary with the provided Addressing Information. """ if (source_address, address_extension) != (None, None): raise UnusedArgumentError("Values of Source Address and Address Extension are not supported by " "Extended Addressing format and all must be None.") addressing_type = AddressingType.validate_member(addressing_type) CanIdHandler.validate_can_id(can_id) # type: ignore validate_raw_byte(target_address) # type: ignore if not CanIdHandler.is_extended_addressed_can_id(can_id): # type: ignore raise InconsistentArgumentsError(f"Provided value of CAN ID is not compatible with " f"Extended Addressing Format. Actual value: {can_id}") return PacketAIParamsAlias(addressing_format=CanAddressingFormat.EXTENDED_ADDRESSING, addressing_type=addressing_type, can_id=can_id, # type: ignore target_address=target_address, source_address=source_address, address_extension=address_extension)