How to use the udsoncan.services.BaseService 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 / Response.py View on Github external
def get_payload(self):
        """
        Generates a payload to be given to the underlying protocol.
        This method is meant to be used by a UDS server

        :return: A payload to be sent through the underlying protocol
        :rtype: bytes
        """
        from udsoncan import services
        if not isinstance(self.service, services.BaseService) and not issubclass(self.service, services.BaseService):
            raise ValueError("Cannot make payload from response object. Given service is not a valid service object")

        if not isinstance(self.code, int):
            raise ValueError("Cannot make payload from response object. Given response code is not a valid integer")

        payload  = b''
        if self.positive:
            payload += struct.pack("B", self.service.response_id())
        else:
            payload += b'\x7F'
            payload += struct.pack("B", self.service.request_id())
            payload += struct.pack('B', self.code)

        if self.data is not None and self.service.has_response_data():
            payload += self.data
        return payload
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
def is_valid_service(service_cls):
	return issubclass(service_cls, BaseService)
github pylessard / python-udsoncan / udsoncan / Response.py View on Github external
def __init__(self, service = None, code = None, data=None):
        from udsoncan import services
        if service is None:
            self.service = None
        elif isinstance(service, services.BaseService):
            self.service = service.__class__
        elif inspect.isclass(service) and issubclass(service, services.BaseService):
            self.service = service
        elif service is not None:
            raise ValueError("Given service must be a service class or instance")

        self.positive = False
        self.code = None
        self.code_name = ""
        self.valid = False
        self.invalid_reason = "Object not initialized"
        self.service_data = None
        self.original_payload = None
        self.unexpected = False

        self.service = service

        if data is not None:
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
def cls_from_response_id(given_id):
	return BaseService.from_response_id(given_id)
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
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):
	_sid = 0x85

	supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
							Response.Code.IncorrectMessageLegthOrInvalidFormat,
							Response.Code.ConditionsNotCorrect,
							Response.Code.RequestOutOfRange
							]
	class SettingType(BaseSubfunction):
		__pretty_name__ = 'setting type'

		on = 1
		off = 2
		vehicleManufacturerSpecific = (0x40, 0x5F)	# To be able to print textual name for logging only.
		systemSupplierSpecific = (0x60, 0x7E)		# To be able to print textual name for logging only.

	def __init__(self, setting_type, data = None):
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
_use_subfunction = False

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

	def __init__(self, memory_location):
		from udsoncan import MemoryLocation
		if not isinstance(memory_location, MemoryLocation):
			raise ValueError('Given memory location must be an instance of MemoryLocation')

		self.memory_location = memory_location

class ReadScalingDataByIdentifier(BaseService):
	_sid = 0x24

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

	def __init__(self):
		pass

class ReadDataByPeriodicIdentifier(BaseService):
	_sid = 0x2A

	supported_negative_response = [	 Response.Code.IncorrectMessageLegthOrInvalidFormat,
							Response.Code.ConditionsNotCorrect,
github pylessard / python-udsoncan / udsoncan / Response.py View on Github external
def __init__(self, service = None, code = None, data=None):
        from udsoncan import services
        if service is None:
            self.service = None
        elif isinstance(service, services.BaseService):
            self.service = service.__class__
        elif inspect.isclass(service) and issubclass(service, services.BaseService):
            self.service = service
        elif service is not None:
            raise ValueError("Given service must be a service class or instance")

        self.positive = False
        self.code = None
        self.code_name = ""
        self.valid = False
        self.invalid_reason = "Object not initialized"
        self.service_data = None
        self.original_payload = None
        self.unexpected = False

        self.service = service
github pylessard / python-udsoncan / udsoncan / Request.py View on Github external
def __init__(self, service = None, subfunction = None, suppress_positive_response = False, data=None):
        if service is None:
            self.service = None
        elif isinstance(service, services.BaseService):
            self.service = service.__class__
        elif inspect.isclass(service) and issubclass(service, services.BaseService):
            self.service = service
        elif service is not None:
            raise ValueError("Given service must be a service class or instance")

        if not isinstance(suppress_positive_response, bool):
            raise ValueError("suppress_positive_response must be a boolean value")

        if subfunction is not None:
            if isinstance(subfunction, int):
                self.subfunction = subfunction
            else:
                raise ValueError("Given subfunction must be a valid integer")
        else:
            self.subfunction = None
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
supported = True
		
		# As specified by Annex A, negative response code ranging above 0x7F can be used anytime if the service can return ConditionNotCorrect
		if code >= 0x80 and code < 0xFF and Response.Code.ConditionsNotCorrect in cls.supported_negative_response:
			supported = True

		# ISO-14229:2006 Table A.1 : "This response code shall be supported by each diagnostic service with a subfunction parameter"
		if code == Response.Code.SubFunctionNotSupportedInActiveSession and cls.use_subfunction():
			supported = True

		return supported

def is_valid_service(service_cls):
	return issubclass(service_cls, BaseService)

class DiagnosticSessionControl(BaseService):
	_sid = 0x10

	supported_negative_response = [	Response.Code.SubFunctionNotSupported, 
									Response.Code.IncorrectMessageLegthOrInvalidFormat,
									Response.Code.ConditionsNotCorrect
									]
	class Session(BaseSubfunction):
		__pretty_name__ = 'session'	# Only to print "custom session" instead of "custom subfunction"

		defaultSession = 1
		programmingSession = 2
		extendedDiagnosticSession = 3
		safetySystemDiagnosticSession = 4

	def __init__(self, session):
		if not isinstance(session, int):