Helper classes

This section provides a definition for several classes included in this project.

CommunicationType

class udsoncan.CommunicationType(subnet, normal_msg=False, network_management_msg=False)[source]

This class represents a pair of subnet and message types. This value is mainly used by the CommunicationControl service

Parameters:
  • subnet (int) – Represent the subnet number. Value ranges from 0 to 0xF

  • normal_msg (bool) – Bit indicating that the normal messages are involved

  • network_management_msg (bool) – Bit indicating that the network management messages are involved


MemoryLocation

class udsoncan.MemoryLocation(address, memorysize, address_format=None, memorysize_format=None)[source]

This class defines a memory block location including : address, size, AddressAndLengthFormatIdentifier (address format and memory size format)

Parameters:
  • address (int) – A memory address pointing to the beginning of the memory block

  • memorysize (int) – The size of the memory block

  • address_format (int or None) – The number of bits on which an address should be encoded. Possible values are 8, 16, 24, 32, 40. If None is specified, the smallest size required to store the given address will be used

  • memorysize_format (int or None) – The number of bits on which a memory size should be encoded. Possible values are 8, 16, 24, 32 If None is specified, the smallest size required to store the given memorysize will be used


DidCodec

class udsoncan.DidCodec(packstr=None)[source]

This class defines how to encode/decode a Data Identifier value to/from a binary payload.

One should extend this class and override the encode, decode, __len__ methods as they will be used to generate or parse binary payloads.

  • encode Must receive any Python object and must return a bytes payload

  • decode Must receive a bytes payload and may return any Python object

  • __len__ Must return the length of the bytes payload or raise a DidCodec.ReadAllRemainingData to read the whole payload. Reading the whole payload is not a feature proposed by ISO-14229.

If a data can be processed by a pack string, then this class may be used as is, without being extended.

Parameters:

packstr (string) – A pack string used with struct.pack / struct.unpack.


Baudrate

class udsoncan.Baudrate(baudrate, baudtype=3)[source]

Represents a link speed in bit per seconds (or symbol per seconds to be more accurate). This class is used by the LinkControl service that controls the underlying protocol speeds.

The class can encode the baudrate in 2 different fashions : Fixed or Specific.

Some standard baudrate values are defined within ISO-14229:2006 Annex B.3

Parameters:
  • baudrate (int) – The baudrate to be used.

  • baudtype (int) –

    Tells how the baudrate shall be encoded. 4 values are possible:

    • Baudrate.Type.Fixed (0) : Will encode the baudrate in a single byte Fixed fashion. baudrate should be a supported value such as 9600, 19200, 125000, 250000, etc.

    • Baudrate.Type.Specific (1) : Will encode the baudrate in a three-byte Specific fashion. baudrate can be any value ranging from 0 to 0xFFFFFF

    • Baudrate.Type.Identifier (2) : Will encode the baudrate in a single byte Fixed fashion. baudrate should be the byte value to encode if the user wants to use a custom type.

    • Baudrate.Type.Auto (3) : Let the class guess the type.

      • If baudrate is a known standard value (19200, 38400, etc), then Fixed shall be used

      • If baudrate is an integer that fits in a single byte, then Identifier shall be used

      • If baudrate is none of the above, then Specific will be used.


DataFormatIdentifier

class udsoncan.DataFormatIdentifier(compression=0, encryption=0)[source]

Defines the compression and encryption method of a specific chunk of data. Mainly used by the RequestUpload and RequestDownload services

Parameters:
  • compression (int) – Value between 0 and 0xF specifying the compression method. Only the value 0 has a meaning defined by UDS standard and it is No compression. All other values are ECU manufacturer specific.

  • encryption (int) – Value between 0 and 0xF specifying the encryption method. Only the value 0 has a meaning defined by UDS standard and it is No encryption. All other values are ECU manufacturer specific.


AddressAndLengthFormatIdentifier

class udsoncan.AddressAndLengthFormatIdentifier(address_format, memorysize_format)[source]

This class defines how many bytes of a memorylocation, composed of an address and a memorysize, should be encoded when sent over the underlying protocol. Mainly used by ReadMemoryByAddress, WriteMemoryByAddress, RequestDownload and RequestUpload services

Defined by ISO-14229:2020, Annex H

Parameters:
  • address_format (int) – The number of bits on which an address should be encoded. Possible values are 8, 16, 24, 32, 40, 48, 56, 64

  • memorysize_format (int) – The number of bits on which a memory size should be encoded. Possible values are 8, 16, 24, 32, 40, 48, 56, 64


Filesize

class udsoncan.Filesize(uncompressed=None, compressed=None, width=None)[source]

This class represent a file size used by the RequestFileTransfer service.

Parameters:
  • uncompressed (int) – Represent the uncompressed size in bytes

  • compressed (int) – Represent the compressed size in bytes

  • width (int) – The number of byte that should be used to encode the filesize in a payload


DTC

class udsoncan.Dtc(dtcid)[source]

Defines a Diagnostic Trouble Code which consist of a 3-byte ID, a status, a severity and some diagnostic data.

Parameters:

dtcid (int) – The 3-byte ID of the DTC


DTC.Status

class Dtc.Status(test_failed=False, test_failed_this_operation_cycle=False, pending=False, confirmed=False, test_not_completed_since_last_clear=False, test_failed_since_last_clear=False, test_not_completed_this_operation_cycle=False, warning_indicator_requested=False)[source]

Represents a DTC status which consists of 8 boolean flags (a byte). All flags can be set after instantiation without problems.

Parameters:
  • test_failed (bool) – DTC is no longer failed at the time of the request

  • test_failed_this_operation_cycle (bool) – DTC never failed on the current operation cycle.

  • pending (bool) – DTC failed on the current or previous operation cycle.

  • confirmed (bool) – DTC is not confirmed at the time of the request.

  • test_not_completed_since_last_clear (bool) – DTC test has been completed since the last codeclear.

  • test_failed_since_last_clear (bool) – DTC test failed at least once since last code clear.

  • test_not_completed_this_operation_cycle (bool) – DTC test completed this operation cycle.

  • warning_indicator_requested (bool) – Server is not requesting warningIndicator to be active.


DTC.Severity

class Dtc.Severity(maintenance_only=False, check_at_next_exit=False, check_immediately=False)[source]

Represents a DTC severity which consists of 3 boolean flags. All flags can be set after instantiation without problems.

Parameters:
  • maintenance_only (bool) – This value indicates that the failure requests maintenance only

  • check_at_next_exit (bool) – This value indicates that the failure requires a check of the vehicle at the next halt.

  • check_immediately (bool) – This value indicates that the failure requires an immediate check of the vehicle.


DTC.Format

class Dtc.Format[source]

Provide a list of DTC formats and their indices. These values are used by the The ReadDTCInformation when requesting a number of DTCs.

ISO15031_6 = 0
ISO14229_1 = 1
SAE_J1939_73 = 2
ISO11992_4 = 3

IOValues

class udsoncan.IOValues(*args, **kwargs)[source]

This class saves a function argument so they can be passed to a callback function.

Parameters:
  • args (Tuple) – Arguments

  • kwargs (Dict[str, Any]) – Named arguments


IOMasks

class udsoncan.IOMasks(*args, **kwargs)[source]

Allow to specify a list of masks for a InputOutputControlByIdentifier composite codec.

Example : IOMasks(mask1,mask2, mask3=True, mask4=False)

Parameters:
  • args (str) – Masks to set to True

  • kwargs (bool) – Masks and their values


Routine

class udsoncan.Routine[source]

Defines a list of constants that are routine identifiers defined by the UDS standard. This class provides no functionality apart from defining these constants

DeployLoopRoutineID = 57856
EraseMemory = 65280
CheckProgrammingDependencies = 65281
EraseMirrorMemoryDTCs = 65282

DataIdentifier

class udsoncan.DataIdentifier[source]

Defines a list of constants that are data identifiers defined by the UDS standard. This class provides no functionality apart from defining these constants

BootSoftwareIdentification = 61824
ApplicationSoftwareIdentification = 61825
ApplicationDataIdentification = 61826
BootSoftwareFingerprint = 61827
ApplicationSoftwareFingerprint = 61828
ApplicationDataFingerprint = 61829
ActiveDiagnosticSession = 61830
VehicleManufacturerSparePartNumber = 61831
VehicleManufacturerECUSoftwareNumber = 61832
VehicleManufacturerECUSoftwareVersionNumber = 61833
SystemSupplierIdentifier = 61834
ECUManufacturingDate = 61835
ECUSerialNumber = 61836
SupportedFunctionalUnits = 61837
VehicleManufacturerKitAssemblyPartNumber = 61838
ISOSAEReservedStandardized = 61839
VIN = 61840
VehicleManufacturerECUHardwareNumber = 61841
SystemSupplierECUHardwareNumber = 61842
SystemSupplierECUHardwareVersionNumber = 61843
SystemSupplierECUSoftwareNumber = 61844
SystemSupplierECUSoftwareVersionNumber = 61845
ExhaustRegulationOrTypeApprovalNumber = 61846
SystemNameOrEngineType = 61847
RepairShopCodeOrTesterSerialNumber = 61848
ProgrammingDate = 61849
CalibrationRepairShopCodeOrCalibrationEquipmentSerialNumber = 61850
CalibrationDate = 61851
CalibrationEquipmentSoftwareNumber = 61852
ECUInstallationDate = 61853
ODXFile = 61854
Entity = 61855

DynamicDidDefinition

class udsoncan.DynamicDidDefinition(*args, **kwargs)[source]

This class serves as a container for the different pieces of a dynamic DID defined by the DynamicallyDefineDataIDentifier service.

add(*args, **kwargs)[source]

Add a piece of definition for a dynamic DID.

When defining by memory address, only memloc can be supplied. Example : myDidDefinition.add(myMemLoc)

When defining with a source DID, these parameters must be supplied : source_did, position, memorysize. Example : myDidDefinition.add(source_did=1234, position=1, memorysize=2)

Parameters:
  • source_did (int) – The source DID from which to fetch data from

  • position (int) – Start position of the data to fetch inside the source DID data

  • memorysize (int) – Length of data to fetch inside the source DID data

  • memloc (MemoryLocation) – MemoryLocation containing an address, a size and an encoding format

Return type:

None