uds.can.segmenter

Segmentation specific for CAN bus.

Classes

CanSegmenter

Segmenter class that provides utilities for segmentation and desegmentation specific for CAN bus.

Module Contents

class uds.can.segmenter.CanSegmenter(*, addressing_information, dlc=CanDlcHandler.MIN_BASE_UDS_DLC, min_dlc=None, use_data_optimization=False, filler_byte=DEFAULT_FILLER_BYTE)[source]

Bases: uds.segmentation.AbstractSegmenter

Inheritance diagram of uds.can.segmenter.CanSegmenter

Segmenter class that provides utilities for segmentation and desegmentation specific for CAN bus.

Configure CAN Segmenter.

Parameters:
  • addressing_information (uds.can.addressing.AbstractCanAddressingInformation) – Addressing Information configuration of a node that is taking part in DoCAN communication.

  • dlc (int) – Base CAN DLC value to use for creating CAN Packets.

  • min_dlc (Optional[int]) – Minimal CAN DLC to use for CAN Packets during Data Optimization. None value means no restriction.

  • use_data_optimization (bool) – Information whether to use CAN Frame Data Optimization in created CAN Packets during segmentation.

  • filler_byte (int) – Filler byte value to use for CAN Frame Data Padding in created CAN Packets during segmentation.

addressing_information: uds.can.addressing.AbstractCanAddressingInformation

Addressing Information configuration for this UDS Entity.

property dlc: int

Value of base CAN DLC to use for CAN Packets.

Note

All output CAN Packets (created by segmentation()) will have this DLC value set unless CAN Frame Data Optimization is used.

Return type:

int

property min_dlc: int | None

Value of minimal CAN DLC to use for CAN Packets during Data Optimization.

Note

Output CAN Packets (created by segmentation()) will never have DLC smaller than this value even if CAN Frame Data Optimization is used.

Return type:

Optional[int]

property use_data_optimization: bool

Information whether to use CAN Frame Data Optimization during CAN Packet creation.

Return type:

bool

property filler_byte: int

Filler byte value to use for CAN Frame Data Padding during segmentation.

Return type:

int

property supported_addressing_information_class: Type[uds.addressing.AbstractAddressingInformation]

Addressing Information class supported by this segmenter.

Return type:

Type[uds.addressing.AbstractAddressingInformation]

property supported_packet_class: Type[uds.packet.AbstractPacket]

Packet class supported by CAN segmenter.

Return type:

Type[uds.packet.AbstractPacket]

property supported_packet_record_class: Type[uds.packet.AbstractPacketRecord]

Packet Record class supported by CAN segmenter.

Return type:

Type[uds.packet.AbstractPacketRecord]

property addressing_format: uds.can.addressing.CanAddressingFormat

CAN Addressing Format used.

Return type:

uds.can.addressing.CanAddressingFormat

__physical_segmentation(message)

Segment physically addressed diagnostic message.

Parameters:

message (uds.message.UdsMessage) – UDS message to divide into packets.

Raises:

SegmentationError – Provided diagnostic message cannot be segmented.

Returns:

CAN packets that are an outcome of UDS message segmentation.

Return type:

Tuple[uds.can.packet.CanPacket, Ellipsis]

__functional_segmentation(message)

Segment functionally addressed diagnostic message.

Parameters:

message (uds.message.UdsMessage) – UDS message to divide into packets.

Raises:

SegmentationError – Provided diagnostic message cannot be segmented.

Returns:

CAN packets that are an outcome of UDS message segmentation.

Return type:

Tuple[uds.can.packet.CanPacket, Ellipsis]

is_desegmented_message(packets)[source]

Check whether provided packets are full sequence of packets that form exactly one diagnostic message.

Parameters:

packets (uds.can.packet.CanPacketsContainersSequence) – Packets sequence to check.

Raises:
  • ValueError – Provided value is not CAN packets sequence.

  • NotImplementedError – There is missing implementation for the provided initial packet type.

Returns:

True if the packets form exactly one diagnostic message. False if there are missing, additional or inconsistent (e.g. two packets that initiate a message) packets.

Return type:

bool

get_flow_control_packet(flow_status, block_size=None, st_min=None)[source]

Create Flow Control CAN packet.

Parameters:
  • flow_status (uds.can.packet.CanFlowStatus) – Value of Flow Status parameter.

  • block_size (Optional[int]) – Value of Block Size parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise.

  • st_min (Optional[int]) – Value of Separation Time minimum (STmin) parameter. This parameter is only required with ContinueToSend Flow Status, leave None otherwise.

Returns:

Flow Control CAN packet with provided parameters.

Return type:

uds.can.packet.CanPacket

desegmentation(packets)[source]

Perform desegmentation of CAN packets.

Parameters:

packets (uds.can.packet.CanPacketsContainersSequence) – CAN packets to desegment into UDS message.

Raises:
  • SegmentationError – Provided packets are not a complete packets sequence that form a diagnostic message.

  • NotImplementedError – There is missing implementation for the provided CAN Packets type.

Returns:

A diagnostic message that is an outcome of CAN packets desegmentation.

Return type:

Union[uds.message.UdsMessage, uds.message.UdsMessageRecord]

segmentation(message)[source]

Perform segmentation of a diagnostic message.

Parameters:

message (uds.message.UdsMessage) – UDS message to divide into packets.

Raises:
  • TypeError – Provided value is not instance of UdsMessage class.

  • NotImplementedError – There is missing implementation for the Addressing Type used by the provided message.

Returns:

CAN packets that are an outcome of UDS message segmentation.

Return type:

Tuple[uds.can.packet.CanPacket, Ellipsis]