diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index f1c6bea..69405b4 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -20,7 +20,7 @@ def __init__(self, callback, filter, bus): self.__bus = bus listener = can.Listener() listener.on_message_received = callback - self.__notifier = can.Notifier(self.__bus, [listener], 0) + self.__notifier = can.Notifier(self.__bus, [listener]) self.__listeners = [listener] self.addFilter(filter) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index aee217d..5d986e3 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -1,5 +1,5 @@ import can -from can.interfaces import pcan, vector +from can.interfaces import pcan, vector, kvaser from uds.uds_configuration.Config import Config from os import path from platform import system @@ -9,6 +9,8 @@ # used to conditionally import socketcan for linux to avoid error messages if system() == "Linux": from can.interfaces import socketcan +else: + from can.interfaces import ics_neovi class CanConnectionFactory(object): @@ -76,6 +78,20 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): else: raise Exception("SocketCAN on Pythoncan currently only supported in Linux") + elif connectionType == 'neovi': + channel = int(CanConnectionFactory.config['neovi']['channel']) + baudrate = int(CanConnectionFactory.config['can']['baudrate']) + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, + ics_neovi.NeoViBus(channel, + bitrate=baudrate)) + return CanConnectionFactory.connections[channel] + elif connectionType == 'kvaser': + channel = int(CanConnectionFactory.config['kvaser']['channel']) + baudrate = int(CanConnectionFactory.config['can']['baudrate']) + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, + kvaser.canlib.KvaserBus(channel, + bitrate=baudrate)) + return CanConnectionFactory.connections[channel] @staticmethod def loadConfiguration(configPath=None): @@ -107,4 +123,6 @@ def checkKwargs(**kwargs): if 'channel' in kwargs: CanConnectionFactory.config['vector']['channel'] = kwargs['channel'] + CanConnectionFactory.config['kvaser']['channel'] = kwargs['channel'] + CanConnectionFactory.config['neovi']['channel'] = kwargs['channel'] diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index bff4871..58c6f0e 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -176,8 +176,7 @@ def __checkKwargs(self, **kwargs): ## # @brief send method # @param [in] payload the payload to be sent - def send(self, payload, functionalReq=False): - + def send(self, payload, functionalReq=False,nodelay=False): payloadLength = len(payload) payloadPtr = 0 @@ -278,15 +277,15 @@ def send(self, payload, functionalReq=False): # timer / exit condition checks if(timeoutTimer.isExpired()): raise Exception("Timeout waiting for message") - - sleep(0.001) + if state != CanTpState.SEND_CONSECUTIVE_FRAME or nodelay==False: + sleep(.001) ## # @brief recv method # @param [in] timeout_ms The timeout to wait before exiting # @return a list def recv(self, timeout_s): - + #print("timeout_s passed to recv is " + str(timeout_s)) timeoutTimer = ResettableTimer(timeout_s) payload = [] diff --git a/uds/uds_communications/TransportProtocols/Can/config.ini b/uds/uds_communications/TransportProtocols/Can/config.ini index 30b33f1..c63620a 100644 --- a/uds/uds_communications/TransportProtocols/Can/config.ini +++ b/uds/uds_communications/TransportProtocols/Can/config.ini @@ -24,3 +24,9 @@ channel=0 [socketcan] channel=can0 + +[neovi] +channel=1 + +[kvaser] +channel=0 \ No newline at end of file diff --git a/uds/uds_communications/Uds/Uds.py b/uds/uds_communications/Uds/Uds.py index 35a3f55..9ff9536 100644 --- a/uds/uds_communications/Uds/Uds.py +++ b/uds/uds_communications/Uds/Uds.py @@ -119,7 +119,7 @@ def transferFile(self,fileName=None,transmitChunkSize=None,compressionMethod=Non ## # @brief - def send(self, msg, responseRequired=True, functionalReq=False): + def send(self, msg, responseRequired=True, functionalReq=False,nodelay=False): # sets a current transmission in progress - tester present (if running) will not send if this flag is set to true self.__transmissionActive_flag = True #print(("__transmissionActive_flag set:",self.__transmissionActive_flag)) @@ -129,7 +129,7 @@ def send(self, msg, responseRequired=True, functionalReq=False): # We're moving to threaded operation, so putting a lock around the send operation. self.sendLock.acquire() try: - a = self.tp.send(msg, functionalReq) + a = self.tp.send(msg, functionalReq,nodelay) finally: self.sendLock.release() diff --git a/uds/uds_config_tool/IHexFunctions.py b/uds/uds_config_tool/IHexFunctions.py index e4d41b5..1d9eae8 100644 --- a/uds/uds_config_tool/IHexFunctions.py +++ b/uds/uds_config_tool/IHexFunctions.py @@ -168,7 +168,11 @@ def __init__(self, filename=None, padding=0xFF, continuousBlocking=True): if recordType == ihexRecordType.Data: # ... We match data first as it's the most common record type, so more efficient if nextAddress is None: - currentBlock.startAddress = baseAddress + address + if currentBlock is None: + currentBlock = ihexData() #... start a new block + currentBlock.startAddress = address + else: + currentBlock.startAddress = baseAddress + address # As each line of data is individually addressed, there may be disconuities present in the data. # If so (i.e. a gap in the addressing), and a continuous record is required, then pad the data. @@ -210,8 +214,9 @@ def __init__(self, filename=None, padding=0xFF, continuousBlocking=True): raise NotImplemented("Start segment address not implemented") elif recordType == ihexRecordType.StartLinearAddress: - hexFile.close() - raise NotImplemented("Start linear address not implemented") + print("Found a Start Linear Address - Ignoring") + #hexFile.close() + #raise NotImplemented("Start linear address not implemented") hexFile.close() @property diff --git a/uds/uds_configuration/defaultConfig.ini b/uds/uds_configuration/defaultConfig.ini index 1f49172..b1ced58 100644 --- a/uds/uds_configuration/defaultConfig.ini +++ b/uds/uds_configuration/defaultConfig.ini @@ -5,8 +5,8 @@ interface=virtual baudrate=500 defaultReqId=0x600 defaultResId=0x650 -P2_Client=1 -P2_Server=1 +P2_Client=3 +P2_Server=3 P3_Client=1 [virtual]