Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct
class WriteDataByIdentifier(BaseService):
_sid = 0x2E
_use_subfunction = False
supported_negative_response = [ Response.Code.IncorrectMessageLegthOrInvalidFormat,
Response.Code.ConditionsNotCorrect,
Response.Code.RequestOutOfRange,
Response.Code.SecurityAccessDenied,
Response.Code.GeneralProgrammingFailure
]
@classmethod
def make_request(cls, did, value, didconfig):
"""
Generates a request for WriteDataByIdentifier
:param did: The data identifier to write
:type did: int
:param value: Value given to the :ref:`DidCodec `.encode method. If involved codec is defined with a pack string (default codec), multiple values may be passed with a tuple.
:type value: object
:param didconfig: Definition of DID codecs. Dictionary mapping a DID (int) to a valid :ref:`DidCodec ` class or pack/unpack string
:type didconfig: dict[int] = :ref:`DidCodec `
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct
class RequestDownload(BaseService):
_sid = 0x34
_use_subfunction = False
supported_negative_response = [ Response.Code.IncorrectMessageLegthOrInvalidFormat,
Response.Code.ConditionsNotCorrect,
Response.Code.RequestOutOfRange,
Response.Code.SecurityAccessDenied,
Response.Code.UploadDownloadNotAccepted
]
@classmethod
def normalize_data_format_identifier(cls, dfi):
from udsoncan import DataFormatIdentifier
if dfi is None:
dfi = DataFormatIdentifier()
if not isinstance(dfi, DataFormatIdentifier):
raise ValueError('dfi must be an instance of DataFormatIdentifier')
return dfi
@classmethod
def make_request(cls, memory_location, dfi=None):
"""
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
class ReadScalingDataByIdentifier(BaseService):
_sid = 0x24
supported_negative_response = [ 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__(ReadScalingDataByIdentifier)
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):
return cls._sid + 0x40
@classmethod # Returns an instance of the service identified by the service ID (Request)
def from_request_id(cls, given_id):
for name, obj in inspect.getmembers(sys.modules[__name__]):
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)
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
class ReadDataByPeriodicIdentifier(BaseService):
_sid = 0x2A
supported_negative_response = [ 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__(ReadDataByPeriodicIdentifier)
class ControlType(BaseSubfunction):
"""
RoutineControl defined subfunctions
"""
__pretty_name__ = 'control type'
startRoutine = 1
stopRoutine = 2
requestRoutineResults = 3
supported_negative_response = [ Response.Code.SubFunctionNotSupported,
Response.Code.IncorrectMessageLegthOrInvalidFormat,
Response.Code.ConditionsNotCorrect,
Response.Code.RequestSequenceError,
Response.Code.RequestOutOfRange,
Response.Code.SecurityAccessDenied,
Response.Code.GeneralProgrammingFailure
]
@classmethod
def make_request(cls, routine_id, control_type, data=None):
"""
Generates a request for RoutineControl
:param routine_id: The routine ID. Value should be between 0 and 0xFFFF
:type routine_id: int
:param control_type: Service subfunction. Allowed values are from 0 to 0x7F
:type control_type: bytes
:param data: Optional additional data to provide to the server
:type data: bytes
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct
class ReadDataByIdentifier(BaseService):
_sid = 0x22
_use_subfunction = False
supported_negative_response = [ Response.Code.IncorrectMessageLegthOrInvalidFormat,
Response.Code.ConditionsNotCorrect,
Response.Code.RequestOutOfRange,
Response.Code.SecurityAccessDenied
]
@classmethod
def validate_didlist_input(cls, dids):
if not isinstance(dids, int) and not isinstance(dids, list):
raise ValueError("Data Identifier must either be an integer or a list of integer")
if isinstance(dids, int):
ServiceHelper.validate_int(dids, min=0, max=0xFFFF, name='Data Identifier')
if isinstance(dids, list):
for did in dids:
ServiceHelper.validate_int(did, min=0, max=0xFFFF, name='Data Identifier')
return [dids] if not isinstance(dids, list) else dids
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
if not isinstance(memory_location, MemoryLocation):
raise ValueError('Given memory location must be an instance of MemoryLocation')
from . import *
from udsoncan.Response import Response
from udsoncan.exceptions import *
import struct
class RequestUpload(BaseService):
_sid = 0x35
_use_subfunction = False
supported_negative_response = [ Response.Code.IncorrectMessageLegthOrInvalidFormat,
Response.Code.ConditionsNotCorrect,
Response.Code.RequestOutOfRange,
Response.Code.SecurityAccessDenied,
Response.Code.UploadDownloadNotAccepted
]
@classmethod
def normalize_data_format_identifier(cls, dfi):
from udsoncan import DataFormatIdentifier
if dfi is None:
dfi = DataFormatIdentifier()
if not isinstance(dfi, DataFormatIdentifier):
raise ValueError('dfi must be an instance of DataFormatIdentifier')
return dfi
@classmethod
def make_request(cls, memory_location, dfi=None):
"""