How to use the udsoncan.Response.Response.Code function in udsoncan

To help you get started, we’ve selected a few udsoncan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pylessard / python-udsoncan / udsoncan / services / RequestTransferExit.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *

class RequestTransferExit(BaseService):
    _sid = 0x37
    _use_subfunction = False
    _no_response_data = True

    supported_negative_response = [	 Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.RequestSequenceError
                                                    ]

    @classmethod
    def make_request(cls, data=None):
        """
        Generates a request for RequestTransferExit

        :param data: Additional optional data to send to the server
        :type data: bytes

        :raises ValueError: If parameters are out of range, missing or wrong type
        """			
        from udsoncan import Request, MemoryLocation

        if data is not None and not isinstance(data, bytes):
github pylessard / python-udsoncan / udsoncan / services / TesterPresent.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *

class TesterPresent(BaseService):
    _sid = 0x3E

    supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
                                                    Response.Code.IncorrectMessageLegthOrInvalidFormat
                                                    ]	

    @classmethod
    def make_request(cls):
        """
        Generates a request for TesterPresent
        """		
        from udsoncan import Request
        return Request(service=cls, subfunction=0)

    @classmethod
    def interpret_response(cls, response):
        """
        Populates the response ``service_data`` property with an instance of :class:`TesterPresent.ResponseData`

        :param response: The received response to interpret
github pylessard / python-udsoncan / udsoncan / services / SecuredDataTransmission.py View on Github external
_sid = 0x84

    class Code:
        GeneralSecurityViolation 			= Response.Code.GeneralSecurityViolation			- 0x38
        SecuredModeRequested 				= Response.Code.SecuredModeRequested				- 0x38
        InsufficientProtection 				= Response.Code.InsufficientProtection				- 0x38
        TerminationWithSignatureRequested 	= Response.Code.TerminationWithSignatureRequested	- 0x38
        AccessDenied 						= Response.Code.AccessDenied						- 0x38
        VersionNotSupported 				= Response.Code.VersionNotSupported					- 0x38
        SecuredLinkNotSupported 			= Response.Code.SecuredLinkNotSupported				- 0x38
        CertificateNotAvailable 			= Response.Code.CertificateNotAvailable				- 0x38
        AuditTrailInformationNotAvailable 	= Response.Code.AuditTrailInformationNotAvailable	- 0x38

    supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
                                                    Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.GeneralSecurityViolation,
                                                    Response.Code.SecuredModeRequested,
                                                    Response.Code.InsufficientProtection,
                                                    Response.Code.TerminationWithSignatureRequested,
                                                    Response.Code.AccessDenied,
                                                    Response.Code.VersionNotSupported,
                                                    Response.Code.SecuredLinkNotSupported,
                                                    Response.Code.CertificateNotAvailable,
                                                    Response.Code.AuditTrailInformationNotAvailable
                                                    ]

    @classmethod
    def make_request(cls):
        raise NotImplementedError('Service is not implemented')

    @classmethod
    def interpret_response(cls, response):
github pylessard / python-udsoncan / udsoncan / services / SecuredDataTransmission.py View on Github external
InsufficientProtection 				= Response.Code.InsufficientProtection				- 0x38
        TerminationWithSignatureRequested 	= Response.Code.TerminationWithSignatureRequested	- 0x38
        AccessDenied 						= Response.Code.AccessDenied						- 0x38
        VersionNotSupported 				= Response.Code.VersionNotSupported					- 0x38
        SecuredLinkNotSupported 			= Response.Code.SecuredLinkNotSupported				- 0x38
        CertificateNotAvailable 			= Response.Code.CertificateNotAvailable				- 0x38
        AuditTrailInformationNotAvailable 	= Response.Code.AuditTrailInformationNotAvailable	- 0x38

    supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
                                                    Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.GeneralSecurityViolation,
                                                    Response.Code.SecuredModeRequested,
                                                    Response.Code.InsufficientProtection,
                                                    Response.Code.TerminationWithSignatureRequested,
                                                    Response.Code.AccessDenied,
                                                    Response.Code.VersionNotSupported,
                                                    Response.Code.SecuredLinkNotSupported,
                                                    Response.Code.CertificateNotAvailable,
                                                    Response.Code.AuditTrailInformationNotAvailable
                                                    ]

    @classmethod
    def make_request(cls):
        raise NotImplementedError('Service is not implemented')

    @classmethod
    def interpret_response(cls, response):
        raise NotImplementedError('Service is not implemented')

    class ResponseData(BaseResponseData):	
        def __init__(self):
            super().__init__(SecuredDataTransmission)
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
subfn_list = [a for a in attributes if not(a[0].startswith('__') and a[0].endswith('__'))]

		for subfn in subfn_list:
			if isinstance(subfn[1], int):
				if subfn[1] == subfn_id:	# [1] is value
					return subfn[0] 		# [0] is property name
			elif isinstance(subfn[1], tuple):
				if subfn_id >= subfn[1][0] or subfn_id <= subfn[1][1]:
					return subfn[0] 
		name = cls.__name__ if not hasattr(cls, '__pretty_name__') else cls.__pretty_name__
		return 'custom %s' % name

class BaseService(ABC):

	always_valid_negative_response = [
		Response.Code.GeneralReject,
		Response.Code.ServiceNotSupported,
		Response.Code.ResponseTooLong,
		Response.Code.BusyRepeatRequest,
		Response.Code.NoResponseFromSubnetComponent,
		Response.Code.FailurePreventsExecutionOfRequestedAction,
		Response.Code.SecurityAccessDenied, # ISO-14229:2006 Table A.1:  "Besides the mandatory use of this negative response code as specified in the applicable services within ISO 14229, this negative response code can also be used for any case where security is required and is not yet granted to perform the required service."
		Response.Code.RequestCorrectlyReceived_ResponsePending,
		Response.Code.ServiceNotSupportedInActiveSession

	]

	@classmethod	# Returns the service ID used for a client request
	def request_id(cls):
		return cls._sid

	@classmethod	# Returns the service ID used for a server response
github pylessard / python-udsoncan / udsoncan / Response.py View on Github external
self.service = service

        if data is not None:
            if not isinstance(data, bytes):
                raise ValueError("Given data must be a valid bytes object")

        self.data = data if data is not None else b''

        if code is not None:
            if not isinstance(code, int):
                raise ValueError("Response code must be a valid integer")
            elif code < 0 or code > 0xFF:
                raise ValueError("Response code must be an integer between 0 and 0xFF")
            self.code=code
            self.code_name = Response.Code.get_name(code)
            if not Response.Code.is_negative(code):
                self.positive=True

        if self.service is not None and self.code is not None:
            self.valid = True
            self.invalid_reason = ""
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
class SecuredDataTransmission(BaseService):
	_sid = 0x84

	class Code:
		GeneralSecurityViolation 			= Response.Code.GeneralSecurityViolation			- 0x38
		SecuredModeRequested 				= Response.Code.SecuredModeRequested				- 0x38
		InsufficientProtection 				= Response.Code.InsufficientProtection				- 0x38
		TerminationWithSignatureRequested 	= Response.Code.TerminationWithSignatureRequested	- 0x38
		AccessDenied 						= Response.Code.AccessDenied						- 0x38
		VersionNotSupported 				= Response.Code.VersionNotSupported					- 0x38
		SecuredLinkNotSupported 			= Response.Code.SecuredLinkNotSupported				- 0x38
		CertificateNotAvailable 			= Response.Code.CertificateNotAvailable				- 0x38
		AuditTrailInformationNotAvailable 	= Response.Code.AuditTrailInformationNotAvailable	- 0x38

	supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
							Response.Code.IncorrectMessageLegthOrInvalidFormat,
							Response.Code.GeneralSecurityViolation,
							Response.Code.SecuredModeRequested,
							Response.Code.InsufficientProtection,
							Response.Code.TerminationWithSignatureRequested,
							Response.Code.AccessDenied,
							Response.Code.VersionNotSupported,
							Response.Code.SecuredLinkNotSupported,
							Response.Code.CertificateNotAvailable,
							Response.Code.AuditTrailInformationNotAvailable
							]

	def __init__(self):
		pass

class ControlDTCSetting(BaseService):
github pylessard / python-udsoncan / udsoncan / services / AccessTimingParameter.py View on Github external
_sid = 0x83

    class AccessType(BaseSubfunction):
        """
        AccessTimingParameter defined subfunctions
        """

        __pretty_name__ = 'access type'

        readExtendedTimingParameterSet = 1
        setTimingParametersToDefaultValues = 2
        readCurrentlyActiveTimingParameters = 3
        setTimingParametersToGivenValues = 4

    supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
                                                    Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.ConditionsNotCorrect,
                                                    Response.Code.RequestOutOfRange
                                                    ]	

    @classmethod
    def make_request(cls, access_type, timing_param_record=None):
        """
        Generates a request for AccessTimingParameter

        :param access_type: Service subfunction. Allowed values are from 0 to 0x7F
        :type access_type: int

        :param timing_param_record: Data associated with request. Must be present only when access_type=``AccessType.setTimingParametersToGivenValues`` (4)
        :type timing_param_record: bytes

        :raises ValueError: If parameters are out of range, missing or wrong type
github pylessard / python-udsoncan / udsoncan / services / TransferData.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct

class TransferData(BaseService):
    _sid = 0x36
    _use_subfunction = False

    supported_negative_response = [	 Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.RequestSequenceError,
                                                    Response.Code.RequestOutOfRange,
                                                    Response.Code.TransferDataSuspended,
                                                    Response.Code.GeneralProgrammingFailure,
                                                    Response.Code.WrongBlockSequenceCounter,
                                                    Response.Code.VoltageTooHigh,
                                                    Response.Code.VoltageTooLow
                                                    ]

    @classmethod
    def make_request(cls, sequence_number, data=None):
        """
        Generates a request for TransferData

        :param sequence_number: Corresponds to an 8bit counter that should increment for each new block transferred.
                Allowed values are from 0 to 0xFF