How to use the udsoncan.Response.Response 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 / ReadDTCInformation.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct

class ReadDTCInformation(BaseService):
    _sid = 0x19

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

    class Subfunction(BaseSubfunction):
        __pretty_name__ = 'subfunction'

        reportNumberOfDTCByStatusMask = 1
        reportDTCByStatusMask = 2
        reportDTCSnapshotIdentification = 3
        reportDTCSnapshotRecordByDTCNumber = 4
        reportDTCSnapshotRecordByRecordNumber = 5
        reportDTCExtendedDataRecordByDTCNumber = 6
        reportNumberOfDTCBySeverityMaskRecord = 7
        reportDTCBySeverityMaskRecord = 8
        reportSeverityInformationOfDTC = 9
        reportSupportedDTCs = 0xA
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
if data is not None:
			if not isinstance(data, bytes):
				raise ValueError('data must be a valid bytes object')

		self.setting_type = setting_type
		self.data = data

	def subfunction_id(self):
		return self.setting_type

class ResponseOnEvent(BaseService):
	_sid = 0x86

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

	def __init__(self):
		pass

class LinkControl(BaseService):
	_sid = 0x87

	supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
							Response.Code.IncorrectMessageLegthOrInvalidFormat,
							Response.Code.ConditionsNotCorrect,
							Response.Code.RequestSequenceError,
							Response.Code.RequestOutOfRange
							]
github pylessard / python-udsoncan / udsoncan / services / __init__.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
    def response_id(cls):
github pylessard / python-udsoncan / udsoncan / services / AccessTimingParameter.py View on Github external
class AccessTimingParameter(BaseService):
    _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

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

class SecurityAccess(BaseService):
    _sid = 0x27

    supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
                                                    Response.Code.IncorrectMessageLegthOrInvalidFormat,
                                                    Response.Code.ConditionsNotCorrect,
                                                    Response.Code.RequestSequenceError,
                                                    Response.Code.RequestOutOfRange,
                                                    Response.Code.InvalidKey,
                                                    Response.Code.ExceedNumberOfAttempts,
                                                    Response.Code.RequiredTimeDelayNotExpired
                                                    ]

    class Mode:
        RequestSeed=0
        SendKey=1

    @classmethod 
    def normalize_level(cls, mode, level):
        cls.validate_mode(mode)
github pylessard / python-udsoncan / udsoncan / services / DynamicallyDefineDataIdentifier.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *

class DynamicallyDefineDataIdentifier(BaseService):
    _sid = 0x2C

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

    @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__(DynamicallyDefineDataIdentifier)
github pylessard / python-udsoncan / udsoncan / services / ReadMemoryByAddress.py View on Github external
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *

class ReadMemoryByAddress(BaseService):
    _sid = 0x23
    _use_subfunction = False

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

    @classmethod
    def make_request(cls, memory_location):
        """
        Generates a request for ReadMemoryByAddress

        :param memory_location: The address and the size of the memory block to read.
        :type memory_location: :ref:`MemoryLocation `

        :raises ValueError: If parameters are out of range, missing or wrong type
        """		
        from udsoncan import Request, MemoryLocation
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`