Request and Response
Messages exchanged by the client and the server are represented by a Request and a Response.
The client sends Requests to the server that include a service number, an optional subfunction and some data. The server processes the request and answers with a Response that contains an echo of the service number, a response code and some additional data.
The following classes provides the necessary interface to manipulate UDS requests and responses.
Request
req = Request(service=ECUReset, subfunction=1, data=b'\x99\x88')
payload = req.get_payload()
print(payload) # b'\x11\x01\x99\x88'
req2 = Request.from_payload(payload)
print(req2) # <Request: [ECUReset] (subfunction=1) - 2 data bytes at 0x12345678>
- class udsoncan.Request(service=None, subfunction=None, suppress_positive_response=False, data=None)[source]
Represents a UDS Request.
- Parameters:
service (class) – The service for which to make the request. This parameter must be a class that extends
udsoncan.services.BaseServicesubfunction (int or None) – The service subfunction. This value may be ignored if the given service does not supports subfunctions
suppress_positive_response (bool) – Indicates that the server should not send a response if the response code is positive. This parameter has effect only when the given service supports subfunctions
data (bytes) – The service data appended after service ID and payload
- Request.get_payload(suppress_positive_response=None)[source]
Generates a payload to be given to the underlying protocol. This method is meant to be used by a UDS client
- Returns:
A payload to be sent through the underlying protocol
- Return type:
bytes
- Parameters:
suppress_positive_response (bool | None) –
Response
response = Response(service=ECUReset, code=Response.Code.PositiveResponse, data=b'\x11\x22')
payload = response.get_payload()
print(payload) # b'\x51\x11\x22'
response2 = Response.from_payload(payload)
print(response2) # <PositiveResponse: [ECUReset] - 2 data bytes at 0x7f9367e619b0>
- class udsoncan.Response(service=None, code=None, data=None)[source]
Represents a server Response to a client Request
- Parameters:
service (class) – The service implied by this response.
code (int) – The response code
data (bytes) – The response data encoded after the service and response code
- valid
(boolean) True if the response content is valid. Only
invalid_reasonis guaranteed to have a meaningful value if this value is False
- invalid_reason
(string) String explaining why the response is invalid.
- positive
(boolean) True if the response code is 0 (PositiveResponse), False otherwise
- unexpected
(boolean) Indicates that the response was unexpected. Set by an external source such as the Client object
- code
(int) The response code.
- code_name
(string) The response code name.
- data
(bytes) The response data. All the payload content, except the service number and the response code
- service_data
(object) The content of
datainterpreted by a service; can be any type of content.
- original_payload
(bytes) When the response is built with Response.from_payload, this property contains a copy of the payload used. None otherwise.
- original_request
(Request) Optional reference to the request object that generated this response.
- Response.get_payload()[source]
Generates a payload to be given to the underlying protocol. This method is meant to be used by a UDS server
- Returns:
A payload to be sent through the underlying protocol
- Return type:
bytes
- classmethod Response.from_payload(payload)[source]
Creates a
Responseobject from a payload coming from the underlying protocol. This method is meant to be used by a UDS client
Response Codes
- class udsoncan.ResponseCode.ResponseCode[source]
- PositiveResponse = 0
- GeneralReject = 16
- ServiceNotSupported = 17
- SubFunctionNotSupported = 18
- IncorrectMessageLengthOrInvalidFormat = 19
- ResponseTooLong = 20
- BusyRepeatRequest = 33
- ConditionsNotCorrect = 34
- RequestSequenceError = 36
- NoResponseFromSubnetComponent = 37
- FailurePreventsExecutionOfRequestedAction = 38
- RequestOutOfRange = 49
- SecurityAccessDenied = 51
- AuthenticationRequired = 52
- InvalidKey = 53
- ExceedNumberOfAttempts = 54
- RequiredTimeDelayNotExpired = 55
- SecureDataTransmissionRequired = 56
- SecureDataTransmissionNotAllowed = 57
- SecureDataVerificationFailed = 58
- CertificateVerificationFailed_InvalidTimePeriod = 80
- CertificateVerificationFailed_InvalidSignature = 81
- CertificateVerificationFailed_InvalidChainOfTrust = 82
- CertificateVerificationFailed_InvalidType = 83
- CertificateVerificationFailed_InvalidFormat = 84
- CertificateVerificationFailed_InvalidContent = 85
- CertificateVerificationFailed_InvalidScope = 86
- CertificateVerificationFailed_InvalidCertificate = 87
- OwnershipVerificationFailed = 88
- ChallengeCalculationFailed = 89
- SettingAccessRightsFailed = 90
- SessionKeyCreationDerivationFailed = 91
- ConfigurationDataUsageFailed = 92
- DeAuthenticationFailed = 93
- UploadDownloadNotAccepted = 112
- TransferDataSuspended = 113
- GeneralProgrammingFailure = 114
- WrongBlockSequenceCounter = 115
- RequestCorrectlyReceived_ResponsePending = 120
- SubFunctionNotSupportedInActiveSession = 126
- ServiceNotSupportedInActiveSession = 127
- RpmTooHigh = 129
- RpmTooLow = 130
- EngineIsRunning = 131
- EngineIsNotRunning = 132
- EngineRunTimeTooLow = 133
- TemperatureTooHigh = 134
- TemperatureTooLow = 135
- VehicleSpeedTooHigh = 136
- VehicleSpeedTooLow = 137
- ThrottlePedalTooHigh = 138
- ThrottlePedalTooLow = 139
- TransmissionRangeNotInNeutral = 140
- TransmissionRangeNotInGear = 141
- BrakeSwitchNotClosed = 143
- ShifterLeverNotInPark = 144
- TorqueConverterClutchLocked = 145
- VoltageTooHigh = 146
- VoltageTooLow = 147
- ResourceTemporarilyNotAvailable = 148
- GeneralSecurityViolation = 56
- SecuredModeRequested = 57
- InsufficientProtection = 58
- TerminationWithSignatureRequested = 59
- AccessDenied = 60
- VersionNotSupported = 61
- SecuredLinkNotSupported = 62
- CertificateNotAvailable = 63
- AuditTrailInformationNotAvailable = 64