From 75f083cc2c8da5a059f9f19759f331a08cb8b59c Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Fri, 18 Sep 2020 11:58:09 +0200 Subject: [PATCH 01/28] fix platform independent path --- MANIFEST.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index f9def91..6a71281 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ -include uds\uds_configuration\defaultConfig.ini -include uds\uds_communications\Uds\config.ini -include uds\uds_communications\TransportProtocols\config.ini -include uds\uds_communications\TransportProtocols\Can\config.ini -include uds\uds_communications\TransportProtocols\Lin\config.ini \ No newline at end of file +include uds/uds_configuration/defaultConfig.ini +include uds/uds_communications/Uds/config.ini +include uds/uds_communications/TransportProtocols/config.ini +include uds/uds_communications/TransportProtocols/Can/config.ini +include uds/uds_communications/TransportProtocols/Lin/config.ini \ No newline at end of file From d60fc5ddec80b7d7150e2a4983f3a46d35320c20 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Fri, 18 Sep 2020 11:58:32 +0200 Subject: [PATCH 02/28] add canfd support for physical interfaces --- .../TransportProtocols/Can/CanConnection.py | 20 +++++++++++++++ .../Can/CanConnectionFactory.py | 13 +++++----- .../TransportProtocols/Can/CanTp.py | 25 +++++++++++++------ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index f1c6bea..db98861 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -11,6 +11,7 @@ import can +from uds import fillArray ## # @brief Small class to wrap the CAN Bus/Notifier/Listeners to allow multiple clients for each bus/connection @@ -47,8 +48,27 @@ def addFilter(self, filter): def transmit(self, data, reqId, extended=False): canMsg = can.Message(arbitration_id=reqId, extended_id=extended) canMsg.dlc = 8 + + length = len(data) + if length <= 8: + canMsg.dlc = 8 + elif length <= 12: + canMsg.dlc = 12 + elif length <= 16: + canMsg.dlc = 16 + elif length <= 20: + canMsg.dlc = 20 + elif length <= 24: + canMsg.dlc = 24 + elif length <= 32: + canMsg.dlc = 32 + elif length <= 48: + canMsg.dlc = 48 + elif length <= 64: + canMsg.dlc = 64 canMsg.data = data + canMsg.is_fd = True self.__bus.send(canMsg) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index aee217d..96ff5ab 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -23,6 +23,9 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): # check config file and load connectionType = CanConnectionFactory.config['can']['interface'] + useFd = CanConnectionFactory.config['can']['canfd'] + baudrate = CanConnectionFactory.config['can']['baudrate'] + data_baudrate = CanConnectionFactory.config['can']['data_baudrate'] if connectionType == 'virtual': connectionName = CanConnectionFactory.config['virtual']['interfaceName'] @@ -38,10 +41,9 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): elif connectionType == 'peak': channel = CanConnectionFactory.config['peak']['device'] if channel not in CanConnectionFactory.connections: - baudrate = CanConnectionFactory.config['can']['baudrate'] CanConnectionFactory.connections[channel] = CanConnection(callback, filter, pcan.PcanBus(channel, - bitrate=baudrate)) + bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd)) else: CanConnectionFactory.connections[channel].addCallback(callback) CanConnectionFactory.connections[channel].addFilter(filter) @@ -55,9 +57,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): if connectionKey not in CanConnectionFactory.connections: baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, - vector.VectorBus(channel, - app_name=app_name, - data_bitrate=baudrate)) + can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd)) else: CanConnectionFactory.connections[connectionKey].addCallback(callback) CanConnectionFactory.connections[connectionKey].addFilter(filter) @@ -68,7 +68,8 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): channel = CanConnectionFactory.config['socketcan']['channel'] if channel not in CanConnectionFactory.connections: CanConnectionFactory.connections[channel] = CanConnection(callback, filter, - socketcan.SocketcanBus(channel=channel)) + socketcan.SocketcanBus(channel=channel, + fd=useFd, bitrate=baudrate, data_bitrate=data_baudrate)) else: CanConnectionFactory.connections[channel].addCallback(callback) CanConnectionFactory.connections[channel].addFilter(filter) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index bff4871..b92de96 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -82,13 +82,15 @@ def __init__(self, configPath=None, **kwargs): (self.__addressingType == CanTpAddressingTypes.NORMAL) | (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) ): - self.__maxPduLength = 7 + self.__minPduLength = 7 + self.__maxPduLength = 63 self.__pduStartIndex = 0 elif( (self.__addressingType == CanTpAddressingTypes.EXTENDED) | (self.__addressingType == CanTpAddressingTypes.MIXED) ): - self.__maxPduLength = 6 + self.__minPduLength = 6 + self.__maxPduLength = 62 self.__pduStartIndex = 1 # set up the CAN connection @@ -241,9 +243,14 @@ def send(self, payload, functionalReq=False): raise Exception("Unexpected response from device") if state == CanTpState.SEND_SINGLE_FRAME: - txPdu[N_PCI_INDEX] += (CanTpMessageType.SINGLE_FRAME << 4) - txPdu[SINGLE_FRAME_DL_INDEX] += payloadLength - txPdu[SINGLE_FRAME_DATA_START_INDEX:] = fillArray(payload, self.__maxPduLength) + if len(payload) < self.__minPduLength: + txPdu[N_PCI_INDEX] += (CanTpMessageType.SINGLE_FRAME << 4) + txPdu[SINGLE_FRAME_DL_INDEX] += payloadLength + txPdu[SINGLE_FRAME_DATA_START_INDEX:] = fillArray(payload, self.__minPduLength) + else: + txPdu[N_PCI_INDEX] = 0 + txPdu[FIRST_FRAME_DL_INDEX_LOW] = payloadLength + txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload self.transmit(txPdu, functionalReq) endOfMessage_flag = True elif state == CanTpState.SEND_FIRST_FRAME: @@ -279,7 +286,7 @@ def send(self, payload, functionalReq=False): if(timeoutTimer.isExpired()): raise Exception("Timeout waiting for message") - sleep(0.001) + #sleep(0.01) ## # @brief recv method @@ -307,7 +314,11 @@ def recv(self, timeout_s): rxPdu = self.getNextBufferedMessage() if rxPdu is not None: - N_PCI = (rxPdu[N_PCI_INDEX] & 0xF0) >> 4 + if rxPdu[N_PCI_INDEX] == 0x00: + rxPdu = rxPdu[1:] + N_PCI = 0 + else: + N_PCI = (rxPdu[N_PCI_INDEX] & 0xF0) >> 4 if state == CanTpState.IDLE: if N_PCI == CanTpMessageType.SINGLE_FRAME: payloadLength = rxPdu[N_PCI_INDEX & 0x0F] From 3928ab8824d1227ca7be8569060b9f74980906d8 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Fri, 18 Sep 2020 11:58:56 +0200 Subject: [PATCH 03/28] increment version to 1.2.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0a142eb..478aa59 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ # Needed for dependencies install_requires=['python-can>=3.0.0', 'python-lin>=0.1.0'], # *strongly* suggested for sharing - version='1.1.0', + version='1.2.0', # The license can be anything you like license='MIT', description='A library for interfacing with UDS using python', From f3ec8560517f486cb776bbc4c626ed65190649bd Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Thu, 22 Oct 2020 07:07:39 +0200 Subject: [PATCH 04/28] fix app_name parameter for CanConnectionFactory --- .../TransportProtocols/Can/CanConnectionFactory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index 96ff5ab..20c21eb 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -57,7 +57,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): if connectionKey not in CanConnectionFactory.connections: baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, - can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd)) + can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) else: CanConnectionFactory.connections[connectionKey].addCallback(callback) CanConnectionFactory.connections[connectionKey].addFilter(filter) From f0371816cc160578401ed489a8a402f1fc8d55b3 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Fri, 4 Dec 2020 15:22:15 +0100 Subject: [PATCH 05/28] add cast --- .../TransportProtocols/Can/CanConnectionFactory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index 20c21eb..79a26c5 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -25,7 +25,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): connectionType = CanConnectionFactory.config['can']['interface'] useFd = CanConnectionFactory.config['can']['canfd'] baudrate = CanConnectionFactory.config['can']['baudrate'] - data_baudrate = CanConnectionFactory.config['can']['data_baudrate'] + data_baudrate = int(CanConnectionFactory.config['can']['data_baudrate']) if connectionType == 'virtual': connectionName = CanConnectionFactory.config['virtual']['interfaceName'] From b586c3348ee66126e3aea1db089c5b351c451d60 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Sat, 5 Dec 2020 17:41:25 +0100 Subject: [PATCH 06/28] add connection shutdown to free can channel --- .../TransportProtocols/Can/CanConnection.py | 8 ++++++++ uds/uds_communications/TransportProtocols/Can/CanTp.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index db98861..5c3de3f 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -72,3 +72,11 @@ def transmit(self, data, reqId, extended=False): self.__bus.send(canMsg) + def shutdown(self): + self.__notifier.stop() + self.__bus.reset() + self.__bus.shutdown() + self.__bus = None + + def get_bus(self): + return self.__bus diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index b92de96..73d7f55 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -363,7 +363,8 @@ def recv(self, timeout_s): def closeConnection(self): # deregister filters, listeners and notifiers etc # close can connection - pass + self.__connection.shutdown() + self.__connection = None ## # @brief clear out the receive list From 6176bca27cffe8d80e848352ece9401fe7193574 Mon Sep 17 00:00:00 2001 From: "EXTERNAL Bekhechi Fahd (TS, EB/ENS)" Date: Fri, 11 Dec 2020 13:46:46 +0100 Subject: [PATCH 07/28] - Parse Data from ODX file of type Integer into an array of bytes based on data bit length instead of integer type. - Negative response returns dictionary with NRC value instead of throwing exception. - Set can message dlc to its length (the bus DLC is already handled in python-can). - Update unit tests for the function containers. --- .../Unit Tests/unittest_ClearDTCFunction.py | 12 +- ...ttest_DiagnosticSessionControlFunctions.py | 58 +++---- .../Unit Tests/unittest_ECUResetFunctions.py | 12 +- .../Unit Tests/unittest_IOControlFunction.py | 26 +-- .../Unit Tests/unittest_RDBIFunctions.py | 24 +-- .../Unit Tests/unittest_ReadDTCFunctions.py | 12 +- .../unittest_ReqDownloadFunctions.py | 62 +++---- .../Unit Tests/unittest_ReqUploadFunctions.py | 52 +++--- .../unittest_RoutineControlFunctions.py | 154 +++++++++--------- .../Unit Tests/unittest_SecurityAccess.py | 8 +- .../unittest_TesterPresentFunctions.py | 32 ++-- .../Unit Tests/unittest_TranDataFunctions.py | 126 +++++++------- .../Unit Tests/unittest_TranExitFunctions.py | 36 ++-- .../Unit Tests/unittest_WDBIFunctions.py | 24 +-- uds/__init__.py | 4 + .../TransportProtocols/Can/CanConnection.py | 20 +-- .../Can/CanConnectionFactory.py | 49 +++++- uds/uds_config_tool/DecodeFunctions.py | 34 ++++ .../FunctionCreation/ClearDTCMethodFactory.py | 29 ++-- .../DiagnosticSessionControlMethodFactory.py | 30 ++-- .../FunctionCreation/ECUResetMethodFactory.py | 31 ++-- .../InputOutputControlMethodFactory.py | 51 +++--- .../FunctionCreation/ReadDTCMethodFactory.py | 31 ++-- .../ReadDataByIdentifierMethodFactory.py | 30 ++-- .../RequestDownloadMethodFactory.py | 29 ++-- .../RequestUploadMethodFactory.py | 29 ++-- .../RoutineControlMethodFactory.py | 51 +++--- .../SecurityAccessMethodFactory.py | 36 +++- .../TesterPresentMethodFactory.py | 29 ++-- .../TransferDataMethodFactory.py | 29 ++-- .../TransferExitMethodFactory.py | 29 ++-- .../WriteDataByIdentifierMethodFactory.py | 53 +++--- .../SupportedServices/ClearDTCContainer.py | 4 +- .../DiagnosticSessionControlContainer.py | 4 +- .../SupportedServices/ECUResetContainer.py | 4 +- .../InputOutputControlContainer.py | 4 +- .../SupportedServices/ReadDTCContainer.py | 4 +- .../ReadDataByIdentifierContainer.py | 4 +- .../RequestDownloadContainer.py | 4 +- .../RequestUploadContainer.py | 4 +- .../RoutineControlContainer.py | 4 +- .../SecurityAccessContainer.py | 6 +- .../TesterPresentContainer.py | 4 +- .../TransferDataContainer.py | 4 +- .../TransferExitContainer.py | 4 +- .../WriteDataByIdentifierContainer.py | 4 +- 46 files changed, 737 insertions(+), 553 deletions(-) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_ClearDTCFunction.py b/test/Uds-Config-Tool/Unit Tests/unittest_ClearDTCFunction.py index 47bc107..34062d3 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_ClearDTCFunction.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_ClearDTCFunction.py @@ -49,7 +49,7 @@ def test_ecuResetNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x14, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -60,7 +60,7 @@ def test_ecuResetNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x14, 0xF1, 0xC8, 0x55],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order @@ -71,7 +71,7 @@ def test_ecuResetNegResponse_0x22(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x22] + tp_recv.return_value = [0x7F, 0x14, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -82,7 +82,7 @@ def test_ecuResetNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x14, 0xF1, 0xC8, 0x55],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) + self.assertEqual(0x22, b['NRC']) # patches are inserted in reverse order @@ -93,7 +93,7 @@ def test_ecuResetNegResponse_0x31(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x31] + tp_recv.return_value = [0x7F, 0x14, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -104,7 +104,7 @@ def test_ecuResetNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x14, 0xF1, 0xC8, 0x55],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) + self.assertEqual(0x31, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_DiagnosticSessionControlFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_DiagnosticSessionControlFunctions.py index e79b611..4b438ef 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_DiagnosticSessionControlFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_DiagnosticSessionControlFunctions.py @@ -20,8 +20,8 @@ class DiagnosticSessionControlTestCase(unittest.TestCase): # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlRequestDfltNoSuppress(self, canTp_send, canTp_recv): @@ -30,7 +30,7 @@ def test_diagSessCtrlRequestDfltNoSuppress(self, canTp_recv.return_value = [0x50, 0x01, 0x00, 0x05, 0x00, 0x0A] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session') # ... calls __diagnosticSessionControl, which does the Uds.send @@ -39,8 +39,8 @@ def test_diagSessCtrlRequestDfltNoSuppress(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlRequestNoSuppress(self, canTp_send, canTp_recv): @@ -49,7 +49,7 @@ def test_diagSessCtrlRequestNoSuppress(self, canTp_recv.return_value = [0x50, 0x01, 0x00, 0x05, 0x00, 0x0A] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session',suppressResponse=False) # ... calls __diagnosticSessionControl, which does the Uds.send @@ -58,14 +58,14 @@ def test_diagSessCtrlRequestNoSuppress(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlRequestSuppress(self, canTp_send): canTp_send.return_value = False # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session',suppressResponse=True) # ... calls __diagnosticSessionControl, which does the Uds.send @@ -76,8 +76,8 @@ def test_diagSessCtrlRequestSuppress(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlRequestProgrammingSession(self, canTp_send, canTp_recv): @@ -86,7 +86,7 @@ def test_diagSessCtrlRequestProgrammingSession(self, canTp_recv.return_value = [0x50, 0x02, 0x00, 0x06, 0x00, 0x09] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Programming Session') # ... calls __diagnosticSessionControl, which does the Uds.send @@ -95,8 +95,8 @@ def test_diagSessCtrlRequestProgrammingSession(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlRequestExtendedDiagnosticSession(self, canTp_send, canTp_recv): @@ -105,7 +105,7 @@ def test_diagSessCtrlRequestExtendedDiagnosticSession(self, canTp_recv.return_value = [0x50, 0x03, 0x00, 0x07, 0x00, 0x08] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Extended Diagnostic Session') # ... calls __diagnosticSessionControl, which does the Uds.send @@ -115,17 +115,17 @@ def test_diagSessCtrlRequestExtendedDiagnosticSession(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlNegResponse_0x12(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x12] + canTp_recv.return_value = [0x7F, 0x10, 0x12] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below try: @@ -133,21 +133,21 @@ def test_diagSessCtrlNegResponse_0x12(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x10, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x12']", b) # ... diagnosticSessionControl should not return a value + self.assertEqual(0x12, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x10, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below try: @@ -155,21 +155,21 @@ def test_diagSessCtrlNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x10, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... diagnosticSessionControl should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_diagSessCtrlNegResponse_0x22(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x22] + canTp_recv.return_value = [0x7F, 0x10, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below try: @@ -177,7 +177,7 @@ def test_diagSessCtrlNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x10, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... diagnosticSessionControl should not return a value + self.assertEqual(0x22, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_ECUResetFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_ECUResetFunctions.py index 822d449..35dda54 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_ECUResetFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_ECUResetFunctions.py @@ -84,7 +84,7 @@ def test_ecuResetNegResponse_0x12(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x12] + tp_recv.return_value = [0x7F, 0x11, 0x12] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -95,7 +95,7 @@ def test_ecuResetNegResponse_0x12(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x11, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x12']", b) # ... wdbi should not return a value + self.assertEqual(0x12, b['NRC']) # patches are inserted in reverse order @@ -106,7 +106,7 @@ def test_ecuResetNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x11, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -117,7 +117,7 @@ def test_ecuResetNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x11, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... wdbi should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order @@ -128,7 +128,7 @@ def test_ecuResetNegResponse_0x22(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x22] + tp_recv.return_value = [0x7F, 0x11, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -139,7 +139,7 @@ def test_ecuResetNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x11, 0x01],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... wdbi should not return a value + self.assertEqual(0x22, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_IOControlFunction.py b/test/Uds-Config-Tool/Unit Tests/unittest_IOControlFunction.py index 9e528eb..b2051ba 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_IOControlFunction.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_IOControlFunction.py @@ -34,7 +34,7 @@ def test_ioControlRequest_adjust(self, a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __inputOutputControl to inputOutputControl in the uds object, so can now call below - b = a.inputOutputControl('Booster Target Speed',IsoOptionRecord.adjust,[8000]) # ... calls __inputOutputControl, which does the Uds.send + b = a.inputOutputControl('Booster Target Speed', IsoOptionRecord.adjust, 8000) # ... calls __inputOutputControl, which does the Uds.send tp_send.assert_called_with([0x2F, 0xFE, 0x16, 0x03, 0x00, 0x00, 0x1F, 0x40],False) self.assertEqual({'Identifier':[0xFE, 0x16],'ControlOptionRecord':[IsoOptionRecord.adjust],'TargetSpeed':[0x00, 0x00, 0x1F, 0x40]}, b) @@ -68,18 +68,18 @@ def test_ecuResetNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x2F, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __inputOutputControl to inputOutputControl in the uds object, so can now call below try: - b = a.inputOutputControl('Booster Target Speed',IsoOptionRecord.adjust,[8000]) # ... calls __inputOutputControl, which does the Uds.send + b = a.inputOutputControl('Booster Target Speed', IsoOptionRecord.adjust, 8000) # ... calls __inputOutputControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2F, 0xFE, 0x16, 0x03, 0x00, 0x00, 0x1F, 0x40],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) + self.assertEqual(0x13, b['NRC']) @@ -91,18 +91,18 @@ def test_ecuResetNegResponse_0x22(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x22] + tp_recv.return_value = [0x7F, 0x2F, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __inputOutputControl to inputOutputControl in the uds object, so can now call below try: - b = a.inputOutputControl('Booster Target Speed',IsoOptionRecord.adjust,[8000]) # ... calls __inputOutputControl, which does the Uds.send + b = a.inputOutputControl('Booster Target Speed', IsoOptionRecord.adjust, 8000) # ... calls __inputOutputControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2F, 0xFE, 0x16, 0x03, 0x00, 0x00, 0x1F, 0x40],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) + self.assertEqual(0x22, b['NRC']) @@ -114,18 +114,18 @@ def test_ecuResetNegResponse_0x31(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x31] + tp_recv.return_value = [0x7F, 0x2F, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __inputOutputControl to inputOutputControl in the uds object, so can now call below try: - b = a.inputOutputControl('Booster Target Speed',IsoOptionRecord.adjust,[8000]) # ... calls __inputOutputControl, which does the Uds.send + b = a.inputOutputControl('Booster Target Speed', IsoOptionRecord.adjust, 8000) # ... calls __inputOutputControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2F, 0xFE, 0x16, 0x03, 0x00, 0x00, 0x1F, 0x40],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) + self.assertEqual(0x31, b['NRC']) @@ -137,18 +137,18 @@ def test_ecuResetNegResponse_0x33(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x33] + tp_recv.return_value = [0x7F, 0x2F, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __inputOutputControl to inputOutputControl in the uds object, so can now call below try: - b = a.inputOutputControl('Booster Target Speed',IsoOptionRecord.adjust,[8000]) # ... calls __inputOutputControl, which does the Uds.send + b = a.inputOutputControl('Booster Target Speed', IsoOptionRecord.adjust, 8000) # ... calls __inputOutputControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2F, 0xFE, 0x16, 0x03, 0x00, 0x00, 0x1F, 0x40],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) + self.assertEqual(0x33, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_RDBIFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_RDBIFunctions.py index 5e26abb..572a9dd 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_RDBIFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_RDBIFunctions.py @@ -117,12 +117,12 @@ def test_rdbiMultipleDIDAlternativeOrdering(self, # patches are inserted in reverse order @mock.patch('uds.TestTp.recv') @mock.patch('uds.TestTp.send') - def test_ecuResetNegResponse_0x13(self, + def test_rdbiNegResponse_0x13(self, tp_send, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x22, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -133,18 +133,18 @@ def test_ecuResetNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x22, 0xF1, 0x8C],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... wdbi should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order @mock.patch('uds.TestTp.recv') @mock.patch('uds.TestTp.send') - def test_ecuResetNegResponse_0x22(self, + def test_rdbiNegResponse_0x22(self, tp_send, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x22] + tp_recv.return_value = [0x7F, 0x22, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -155,18 +155,18 @@ def test_ecuResetNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x22, 0xF1, 0x8C],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... wdbi should not return a value + self.assertEqual(0x22, b['NRC']) # patches are inserted in reverse order @mock.patch('uds.TestTp.recv') @mock.patch('uds.TestTp.send') - def test_ecuResetNegResponse_0x31(self, + def test_rdbiNegResponse_0x31(self, tp_send, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x31] + tp_recv.return_value = [0x7F, 0x22, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -177,18 +177,18 @@ def test_ecuResetNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x22, 0xF1, 0x8C],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) # ... wdbi should not return a value + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order @mock.patch('uds.TestTp.recv') @mock.patch('uds.TestTp.send') - def test_ecuResetNegResponse_0x33(self, + def test_rdbiNegResponse_0x33(self, tp_send, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x33] + tp_recv.return_value = [0x7F, 0x22, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -199,7 +199,7 @@ def test_ecuResetNegResponse_0x33(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x22, 0xF1, 0x8C],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) # ... wdbi should not return a value + self.assertEqual(0x33, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_ReadDTCFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_ReadDTCFunctions.py index 1a63ba1..5f3cca3 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_ReadDTCFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_ReadDTCFunctions.py @@ -383,7 +383,7 @@ def test_readDTCNegResponse_0x12(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x12] + tp_recv.return_value = [0x7F, 0x19, 0x12] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -394,7 +394,7 @@ def test_readDTCNegResponse_0x12(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x19, 0x02, 0x28],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x12']", b) + self.assertEqual(0x12, b['NRC']) @@ -406,7 +406,7 @@ def test_readDTCNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x19, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -417,7 +417,7 @@ def test_readDTCNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x19, 0x02, 0x28],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order @@ -428,7 +428,7 @@ def test_readDTCNegResponse_0x31(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x31] + tp_recv.return_value = [0x7F, 0x19, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/EBC-Diagnostics_old.odx', 'bootloader', transportProtocol="TEST") @@ -439,7 +439,7 @@ def test_readDTCNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x19, 0x02, 0x28],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) + self.assertEqual(0x31, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_ReqDownloadFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_ReqDownloadFunctions.py index 1e751d0..af43144 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_ReqDownloadFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_ReqDownloadFunctions.py @@ -20,8 +20,8 @@ class RequestDownloadTestCase(unittest.TestCase): # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqDownloadRequest(self, canTp_send, canTp_recv): @@ -30,7 +30,7 @@ def test_reqDownloadRequest(self, canTp_recv.return_value = [0x74, 0x20, 0x05, 0x00] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestDownload to requestDownload in the uds object, so can now call below b = a.requestDownload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # ... calls __requestDownload, which does the Uds.send @@ -41,8 +41,8 @@ def test_reqDownloadRequest(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqDownloadRequest02(self, canTp_send, canTp_recv): @@ -51,7 +51,7 @@ def test_reqDownloadRequest02(self, canTp_recv.return_value = [0x74, 0x40, 0x01, 0x00, 0x05, 0x08] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestDownload to requestDownload in the uds object, so can now call below b = a.requestDownload(FormatIdentifier=[0x00],MemoryAddress=[0x01, 0xFF, 0x0A, 0x80],MemorySize=[0x03, 0xFF]) # ... calls __requestDownload, which does the Uds.send @@ -62,17 +62,17 @@ def test_reqDownloadRequest02(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqDownloadNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x34, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestDownload to requestDownload in the uds object, so can now call below try: @@ -80,7 +80,7 @@ def test_reqDownloadNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... requestDownload should not return a value + self.assertEqual(0x13, b['NRC']) @@ -88,17 +88,17 @@ def test_reqDownloadNegResponse_0x13(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x22(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x22] + canTp_recv.return_value = [0x7F, 0x34, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -106,22 +106,22 @@ def test_wdbiNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... wdbi should not return a value + self.assertEqual(0x22, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x31(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x31] + canTp_recv.return_value = [0x7F, 0x34, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -129,21 +129,21 @@ def test_wdbiNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) # ... wdbi should not return a value + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x33(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x33] + canTp_recv.return_value = [0x7F, 0x34, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -151,21 +151,21 @@ def test_wdbiNegResponse_0x33(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) # ... wdbi should not return a value + self.assertEqual(0x33, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x72(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x72] + canTp_recv.return_value = [0x7F, 0x34, 0x72] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -173,7 +173,7 @@ def test_wdbiNegResponse_0x72(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x72']", b) # ... wdbi should not return a value + self.assertEqual(0x72, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_ReqUploadFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_ReqUploadFunctions.py index 084410e..1d43370 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_ReqUploadFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_ReqUploadFunctions.py @@ -25,8 +25,8 @@ class RequestUploadTestCase(unittest.TestCase): # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqUploadRequest(self, canTp_send, canTp_recv): @@ -35,7 +35,7 @@ def test_reqUploadRequest(self, canTp_recv.return_value = [0x74, 0x20, 0x05, 0x00] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestUpload to requestUpload in the uds object, so can now call below b = a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # ... calls __requestUpload, which does the Uds.send @@ -46,8 +46,8 @@ def test_reqUploadRequest(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqUploadRequest02(self, canTp_send, canTp_recv): @@ -56,7 +56,7 @@ def test_reqUploadRequest02(self, canTp_recv.return_value = [0x74, 0x40, 0x01, 0x00, 0x05, 0x08] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestUpload to requestUpload in the uds object, so can now call below b = a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x01, 0xFF, 0x0A, 0x80],MemorySize=[0x03, 0xFF]) # ... calls __requestUpload, which does the Uds.send @@ -67,17 +67,17 @@ def test_reqUploadRequest02(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_reqUploadNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x34, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __requestUpload to requestUpload in the uds object, so can now call below try: @@ -85,22 +85,22 @@ def test_reqUploadNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... requestUpload should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x31(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x31] + canTp_recv.return_value = [0x7F, 0x34, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -108,21 +108,21 @@ def test_wdbiNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) # ... wdbi should not return a value + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x33(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x33] + canTp_recv.return_value = [0x7F, 0x34, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -130,21 +130,21 @@ def test_wdbiNegResponse_0x33(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) # ... wdbi should not return a value + self.assertEqual(0x33, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_wdbiNegResponse_0x70(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x70] + canTp_recv.return_value = [0x7F, 0x34, 0x70] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __readDataByIdentifier to readDataByIdentifier in the uds object, so can now call below try: @@ -152,7 +152,7 @@ def test_wdbiNegResponse_0x70(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x34, 0x00, 0x44, 0x40, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x0E, 0x56],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x70']", b) # ... wdbi should not return a value + self.assertEqual(0x70, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_RoutineControlFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_RoutineControlFunctions.py index a3f5310..d406644 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_RoutineControlFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_RoutineControlFunctions.py @@ -17,11 +17,11 @@ import sys, traceback from uds.uds_config_tool.ISOStandard.ISOStandard import IsoRoutineControlType -class ECUResetTestCase(unittest.TestCase): +class RoutineControlTestCase(unittest.TestCase): # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestDfltNoSuppress(self, canTp_send, canTp_recv): @@ -30,18 +30,18 @@ def test_routineControlRequestDfltNoSuppress(self, canTp_recv.return_value = [0x71, 0x01, 0xFF, 0x00, 0x30] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) self.assertEqual({'Erase Memory Status':[0x30],'RoutineControlType':[0x01],'Identifier':[0xFF, 0x00]}, b) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestNoSuppress(self, canTp_send, canTp_recv): @@ -50,35 +50,35 @@ def test_routineControlRequestNoSuppress(self, canTp_recv.return_value = [0x71, 0x01, 0xFF, 0x00, 0x30] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])],suppressResponse=False) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)],suppressResponse=False) # ... calls __routineControl, which does the Uds.send canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) self.assertEqual({'Erase Memory Status':[0x30],'RoutineControlType':[0x01],'Identifier':[0xFF, 0x00]}, b) # patches are inserted in reverse order - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.send') def test_routineControlRequestSuppress(self, canTp_send): canTp_send.return_value = False # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])],suppressResponse=True) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)],suppressResponse=True) # ... calls __routineControl, which does the Uds.send canTp_send.assert_called_with([0x31, 0x81, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) self.assertEqual(None, b) # ... routineControl should not return a value # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestStop(self, canTp_send, canTp_recv): @@ -87,7 +87,7 @@ def test_routineControlRequestStop(self, canTp_recv.return_value = [0x71, 0x02, 0xFF, 0x00] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below b = a.routineControl('Erase Memory',IsoRoutineControlType.stopRoutine) # ... calls __routineControl, which does the Uds.send @@ -97,8 +97,8 @@ def test_routineControlRequestStop(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestRequestResult(self, canTp_send, canTp_recv): @@ -107,7 +107,7 @@ def test_routineControlRequestRequestResult(self, canTp_recv.return_value = [0x71, 0x03, 0xFF, 0x00, 0x30] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below b = a.routineControl('Erase Memory',IsoRoutineControlType.requestRoutineResults) # ... calls __routineControl, which does the Uds.send @@ -117,8 +117,8 @@ def test_routineControlRequestRequestResult(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestCheckAppStart(self, canTp_send, canTp_recv): @@ -127,7 +127,7 @@ def test_routineControlRequestCheckAppStart(self, canTp_recv.return_value = [0x71, 0x01, 0x03, 0x04, 0x30, 0x02] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below b = a.routineControl('Check Valid Application',IsoRoutineControlType.startRoutine) # ... calls __routineControl, which does the Uds.send @@ -136,8 +136,8 @@ def test_routineControlRequestCheckAppStart(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestCheckAppStartResult(self, canTp_send, canTp_recv): @@ -146,7 +146,7 @@ def test_routineControlRequestCheckAppStartResult(self, canTp_recv.return_value = [0x71, 0x03, 0x03, 0x04, 0x30, 0x02] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below b = a.routineControl('Check Valid Application',IsoRoutineControlType.requestRoutineResults) # ... calls __routineControl, which does the Uds.send @@ -157,8 +157,8 @@ def test_routineControlRequestCheckAppStartResult(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestSBLStart(self, canTp_send, canTp_recv): @@ -167,18 +167,18 @@ def test_routineControlRequestSBLStart(self, canTp_recv.return_value = [0x71, 0x01, 0x03, 0x01, 0xA7] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below - b = a.routineControl('Start Secondary Bootloader',IsoRoutineControlType.startRoutine,[0xFF]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Start Secondary Bootloader',IsoRoutineControlType.startRoutine,0xFF) # ... calls __routineControl, which does the Uds.send canTp_send.assert_called_with([0x31, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0xFF],False) self.assertEqual({'strSBLRoutineInfo':[0xA7],'RoutineControlType':[0x01],'Identifier':[0x03, 0x01]}, b) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestProgDepStart(self, canTp_send, canTp_recv): @@ -187,17 +187,17 @@ def test_routineControlRequestProgDepStart(self, canTp_recv.return_value = [0x71, 0x01, 0xFF, 0x01, 0x30, 0xB9, 0x2E] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below - b = a.routineControl('Check Programming Dependencies',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Check Programming Dependencies',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) self.assertEqual({'RoutineStatusInfo':[0x30],'Check Sum Value':[0xB9, 0x2E],'RoutineControlType':[0x01],'Identifier':[0xFF, 0x01]}, b) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_routineControlRequestProgDepResult(self, canTp_send, canTp_recv): @@ -206,7 +206,7 @@ def test_routineControlRequestProgDepResult(self, canTp_recv.return_value = [0x71, 0x03, 0xFF, 0x01, 0x30, 0xB9, 0x2E] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below b = a.routineControl('Check Programming Dependencies',IsoRoutineControlType.requestRoutineResults) # ... calls __routineControl, which does the Uds.send @@ -216,157 +216,157 @@ def test_routineControlRequestProgDepResult(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x12(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x12] + canTp_recv.return_value = [0x7F, 0x31, 0x12] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x12']", b) + self.assertEqual(0x12, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x31, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x22(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x22] + canTp_recv.return_value = [0x7F, 0x31, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) + self.assertEqual(0x22, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x24(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x24] + canTp_recv.return_value = [0x7F, 0x31, 0x24] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x24']", b) + self.assertEqual(0x24, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x31(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x31] + canTp_recv.return_value = [0x7F, 0x31, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x33(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x33] + canTp_recv.return_value = [0x7F, 0x31, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) + self.assertEqual(0x33, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_ecuResetNegResponse_0x72(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x72] + canTp_recv.return_value = [0x7F, 0x31, 0x72] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __routineControl to routineControl in the uds object, so can now call below try: - b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) # ... calls __routineControl, which does the Uds.send + b = a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',0x01),('memorySize',0xF000)]) # ... calls __routineControl, which does the Uds.send except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x31, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x72']", b) + self.assertEqual(0x72, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_SecurityAccess.py b/test/Uds-Config-Tool/Unit Tests/unittest_SecurityAccess.py index 223008e..93e454e 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_SecurityAccess.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_SecurityAccess.py @@ -45,17 +45,17 @@ def test_securityAccessNegativeResponse(self, tp_send, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x00, 0x00] + tp_recv.return_value = [0x7F, 0x21, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") - with self.assertRaises(Exception) as context: - b = a.securityAccess('Programming Request') + b = a.securityAccess('Programming Request') - self.assertTrue("Found negative response" in str(context.exception)) + tp_send.assert_called_with([0x27, 0x01], False) + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order @mock.patch('uds.TestTp.recv') diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_TesterPresentFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_TesterPresentFunctions.py index 962a011..81a00bc 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_TesterPresentFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_TesterPresentFunctions.py @@ -85,7 +85,7 @@ def test_ecuResetNegResponse_0x12(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x12] + tp_recv.return_value = [0x7F, 0x3E, 0x12] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -96,7 +96,7 @@ def test_ecuResetNegResponse_0x12(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x3E, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x12']", b) + self.assertEqual(0x12, b['NRC']) # patches are inserted in reverse order @@ -107,7 +107,7 @@ def test_ecuResetNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x3E, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -118,12 +118,12 @@ def test_ecuResetNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x3E, 0x00],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_testerPresentNotReqd(self, canTp_send, canTp_recv): @@ -132,7 +132,7 @@ def test_testerPresentNotReqd(self, canTp_recv.return_value = [0x50, 0x01, 0x00, 0x05, 0x00, 0x0A] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the testerPresent info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session') # ... calls __diagnosticSessionControl, which does the Uds.send @@ -143,8 +143,8 @@ def test_testerPresentNotReqd(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_testerPresentReqdDfltTO(self, canTp_send, canTp_recv): @@ -153,7 +153,7 @@ def test_testerPresentReqdDfltTO(self, canTp_recv.return_value = [0x50, 0x01, 0x00, 0x05, 0x00, 0x0A] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the testerPresent info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session',testerPresent=True) # ... calls __diagnosticSessionControl, which does the Uds.send @@ -164,8 +164,8 @@ def test_testerPresentReqdDfltTO(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_testerPresentReqdUpdatedTO(self, canTp_send, canTp_recv): @@ -174,7 +174,7 @@ def test_testerPresentReqdUpdatedTO(self, canTp_recv.return_value = [0x50, 0x01, 0x00, 0x05, 0x00, 0x0A] # ... can return 1 to N bytes in the sessionParameterRecord - looking into this one # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the testerPresent info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below b = a.diagnosticSessionControl('Default Session',testerPresent=True,tpTimeout=250) # ... calls __diagnosticSessionControl, which does the Uds.send @@ -185,8 +185,8 @@ def test_testerPresentReqdUpdatedTO(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_testerPresentSessionSwitching(self, canTp_send, canTp_recv): @@ -194,7 +194,7 @@ def test_testerPresentSessionSwitching(self, canTp_send.return_value = False # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the testerPresent info and attaches the __diagnosticSessionControl to diagnosticSessionControl in the uds object, so can now call below # Confirm initial default session with no tester present handling ... diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_TranDataFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_TranDataFunctions.py index dfc29e7..98520ca 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_TranDataFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_TranDataFunctions.py @@ -22,8 +22,8 @@ class TransferDataTestCase(unittest.TestCase): """ Note: this has been run with a modified Uds.py transferIHexFile() function to skip the reqDownload and transExit (I couldn't figure out how to mock these here) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex(self, canTp_send, canTp_recv, @@ -34,7 +34,7 @@ def test_transDataRequest_ihex(self, canTp_recv.return_value = [0x76, 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below b = a.transferFile("./unitTest01.hex",1280) # ... calls __transferData, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -46,8 +46,8 @@ def test_transDataRequest_ihex(self, """ REMOVING THIS TEST AS "block" list is no longer exposed this way ... # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex01(self, canTp_send, canTp_recv): @@ -59,7 +59,7 @@ def test_transDataRequest_ihex01(self, app_blocks.transmitChunksize = 1280 # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below b = a.transferData(transferBlock=app_blocks.block[0]) # ... calls __transferData, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -70,8 +70,8 @@ def test_transDataRequest_ihex01(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex02(self, canTp_send, canTp_recv): @@ -83,7 +83,7 @@ def test_transDataRequest_ihex02(self, app_blocks.transmitChunksize = 1280 # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below b = a.transferData(transferBlocks=app_blocks) # ... calls __transferData, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -94,8 +94,8 @@ def test_transDataRequest_ihex02(self, """ REMOVING THIS TEST AS "block" list is no longer exposed this way ... # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex03(self, canTp_send, canTp_recv): @@ -116,8 +116,8 @@ def test_transDataRequest_ihex03(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex04(self, canTp_send, canTp_recv): @@ -126,7 +126,7 @@ def test_transDataRequest_ihex04(self, canTp_recv.return_value = [0x76, 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader',ihexFile="./unitTest01.hex") + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader',ihexFile="./unitTest01.hex", transportProtocol="TEST") a.ihexFile.transmitChunksize = 1280 # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below @@ -137,8 +137,8 @@ def test_transDataRequest_ihex04(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest_ihex05(self, canTp_send, canTp_recv): @@ -147,7 +147,7 @@ def test_transDataRequest_ihex05(self, canTp_recv.return_value = [0x76, 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") a.ihexFile = "./unitTest01.hex" a.ihexFile.transmitChunksize = 1280 # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below @@ -159,8 +159,8 @@ def test_transDataRequest_ihex05(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequest(self, canTp_send, canTp_recv): @@ -169,7 +169,7 @@ def test_transDataRequest(self, canTp_recv.return_value = [0x76, 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below b = a.transferData(0x01,[0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) # ... calls __transferData, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -179,8 +179,8 @@ def test_transDataRequest(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataRequestSeq02(self, canTp_send, canTp_recv): @@ -189,7 +189,7 @@ def test_transDataRequestSeq02(self, canTp_recv.return_value = [0x76, 0x02, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below b = a.transferData(0x02,[0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) # ... calls __transferData, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -201,17 +201,17 @@ def test_transDataRequestSeq02(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x36, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -219,21 +219,21 @@ def test_transDataNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... transferData should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x24(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x24] + canTp_recv.return_value = [0x7F, 0x36, 0x24] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -241,21 +241,21 @@ def test_transDataNegResponse_0x24(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x24']", b) # ... transferData should not return a value + self.assertEqual(0x24, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x31(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x31] + canTp_recv.return_value = [0x7F, 0x36, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -263,21 +263,21 @@ def test_transDataNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) # ... transferData should not return a value + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x71(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x71] + canTp_recv.return_value = [0x7F, 0x36, 0x71] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -285,21 +285,21 @@ def test_transDataNegResponse_0x71(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x71']", b) # ... transferData should not return a value + self.assertEqual(0x71, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x72(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x72] + canTp_recv.return_value = [0x7F, 0x36, 0x72] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -307,21 +307,21 @@ def test_transDataNegResponse_0x72(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x72']", b) # ... transferData should not return a value + self.assertEqual(0x72, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x73(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x73] + canTp_recv.return_value = [0x7F, 0x36, 0x73] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -329,21 +329,21 @@ def test_transDataNegResponse_0x73(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x73']", b) # ... transferData should not return a value + self.assertEqual(0x73, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x92(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x92] + canTp_recv.return_value = [0x7F, 0x36, 0x92] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -351,21 +351,21 @@ def test_transDataNegResponse_0x92(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x92']", b) # ... transferData should not return a value + self.assertEqual(0x92, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transDataNegResponse_0x93(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x93] + canTp_recv.return_value = [0x7F, 0x36, 0x93] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferData to transferData in the uds object, so can now call below try: @@ -373,7 +373,7 @@ def test_transDataNegResponse_0x93(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x36, 0x01, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x93']", b) # ... transferData should not return a value + self.assertEqual(0x93, b['NRC']) if __name__ == "__main__": diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_TranExitFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_TranExitFunctions.py index 1513cc3..43a365b 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_TranExitFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_TranExitFunctions.py @@ -20,8 +20,8 @@ class TransferExitTestCase(unittest.TestCase): # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transExitRequest(self, canTp_send, canTp_recv): @@ -30,7 +30,7 @@ def test_transExitRequest(self, canTp_recv.return_value = [0x77, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferExit to transferExit in the uds object, so can now call below b = a.transferExit([0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) # ... calls __transferExit, which does the Uds.send - takes blockSequenceCounter and parameterRecord @@ -39,17 +39,17 @@ def test_transExitRequest(self, # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transExitNegResponse_0x13(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x13] + canTp_recv.return_value = [0x7F, 0x37, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferExit to transferExit in the uds object, so can now call below try: @@ -57,21 +57,21 @@ def test_transExitNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x37, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... transferExit should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transExitNegResponse_0x22(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x22] + canTp_recv.return_value = [0x7F, 0x37, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferExit to transferExit in the uds object, so can now call below try: @@ -79,21 +79,21 @@ def test_transExitNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x37, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... transferExit should not return a value + self.assertEqual(0x22, b['NRC']) # patches are inserted in reverse order - @mock.patch('uds.CanTp.recv') - @mock.patch('uds.CanTp.send') + @mock.patch('uds.TestTp.recv') + @mock.patch('uds.TestTp.send') def test_transExitNegResponse_0x24(self, canTp_send, canTp_recv): canTp_send.return_value = False - canTp_recv.return_value = [0x7F, 0x24] + canTp_recv.return_value = [0x7F, 0x37, 0x24] # Parameters: xml file (odx file), ecu name (not currently used) ... - a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader') + a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") # ... creates the uds object and returns it; also parses out the rdbi info and attaches the __transferExit to transferExit in the uds object, so can now call below try: @@ -101,7 +101,7 @@ def test_transExitNegResponse_0x24(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text canTp_send.assert_called_with([0x37, 0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x24']", b) # ... transferExit should not return a value + self.assertEqual(0x24, b['NRC']) diff --git a/test/Uds-Config-Tool/Unit Tests/unittest_WDBIFunctions.py b/test/Uds-Config-Tool/Unit Tests/unittest_WDBIFunctions.py index 3eef7af..8cd1dd0 100644 --- a/test/Uds-Config-Tool/Unit Tests/unittest_WDBIFunctions.py +++ b/test/Uds-Config-Tool/Unit Tests/unittest_WDBIFunctions.py @@ -56,7 +56,7 @@ def test_wdbiMixedRequest(self, b = a.writeDataByIdentifier('Boot Software Identification',[('Boot Software Identification','SwId12345678901234567890'),('numberOfModules',[0x01])]) # ... calls __readDataByIdentifier, which does the Uds.send - tp_send.assert_called_with([0x2E, 0xF1, 0x80, 0x00, 0x00, 0x00, 0x01, 0x53, 0x77, 0x49, 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30],False) + tp_send.assert_called_with([0x2E, 0xF1, 0x80, 0x01, 0x53, 0x77, 0x49, 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30],False) self.assertEqual(None, b) # ... wdbi should not return a value @@ -77,7 +77,7 @@ def test_wdbiMixedRequestReverseOrder(self, b = a.writeDataByIdentifier('Boot Software Identification',[('numberOfModules',[0x01]),('Boot Software Identification','SwId12345678901234567890')]) # ... calls __readDataByIdentifier, which does the Uds.send - tp_send.assert_called_with([0x2E, 0xF1, 0x80, 0x00, 0x00, 0x00, 0x01, 0x53, 0x77, 0x49, 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30],False) + tp_send.assert_called_with([0x2E, 0xF1, 0x80, 0x01, 0x53, 0x77, 0x49, 0x64, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30],False) self.assertEqual(None, b) # ... wdbi should not return a value @@ -90,7 +90,7 @@ def test_wdbiNegResponse_0x13(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x13] + tp_recv.return_value = [0x7F, 0x2E, 0x13] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -101,7 +101,7 @@ def test_wdbiNegResponse_0x13(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2E, 0xF1, 0x8C, 0x41, 0x42, 0x43, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x36],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x13']", b) # ... wdbi should not return a value + self.assertEqual(0x13, b['NRC']) # patches are inserted in reverse order @@ -112,7 +112,7 @@ def test_wdbiNegResponse_0x22(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x22] + tp_recv.return_value = [0x7F, 0x2E, 0x22] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -123,7 +123,7 @@ def test_wdbiNegResponse_0x22(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2E, 0xF1, 0x8C, 0x41, 0x42, 0x43, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x36],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x22']", b) # ... wdbi should not return a value + self.assertEqual(0x22, b['NRC']) @@ -135,7 +135,7 @@ def test_wdbiNegResponse_0x31(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x31] + tp_recv.return_value = [0x7F, 0x2E, 0x31] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -146,7 +146,7 @@ def test_wdbiNegResponse_0x31(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2E, 0xF1, 0x8C, 0x41, 0x42, 0x43, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x36],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x31']", b) # ... wdbi should not return a value + self.assertEqual(0x31, b['NRC']) # patches are inserted in reverse order @@ -157,7 +157,7 @@ def test_wdbiNegResponse_0x33(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x33] + tp_recv.return_value = [0x7F, 0x2E, 0x33] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -168,7 +168,7 @@ def test_wdbiNegResponse_0x33(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2E, 0xF1, 0x8C, 0x41, 0x42, 0x43, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x36],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x33']", b) # ... wdbi should not return a value + self.assertEqual(0x33, b['NRC']) # patches are inserted in reverse order @@ -179,7 +179,7 @@ def test_wdbiNegResponse_0x72(self, tp_recv): tp_send.return_value = False - tp_recv.return_value = [0x7F, 0x72] + tp_recv.return_value = [0x7F, 0x2E, 0x72] # Parameters: xml file (odx file), ecu name (not currently used) ... a = createUdsConnection('../Functional Tests/Bootloader.odx', 'bootloader', transportProtocol="TEST") @@ -190,7 +190,7 @@ def test_wdbiNegResponse_0x72(self, except: b = traceback.format_exc().split("\n")[-2:-1][0] # ... extract the exception text tp_send.assert_called_with([0x2E, 0xF1, 0x8C, 0x41, 0x42, 0x43, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x36],False) - self.assertEqual("Exception: Detected negative response: ['0x7f', '0x72']", b) # ... wdbi should not return a value + self.assertEqual(0x72, b['NRC']) if __name__ == "__main__": diff --git a/uds/__init__.py b/uds/__init__.py index 20d1a27..b6a5f2a 100644 --- a/uds/__init__.py +++ b/uds/__init__.py @@ -34,6 +34,10 @@ from uds.uds_config_tool import FunctionCreation from uds.uds_config_tool import SupportedServices from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoRoutineControlType +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoInputOutputControlOptionRecord +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoReadDTCSubfunction +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoReadDTCStatusMask from uds.uds_config_tool.IHexFunctions import ihexFile # main uds import diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index 5c3de3f..8c5e4ee 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -47,26 +47,8 @@ def addFilter(self, filter): # @brief transmits the data over can using can connection def transmit(self, data, reqId, extended=False): canMsg = can.Message(arbitration_id=reqId, extended_id=extended) - canMsg.dlc = 8 + canMsg.dlc = len(data) - length = len(data) - if length <= 8: - canMsg.dlc = 8 - elif length <= 12: - canMsg.dlc = 12 - elif length <= 16: - canMsg.dlc = 16 - elif length <= 20: - canMsg.dlc = 20 - elif length <= 24: - canMsg.dlc = 24 - elif length <= 32: - canMsg.dlc = 32 - elif length <= 48: - canMsg.dlc = 48 - elif length <= 64: - canMsg.dlc = 64 - canMsg.data = data canMsg.is_fd = True diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index 79a26c5..918e799 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -14,6 +14,7 @@ class CanConnectionFactory(object): connections = {} config = None + bus = None @staticmethod def __call__(callback=None, filter=None, configPath=None, **kwargs): @@ -24,7 +25,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): # check config file and load connectionType = CanConnectionFactory.config['can']['interface'] useFd = CanConnectionFactory.config['can']['canfd'] - baudrate = CanConnectionFactory.config['can']['baudrate'] + baudrate = int(CanConnectionFactory.config['can']['baudrate']) data_baudrate = int(CanConnectionFactory.config['can']['data_baudrate']) if connectionType == 'virtual': @@ -39,11 +40,35 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): return CanConnectionFactory.connections[connectionName] elif connectionType == 'peak': - channel = CanConnectionFactory.config['peak']['device'] + channel = CanConnectionFactory.config['peak']['device'] if channel not in CanConnectionFactory.connections: - CanConnectionFactory.connections[channel] = CanConnection(callback, filter, - pcan.PcanBus(channel, - bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd)) + if CanConnectionFactory.bus: + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, CanConnectionFactory.bus) + else: + f_clock_mhz = int(CanConnectionFactory.config['peak']['f_clock_mhz']) + nom_brp = int(CanConnectionFactory.config['peak']['nom_brp']) + nom_tseg1 = int(CanConnectionFactory.config['peak']['nom_tseg1']) + nom_tseg2 = int(CanConnectionFactory.config['peak']['nom_tseg2']) + nom_sjw = int(CanConnectionFactory.config['peak']['nom_sjw']) + data_brp = int(CanConnectionFactory.config['peak']['data_brp']) + data_tseg1 = int(CanConnectionFactory.config['peak']['data_tseg1']) + data_tseg2 = int(CanConnectionFactory.config['peak']['data_tseg2']) + data_sjw = int(CanConnectionFactory.config['peak']['data_sjw']) + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, + can.interface.Bus(interface='pcan', + channel=channel, + state=can.bus.BusState['ACTIVE'], + bitrate=500000, + fd=useFd, + f_clock_mhz=f_clock_mhz, + nom_brp=nom_brp, + nom_tseg1=nom_tseg1, + nom_tseg2=nom_tseg2, + nom_sjw=nom_sjw, + data_brp=data_brp, + data_tseg1=data_tseg1, + data_tseg2=data_tseg2, + data_sjw=data_sjw)) else: CanConnectionFactory.connections[channel].addCallback(callback) CanConnectionFactory.connections[channel].addFilter(filter) @@ -52,12 +77,15 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): elif connectionType == 'vector': channel = int(CanConnectionFactory.config['vector']['channel']) - app_name = CanConnectionFactory.config['vector']['appName'] + app_name = CanConnectionFactory.config['vector']['appName'] connectionKey = str("{0}_{1}").format(app_name, channel) if connectionKey not in CanConnectionFactory.connections: - baudrate = int(CanConnectionFactory.config['can']['baudrate']) - CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, - can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) + if CanConnectionFactory.bus: + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, CanConnectionFactory.bus) + else: + serial = int(CanConnectionFactory.config['vector']['serial']) + CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, + can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, serial=serial, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) else: CanConnectionFactory.connections[connectionKey].addCallback(callback) CanConnectionFactory.connections[connectionKey].addFilter(filter) @@ -109,3 +137,6 @@ def checkKwargs(**kwargs): if 'channel' in kwargs: CanConnectionFactory.config['vector']['channel'] = kwargs['channel'] + if 'bus' in kwargs: + CanConnectionFactory.bus = kwargs['bus'] + diff --git a/uds/uds_config_tool/DecodeFunctions.py b/uds/uds_config_tool/DecodeFunctions.py index 707c9d3..981c854 100644 --- a/uds/uds_config_tool/DecodeFunctions.py +++ b/uds/uds_config_tool/DecodeFunctions.py @@ -82,6 +82,24 @@ def intArrayToIntArray(aArray, inputType, outputType): output = list(map(buildIntFromList, [result[(i * size):(i * size + size)] for i in range(numberOfEntries)])) return output +## +# @brief convert an data input of integer type to a list of bytes. +def intValueToByteArray(intInput, bitLength): + if not isinstance(intInput, int): + return intInput + + if (bitLength <= 8): + inputFunc = lambda x: [x] + elif (bitLength <= 16): + inputFunc = lambda x: [extractIntFromPosition(x, 8, 8), extractIntFromPosition(x, 8, 0)] + elif (bitLength <= 24): + inputFunc = lambda x: [extractIntFromPosition(x, 8, 16), extractIntFromPosition(x, 8, 8), extractIntFromPosition(x, 8, 0)] + elif (bitLength <= 32): + inputFunc = lambda x: [extractIntFromPosition(x, 8, 24), extractIntFromPosition(x, 8, 16), extractIntFromPosition(x, 8, 8), extractIntFromPosition(x, 8, 0)] + else: + raise TypeError('input length of integer type is too long!') + + return(inputFunc(intInput)) if __name__ == "__main__": a = intArrayToIntArray([0x5AA55AA5, 0xA55AA55A], 'int32', 'int32') @@ -120,3 +138,19 @@ def intArrayToIntArray(aArray, inputType, outputType): a = intArrayToUInt8Array([0x01], 'int8') print(a) + + a= intValueToByteArray([0x00, 0xB1], 16) + print(a) + assert ([0x00, 0xB1] == a) + + a= intValueToByteArray([0x00, 0xB1], 32) + print(a) + assert ([0x00, 0xB1] == a) + + a= intValueToByteArray(0xB1, 16) + print(a) + assert ([0x00, 0xB1] == a) + + a= intValueToByteArray(0xB1, 32) + print(a) + assert ([0x00, 0x00, 0x00, 0xB1] == a) diff --git a/uds/uds_config_tool/FunctionCreation/ClearDTCMethodFactory.py b/uds/uds_config_tool/FunctionCreation/ClearDTCMethodFactory.py index 1bce69a..de2eec3 100644 --- a/uds/uds_config_tool/FunctionCreation/ClearDTCMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/ClearDTCMethodFactory.py @@ -29,7 +29,12 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " return") @@ -162,6 +167,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -169,16 +176,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/DiagnosticSessionControlMethodFactory.py b/uds/uds_config_tool/FunctionCreation/DiagnosticSessionControlMethodFactory.py index 228372c..b4c098c 100644 --- a/uds/uds_config_tool/FunctionCreation/DiagnosticSessionControlMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/DiagnosticSessionControlMethodFactory.py @@ -33,7 +33,12 @@ " if(sessionType != sessionTypeExpected): raise Exception(\"Session Type Received not as expected. Expected: {{0}}; Got {{1}}\".format(sessionTypeExpected, sessionType))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") # Note: we do not need to cater for response suppression checking as nothing to check if response is suppressed - always unsuppressed encodePositiveResponseFuncTemplate = str("def {0}(input):\n" @@ -288,6 +293,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -295,16 +302,19 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) + exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/ECUResetMethodFactory.py b/uds/uds_config_tool/FunctionCreation/ECUResetMethodFactory.py index d471f3f..41c2420 100644 --- a/uds/uds_config_tool/FunctionCreation/ECUResetMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/ECUResetMethodFactory.py @@ -34,7 +34,12 @@ " if(resetType != resetTypeExpected): raise Exception(\"Reset Type Received not as expected. Expected: {{0}}; Got {{1}}\".format(resetTypeExpected, resetType))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") # Note: we do not need to cater for response suppression checking as nothing to check if response is suppressed - always unsuppressed encodePositiveResponseFuncTemplate = str("def {0}(input):\n" @@ -283,6 +288,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -290,16 +297,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/InputOutputControlMethodFactory.py b/uds/uds_config_tool/FunctionCreation/InputOutputControlMethodFactory.py index 2d6d41a..0cca0fb 100644 --- a/uds/uds_config_tool/FunctionCreation/InputOutputControlMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/InputOutputControlMethodFactory.py @@ -38,7 +38,12 @@ " if(optionRecord != optionRecordExpected): raise Exception(\"Option Record Received not as expected. Expected: {{0}}; Got {{1}}\".format(optionRecordExpected, optionRecord))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " result = {{}}\n" @@ -83,29 +88,15 @@ def create_requestFunction(diagServiceElement, xmlElements): # Catching any exceptions where we don't know the type - these will fail elsewhere, but at least we can test what does work. try: encodingType = dataObjectElement.find('DIAG-CODED-TYPE').attrib['BASE-DATA-TYPE'] + bitLength = dataObjectElement.find('DIAG-CODED-TYPE').find('BIT-LENGTH').text except: encodingType = "unknown" # ... for now just drop into the "else" catch-all if(encodingType) == "A_ASCIISTRING": functionStringList = "DecodeFunctions.stringToIntList(drDict['{0}'], None)".format(longName) functionStringSingle = "DecodeFunctions.stringToIntList(dataRecord, None)" - elif(encodingType) == "A_INT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int8', 'int8')" - elif(encodingType) == "A_INT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int16', 'int8')" - elif(encodingType) == "A_INT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int32', 'int8')" - elif(encodingType) == "A_UINT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint8', 'int8')" - elif(encodingType) == "A_UINT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint16', 'int8')" - elif(encodingType) == "A_UINT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint32', 'int8')" + elif (encodingType in ("A_INT8", "A_INT16", "A_INT32", "A_UINT8", "A_UINT16", "A_UINT32")): + functionStringList = "DecodeFunctions.intValueToByteArray(drDict['{0}'], {1})".format(longName, bitLength) + functionStringSingle = "DecodeFunctions.intValueToByteArray(dataRecord, {0})".format(bitLength) else: functionStringList = "drDict['{0}']".format(longName) functionStringSingle = "dataRecord" @@ -348,6 +339,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -355,16 +348,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/ReadDTCMethodFactory.py b/uds/uds_config_tool/FunctionCreation/ReadDTCMethodFactory.py index 83bb7ea..0819e7d 100644 --- a/uds/uds_config_tool/FunctionCreation/ReadDTCMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/ReadDTCMethodFactory.py @@ -31,7 +31,12 @@ "{7}") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " encoded = []\n" @@ -253,6 +258,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -260,16 +267,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/ReadDataByIdentifierMethodFactory.py b/uds/uds_config_tool/FunctionCreation/ReadDataByIdentifierMethodFactory.py index f6d8644..83b034f 100644 --- a/uds/uds_config_tool/FunctionCreation/ReadDataByIdentifierMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/ReadDataByIdentifierMethodFactory.py @@ -40,7 +40,12 @@ " return {1}") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input,offset):\n" " result = {{}}\n" @@ -247,6 +252,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -254,16 +261,19 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('LOWER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass + + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/RequestDownloadMethodFactory.py b/uds/uds_config_tool/FunctionCreation/RequestDownloadMethodFactory.py index 789ac0e..b9110f1 100644 --- a/uds/uds_config_tool/FunctionCreation/RequestDownloadMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/RequestDownloadMethodFactory.py @@ -30,7 +30,12 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " result = {{}}\n" @@ -201,6 +206,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -208,16 +215,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/RequestUploadMethodFactory.py b/uds/uds_config_tool/FunctionCreation/RequestUploadMethodFactory.py index 89a06a6..0abecde 100644 --- a/uds/uds_config_tool/FunctionCreation/RequestUploadMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/RequestUploadMethodFactory.py @@ -30,7 +30,12 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " result = {{}}\n" @@ -201,6 +206,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -208,16 +215,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/RoutineControlMethodFactory.py b/uds/uds_config_tool/FunctionCreation/RoutineControlMethodFactory.py index 4d6ad13..3a24ec0 100644 --- a/uds/uds_config_tool/FunctionCreation/RoutineControlMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/RoutineControlMethodFactory.py @@ -42,7 +42,12 @@ " if(routineId != routineIdExpected): raise Exception(\"Routine Id Received not as expected. Expected: {{0}}; Got {{1}}\".format(routineIdExpected, routineId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") # Note: we do not need to cater for response suppression checking as nothing to check if response is suppressed - always unsuppressed encodePositiveResponseFuncTemplate = str("def {0}(input):\n" @@ -100,29 +105,15 @@ def create_requestFunction(diagServiceElement, xmlElements): # Catching any exceptions where we don't know the type - these will fail elsewhere, but at least we can test what does work. try: encodingType = dataObjectElement.find('DIAG-CODED-TYPE').attrib['BASE-DATA-TYPE'] + bitLength = dataObjectElement.find('DIAG-CODED-TYPE').find('BIT-LENGTH').text except: encodingType = "unknown" # ... for now just drop into the "else" catch-all ?????????????????????????????????????????????? if(encodingType) == "A_ASCIISTRING": functionStringList = "DecodeFunctions.stringToIntList(drDict['{0}'], None)".format(longName) functionStringSingle = "DecodeFunctions.stringToIntList(optionRecord, None)" - elif(encodingType) == "A_INT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'int8', 'int8')" - elif(encodingType) == "A_INT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'int16', 'int8')" - elif(encodingType) == "A_INT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'int32', 'int8')" - elif(encodingType) == "A_UINT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'uint8', 'int8')" - elif(encodingType) == "A_UINT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'uint16', 'int8')" - elif(encodingType) == "A_UINT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(optionRecord, 'uint32', 'int8')" + elif (encodingType in ("A_INT8", "A_INT16", "A_INT32", "A_UINT8", "A_UINT16", "A_UINT32")): + functionStringList = "DecodeFunctions.intValueToByteArray(drDict['{0}'], {1})".format(longName, bitLength) + functionStringSingle = "DecodeFunctions.intValueToByteArray(optionRecord, {0})".format(bitLength) else: functionStringList = "drDict['{0}']".format(longName) functionStringSingle = "optionRecord" @@ -382,6 +373,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -389,16 +382,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/SecurityAccessMethodFactory.py b/uds/uds_config_tool/FunctionCreation/SecurityAccessMethodFactory.py index 573353e..ef05fd8 100644 --- a/uds/uds_config_tool/FunctionCreation/SecurityAccessMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/SecurityAccessMethodFactory.py @@ -47,10 +47,13 @@ " if expectedDataLength != len(data): raise Exception(\"Returned data length not expected\")" ) -checkNegativeResponseTemplate = str("def {0}(data):\n" - " if data[0] == 0x7F: raise Exception(\"Found negative response\")" - ) - +checkNegativeResponseTemplate = str("def {0}(input):\n" + " result = {{}}\n" + " nrcList = {1}\n" + " if input[0] == 0x7F:\n" + " result['NRC'] = input[2]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") ## # inputs: # Length @@ -179,8 +182,31 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): checkNegativeResponseFunctionName = "check_{0}_negResponse".format(diagInstanceQualifier) - checkNegativeResponseFunctionString = checkNegativeResponseTemplate.format(checkNegativeResponseFunctionName) + negativeResponsesElement = diagServiceElement.find('NEG-RESPONSE-REFS') + + negativeResponseChecks = [] + + for negativeResponse in negativeResponsesElement: + negativeResponseRef = xmlElements[negativeResponse.attrib['ID-REF']] + + negativeResponseParams = negativeResponseRef.find('PARAMS') + + for param in negativeResponseParams: + bytePosition = int(param.find('BYTE-POSITION').text) + + if bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass + pass + checkNegativeResponseFunctionString = checkNegativeResponseTemplate.format(checkNegativeResponseFunctionName, expectedNrcDict) exec(checkNegativeResponseFunctionString) return locals()[checkNegativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/TesterPresentMethodFactory.py b/uds/uds_config_tool/FunctionCreation/TesterPresentMethodFactory.py index 7cfb198..d265756 100644 --- a/uds/uds_config_tool/FunctionCreation/TesterPresentMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/TesterPresentMethodFactory.py @@ -29,7 +29,12 @@ " if(zeroSubFunction != 0x00): raise Exception(\"Zero Sub Function Received not as expected. Expected {{0}}; Got {{1}}\".format(0x00,zeroSubFunction))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") # Note: we do not need to cater for response suppression checking as nothing to check if response is suppressed - always unsuppressed. # For tester present there is no response data to return, so hardcoding an empty response. @@ -160,6 +165,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -167,16 +174,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/TransferDataMethodFactory.py b/uds/uds_config_tool/FunctionCreation/TransferDataMethodFactory.py index f4ef688..11368b8 100644 --- a/uds/uds_config_tool/FunctionCreation/TransferDataMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/TransferDataMethodFactory.py @@ -24,7 +24,12 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " result = {{}}\n" @@ -164,6 +169,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -171,16 +178,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/TransferExitMethodFactory.py b/uds/uds_config_tool/FunctionCreation/TransferExitMethodFactory.py index ce61172..b861c0a 100644 --- a/uds/uds_config_tool/FunctionCreation/TransferExitMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/TransferExitMethodFactory.py @@ -26,7 +26,12 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))") negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " result = {{}}\n" @@ -165,6 +170,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -172,16 +179,18 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/FunctionCreation/WriteDataByIdentifierMethodFactory.py b/uds/uds_config_tool/FunctionCreation/WriteDataByIdentifierMethodFactory.py index fd316c4..02e11ee 100644 --- a/uds/uds_config_tool/FunctionCreation/WriteDataByIdentifierMethodFactory.py +++ b/uds/uds_config_tool/FunctionCreation/WriteDataByIdentifierMethodFactory.py @@ -35,8 +35,14 @@ " if(serviceId != serviceIdExpected): raise Exception(\"Service Id Received not expected. Expected {{0}}; Got {{1}} \".format(serviceIdExpected, serviceId))\n" " if(diagnosticId != diagnosticIdExpected): raise Exception(\"Diagnostic Id Received not as expected. Expected: {{0}}; Got {{1}}\".format(diagnosticIdExpected, diagnosticId))") + negativeResponseFuncTemplate = str("def {0}(input):\n" - " {1}") + " result = {{}}\n" + " nrcList = {5}\n" + " if input[{1}:{2}] == [{3}]:\n" + " result['NRC'] = input[{4}]\n" + " result['NRC_Label'] = nrcList.get(result['NRC'])\n" + " return result") encodePositiveResponseFuncTemplate = str("def {0}(input):\n" " return") @@ -75,29 +81,15 @@ def create_requestFunction(diagServiceElement, xmlElements): # Catching any exceptions where we don't know the type - these will fail elsewhere, but at least we can test what does work. try: encodingType = dataObjectElement.find('DIAG-CODED-TYPE').attrib['BASE-DATA-TYPE'] + bitLength = dataObjectElement.find('DIAG-CODED-TYPE').find('BIT-LENGTH').text except: encodingType = "unknown" # ... for now just drop into the "else" catch-all ?????????????????????????????????????????????? if(encodingType) == "A_ASCIISTRING": functionStringList = "DecodeFunctions.stringToIntList(drDict['{0}'], None)".format(longName) functionStringSingle = "DecodeFunctions.stringToIntList(dataRecord, None)" - elif(encodingType) == "A_INT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int8', 'int8')" - elif(encodingType) == "A_INT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int16', 'int8')" - elif(encodingType) == "A_INT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'int32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'int32', 'int8')" - elif(encodingType) == "A_UINT8": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint8', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint8', 'int8')" - elif(encodingType) == "A_UINT16": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint16', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint16', 'int8')" - elif(encodingType) == "A_UINT32": - functionStringList = "DecodeFunctions.intArrayToIntArray(drDict['{0}'], 'uint32', 'int8')".format(longName) - functionStringSingle = "DecodeFunctions.intArrayToIntArray(dataRecord, 'uint32', 'int8')" + elif (encodingType in ("A_INT8", "A_INT16", "A_INT32", "A_UINT8", "A_UINT16", "A_UINT32")): + functionStringList = "DecodeFunctions.intValueToByteArray(drDict['{0}'], {1})".format(longName, bitLength) + functionStringSingle = "DecodeFunctions.intValueToByteArray(dataRecord, {0})".format(bitLength) else: functionStringList = "drDict['{0}']".format(longName) functionStringSingle = "dataRecord" @@ -238,6 +230,8 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): except: semantic = None + bytePosition = int(param.find('BYTE-POSITION').text) + if semantic == 'SERVICE-ID': serviceId = param.find('CODED-VALUE').text start = int(param.find('BYTE-POSITION').text) @@ -245,16 +239,19 @@ def create_checkNegativeResponseFunction(diagServiceElement, xmlElements): bitLength = int((param.find('DIAG-CODED-TYPE')).find('BIT-LENGTH').text) listLength = int(bitLength/8) end = start + listLength - - checkString = "if input[{0}:{1}] == [{2}]: raise Exception(\"Detected negative response: {{0}}\".format(str([hex(n) for n in input])))".format(start, - end, - serviceId) - negativeResponseChecks.append(checkString) - - pass + elif bytePosition == 2: + nrcPos = bytePosition + expectedNrcDict = {} + try: + dataObjectElement = xmlElements[(param.find('DOP-REF')).attrib['ID-REF']] + nrcList = dataObjectElement.find('COMPU-METHOD').find('COMPU-INTERNAL-TO-PHYS').find('COMPU-SCALES') + for nrcElem in nrcList: + expectedNrcDict[int(nrcElem.find('UPPER-LIMIT').text)] = nrcElem.find('COMPU-CONST').find('VT').text + except: + pass pass - negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, - "\n....".join(negativeResponseChecks)) + negativeResponseFunctionString = negativeResponseFuncTemplate.format(check_negativeResponseFunctionName, start, end, serviceId, nrcPos, expectedNrcDict) + exec(negativeResponseFunctionString) return locals()[check_negativeResponseFunctionName] diff --git a/uds/uds_config_tool/SupportedServices/ClearDTCContainer.py b/uds/uds_config_tool/SupportedServices/ClearDTCContainer.py index 73a4a2b..591c278 100644 --- a/uds/uds_config_tool/SupportedServices/ClearDTCContainer.py +++ b/uds/uds_config_tool/SupportedServices/ClearDTCContainer.py @@ -46,7 +46,9 @@ def __clearDTC(target, groupOfDTC, **kwargs): # Send request and receive the response ... response = target.send(request) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/DiagnosticSessionControlContainer.py b/uds/uds_config_tool/SupportedServices/DiagnosticSessionControlContainer.py index 4c2fe9c..13a059c 100644 --- a/uds/uds_config_tool/SupportedServices/DiagnosticSessionControlContainer.py +++ b/uds/uds_config_tool/SupportedServices/DiagnosticSessionControlContainer.py @@ -70,7 +70,9 @@ def __diagnosticSessionControl(target, parameter, suppressResponse=False, tester if suppressResponse == False: # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/ECUResetContainer.py b/uds/uds_config_tool/SupportedServices/ECUResetContainer.py index 36d108e..cfb22fe 100644 --- a/uds/uds_config_tool/SupportedServices/ECUResetContainer.py +++ b/uds/uds_config_tool/SupportedServices/ECUResetContainer.py @@ -56,7 +56,9 @@ def __ecuReset(target, parameter, suppressResponse=False, **kwargs): if suppressResponse == False: # Send request and receive the response ... response = target.send(request, responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/InputOutputControlContainer.py b/uds/uds_config_tool/SupportedServices/InputOutputControlContainer.py index 4c97d38..86d3c8a 100644 --- a/uds/uds_config_tool/SupportedServices/InputOutputControlContainer.py +++ b/uds/uds_config_tool/SupportedServices/InputOutputControlContainer.py @@ -46,7 +46,9 @@ def __inputOutputControl(target, parameter, optionRecord, dataRecord, **kwargs): # Send request and receive the response ... response = target.send(request) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/ReadDTCContainer.py b/uds/uds_config_tool/SupportedServices/ReadDTCContainer.py index 0d7c12c..97c6514 100644 --- a/uds/uds_config_tool/SupportedServices/ReadDTCContainer.py +++ b/uds/uds_config_tool/SupportedServices/ReadDTCContainer.py @@ -50,7 +50,9 @@ def __readDTC(target, subfunction, DTCStatusMask=None, DTCMaskRecord=None, DTCSn # Send request and receive the response ... response = target.send(request) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/ReadDataByIdentifierContainer.py b/uds/uds_config_tool/SupportedServices/ReadDataByIdentifierContainer.py index a9a526d..ba34442 100644 --- a/uds/uds_config_tool/SupportedServices/ReadDataByIdentifierContainer.py +++ b/uds/uds_config_tool/SupportedServices/ReadDataByIdentifierContainer.py @@ -89,7 +89,9 @@ def popResponseElement(input,expectedList): # Send request and receive the response ... response = target.send(request) # ... this returns a single response which may cover 1 or more DID response values - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + negativeResponse = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if negativeResponse: + return negativeResponse # We have a positive response so check that it makes sense to us ... SIDLength = checkSIDLengthFunction() diff --git a/uds/uds_config_tool/SupportedServices/RequestDownloadContainer.py b/uds/uds_config_tool/SupportedServices/RequestDownloadContainer.py index 3856e78..85033be 100644 --- a/uds/uds_config_tool/SupportedServices/RequestDownloadContainer.py +++ b/uds/uds_config_tool/SupportedServices/RequestDownloadContainer.py @@ -49,7 +49,9 @@ def __requestDownload(target, FormatIdentifier, MemoryAddress, MemorySize, **kwa # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/RequestUploadContainer.py b/uds/uds_config_tool/SupportedServices/RequestUploadContainer.py index 0537bb4..06aad0a 100644 --- a/uds/uds_config_tool/SupportedServices/RequestUploadContainer.py +++ b/uds/uds_config_tool/SupportedServices/RequestUploadContainer.py @@ -49,7 +49,9 @@ def __requestUpload(target, FormatIdentifier, MemoryAddress, MemorySize, **kwarg # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/RoutineControlContainer.py b/uds/uds_config_tool/SupportedServices/RoutineControlContainer.py index 8a333b3..8a49c7b 100644 --- a/uds/uds_config_tool/SupportedServices/RoutineControlContainer.py +++ b/uds/uds_config_tool/SupportedServices/RoutineControlContainer.py @@ -56,7 +56,9 @@ def __routineControl(target, parameter, controlType, optionRecord=None, suppress if suppressResponse == False: # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/SecurityAccessContainer.py b/uds/uds_config_tool/SupportedServices/SecurityAccessContainer.py index 7d75bde..4c0a1ad 100644 --- a/uds/uds_config_tool/SupportedServices/SecurityAccessContainer.py +++ b/uds/uds_config_tool/SupportedServices/SecurityAccessContainer.py @@ -41,9 +41,11 @@ def __securityAccess(target, parameter, key=None, suppressResponse=False): response = target.send(requestFunction(key, suppressResponse), responseRequired=not(suppressResponse)) else: response = target.send(requestFunction(suppressResponse)) - + if suppressResponse is False: - checkNegativeResponseFunction(response) + nrc = checkNegativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc if checkDataFunction is None: output = None diff --git a/uds/uds_config_tool/SupportedServices/TesterPresentContainer.py b/uds/uds_config_tool/SupportedServices/TesterPresentContainer.py index fc3e708..b72a20f 100644 --- a/uds/uds_config_tool/SupportedServices/TesterPresentContainer.py +++ b/uds/uds_config_tool/SupportedServices/TesterPresentContainer.py @@ -65,7 +65,9 @@ def __testerPresent(target, suppressResponse=True, disable=False, **kwargs): if suppressResponse == False: # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/TransferDataContainer.py b/uds/uds_config_tool/SupportedServices/TransferDataContainer.py index 847d1cb..d69e933 100644 --- a/uds/uds_config_tool/SupportedServices/TransferDataContainer.py +++ b/uds/uds_config_tool/SupportedServices/TransferDataContainer.py @@ -62,7 +62,9 @@ def transferChunks(transmitChunks): # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/TransferExitContainer.py b/uds/uds_config_tool/SupportedServices/TransferExitContainer.py index 00fb04b..7e7ee55 100644 --- a/uds/uds_config_tool/SupportedServices/TransferExitContainer.py +++ b/uds/uds_config_tool/SupportedServices/TransferExitContainer.py @@ -47,7 +47,9 @@ def __transferExit(target, transferRequestParameterRecord=None, **kwargs): # Send request and receive the response ... response = target.send(request,responseRequired=True) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + nrc = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if nrc: + return nrc # We have a positive response so check that it makes sense to us ... checkFunction(response) diff --git a/uds/uds_config_tool/SupportedServices/WriteDataByIdentifierContainer.py b/uds/uds_config_tool/SupportedServices/WriteDataByIdentifierContainer.py index 85d9b20..cf511b6 100644 --- a/uds/uds_config_tool/SupportedServices/WriteDataByIdentifierContainer.py +++ b/uds/uds_config_tool/SupportedServices/WriteDataByIdentifierContainer.py @@ -46,7 +46,9 @@ def __writeDataByIdentifier(target, parameter, dataRecord, **kwargs): # Send request and receive the response ... response = target.send(request) # ... this returns a single response - negativeResponseFunction(response) # ... throws an exception to be handled at a higher level if a negative response is received + negativeResponse = negativeResponseFunction(response) # ... return nrc value if a negative response is received + if negativeResponse: + return negativeResponse # We have a positive response so check that it makes sense to us ... checkFunction(response) From ee6926913d5ba2a5023ed205bbeec9ff444f172b Mon Sep 17 00:00:00 2001 From: Floroan Geyer Date: Thu, 24 Dec 2020 12:37:17 +0000 Subject: [PATCH 08/28] readd sleep which is better for performance --- uds/uds_communications/TransportProtocols/Can/CanTp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 73d7f55..7514186 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -286,7 +286,7 @@ def send(self, payload, functionalReq=False): if(timeoutTimer.isExpired()): raise Exception("Timeout waiting for message") - #sleep(0.01) + sleep(0.01) ## # @brief recv method From 96066aa04c87164a207c4f83dcdf24a701d57e13 Mon Sep 17 00:00:00 2001 From: "EXTERNAL Bekhechi Fahd (TS,EB/ENS)" Date: Mon, 4 Jan 2021 16:41:53 +0100 Subject: [PATCH 09/28] - Shutdown CAN connection only if not created externally. - Correct bug for external can vector bus connection. --- .../TransportProtocols/Can/CanConnection.py | 10 ++++++---- .../TransportProtocols/Can/CanConnectionFactory.py | 4 ++-- uds/uds_communications/TransportProtocols/Can/CanTp.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index 8c5e4ee..3e42e27 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -17,8 +17,9 @@ # @brief Small class to wrap the CAN Bus/Notifier/Listeners to allow multiple clients for each bus/connection class CanConnection(object): - def __init__(self, callback, filter, bus): + def __init__(self, callback, filter, bus, is_external=False): self.__bus = bus + self.__is_external = is_external listener = can.Listener() listener.on_message_received = callback self.__notifier = can.Notifier(self.__bus, [listener], 0) @@ -56,9 +57,10 @@ def transmit(self, data, reqId, extended=False): def shutdown(self): self.__notifier.stop() - self.__bus.reset() - self.__bus.shutdown() - self.__bus = None + if self.__is_external == False: + self.__bus.reset() + self.__bus.shutdown() + self.__bus = None def get_bus(self): return self.__bus diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index 918e799..b458a38 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -43,7 +43,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): channel = CanConnectionFactory.config['peak']['device'] if channel not in CanConnectionFactory.connections: if CanConnectionFactory.bus: - CanConnectionFactory.connections[channel] = CanConnection(callback, filter, CanConnectionFactory.bus) + CanConnectionFactory.connections[channel] = CanConnection(callback, filter, CanConnectionFactory.bus, True) else: f_clock_mhz = int(CanConnectionFactory.config['peak']['f_clock_mhz']) nom_brp = int(CanConnectionFactory.config['peak']['nom_brp']) @@ -81,7 +81,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): connectionKey = str("{0}_{1}").format(app_name, channel) if connectionKey not in CanConnectionFactory.connections: if CanConnectionFactory.bus: - CanConnectionFactory.connections[channel] = CanConnection(callback, filter, CanConnectionFactory.bus) + CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, CanConnectionFactory.bus, True) else: serial = int(CanConnectionFactory.config['vector']['serial']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 73d7f55..7514186 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -286,7 +286,7 @@ def send(self, payload, functionalReq=False): if(timeoutTimer.isExpired()): raise Exception("Timeout waiting for message") - #sleep(0.01) + sleep(0.01) ## # @brief recv method From ecc4b241bd1b89f5ba974f69c4ec1825f9825d46 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Tue, 19 Jan 2021 07:01:45 +0100 Subject: [PATCH 10/28] add vector serial auto detection --- .../TransportProtocols/Can/CanConnectionFactory.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index b458a38..af49390 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -83,7 +83,9 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): if CanConnectionFactory.bus: CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, CanConnectionFactory.bus, True) else: - serial = int(CanConnectionFactory.config['vector']['serial']) + serial = None; + if CanConnectionFactory.config['vector']['serial'] != None: + serial = int(CanConnectionFactory.config['vector']['serial']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, serial=serial, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) else: From 9a06e179bdb8b6f4475f0ae666c531e9a7583e41 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Tue, 19 Jan 2021 07:49:01 +0100 Subject: [PATCH 11/28] fix key check --- .../TransportProtocols/Can/CanConnectionFactory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index af49390..cc6a159 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -84,7 +84,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, CanConnectionFactory.bus, True) else: serial = None; - if CanConnectionFactory.config['vector']['serial'] != None: + if 'serial' in CanConnectionFactory.config['vector']: serial = int(CanConnectionFactory.config['vector']['serial']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, serial=serial, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) From c7a4c5f8173b3443915fde937c9c03caed7111d1 Mon Sep 17 00:00:00 2001 From: "Geyer Florian (EB-DU/ENP4)" Date: Fri, 12 Feb 2021 06:39:27 +0100 Subject: [PATCH 12/28] fix deprecation warning --- uds/uds_communications/TransportProtocols/Can/CanConnection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index 3e42e27..117335d 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -47,7 +47,7 @@ def addFilter(self, filter): ## # @brief transmits the data over can using can connection def transmit(self, data, reqId, extended=False): - canMsg = can.Message(arbitration_id=reqId, extended_id=extended) + canMsg = can.Message(arbitration_id=reqId, is_extended_id=extended) canMsg.dlc = len(data) canMsg.data = data From 6e6a5d860c672400e6046602b06b27906eb35612 Mon Sep 17 00:00:00 2001 From: "EXTERNAL Bekhechi Fahd (TS,EB/ENS)" Date: Tue, 16 Feb 2021 17:54:07 +0100 Subject: [PATCH 13/28] - Fix min payload single frame bug. --- uds/uds_communications/TransportProtocols/Can/CanTp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 7514186..fb4c951 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -243,7 +243,7 @@ def send(self, payload, functionalReq=False): raise Exception("Unexpected response from device") if state == CanTpState.SEND_SINGLE_FRAME: - if len(payload) < self.__minPduLength: + if len(payload) <= self.__minPduLength: txPdu[N_PCI_INDEX] += (CanTpMessageType.SINGLE_FRAME << 4) txPdu[SINGLE_FRAME_DL_INDEX] += payloadLength txPdu[SINGLE_FRAME_DATA_START_INDEX:] = fillArray(payload, self.__minPduLength) From 47ea211e804afdf70998cd11cadf5bd0cb76059d Mon Sep 17 00:00:00 2001 From: "EXTERNAL Bekhechi Fahd (TS,EB/ENS)" Date: Thu, 18 Feb 2021 14:38:27 +0100 Subject: [PATCH 14/28] - Add property to change reqId and resId --- .../TransportProtocols/Can/CanTp.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index fb4c951..273d185 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -457,7 +457,6 @@ def create_blockList(self, payload, blockSize): # self.__connection.transmit(data, self.__reqId, self.__addressingType) def transmit(self, data, functionalReq=False): - # check functional request if functionalReq: raise Exception("Functional requests are currently not supported") @@ -476,3 +475,21 @@ def transmit(self, data, functionalReq=False): raise Exception("I do not know how to send this addressing type") self.__connection.transmit(transmitData, self.__reqId, ) + + @property + def reqIdAddress(self): + return self.__reqId + + @reqIdAddress.setter + def reqIdAddress(self, value): + self.__reqId = value + + @property + def resIdAddress(self): + return self.__resId + + @resIdAddress.setter + def resIdAddress(self, value): + self.__resId = value + + \ No newline at end of file From 9056fbdb1ea157af35856b3d125770813c4e8aec Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Fri, 26 Feb 2021 07:09:55 +0100 Subject: [PATCH 15/28] add vector serial auto detection --- .../Can/CanConnectionFactory.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index cc6a159..24b9392 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -1,5 +1,6 @@ import can from can.interfaces import pcan, vector +from can.interfaces.vector.canlib import get_channel_configs from uds.uds_configuration.Config import Config from os import path from platform import system @@ -85,7 +86,10 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): else: serial = None; if 'serial' in CanConnectionFactory.config['vector']: - serial = int(CanConnectionFactory.config['vector']['serial']) + if str(CanConnectionFactory.config['vector']['serial']).upper() == "AUTO": + serial = CanConnectionFactory.detectVectorSerial() + else: + serial = int(CanConnectionFactory.config['vector']['serial']) CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, can.interface.Bus(bustype='vector', poll_interval=0.001, channel=channel, serial=serial, bitrate=baudrate, data_bitrate=data_baudrate, fd=useFd, app_name=app_name)) else: @@ -136,9 +140,27 @@ def checkKwargs(**kwargs): if 'appName' in kwargs: CanConnectionFactory.config['vector']['appName'] = kwargs['appName'] + if 'serial' in kwargs: + CanConnectionFactory.config['vector']['serial'] = kwargs['serial'] + if 'channel' in kwargs: CanConnectionFactory.config['vector']['channel'] = kwargs['channel'] if 'bus' in kwargs: CanConnectionFactory.bus = kwargs['bus'] + @staticmethod + def detectVectorSerial() -> int: + # Get all channels configuration + channel_configs = get_channel_configs() + # Getting all serial numbers + serial_numbers = set() + for channel_config in channel_configs: + serial_number = channel_config.serialNumber + if serial_number != 0: + serial_numbers.add(channel_config.serialNumber) + if serial_numbers: + # if several devices are discovered, the first Vector Box is chosen + serial_number = min(serial_numbers) + return serial_number + return None \ No newline at end of file From bb94f3d82df2174e52ae184982eeded92c6c2504 Mon Sep 17 00:00:00 2001 From: fgeyer Date: Wed, 10 Mar 2021 16:46:34 +0100 Subject: [PATCH 16/28] Update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 478aa59..31842a7 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ # Needed for dependencies install_requires=['python-can>=3.0.0', 'python-lin>=0.1.0'], # *strongly* suggested for sharing - version='1.2.0', + version='1.2.1', # The license can be anything you like license='MIT', description='A library for interfacing with UDS using python', From e7268519ec6962f8581e1d183dd7722553d47d6a Mon Sep 17 00:00:00 2001 From: "EXTERNAL Bekhechi Fahd (TS,EB/ENS)" Date: Fri, 9 Apr 2021 11:05:46 +0200 Subject: [PATCH 17/28] - reset CanConnectionFactory at can disconnect --- .../TransportProtocols/Can/CanConnectionFactory.py | 7 ++++++- uds/uds_communications/TransportProtocols/Can/CanTp.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py index 24b9392..06aeb7f 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -163,4 +163,9 @@ def detectVectorSerial() -> int: # if several devices are discovered, the first Vector Box is chosen serial_number = min(serial_numbers) return serial_number - return None \ No newline at end of file + return None + + @staticmethod + def clearConnections(): + # purge connections dict at can disconnect + CanConnectionFactory.connections = {} \ No newline at end of file diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 273d185..3781979 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -363,6 +363,7 @@ def recv(self, timeout_s): def closeConnection(self): # deregister filters, listeners and notifiers etc # close can connection + CanConnectionFactory.clearConnections() self.__connection.shutdown() self.__connection = None From 39b00d2ed4b89a30d2c81c5a11a6687b9cfbf825 Mon Sep 17 00:00:00 2001 From: Elsayed Mostafa Date: Mon, 17 May 2021 17:51:23 +0200 Subject: [PATCH 18/28] Refactored CanTp.py and UdsConfigTool.py for usage of uds auxiliary --- .../TransportProtocols/Can/CanTp.py | 156 ++++++----- uds/uds_config_tool/UdsConfigTool.py | 255 +++++++++++------- 2 files changed, 234 insertions(+), 177 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 3781979..937e621 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -9,8 +9,6 @@ __email__ = "richard.clubb@embeduk.com" __status__ = "Development" -import can -from can.interfaces import pcan, vector from time import sleep from uds import iTp @@ -23,7 +21,7 @@ FIRST_FRAME_DATA_START_INDEX, SINGLE_FRAME_DATA_START_INDEX, CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX, \ CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX, FLOW_CONTROL_BS_INDEX, FLOW_CONTROL_STMIN_INDEX from uds import CanConnectionFactory -#from uds import CanConnection +# from uds import CanConnection from uds import Config from os import path @@ -36,7 +34,6 @@ # Will spawn a CanTpListener class for incoming messages # depends on a bus object for communication on CAN class CanTp(iTp): - configParams = ['reqId', 'resId', 'addressingType'] ## @@ -48,16 +45,16 @@ def __init__(self, configPath=None, **kwargs): self.__loadConfiguration(configPath) self.__checkKwargs(**kwargs) - + self.endOfMessage_flag = False # load variables from the config self.__N_AE = int(self.__config['canTp']['N_AE'], 16) self.__N_TA = int(self.__config['canTp']['N_TA'], 16) self.__N_SA = int(self.__config['canTp']['N_SA'], 16) Mtype = self.__config['canTp']['Mtype'] - if (Mtype == "DIAGNOSTICS"): + if Mtype == "DIAGNOSTICS": self.__Mtype = CanTpMTypes.DIAGNOSTICS - elif (Mtype == "REMOTE_DIAGNOSTICS"): + elif Mtype == "REMOTE_DIAGNOSTICS": self.__Mtype = CanTpMTypes.REMOTE_DIAGNOSTICS else: raise Exception("Do not understand the Mtype config") @@ -78,14 +75,14 @@ def __init__(self, configPath=None, **kwargs): self.__resId = int(self.__config['canTp']['resId'], 16) # sets up the relevant parameters in the instance - if( + if ( (self.__addressingType == CanTpAddressingTypes.NORMAL) | (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) ): self.__minPduLength = 7 self.__maxPduLength = 63 self.__pduStartIndex = 0 - elif( + elif ( (self.__addressingType == CanTpAddressingTypes.EXTENDED) | (self.__addressingType == CanTpAddressingTypes.MIXED) ): @@ -96,7 +93,7 @@ def __init__(self, configPath=None, **kwargs): # set up the CAN connection canConnectionFactory = CanConnectionFactory() self.__connection = canConnectionFactory(self.callback_onReceive, - self.__resId, # <-filter + self.__resId, # <-filter configPath, **kwargs) self.__recvBuffer = [] @@ -107,7 +104,7 @@ def __init__(self, configPath=None, **kwargs): # @brief used to load the local configuration options and override them with any passed in from a config file def __loadConfiguration(self, configPath, **kwargs): - #load the base config + # load the base config baseConfig = path.dirname(__file__) + "/config.ini" self.__config = Config() if path.exists(baseConfig): @@ -179,40 +176,43 @@ def __checkKwargs(self, **kwargs): # @brief send method # @param [in] payload the payload to be sent def send(self, payload, functionalReq=False): + self.clearBufferedMessages() + self.encode_isotp(payload, functionalReq) + sleep(0.01) - payloadLength = len(payload) - payloadPtr = 0 - - state = CanTpState.IDLE - - if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: - raise Exception("Payload too large for CAN Transport Protocol") - - if payloadLength < self.__maxPduLength: - state = CanTpState.SEND_SINGLE_FRAME - else: - # we might need a check for functional request as we may not be able to service functional requests for - # multi frame requests - state = CanTpState.SEND_FIRST_FRAME - - txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + ## + # @brief encoding method + # @param payload the payload to be sent + # @param ITF_Automation boolean to state if ITF Automation is the one using the decoder + def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: bool = False): + data = None + while self.endOfMessage_flag is False: + rxPdu = self.getNextBufferedMessage() + payloadLength = len(payload) + payloadPtr = 0 - sequenceNumber = 1 - endOfMessage_flag = False + state = CanTpState.IDLE - blockList = [] - currBlock = [] + if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: + raise Exception("Payload too large for CAN Transport Protocol") - ## this needs fixing to get the timing from the config - timeoutTimer = ResettableTimer(1) - stMinTimer = ResettableTimer() + if payloadLength < self.__maxPduLength: + state = CanTpState.SEND_SINGLE_FRAME + else: + # we might need a check for functional request as we may not be able to service functional requests for + # multi frame requests + state = CanTpState.SEND_FIRST_FRAME - self.clearBufferedMessages() + txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - while endOfMessage_flag is False: + sequenceNumber = 1 - rxPdu = self.getNextBufferedMessage() + blockList = [] + currBlock = [] + # this needs fixing to get the timing from the config + timeoutTimer = ResettableTimer(1) + stMinTimer = ResettableTimer() if rxPdu is not None: N_PCI = (rxPdu[0] & 0xF0) >> 4 if N_PCI == CanTpMessageType.FLOW_CONTROL: @@ -225,7 +225,7 @@ def send(self, payload, functionalReq=False): if state == CanTpState.WAIT_FLOW_CONTROL: if fs == CanTpFsTypes.CONTINUE_TO_SEND: bs = rxPdu[FC_BS_INDEX] - if(bs == 0): + if bs == 0: bs = 585 blockList = self.create_blockList(payload[payloadPtr:], bs) @@ -251,49 +251,56 @@ def send(self, payload, functionalReq=False): txPdu[N_PCI_INDEX] = 0 txPdu[FIRST_FRAME_DL_INDEX_LOW] = payloadLength txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload - self.transmit(txPdu, functionalReq) - endOfMessage_flag = True + data = self.transmit(txPdu, functionalReq, ITF_Automation) + self.endOfMessage_flag = True elif state == CanTpState.SEND_FIRST_FRAME: payloadLength_highNibble = (payloadLength & 0xF00) >> 8 - payloadLength_lowNibble = (payloadLength & 0x0FF) + payloadLength_lowNibble = (payloadLength & 0x0FF) txPdu[N_PCI_INDEX] += (CanTpMessageType.FIRST_FRAME << 4) txPdu[FIRST_FRAME_DL_INDEX_HIGH] += payloadLength_highNibble txPdu[FIRST_FRAME_DL_INDEX_LOW] += payloadLength_lowNibble - txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength-1] - payloadPtr += self.__maxPduLength-1 - self.transmit(txPdu, functionalReq) + txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength - 1] + payloadPtr += self.__maxPduLength - 1 + data = self.transmit(txPdu, functionalReq, ITF_Automation) timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL elif state == CanTpState.SEND_CONSECUTIVE_FRAME: - if(stMinTimer.isExpired()): + if (stMinTimer.isExpired()): txPdu[N_PCI_INDEX] += (CanTpMessageType.CONSECUTIVE_FRAME << 4) txPdu[CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX] += sequenceNumber txPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] = currBlock.pop(0) payloadPtr += self.__maxPduLength - self.transmit(txPdu, functionalReq) + data = self.transmit(txPdu, functionalReq, ITF_Automation) sequenceNumber = (sequenceNumber + 1) % 16 stMinTimer.restart() - if(len(currBlock) == 0): - if(len(blockList) == 0): - endOfMessage_flag = True + if (len(currBlock) == 0): + if (len(blockList) == 0): + self.endOfMessage_flag = True else: timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL - #print("waiting for flow control") - + # print("waiting for flow control") txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # timer / exit condition checks - if(timeoutTimer.isExpired()): + if timeoutTimer.isExpired(): raise Exception("Timeout waiting for message") - - sleep(0.01) + if ITF_Automation: + return data ## # @brief recv method # @param [in] timeout_ms The timeout to wait before exiting # @return a list - def recv(self, timeout_s): + def recv(self, timeout_s=1): + self.decode_isotp(timeout_s) + ## + # @breif decoding method + # @param timeout_ms the timeout to wait before exiting + # @param received_data the data that should be decoded in case of ITF Automation + # @param ITF_Automation boolean to state if ITF Automation is the one using the decoder + # return a list + def decode_isotp(self, timeout_ms=1, received_data=None, ITF_Automation: bool = False): timeoutTimer = ResettableTimer(timeout_s) payload = [] @@ -304,15 +311,17 @@ def recv(self, timeout_s): txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - endOfMessage_flag = False + self.endOfMessage_flag = False state = CanTpState.IDLE timeoutTimer.start() - while endOfMessage_flag is False: - rxPdu = self.getNextBufferedMessage() + while self.endOfMessage_flag is False: + rxPdu = self.getNextBufferedMessage() + if ITF_Automation: + rxPdu = received_data if rxPdu is not None: if rxPdu[N_PCI_INDEX] == 0x00: rxPdu = rxPdu[1:] @@ -323,10 +332,11 @@ def recv(self, timeout_s): if N_PCI == CanTpMessageType.SINGLE_FRAME: payloadLength = rxPdu[N_PCI_INDEX & 0x0F] payload = rxPdu[SINGLE_FRAME_DATA_START_INDEX: SINGLE_FRAME_DATA_START_INDEX + payloadLength] - endOfMessage_flag = True + self.endOfMessage_flag = True elif N_PCI == CanTpMessageType.FIRST_FRAME: payload = rxPdu[FIRST_FRAME_DATA_START_INDEX:] - payloadLength = ((rxPdu[FIRST_FRAME_DL_INDEX_HIGH] & 0x0F) << 8) + rxPdu[FIRST_FRAME_DL_INDEX_LOW] + payloadLength = ((rxPdu[FIRST_FRAME_DL_INDEX_HIGH] & 0x0F) << 8) + rxPdu[ + FIRST_FRAME_DL_INDEX_LOW] payloadPtr = self.__maxPduLength - 1 state = CanTpState.SEND_FLOW_CONTROL elif state == CanTpState.RECEIVING_CONSECUTIVE_FRAME: @@ -337,7 +347,7 @@ def recv(self, timeout_s): else: sequenceNumberExpected = (sequenceNumberExpected + 1) % 16 payload += rxPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] - payloadPtr += (self.__maxPduLength) + payloadPtr += self.__maxPduLength timeoutTimer.restart() else: raise Exception("Unexpected PDU received") @@ -351,7 +361,7 @@ def recv(self, timeout_s): if payloadLength is not None: if payloadPtr >= payloadLength: - endOfMessage_flag = True + self.endOfMessage_flag = True if timeoutTimer.isExpired(): raise Exception("Timeout in waiting for message") @@ -363,7 +373,6 @@ def recv(self, timeout_s): def closeConnection(self): # deregister filters, listeners and notifiers etc # close can connection - CanConnectionFactory.clearConnections() self.__connection.shutdown() self.__connection = None @@ -377,7 +386,7 @@ def clearBufferedMessages(self): # @return list, or None if nothing is on the receive list def getNextBufferedMessage(self): length = len(self.__recvBuffer) - if(length != 0): + if length != 0: return self.__recvBuffer.pop(0) else: return None @@ -399,7 +408,7 @@ def callback_onReceive(self, msg): # @brief function to decode the StMin parameter @staticmethod def decode_stMin(val): - if (val <= 0x7F): + if val <= 0x7F: time = val / 1000 return time elif ( @@ -427,7 +436,7 @@ def create_blockList(self, payload, blockSize): blockLength = blockSize * pduLength working = True - while(working): + while working: if (payloadPtr + pduLength) >= payloadLength: working = False currPdu = fillArray(payload[payloadPtr:], pduLength) @@ -435,12 +444,12 @@ def create_blockList(self, payload, blockSize): blockList.append(currBlock) if working: - currPdu = payload[payloadPtr:payloadPtr+pduLength] + currPdu = payload[payloadPtr:payloadPtr + pduLength] currBlock.append(currPdu) payloadPtr += pduLength blockPtr += pduLength - if(blockPtr == blockLength): + if blockPtr == blockLength: blockList.append(currBlock) currBlock = [] blockPtr = 0 @@ -457,7 +466,7 @@ def create_blockList(self, payload, blockSize): # else: # self.__connection.transmit(data, self.__reqId, self.__addressingType) - def transmit(self, data, functionalReq=False): + def transmit(self, data, functionalReq=False, ITF_Automation: bool = False): # check functional request if functionalReq: raise Exception("Functional requests are currently not supported") @@ -465,8 +474,8 @@ def transmit(self, data, functionalReq=False): transmitData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] if ( - (self.__addressingType == CanTpAddressingTypes.NORMAL) | - (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) + (self.__addressingType == CanTpAddressingTypes.NORMAL) | + (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) ): transmitData = data elif self.__addressingType == CanTpAddressingTypes.MIXED: @@ -474,7 +483,8 @@ def transmit(self, data, functionalReq=False): transmitData[1:] = data else: raise Exception("I do not know how to send this addressing type") - + if ITF_Automation: + return transmitData self.__connection.transmit(transmitData, self.__reqId, ) @property @@ -492,5 +502,3 @@ def resIdAddress(self): @resIdAddress.setter def resIdAddress(self, value): self.__resId = value - - \ No newline at end of file diff --git a/uds/uds_config_tool/UdsConfigTool.py b/uds/uds_config_tool/UdsConfigTool.py index 310e2f2..d044072 100644 --- a/uds/uds_config_tool/UdsConfigTool.py +++ b/uds/uds_config_tool/UdsConfigTool.py @@ -9,13 +9,13 @@ __email__ = "richard.clubb@embeduk.com" __status__ = "Development" - import xml.etree.ElementTree as ET from uds.uds_config_tool.UtilityFunctions import isDiagServiceTransmissionOnly from uds.uds_communications.Uds.Uds import Uds from uds.uds_config_tool.SupportedServices.DiagnosticSessionControlContainer import DiagnosticSessionControlContainer -from uds.uds_config_tool.FunctionCreation.DiagnosticSessionControlMethodFactory import DiagnosticSessionControlMethodFactory +from uds.uds_config_tool.FunctionCreation.DiagnosticSessionControlMethodFactory import \ + DiagnosticSessionControlMethodFactory from uds.uds_config_tool.SupportedServices.ECUResetContainer import ECUResetContainer from uds.uds_config_tool.FunctionCreation.ECUResetMethodFactory import ECUResetMethodFactory from uds.uds_config_tool.SupportedServices.ReadDataByIdentifierContainer import ReadDataByIdentifierContainer @@ -43,18 +43,24 @@ from uds.uds_config_tool.FunctionCreation.TransferExitMethodFactory import TransferExitMethodFactory from uds.uds_config_tool.SupportedServices.TesterPresentContainer import TesterPresentContainer from uds.uds_config_tool.FunctionCreation.TesterPresentMethodFactory import TesterPresentMethodFactory -from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices, IsoRoutineControlType, IsoInputOutputControlOptionRecord, IsoReadDTCSubfunction, IsoReadDTCStatusMask as Mask +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices, IsoRoutineControlType, \ + IsoInputOutputControlOptionRecord, IsoReadDTCSubfunction, IsoReadDTCStatusMask as Mask from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices -def get_serviceIdFromXmlElement(diagServiceElement, xmlElements): +class UdsContainerAccess: + containers: list = [] + + + +def get_serviceIdFromXmlElement(diagServiceElement, xmlElements): requestKey = diagServiceElement.find('REQUEST-REF').attrib['ID-REF'] requestElement = xmlElements[requestKey] params = requestElement.find('PARAMS') for i in params: try: - if(i.attrib['SEMANTIC'] == 'SERVICE-ID'): + if (i.attrib['SEMANTIC'] == 'SERVICE-ID'): return int(i.find('CODED-VALUE').text) except: pass @@ -71,7 +77,6 @@ def fill_dictionary(xmlElement): def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): - root = ET.parse(xmlFile) # create any supported containers @@ -123,30 +128,33 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): humanName = sd.text except KeyError: pass - - if serviceId == IsoServices.DiagnosticSessionControl: sessionService_flag = True requestFunc = DiagnosticSessionControlMethodFactory.create_requestFunction(value, xmlElements) diagnosticSessionControlContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = DiagnosticSessionControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = DiagnosticSessionControlMethodFactory.create_checkNegativeResponseFunction( + value, xmlElements) diagnosticSessionControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) - checkFunc = DiagnosticSessionControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) + checkFunc = DiagnosticSessionControlMethodFactory.create_checkPositiveResponseFunction(value, + xmlElements) diagnosticSessionControlContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = DiagnosticSessionControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = DiagnosticSessionControlMethodFactory.create_encodePositiveResponseFunction( + value, xmlElements) diagnosticSessionControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if diagnosticSessionControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(diagnosticSessionControlContainer) elif serviceId == IsoServices.EcuReset: ecuResetService_flag = True requestFunc = ECUResetMethodFactory.create_requestFunction(value, xmlElements) ecuResetContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = ECUResetMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = ECUResetMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) ecuResetContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) try: @@ -161,197 +169,238 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = None else: checkFunc = ECUResetMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - positiveResponseFunction = ECUResetMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = ECUResetMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) ecuResetContainer.add_checkFunction(checkFunc, humanName) ecuResetContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - pass - + if ecuResetContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(ecuResetContainer) elif serviceId == IsoServices.ReadDataByIdentifier: rdbiService_flag = True # The new code extends the range of functions required, in order to handle RDBI working for concatenated lists of DIDs ... requestFunctions = ReadDataByIdentifierMethodFactory.create_requestFunctions(value, xmlElements) - rdbiContainer.add_requestSIDFunction(requestFunctions[0], humanName) # ... note: this will now need to handle replication of this one!!!! + rdbiContainer.add_requestSIDFunction(requestFunctions[0], + humanName) # ... note: this will now need to handle replication of this one!!!! rdbiContainer.add_requestDIDFunction(requestFunctions[1], humanName) - - negativeResponseFunction = ReadDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = ReadDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) rdbiContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) - - checkFunctions = ReadDataByIdentifierMethodFactory.create_checkPositiveResponseFunctions(value, xmlElements) + checkFunctions = ReadDataByIdentifierMethodFactory.create_checkPositiveResponseFunctions(value, + xmlElements) rdbiContainer.add_checkSIDResponseFunction(checkFunctions[0], humanName) rdbiContainer.add_checkSIDLengthFunction(checkFunctions[1], humanName) rdbiContainer.add_checkDIDResponseFunction(checkFunctions[2], humanName) rdbiContainer.add_checkDIDLengthFunction(checkFunctions[3], humanName) - - positiveResponseFunction = ReadDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = ReadDataByIdentifierMethodFactory.create_encodePositiveResponseFunction( + value, xmlElements) rdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if rdbiContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(rdbiContainer) elif serviceId == IsoServices.SecurityAccess: if isDiagServiceTransmissionOnly(value) == False: requestFunction = SecurityAccessMethodFactory.create_requestFunction(value, xmlElements) securityAccessContainer.add_requestFunction(requestFunction, humanName) - negativeResponseFunction = SecurityAccessMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = SecurityAccessMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) securityAccessContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunction = SecurityAccessMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) securityAccessContainer.add_positiveResponseFunction(checkFunction, humanName) securityAccess_flag = True - + if diagnosticSessionControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(securityAccessContainer) elif serviceId == IsoServices.WriteDataByIdentifier: wdbiService_flag = True requestFunc = WriteDataByIdentifierMethodFactory.create_requestFunction(value, xmlElements) wdbiContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = WriteDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = WriteDataByIdentifierMethodFactory.create_checkNegativeResponseFunction( + value, xmlElements) wdbiContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = WriteDataByIdentifierMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) wdbiContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = WriteDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = WriteDataByIdentifierMethodFactory.create_encodePositiveResponseFunction( + value, xmlElements) wdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if wdbiContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(wdbiContainer) elif serviceId == IsoServices.ClearDiagnosticInformation: clearDTCService_flag = True requestFunc = ClearDTCMethodFactory.create_requestFunction(value, xmlElements) clearDTCContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = ClearDTCMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = ClearDTCMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) clearDTCContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = ClearDTCMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) clearDTCContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = ClearDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = ClearDTCMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) clearDTCContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if clearDTCContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(clearDTCContainer) elif serviceId == IsoServices.ReadDTCInformation: readDTCService_flag = True requestFunction, qualifier = ReadDTCMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - readDTCContainer.add_requestFunction(requestFunction, "FaultMemoryRead"+qualifier) + readDTCContainer.add_requestFunction(requestFunction, "FaultMemoryRead" + qualifier) - negativeResponseFunction = ReadDTCMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) - readDTCContainer.add_negativeResponseFunction(negativeResponseFunction, "FaultMemoryRead"+qualifier) + negativeResponseFunction = ReadDTCMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) + readDTCContainer.add_negativeResponseFunction(negativeResponseFunction, + "FaultMemoryRead" + qualifier) checkFunction = ReadDTCMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - readDTCContainer.add_checkFunction(checkFunction, "FaultMemoryRead"+qualifier) - - positiveResponseFunction = ReadDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) - readDTCContainer.add_positiveResponseFunction(positiveResponseFunction, "FaultMemoryRead"+qualifier) - + readDTCContainer.add_checkFunction(checkFunction, "FaultMemoryRead" + qualifier) + + positiveResponseFunction = ReadDTCMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) + readDTCContainer.add_positiveResponseFunction(positiveResponseFunction, + "FaultMemoryRead" + qualifier) + if readDTCContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(readDTCContainer) elif serviceId == IsoServices.InputOutputControlByIdentifier: ioCtrlService_flag = True - requestFunc, qualifier = InputOutputControlMethodFactory.create_requestFunction(value, xmlElements) + requestFunc, qualifier = InputOutputControlMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - inputOutputControlContainer.add_requestFunction(requestFunc, humanName+qualifier) + inputOutputControlContainer.add_requestFunction(requestFunc, humanName + qualifier) - negativeResponseFunction = InputOutputControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) - inputOutputControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName+qualifier) + negativeResponseFunction = InputOutputControlMethodFactory.create_checkNegativeResponseFunction( + value, xmlElements) + inputOutputControlContainer.add_negativeResponseFunction(negativeResponseFunction, + humanName + qualifier) checkFunc = InputOutputControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - inputOutputControlContainer.add_checkFunction(checkFunc, humanName+qualifier) - - positiveResponseFunction = InputOutputControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) - inputOutputControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) - + inputOutputControlContainer.add_checkFunction(checkFunc, humanName + qualifier) + + positiveResponseFunction = InputOutputControlMethodFactory.create_encodePositiveResponseFunction( + value, xmlElements) + inputOutputControlContainer.add_positiveResponseFunction(positiveResponseFunction, + humanName + qualifier) + if inputOutputControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(inputOutputControlContainer) elif serviceId == IsoServices.RoutineControl: routineCtrlService_flag = True # We need a qualifier, as the human name for the start stop, and results calls are all the same, so they otherwise overwrite each other requestFunc, qualifier = RoutineControlMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - routineControlContainer.add_requestFunction(requestFunc, humanName+qualifier) + routineControlContainer.add_requestFunction(requestFunc, humanName + qualifier) - negativeResponseFunction = RoutineControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) - routineControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName+qualifier) + negativeResponseFunction = RoutineControlMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) + routineControlContainer.add_negativeResponseFunction(negativeResponseFunction, + humanName + qualifier) checkFunc = RoutineControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - routineControlContainer.add_checkFunction(checkFunc, humanName+qualifier) - - positiveResponseFunction = RoutineControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) - routineControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) - + routineControlContainer.add_checkFunction(checkFunc, humanName + qualifier) + + positiveResponseFunction = RoutineControlMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) + routineControlContainer.add_positiveResponseFunction(positiveResponseFunction, + humanName + qualifier) + if routineControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(routineControlContainer) elif serviceId == IsoServices.RequestDownload: reqDownloadService_flag = True requestFunc = RequestDownloadMethodFactory.create_requestFunction(value, xmlElements) requestDownloadContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = RequestDownloadMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = RequestDownloadMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) requestDownloadContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = RequestDownloadMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) requestDownloadContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = RequestDownloadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = RequestDownloadMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) requestDownloadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if requestDownloadContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(requestDownloadContainer) elif serviceId == IsoServices.RequestUpload: reqUploadService_flag = True requestFunc = RequestUploadMethodFactory.create_requestFunction(value, xmlElements) requestUploadContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = RequestUploadMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = RequestUploadMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) requestUploadContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = RequestUploadMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) requestUploadContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = RequestUploadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = RequestUploadMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) requestUploadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if requestUploadContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(requestUploadContainer) elif serviceId == IsoServices.TransferData: transDataService_flag = True requestFunc = TransferDataMethodFactory.create_requestFunction(value, xmlElements) transferDataContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = TransferDataMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = TransferDataMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) transferDataContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = TransferDataMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) transferDataContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = TransferDataMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = TransferDataMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) transferDataContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if transferDataContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(transferDataContainer) elif serviceId == IsoServices.RequestTransferExit: transExitService_flag = True requestFunc = TransferExitMethodFactory.create_requestFunction(value, xmlElements) transferExitContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = TransferExitMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = TransferExitMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) transferExitContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = TransferExitMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) transferExitContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = TransferExitMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = TransferExitMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) transferExitContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - + if transferExitContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(transferExitContainer) elif serviceId == IsoServices.TesterPresent: - # Note: Tester Present is presented here as an exposed service, but it will typically not be called directly, as we'll hook it + # Note: Tester Present is presented here as an exposed service, but it will typically not be called directly, as we'll hook it # in to keep the session alive automatically if requested (details to come, but this is just getting the comms into place). testerPresentService_flag = True requestFunc = TesterPresentMethodFactory.create_requestFunction(value, xmlElements) testerPresentContainer.add_requestFunction(requestFunc, "TesterPresent") - negativeResponseFunction = TesterPresentMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + negativeResponseFunction = TesterPresentMethodFactory.create_checkNegativeResponseFunction(value, + xmlElements) testerPresentContainer.add_negativeResponseFunction(negativeResponseFunction, "TesterPresent") checkFunc = TesterPresentMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) testerPresentContainer.add_checkFunction(checkFunc, "TesterPresent") - positiveResponseFunction = TesterPresentMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + positiveResponseFunction = TesterPresentMethodFactory.create_encodePositiveResponseFunction(value, + xmlElements) testerPresentContainer.add_positiveResponseFunction(positiveResponseFunction, "TesterPresent") + if testerPresentContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(testerPresentContainer) - - #need to be able to extract the reqId and resId + # need to be able to extract the reqId and resId outputEcu = Uds(ihexFile=ihexFile, **kwargs) # Bind any ECU Reset services that have been found @@ -423,42 +472,42 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): if testerPresentService_flag: setattr(outputEcu, 'testerPresentContainer', testerPresentContainer) testerPresentContainer.bind_function(outputEcu) - return outputEcu if __name__ == "__main__": - a = createUdsConnection('Bootloader.odx', 'bootloader') a.diagnosticSessionControl('Default Session') - a.ecuReset('Hard Reset',suppressResponse=False) + a.ecuReset('Hard Reset', suppressResponse=False) a.readDataByIdentifier('ECU Serial Number') - a.writeDataByIdentifier('ECU Serial Number','ABC0011223344556') + a.writeDataByIdentifier('ECU Serial Number', 'ABC0011223344556') a.clearDTC([0xF1, 0xC8, 0x55]) - #a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - #a.readDTC(IsoReadDTCSubfunction.reportDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotIdentification, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) - #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) - #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByRecordNumber, DTCSnapshotRecordNumber=0x34) - #a.readDTC(IsoReadDTCSubfunction.reportDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) - #a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) - #a.readDTC(IsoReadDTCSubfunction.reportDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) - #a.readDTC(IsoReadDTCSubfunction.reportSeverityInformationOfDTC, DTCMaskRecord=[0xF1, 0xC8, 0x55]) - #a.readDTC(IsoReadDTCSubfunction.reportSupportedDTC) - #a.readDTC(IsoReadDTCSubfunction.reportFirstTestFailedDTC) - #a.readDTC(IsoReadDTCSubfunction.reportFirstConfirmedDTC) - #a.readDTC(IsoReadDTCSubfunction.reportMostRecentTestFailedDTC) - #a.readDTC(IsoReadDTCSubfunction.reportMostRecentConfirmedDTC) - #a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - #a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) - #a.readDTC(IsoReadDTCSubfunction.reportNumberOfMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - #a.readDTC(IsoReadDTCSubfunction.reportNumberOfEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - #a.readDTC(IsoReadDTCSubfunction.reportEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - a.inputOutputControl('Booster Target Speed',IsoInputOutputControlOptionRecord.adjust,[8000]) - a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) - a.requestDownload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) - #a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # Not tested or runnable at present - a.transferData(0x01,[0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) - a.transferExit([0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) + # a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + # a.readDTC(IsoReadDTCSubfunction.reportDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotIdentification, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) + # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) + # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByRecordNumber, DTCSnapshotRecordNumber=0x34) + # a.readDTC(IsoReadDTCSubfunction.reportDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) + # a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) + # a.readDTC(IsoReadDTCSubfunction.reportDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) + # a.readDTC(IsoReadDTCSubfunction.reportSeverityInformationOfDTC, DTCMaskRecord=[0xF1, 0xC8, 0x55]) + # a.readDTC(IsoReadDTCSubfunction.reportSupportedDTC) + # a.readDTC(IsoReadDTCSubfunction.reportFirstTestFailedDTC) + # a.readDTC(IsoReadDTCSubfunction.reportFirstConfirmedDTC) + # a.readDTC(IsoReadDTCSubfunction.reportMostRecentTestFailedDTC) + # a.readDTC(IsoReadDTCSubfunction.reportMostRecentConfirmedDTC) + # a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + # a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) + # a.readDTC(IsoReadDTCSubfunction.reportNumberOfMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + # a.readDTC(IsoReadDTCSubfunction.reportNumberOfEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + # a.readDTC(IsoReadDTCSubfunction.reportEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + a.inputOutputControl('Booster Target Speed', IsoInputOutputControlOptionRecord.adjust, [8000]) + a.routineControl('Erase Memory', IsoRoutineControlType.startRoutine, + [('memoryAddress', [0x01]), ('memorySize', [0xF000])]) + a.requestDownload(FormatIdentifier=[0x00], MemoryAddress=[0x40, 0x03, 0xE0, 0x00], + MemorySize=[0x00, 0x00, 0x0E, 0x56]) + # a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # Not tested or runnable at present + a.transferData(0x01, [0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF]) + a.transferExit([0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF]) a.testerPresent(suppressResponse=False) From 79e5f650a0e2c6733eec81d04b43a8b81bb941ff Mon Sep 17 00:00:00 2001 From: Elsayed Mostafa Date: Tue, 18 May 2021 16:32:27 +0200 Subject: [PATCH 19/28] Refactored CanTp.py and UdsConfigTool.py for usage of uds auxiliary --- .../TransportProtocols/Can/CanTp.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 937e621..40be49d 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -45,7 +45,6 @@ def __init__(self, configPath=None, **kwargs): self.__loadConfiguration(configPath) self.__checkKwargs(**kwargs) - self.endOfMessage_flag = False # load variables from the config self.__N_AE = int(self.__config['canTp']['N_AE'], 16) self.__N_TA = int(self.__config['canTp']['N_TA'], 16) @@ -183,10 +182,11 @@ def send(self, payload, functionalReq=False): ## # @brief encoding method # @param payload the payload to be sent - # @param ITF_Automation boolean to state if ITF Automation is the one using the decoder - def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: bool = False): + # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used + def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False): data = None - while self.endOfMessage_flag is False: + endOfMessage_flag = False + while endOfMessage_flag is False: rxPdu = self.getNextBufferedMessage() payloadLength = len(payload) payloadPtr = 0 @@ -251,8 +251,8 @@ def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: boo txPdu[N_PCI_INDEX] = 0 txPdu[FIRST_FRAME_DL_INDEX_LOW] = payloadLength txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload - data = self.transmit(txPdu, functionalReq, ITF_Automation) - self.endOfMessage_flag = True + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) + endOfMessage_flag = True elif state == CanTpState.SEND_FIRST_FRAME: payloadLength_highNibble = (payloadLength & 0xF00) >> 8 payloadLength_lowNibble = (payloadLength & 0x0FF) @@ -261,7 +261,7 @@ def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: boo txPdu[FIRST_FRAME_DL_INDEX_LOW] += payloadLength_lowNibble txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength - 1] payloadPtr += self.__maxPduLength - 1 - data = self.transmit(txPdu, functionalReq, ITF_Automation) + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL elif state == CanTpState.SEND_CONSECUTIVE_FRAME: @@ -270,12 +270,12 @@ def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: boo txPdu[CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX] += sequenceNumber txPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] = currBlock.pop(0) payloadPtr += self.__maxPduLength - data = self.transmit(txPdu, functionalReq, ITF_Automation) + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) sequenceNumber = (sequenceNumber + 1) % 16 stMinTimer.restart() if (len(currBlock) == 0): if (len(blockList) == 0): - self.endOfMessage_flag = True + endOfMessage_flag = True else: timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL @@ -284,7 +284,7 @@ def encode_isotp(self, payload, functionalReq: bool = False, ITF_Automation: boo # timer / exit condition checks if timeoutTimer.isExpired(): raise Exception("Timeout waiting for message") - if ITF_Automation: + if use_external_snd_rcv_functions: return data ## @@ -298,9 +298,9 @@ def recv(self, timeout_s=1): # @breif decoding method # @param timeout_ms the timeout to wait before exiting # @param received_data the data that should be decoded in case of ITF Automation - # @param ITF_Automation boolean to state if ITF Automation is the one using the decoder + # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used # return a list - def decode_isotp(self, timeout_ms=1, received_data=None, ITF_Automation: bool = False): + def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_functions: bool = False): timeoutTimer = ResettableTimer(timeout_s) payload = [] @@ -311,16 +311,16 @@ def decode_isotp(self, timeout_ms=1, received_data=None, ITF_Automation: bool = txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - self.endOfMessage_flag = False + endOfMessage_flag = False state = CanTpState.IDLE timeoutTimer.start() - while self.endOfMessage_flag is False: + while endOfMessage_flag is False: rxPdu = self.getNextBufferedMessage() - if ITF_Automation: + if use_external_snd_rcv_functions: rxPdu = received_data if rxPdu is not None: if rxPdu[N_PCI_INDEX] == 0x00: @@ -332,7 +332,7 @@ def decode_isotp(self, timeout_ms=1, received_data=None, ITF_Automation: bool = if N_PCI == CanTpMessageType.SINGLE_FRAME: payloadLength = rxPdu[N_PCI_INDEX & 0x0F] payload = rxPdu[SINGLE_FRAME_DATA_START_INDEX: SINGLE_FRAME_DATA_START_INDEX + payloadLength] - self.endOfMessage_flag = True + endOfMessage_flag = True elif N_PCI == CanTpMessageType.FIRST_FRAME: payload = rxPdu[FIRST_FRAME_DATA_START_INDEX:] payloadLength = ((rxPdu[FIRST_FRAME_DL_INDEX_HIGH] & 0x0F) << 8) + rxPdu[ @@ -361,7 +361,7 @@ def decode_isotp(self, timeout_ms=1, received_data=None, ITF_Automation: bool = if payloadLength is not None: if payloadPtr >= payloadLength: - self.endOfMessage_flag = True + endOfMessage_flag = True if timeoutTimer.isExpired(): raise Exception("Timeout in waiting for message") @@ -466,7 +466,7 @@ def create_blockList(self, payload, blockSize): # else: # self.__connection.transmit(data, self.__reqId, self.__addressingType) - def transmit(self, data, functionalReq=False, ITF_Automation: bool = False): + def transmit(self, data, functionalReq=False, use_external_snd_rcv_functions: bool = False): # check functional request if functionalReq: raise Exception("Functional requests are currently not supported") @@ -483,7 +483,7 @@ def transmit(self, data, functionalReq=False, ITF_Automation: bool = False): transmitData[1:] = data else: raise Exception("I do not know how to send this addressing type") - if ITF_Automation: + if use_external_snd_rcv_functions: return transmitData self.__connection.transmit(transmitData, self.__reqId, ) From ee838a4682d730b21c3e699705ba46225d230bed Mon Sep 17 00:00:00 2001 From: fgeyer Date: Thu, 20 May 2021 19:08:38 +0200 Subject: [PATCH 20/28] Revert "Refactored CanTp.py and UdsConfigTool.py for usage of uds auxiliary" --- .../TransportProtocols/Can/CanTp.py | 144 +++++----- uds/uds_config_tool/UdsConfigTool.py | 255 +++++++----------- 2 files changed, 171 insertions(+), 228 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 40be49d..3781979 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -9,6 +9,8 @@ __email__ = "richard.clubb@embeduk.com" __status__ = "Development" +import can +from can.interfaces import pcan, vector from time import sleep from uds import iTp @@ -21,7 +23,7 @@ FIRST_FRAME_DATA_START_INDEX, SINGLE_FRAME_DATA_START_INDEX, CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX, \ CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX, FLOW_CONTROL_BS_INDEX, FLOW_CONTROL_STMIN_INDEX from uds import CanConnectionFactory -# from uds import CanConnection +#from uds import CanConnection from uds import Config from os import path @@ -34,6 +36,7 @@ # Will spawn a CanTpListener class for incoming messages # depends on a bus object for communication on CAN class CanTp(iTp): + configParams = ['reqId', 'resId', 'addressingType'] ## @@ -45,15 +48,16 @@ def __init__(self, configPath=None, **kwargs): self.__loadConfiguration(configPath) self.__checkKwargs(**kwargs) + # load variables from the config self.__N_AE = int(self.__config['canTp']['N_AE'], 16) self.__N_TA = int(self.__config['canTp']['N_TA'], 16) self.__N_SA = int(self.__config['canTp']['N_SA'], 16) Mtype = self.__config['canTp']['Mtype'] - if Mtype == "DIAGNOSTICS": + if (Mtype == "DIAGNOSTICS"): self.__Mtype = CanTpMTypes.DIAGNOSTICS - elif Mtype == "REMOTE_DIAGNOSTICS": + elif (Mtype == "REMOTE_DIAGNOSTICS"): self.__Mtype = CanTpMTypes.REMOTE_DIAGNOSTICS else: raise Exception("Do not understand the Mtype config") @@ -74,14 +78,14 @@ def __init__(self, configPath=None, **kwargs): self.__resId = int(self.__config['canTp']['resId'], 16) # sets up the relevant parameters in the instance - if ( + if( (self.__addressingType == CanTpAddressingTypes.NORMAL) | (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) ): self.__minPduLength = 7 self.__maxPduLength = 63 self.__pduStartIndex = 0 - elif ( + elif( (self.__addressingType == CanTpAddressingTypes.EXTENDED) | (self.__addressingType == CanTpAddressingTypes.MIXED) ): @@ -92,7 +96,7 @@ def __init__(self, configPath=None, **kwargs): # set up the CAN connection canConnectionFactory = CanConnectionFactory() self.__connection = canConnectionFactory(self.callback_onReceive, - self.__resId, # <-filter + self.__resId, # <-filter configPath, **kwargs) self.__recvBuffer = [] @@ -103,7 +107,7 @@ def __init__(self, configPath=None, **kwargs): # @brief used to load the local configuration options and override them with any passed in from a config file def __loadConfiguration(self, configPath, **kwargs): - # load the base config + #load the base config baseConfig = path.dirname(__file__) + "/config.ini" self.__config = Config() if path.exists(baseConfig): @@ -175,44 +179,40 @@ def __checkKwargs(self, **kwargs): # @brief send method # @param [in] payload the payload to be sent def send(self, payload, functionalReq=False): - self.clearBufferedMessages() - self.encode_isotp(payload, functionalReq) - sleep(0.01) - ## - # @brief encoding method - # @param payload the payload to be sent - # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used - def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False): - data = None - endOfMessage_flag = False - while endOfMessage_flag is False: - rxPdu = self.getNextBufferedMessage() - payloadLength = len(payload) - payloadPtr = 0 + payloadLength = len(payload) + payloadPtr = 0 - state = CanTpState.IDLE + state = CanTpState.IDLE - if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: - raise Exception("Payload too large for CAN Transport Protocol") + if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: + raise Exception("Payload too large for CAN Transport Protocol") - if payloadLength < self.__maxPduLength: - state = CanTpState.SEND_SINGLE_FRAME - else: - # we might need a check for functional request as we may not be able to service functional requests for - # multi frame requests - state = CanTpState.SEND_FIRST_FRAME + if payloadLength < self.__maxPduLength: + state = CanTpState.SEND_SINGLE_FRAME + else: + # we might need a check for functional request as we may not be able to service functional requests for + # multi frame requests + state = CanTpState.SEND_FIRST_FRAME - txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + + sequenceNumber = 1 + endOfMessage_flag = False - sequenceNumber = 1 + blockList = [] + currBlock = [] - blockList = [] - currBlock = [] + ## this needs fixing to get the timing from the config + timeoutTimer = ResettableTimer(1) + stMinTimer = ResettableTimer() + + self.clearBufferedMessages() + + while endOfMessage_flag is False: + + rxPdu = self.getNextBufferedMessage() - # this needs fixing to get the timing from the config - timeoutTimer = ResettableTimer(1) - stMinTimer = ResettableTimer() if rxPdu is not None: N_PCI = (rxPdu[0] & 0xF0) >> 4 if N_PCI == CanTpMessageType.FLOW_CONTROL: @@ -225,7 +225,7 @@ def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rc if state == CanTpState.WAIT_FLOW_CONTROL: if fs == CanTpFsTypes.CONTINUE_TO_SEND: bs = rxPdu[FC_BS_INDEX] - if bs == 0: + if(bs == 0): bs = 585 blockList = self.create_blockList(payload[payloadPtr:], bs) @@ -251,56 +251,49 @@ def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rc txPdu[N_PCI_INDEX] = 0 txPdu[FIRST_FRAME_DL_INDEX_LOW] = payloadLength txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload - data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) + self.transmit(txPdu, functionalReq) endOfMessage_flag = True elif state == CanTpState.SEND_FIRST_FRAME: payloadLength_highNibble = (payloadLength & 0xF00) >> 8 - payloadLength_lowNibble = (payloadLength & 0x0FF) + payloadLength_lowNibble = (payloadLength & 0x0FF) txPdu[N_PCI_INDEX] += (CanTpMessageType.FIRST_FRAME << 4) txPdu[FIRST_FRAME_DL_INDEX_HIGH] += payloadLength_highNibble txPdu[FIRST_FRAME_DL_INDEX_LOW] += payloadLength_lowNibble - txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength - 1] - payloadPtr += self.__maxPduLength - 1 - data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) + txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength-1] + payloadPtr += self.__maxPduLength-1 + self.transmit(txPdu, functionalReq) timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL elif state == CanTpState.SEND_CONSECUTIVE_FRAME: - if (stMinTimer.isExpired()): + if(stMinTimer.isExpired()): txPdu[N_PCI_INDEX] += (CanTpMessageType.CONSECUTIVE_FRAME << 4) txPdu[CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX] += sequenceNumber txPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] = currBlock.pop(0) payloadPtr += self.__maxPduLength - data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) + self.transmit(txPdu, functionalReq) sequenceNumber = (sequenceNumber + 1) % 16 stMinTimer.restart() - if (len(currBlock) == 0): - if (len(blockList) == 0): + if(len(currBlock) == 0): + if(len(blockList) == 0): endOfMessage_flag = True else: timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL - # print("waiting for flow control") + #print("waiting for flow control") + txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # timer / exit condition checks - if timeoutTimer.isExpired(): + if(timeoutTimer.isExpired()): raise Exception("Timeout waiting for message") - if use_external_snd_rcv_functions: - return data + + sleep(0.01) ## # @brief recv method # @param [in] timeout_ms The timeout to wait before exiting # @return a list - def recv(self, timeout_s=1): - self.decode_isotp(timeout_s) + def recv(self, timeout_s): - ## - # @breif decoding method - # @param timeout_ms the timeout to wait before exiting - # @param received_data the data that should be decoded in case of ITF Automation - # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used - # return a list - def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_functions: bool = False): timeoutTimer = ResettableTimer(timeout_s) payload = [] @@ -316,12 +309,10 @@ def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_fun state = CanTpState.IDLE timeoutTimer.start() - while endOfMessage_flag is False: rxPdu = self.getNextBufferedMessage() - if use_external_snd_rcv_functions: - rxPdu = received_data + if rxPdu is not None: if rxPdu[N_PCI_INDEX] == 0x00: rxPdu = rxPdu[1:] @@ -335,8 +326,7 @@ def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_fun endOfMessage_flag = True elif N_PCI == CanTpMessageType.FIRST_FRAME: payload = rxPdu[FIRST_FRAME_DATA_START_INDEX:] - payloadLength = ((rxPdu[FIRST_FRAME_DL_INDEX_HIGH] & 0x0F) << 8) + rxPdu[ - FIRST_FRAME_DL_INDEX_LOW] + payloadLength = ((rxPdu[FIRST_FRAME_DL_INDEX_HIGH] & 0x0F) << 8) + rxPdu[FIRST_FRAME_DL_INDEX_LOW] payloadPtr = self.__maxPduLength - 1 state = CanTpState.SEND_FLOW_CONTROL elif state == CanTpState.RECEIVING_CONSECUTIVE_FRAME: @@ -347,7 +337,7 @@ def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_fun else: sequenceNumberExpected = (sequenceNumberExpected + 1) % 16 payload += rxPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] - payloadPtr += self.__maxPduLength + payloadPtr += (self.__maxPduLength) timeoutTimer.restart() else: raise Exception("Unexpected PDU received") @@ -373,6 +363,7 @@ def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_fun def closeConnection(self): # deregister filters, listeners and notifiers etc # close can connection + CanConnectionFactory.clearConnections() self.__connection.shutdown() self.__connection = None @@ -386,7 +377,7 @@ def clearBufferedMessages(self): # @return list, or None if nothing is on the receive list def getNextBufferedMessage(self): length = len(self.__recvBuffer) - if length != 0: + if(length != 0): return self.__recvBuffer.pop(0) else: return None @@ -408,7 +399,7 @@ def callback_onReceive(self, msg): # @brief function to decode the StMin parameter @staticmethod def decode_stMin(val): - if val <= 0x7F: + if (val <= 0x7F): time = val / 1000 return time elif ( @@ -436,7 +427,7 @@ def create_blockList(self, payload, blockSize): blockLength = blockSize * pduLength working = True - while working: + while(working): if (payloadPtr + pduLength) >= payloadLength: working = False currPdu = fillArray(payload[payloadPtr:], pduLength) @@ -444,12 +435,12 @@ def create_blockList(self, payload, blockSize): blockList.append(currBlock) if working: - currPdu = payload[payloadPtr:payloadPtr + pduLength] + currPdu = payload[payloadPtr:payloadPtr+pduLength] currBlock.append(currPdu) payloadPtr += pduLength blockPtr += pduLength - if blockPtr == blockLength: + if(blockPtr == blockLength): blockList.append(currBlock) currBlock = [] blockPtr = 0 @@ -466,7 +457,7 @@ def create_blockList(self, payload, blockSize): # else: # self.__connection.transmit(data, self.__reqId, self.__addressingType) - def transmit(self, data, functionalReq=False, use_external_snd_rcv_functions: bool = False): + def transmit(self, data, functionalReq=False): # check functional request if functionalReq: raise Exception("Functional requests are currently not supported") @@ -474,8 +465,8 @@ def transmit(self, data, functionalReq=False, use_external_snd_rcv_functions: bo transmitData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] if ( - (self.__addressingType == CanTpAddressingTypes.NORMAL) | - (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) + (self.__addressingType == CanTpAddressingTypes.NORMAL) | + (self.__addressingType == CanTpAddressingTypes.NORMAL_FIXED) ): transmitData = data elif self.__addressingType == CanTpAddressingTypes.MIXED: @@ -483,8 +474,7 @@ def transmit(self, data, functionalReq=False, use_external_snd_rcv_functions: bo transmitData[1:] = data else: raise Exception("I do not know how to send this addressing type") - if use_external_snd_rcv_functions: - return transmitData + self.__connection.transmit(transmitData, self.__reqId, ) @property @@ -502,3 +492,5 @@ def resIdAddress(self): @resIdAddress.setter def resIdAddress(self, value): self.__resId = value + + \ No newline at end of file diff --git a/uds/uds_config_tool/UdsConfigTool.py b/uds/uds_config_tool/UdsConfigTool.py index d044072..310e2f2 100644 --- a/uds/uds_config_tool/UdsConfigTool.py +++ b/uds/uds_config_tool/UdsConfigTool.py @@ -9,13 +9,13 @@ __email__ = "richard.clubb@embeduk.com" __status__ = "Development" + import xml.etree.ElementTree as ET from uds.uds_config_tool.UtilityFunctions import isDiagServiceTransmissionOnly from uds.uds_communications.Uds.Uds import Uds from uds.uds_config_tool.SupportedServices.DiagnosticSessionControlContainer import DiagnosticSessionControlContainer -from uds.uds_config_tool.FunctionCreation.DiagnosticSessionControlMethodFactory import \ - DiagnosticSessionControlMethodFactory +from uds.uds_config_tool.FunctionCreation.DiagnosticSessionControlMethodFactory import DiagnosticSessionControlMethodFactory from uds.uds_config_tool.SupportedServices.ECUResetContainer import ECUResetContainer from uds.uds_config_tool.FunctionCreation.ECUResetMethodFactory import ECUResetMethodFactory from uds.uds_config_tool.SupportedServices.ReadDataByIdentifierContainer import ReadDataByIdentifierContainer @@ -43,24 +43,18 @@ from uds.uds_config_tool.FunctionCreation.TransferExitMethodFactory import TransferExitMethodFactory from uds.uds_config_tool.SupportedServices.TesterPresentContainer import TesterPresentContainer from uds.uds_config_tool.FunctionCreation.TesterPresentMethodFactory import TesterPresentMethodFactory -from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices, IsoRoutineControlType, \ - IsoInputOutputControlOptionRecord, IsoReadDTCSubfunction, IsoReadDTCStatusMask as Mask +from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices, IsoRoutineControlType, IsoInputOutputControlOptionRecord, IsoReadDTCSubfunction, IsoReadDTCStatusMask as Mask from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices - -class UdsContainerAccess: - containers: list = [] - - - def get_serviceIdFromXmlElement(diagServiceElement, xmlElements): + requestKey = diagServiceElement.find('REQUEST-REF').attrib['ID-REF'] requestElement = xmlElements[requestKey] params = requestElement.find('PARAMS') for i in params: try: - if (i.attrib['SEMANTIC'] == 'SERVICE-ID'): + if(i.attrib['SEMANTIC'] == 'SERVICE-ID'): return int(i.find('CODED-VALUE').text) except: pass @@ -77,6 +71,7 @@ def fill_dictionary(xmlElement): def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): + root = ET.parse(xmlFile) # create any supported containers @@ -128,33 +123,30 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): humanName = sd.text except KeyError: pass + + if serviceId == IsoServices.DiagnosticSessionControl: sessionService_flag = True requestFunc = DiagnosticSessionControlMethodFactory.create_requestFunction(value, xmlElements) diagnosticSessionControlContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = DiagnosticSessionControlMethodFactory.create_checkNegativeResponseFunction( - value, xmlElements) + negativeResponseFunction = DiagnosticSessionControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) diagnosticSessionControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) - checkFunc = DiagnosticSessionControlMethodFactory.create_checkPositiveResponseFunction(value, - xmlElements) + checkFunc = DiagnosticSessionControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) diagnosticSessionControlContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = DiagnosticSessionControlMethodFactory.create_encodePositiveResponseFunction( - value, xmlElements) + positiveResponseFunction = DiagnosticSessionControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) diagnosticSessionControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if diagnosticSessionControlContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(diagnosticSessionControlContainer) + elif serviceId == IsoServices.EcuReset: ecuResetService_flag = True requestFunc = ECUResetMethodFactory.create_requestFunction(value, xmlElements) ecuResetContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = ECUResetMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = ECUResetMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) ecuResetContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) try: @@ -169,238 +161,197 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = None else: checkFunc = ECUResetMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - positiveResponseFunction = ECUResetMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = ECUResetMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) ecuResetContainer.add_checkFunction(checkFunc, humanName) ecuResetContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if ecuResetContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(ecuResetContainer) + pass + elif serviceId == IsoServices.ReadDataByIdentifier: rdbiService_flag = True # The new code extends the range of functions required, in order to handle RDBI working for concatenated lists of DIDs ... requestFunctions = ReadDataByIdentifierMethodFactory.create_requestFunctions(value, xmlElements) - rdbiContainer.add_requestSIDFunction(requestFunctions[0], - humanName) # ... note: this will now need to handle replication of this one!!!! + rdbiContainer.add_requestSIDFunction(requestFunctions[0], humanName) # ... note: this will now need to handle replication of this one!!!! rdbiContainer.add_requestDIDFunction(requestFunctions[1], humanName) - negativeResponseFunction = ReadDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + + negativeResponseFunction = ReadDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) rdbiContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) - checkFunctions = ReadDataByIdentifierMethodFactory.create_checkPositiveResponseFunctions(value, - xmlElements) + + checkFunctions = ReadDataByIdentifierMethodFactory.create_checkPositiveResponseFunctions(value, xmlElements) rdbiContainer.add_checkSIDResponseFunction(checkFunctions[0], humanName) rdbiContainer.add_checkSIDLengthFunction(checkFunctions[1], humanName) rdbiContainer.add_checkDIDResponseFunction(checkFunctions[2], humanName) rdbiContainer.add_checkDIDLengthFunction(checkFunctions[3], humanName) - positiveResponseFunction = ReadDataByIdentifierMethodFactory.create_encodePositiveResponseFunction( - value, xmlElements) + + positiveResponseFunction = ReadDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) rdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if rdbiContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(rdbiContainer) + elif serviceId == IsoServices.SecurityAccess: if isDiagServiceTransmissionOnly(value) == False: requestFunction = SecurityAccessMethodFactory.create_requestFunction(value, xmlElements) securityAccessContainer.add_requestFunction(requestFunction, humanName) - negativeResponseFunction = SecurityAccessMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = SecurityAccessMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) securityAccessContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunction = SecurityAccessMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) securityAccessContainer.add_positiveResponseFunction(checkFunction, humanName) securityAccess_flag = True - if diagnosticSessionControlContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(securityAccessContainer) + elif serviceId == IsoServices.WriteDataByIdentifier: wdbiService_flag = True requestFunc = WriteDataByIdentifierMethodFactory.create_requestFunction(value, xmlElements) wdbiContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = WriteDataByIdentifierMethodFactory.create_checkNegativeResponseFunction( - value, xmlElements) + negativeResponseFunction = WriteDataByIdentifierMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) wdbiContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = WriteDataByIdentifierMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) wdbiContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = WriteDataByIdentifierMethodFactory.create_encodePositiveResponseFunction( - value, xmlElements) + positiveResponseFunction = WriteDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) wdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if wdbiContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(wdbiContainer) + elif serviceId == IsoServices.ClearDiagnosticInformation: clearDTCService_flag = True requestFunc = ClearDTCMethodFactory.create_requestFunction(value, xmlElements) clearDTCContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = ClearDTCMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = ClearDTCMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) clearDTCContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = ClearDTCMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) clearDTCContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = ClearDTCMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = ClearDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) clearDTCContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if clearDTCContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(clearDTCContainer) + elif serviceId == IsoServices.ReadDTCInformation: readDTCService_flag = True requestFunction, qualifier = ReadDTCMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - readDTCContainer.add_requestFunction(requestFunction, "FaultMemoryRead" + qualifier) + readDTCContainer.add_requestFunction(requestFunction, "FaultMemoryRead"+qualifier) - negativeResponseFunction = ReadDTCMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) - readDTCContainer.add_negativeResponseFunction(negativeResponseFunction, - "FaultMemoryRead" + qualifier) + negativeResponseFunction = ReadDTCMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + readDTCContainer.add_negativeResponseFunction(negativeResponseFunction, "FaultMemoryRead"+qualifier) checkFunction = ReadDTCMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - readDTCContainer.add_checkFunction(checkFunction, "FaultMemoryRead" + qualifier) - - positiveResponseFunction = ReadDTCMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) - readDTCContainer.add_positiveResponseFunction(positiveResponseFunction, - "FaultMemoryRead" + qualifier) - if readDTCContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(readDTCContainer) + readDTCContainer.add_checkFunction(checkFunction, "FaultMemoryRead"+qualifier) + + positiveResponseFunction = ReadDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + readDTCContainer.add_positiveResponseFunction(positiveResponseFunction, "FaultMemoryRead"+qualifier) + elif serviceId == IsoServices.InputOutputControlByIdentifier: ioCtrlService_flag = True - requestFunc, qualifier = InputOutputControlMethodFactory.create_requestFunction(value, xmlElements) + requestFunc, qualifier = InputOutputControlMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - inputOutputControlContainer.add_requestFunction(requestFunc, humanName + qualifier) + inputOutputControlContainer.add_requestFunction(requestFunc, humanName+qualifier) - negativeResponseFunction = InputOutputControlMethodFactory.create_checkNegativeResponseFunction( - value, xmlElements) - inputOutputControlContainer.add_negativeResponseFunction(negativeResponseFunction, - humanName + qualifier) + negativeResponseFunction = InputOutputControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + inputOutputControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName+qualifier) checkFunc = InputOutputControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - inputOutputControlContainer.add_checkFunction(checkFunc, humanName + qualifier) - - positiveResponseFunction = InputOutputControlMethodFactory.create_encodePositiveResponseFunction( - value, xmlElements) - inputOutputControlContainer.add_positiveResponseFunction(positiveResponseFunction, - humanName + qualifier) - if inputOutputControlContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(inputOutputControlContainer) + inputOutputControlContainer.add_checkFunction(checkFunc, humanName+qualifier) + + positiveResponseFunction = InputOutputControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + inputOutputControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) + elif serviceId == IsoServices.RoutineControl: routineCtrlService_flag = True # We need a qualifier, as the human name for the start stop, and results calls are all the same, so they otherwise overwrite each other requestFunc, qualifier = RoutineControlMethodFactory.create_requestFunction(value, xmlElements) if qualifier != "": - routineControlContainer.add_requestFunction(requestFunc, humanName + qualifier) + routineControlContainer.add_requestFunction(requestFunc, humanName+qualifier) - negativeResponseFunction = RoutineControlMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) - routineControlContainer.add_negativeResponseFunction(negativeResponseFunction, - humanName + qualifier) + negativeResponseFunction = RoutineControlMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) + routineControlContainer.add_negativeResponseFunction(negativeResponseFunction, humanName+qualifier) checkFunc = RoutineControlMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) - routineControlContainer.add_checkFunction(checkFunc, humanName + qualifier) - - positiveResponseFunction = RoutineControlMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) - routineControlContainer.add_positiveResponseFunction(positiveResponseFunction, - humanName + qualifier) - if routineControlContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(routineControlContainer) + routineControlContainer.add_checkFunction(checkFunc, humanName+qualifier) + + positiveResponseFunction = RoutineControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) + routineControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) + elif serviceId == IsoServices.RequestDownload: reqDownloadService_flag = True requestFunc = RequestDownloadMethodFactory.create_requestFunction(value, xmlElements) requestDownloadContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = RequestDownloadMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = RequestDownloadMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) requestDownloadContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = RequestDownloadMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) requestDownloadContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = RequestDownloadMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = RequestDownloadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) requestDownloadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if requestDownloadContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(requestDownloadContainer) + elif serviceId == IsoServices.RequestUpload: reqUploadService_flag = True requestFunc = RequestUploadMethodFactory.create_requestFunction(value, xmlElements) requestUploadContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = RequestUploadMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = RequestUploadMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) requestUploadContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = RequestUploadMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) requestUploadContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = RequestUploadMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = RequestUploadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) requestUploadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if requestUploadContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(requestUploadContainer) + elif serviceId == IsoServices.TransferData: transDataService_flag = True requestFunc = TransferDataMethodFactory.create_requestFunction(value, xmlElements) transferDataContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = TransferDataMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = TransferDataMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) transferDataContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = TransferDataMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) transferDataContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = TransferDataMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = TransferDataMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) transferDataContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if transferDataContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(transferDataContainer) + elif serviceId == IsoServices.RequestTransferExit: transExitService_flag = True requestFunc = TransferExitMethodFactory.create_requestFunction(value, xmlElements) transferExitContainer.add_requestFunction(requestFunc, humanName) - negativeResponseFunction = TransferExitMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = TransferExitMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) transferExitContainer.add_negativeResponseFunction(negativeResponseFunction, humanName) checkFunc = TransferExitMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) transferExitContainer.add_checkFunction(checkFunc, humanName) - positiveResponseFunction = TransferExitMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = TransferExitMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) transferExitContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) - if transferExitContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(transferExitContainer) + elif serviceId == IsoServices.TesterPresent: - # Note: Tester Present is presented here as an exposed service, but it will typically not be called directly, as we'll hook it + # Note: Tester Present is presented here as an exposed service, but it will typically not be called directly, as we'll hook it # in to keep the session alive automatically if requested (details to come, but this is just getting the comms into place). testerPresentService_flag = True requestFunc = TesterPresentMethodFactory.create_requestFunction(value, xmlElements) testerPresentContainer.add_requestFunction(requestFunc, "TesterPresent") - negativeResponseFunction = TesterPresentMethodFactory.create_checkNegativeResponseFunction(value, - xmlElements) + negativeResponseFunction = TesterPresentMethodFactory.create_checkNegativeResponseFunction(value, xmlElements) testerPresentContainer.add_negativeResponseFunction(negativeResponseFunction, "TesterPresent") checkFunc = TesterPresentMethodFactory.create_checkPositiveResponseFunction(value, xmlElements) testerPresentContainer.add_checkFunction(checkFunc, "TesterPresent") - positiveResponseFunction = TesterPresentMethodFactory.create_encodePositiveResponseFunction(value, - xmlElements) + positiveResponseFunction = TesterPresentMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) testerPresentContainer.add_positiveResponseFunction(positiveResponseFunction, "TesterPresent") - if testerPresentContainer not in UdsContainerAccess.containers: - UdsContainerAccess.containers.append(testerPresentContainer) - # need to be able to extract the reqId and resId + + #need to be able to extract the reqId and resId outputEcu = Uds(ihexFile=ihexFile, **kwargs) # Bind any ECU Reset services that have been found @@ -472,42 +423,42 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): if testerPresentService_flag: setattr(outputEcu, 'testerPresentContainer', testerPresentContainer) testerPresentContainer.bind_function(outputEcu) + return outputEcu if __name__ == "__main__": + a = createUdsConnection('Bootloader.odx', 'bootloader') a.diagnosticSessionControl('Default Session') - a.ecuReset('Hard Reset', suppressResponse=False) + a.ecuReset('Hard Reset',suppressResponse=False) a.readDataByIdentifier('ECU Serial Number') - a.writeDataByIdentifier('ECU Serial Number', 'ABC0011223344556') + a.writeDataByIdentifier('ECU Serial Number','ABC0011223344556') a.clearDTC([0xF1, 0xC8, 0x55]) - # a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - # a.readDTC(IsoReadDTCSubfunction.reportDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotIdentification, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) - # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) - # a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByRecordNumber, DTCSnapshotRecordNumber=0x34) - # a.readDTC(IsoReadDTCSubfunction.reportDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) - # a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) - # a.readDTC(IsoReadDTCSubfunction.reportDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) - # a.readDTC(IsoReadDTCSubfunction.reportSeverityInformationOfDTC, DTCMaskRecord=[0xF1, 0xC8, 0x55]) - # a.readDTC(IsoReadDTCSubfunction.reportSupportedDTC) - # a.readDTC(IsoReadDTCSubfunction.reportFirstTestFailedDTC) - # a.readDTC(IsoReadDTCSubfunction.reportFirstConfirmedDTC) - # a.readDTC(IsoReadDTCSubfunction.reportMostRecentTestFailedDTC) - # a.readDTC(IsoReadDTCSubfunction.reportMostRecentConfirmedDTC) - # a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - # a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) - # a.readDTC(IsoReadDTCSubfunction.reportNumberOfMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - # a.readDTC(IsoReadDTCSubfunction.reportNumberOfEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - # a.readDTC(IsoReadDTCSubfunction.reportEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) - a.inputOutputControl('Booster Target Speed', IsoInputOutputControlOptionRecord.adjust, [8000]) - a.routineControl('Erase Memory', IsoRoutineControlType.startRoutine, - [('memoryAddress', [0x01]), ('memorySize', [0xF000])]) - a.requestDownload(FormatIdentifier=[0x00], MemoryAddress=[0x40, 0x03, 0xE0, 0x00], - MemorySize=[0x00, 0x00, 0x0E, 0x56]) - # a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # Not tested or runnable at present - a.transferData(0x01, [0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF]) - a.transferExit([0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF]) + #a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + #a.readDTC(IsoReadDTCSubfunction.reportDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotIdentification, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) + #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCSnapshotRecordNumber=0x34) + #a.readDTC(IsoReadDTCSubfunction.reportDTCSnapshotRecordByRecordNumber, DTCSnapshotRecordNumber=0x34) + #a.readDTC(IsoReadDTCSubfunction.reportDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) + #a.readDTC(IsoReadDTCSubfunction.reportNumberOfDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) + #a.readDTC(IsoReadDTCSubfunction.reportDTCBySeverityMaskRecord, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear, DTCSeverityMaskRecord=Mask.confirmedDtc) + #a.readDTC(IsoReadDTCSubfunction.reportSeverityInformationOfDTC, DTCMaskRecord=[0xF1, 0xC8, 0x55]) + #a.readDTC(IsoReadDTCSubfunction.reportSupportedDTC) + #a.readDTC(IsoReadDTCSubfunction.reportFirstTestFailedDTC) + #a.readDTC(IsoReadDTCSubfunction.reportFirstConfirmedDTC) + #a.readDTC(IsoReadDTCSubfunction.reportMostRecentTestFailedDTC) + #a.readDTC(IsoReadDTCSubfunction.reportMostRecentConfirmedDTC) + #a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + #a.readDTC(IsoReadDTCSubfunction.reportMirrorMemoryDTCExtendedDataRecordByDTCNumber, DTCMaskRecord=[0xF1, 0xC8, 0x55], DTCExtendedRecordNumber=0x12) + #a.readDTC(IsoReadDTCSubfunction.reportNumberOfMirrorMemoryDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + #a.readDTC(IsoReadDTCSubfunction.reportNumberOfEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + #a.readDTC(IsoReadDTCSubfunction.reportEmissionsRelatedOBDDTCByStatusMask, DTCStatusMask=Mask.confirmedDtc + Mask.testFailedSinceLastClear) + a.inputOutputControl('Booster Target Speed',IsoInputOutputControlOptionRecord.adjust,[8000]) + a.routineControl('Erase Memory',IsoRoutineControlType.startRoutine,[('memoryAddress',[0x01]),('memorySize',[0xF000])]) + a.requestDownload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) + #a.requestUpload(FormatIdentifier=[0x00],MemoryAddress=[0x40, 0x03, 0xE0, 0x00],MemorySize=[0x00, 0x00, 0x0E, 0x56]) # Not tested or runnable at present + a.transferData(0x01,[0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) + a.transferExit([0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF]) a.testerPresent(suppressResponse=False) From e848581588f900d7e1b8f967744c8cf559f5a4f7 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 20 Jun 2021 11:37:49 +0200 Subject: [PATCH 21/28] prepare 1.2.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 31842a7..b6f5996 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ # Needed for dependencies install_requires=['python-can>=3.0.0', 'python-lin>=0.1.0'], # *strongly* suggested for sharing - version='1.2.1', + version='1.2.2', # The license can be anything you like license='MIT', description='A library for interfacing with UDS using python', From e68346c3f1c3869ec6574e69214bff5c1f701d0b Mon Sep 17 00:00:00 2001 From: fgeyer Date: Mon, 21 Jun 2021 06:56:30 +0200 Subject: [PATCH 22/28] Tmsea3 1232 itf refactor can uds (#5) * Refactored CanTp.py and UdsConfigTool.py for usage of uds auxiliary * add parametrized wait time to iso tp/uds send --- setup.py | 2 +- .../TransportProtocols/Can/CanTp.py | 111 +++++++++--------- uds/uds_communications/Uds/Uds.py | 4 +- uds/uds_config_tool/UdsConfigTool.py | 44 +++++++ 4 files changed, 105 insertions(+), 56 deletions(-) diff --git a/setup.py b/setup.py index b6f5996..a14d366 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ # Needed for dependencies install_requires=['python-can>=3.0.0', 'python-lin>=0.1.0'], # *strongly* suggested for sharing - version='1.2.2', + version='1.2.3', # The license can be anything you like license='MIT', description='A library for interfacing with UDS using python', diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 3781979..18f154c 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -9,8 +9,6 @@ __email__ = "richard.clubb@embeduk.com" __status__ = "Development" -import can -from can.interfaces import pcan, vector from time import sleep from uds import iTp @@ -99,10 +97,6 @@ def __init__(self, configPath=None, **kwargs): self.__resId, # <-filter configPath, **kwargs) - self.__recvBuffer = [] - - self.__discardNegResp = bool(self.__config['canTp']['discardNegResp']) - ## # @brief used to load the local configuration options and override them with any passed in from a config file def __loadConfiguration(self, configPath, **kwargs): @@ -178,41 +172,45 @@ def __checkKwargs(self, **kwargs): ## # @brief send method # @param [in] payload the payload to be sent - def send(self, payload, functionalReq=False): - - payloadLength = len(payload) - payloadPtr = 0 - - state = CanTpState.IDLE - - if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: - raise Exception("Payload too large for CAN Transport Protocol") - - if payloadLength < self.__maxPduLength: - state = CanTpState.SEND_SINGLE_FRAME - else: - # we might need a check for functional request as we may not be able to service functional requests for - # multi frame requests - state = CanTpState.SEND_FIRST_FRAME - - txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + def send(self, payload, functionalReq=False, tpWaitTime = 0.01): + self.clearBufferedMessages() + self.encode_isotp(payload, functionalReq) + sleep(tpWaitTime) - sequenceNumber = 1 + ## + # @brief encoding method + # @param payload the payload to be sent + # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used + def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False): + data = None endOfMessage_flag = False + while endOfMessage_flag is False: + rxPdu = self.getNextBufferedMessage() + payloadLength = len(payload) + payloadPtr = 0 - blockList = [] - currBlock = [] + state = CanTpState.IDLE - ## this needs fixing to get the timing from the config - timeoutTimer = ResettableTimer(1) - stMinTimer = ResettableTimer() + if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: + raise Exception("Payload too large for CAN Transport Protocol") - self.clearBufferedMessages() + if payloadLength < self.__maxPduLength: + state = CanTpState.SEND_SINGLE_FRAME + else: + # we might need a check for functional request as we may not be able to service functional requests for + # multi frame requests + state = CanTpState.SEND_FIRST_FRAME - while endOfMessage_flag is False: + txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - rxPdu = self.getNextBufferedMessage() + sequenceNumber = 1 + blockList = [] + currBlock = [] + + # this needs fixing to get the timing from the config + timeoutTimer = ResettableTimer(1) + stMinTimer = ResettableTimer() if rxPdu is not None: N_PCI = (rxPdu[0] & 0xF0) >> 4 if N_PCI == CanTpMessageType.FLOW_CONTROL: @@ -251,49 +249,56 @@ def send(self, payload, functionalReq=False): txPdu[N_PCI_INDEX] = 0 txPdu[FIRST_FRAME_DL_INDEX_LOW] = payloadLength txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload - self.transmit(txPdu, functionalReq) + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) endOfMessage_flag = True elif state == CanTpState.SEND_FIRST_FRAME: payloadLength_highNibble = (payloadLength & 0xF00) >> 8 - payloadLength_lowNibble = (payloadLength & 0x0FF) + payloadLength_lowNibble = (payloadLength & 0x0FF) txPdu[N_PCI_INDEX] += (CanTpMessageType.FIRST_FRAME << 4) txPdu[FIRST_FRAME_DL_INDEX_HIGH] += payloadLength_highNibble txPdu[FIRST_FRAME_DL_INDEX_LOW] += payloadLength_lowNibble - txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength-1] - payloadPtr += self.__maxPduLength-1 - self.transmit(txPdu, functionalReq) + txPdu[FIRST_FRAME_DATA_START_INDEX:] = payload[0:self.__maxPduLength - 1] + payloadPtr += self.__maxPduLength - 1 + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL elif state == CanTpState.SEND_CONSECUTIVE_FRAME: - if(stMinTimer.isExpired()): + if (stMinTimer.isExpired()): txPdu[N_PCI_INDEX] += (CanTpMessageType.CONSECUTIVE_FRAME << 4) txPdu[CONSECUTIVE_FRAME_SEQUENCE_NUMBER_INDEX] += sequenceNumber txPdu[CONSECUTIVE_FRAME_SEQUENCE_DATA_START_INDEX:] = currBlock.pop(0) payloadPtr += self.__maxPduLength - self.transmit(txPdu, functionalReq) + data = self.transmit(txPdu, functionalReq, use_external_snd_rcv_functions) sequenceNumber = (sequenceNumber + 1) % 16 stMinTimer.restart() - if(len(currBlock) == 0): - if(len(blockList) == 0): + if (len(currBlock) == 0): + if (len(blockList) == 0): endOfMessage_flag = True else: timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL - #print("waiting for flow control") - + # print("waiting for flow control") txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # timer / exit condition checks - if(timeoutTimer.isExpired()): + if timeoutTimer.isExpired(): raise Exception("Timeout waiting for message") - - sleep(0.01) + if use_external_snd_rcv_functions: + return data ## # @brief recv method # @param [in] timeout_ms The timeout to wait before exiting # @return a list - def recv(self, timeout_s): + def recv(self, timeout_s=1): + self.decode_isotp(timeout_s) + ## + # @breif decoding method + # @param timeout_ms the timeout to wait before exiting + # @param received_data the data that should be decoded in case of ITF Automation + # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used + # return a list + def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_functions: bool = False): timeoutTimer = ResettableTimer(timeout_s) payload = [] @@ -312,7 +317,8 @@ def recv(self, timeout_s): while endOfMessage_flag is False: rxPdu = self.getNextBufferedMessage() - + if use_external_snd_rcv_functions: + rxPdu = received_data if rxPdu is not None: if rxPdu[N_PCI_INDEX] == 0x00: rxPdu = rxPdu[1:] @@ -363,7 +369,6 @@ def recv(self, timeout_s): def closeConnection(self): # deregister filters, listeners and notifiers etc # close can connection - CanConnectionFactory.clearConnections() self.__connection.shutdown() self.__connection = None @@ -457,7 +462,7 @@ def create_blockList(self, payload, blockSize): # else: # self.__connection.transmit(data, self.__reqId, self.__addressingType) - def transmit(self, data, functionalReq=False): + def transmit(self, data, functionalReq=False, use_external_snd_rcv_functions: bool = False): # check functional request if functionalReq: raise Exception("Functional requests are currently not supported") @@ -474,7 +479,8 @@ def transmit(self, data, functionalReq=False): transmitData[1:] = data else: raise Exception("I do not know how to send this addressing type") - + if use_external_snd_rcv_functions: + return transmitData self.__connection.transmit(transmitData, self.__reqId, ) @property @@ -493,4 +499,3 @@ def resIdAddress(self): def resIdAddress(self, value): self.__resId = value - \ No newline at end of file diff --git a/uds/uds_communications/Uds/Uds.py b/uds/uds_communications/Uds/Uds.py index 35a3f55..8eede5a 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, tpWaitTime = 0.01): # 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, toWaitTime) finally: self.sendLock.release() diff --git a/uds/uds_config_tool/UdsConfigTool.py b/uds/uds_config_tool/UdsConfigTool.py index 310e2f2..9992a34 100644 --- a/uds/uds_config_tool/UdsConfigTool.py +++ b/uds/uds_config_tool/UdsConfigTool.py @@ -47,6 +47,10 @@ from uds.uds_config_tool.ISOStandard.ISOStandard import IsoServices +class UdsContainerAccess: + containers: list = [] + + def get_serviceIdFromXmlElement(diagServiceElement, xmlElements): requestKey = diagServiceElement.find('REQUEST-REF').attrib['ID-REF'] @@ -139,6 +143,8 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = DiagnosticSessionControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) diagnosticSessionControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if diagnosticSessionControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(diagnosticSessionControlContainer) elif serviceId == IsoServices.EcuReset: ecuResetService_flag = True @@ -165,6 +171,8 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): ecuResetContainer.add_checkFunction(checkFunc, humanName) ecuResetContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if ecuResetContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(ecuResetContainer) pass elif serviceId == IsoServices.ReadDataByIdentifier: @@ -189,6 +197,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = ReadDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) rdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + + if rdbiContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(rdbiContainer) elif serviceId == IsoServices.SecurityAccess: if isDiagServiceTransmissionOnly(value) == False: @@ -203,6 +214,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): securityAccess_flag = True + if securityAccessContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(securityAccessContainer) + elif serviceId == IsoServices.WriteDataByIdentifier: wdbiService_flag = True @@ -218,6 +232,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = WriteDataByIdentifierMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) wdbiContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if wdbiContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(wdbiContainer) + elif serviceId == IsoServices.ClearDiagnosticInformation: clearDTCService_flag = True requestFunc = ClearDTCMethodFactory.create_requestFunction(value, xmlElements) @@ -232,6 +249,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = ClearDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) clearDTCContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if clearDTCContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(clearDTCContainer) + elif serviceId == IsoServices.ReadDTCInformation: readDTCService_flag = True requestFunction, qualifier = ReadDTCMethodFactory.create_requestFunction(value, xmlElements) @@ -247,6 +267,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = ReadDTCMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) readDTCContainer.add_positiveResponseFunction(positiveResponseFunction, "FaultMemoryRead"+qualifier) + if readDTCContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(readDTCContainer) + elif serviceId == IsoServices.InputOutputControlByIdentifier: ioCtrlService_flag = True requestFunc, qualifier = InputOutputControlMethodFactory.create_requestFunction(value, xmlElements) @@ -262,6 +285,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = InputOutputControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) inputOutputControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) + if inputOutputControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(inputOutputControlContainer) + elif serviceId == IsoServices.RoutineControl: routineCtrlService_flag = True # We need a qualifier, as the human name for the start stop, and results calls are all the same, so they otherwise overwrite each other @@ -278,6 +304,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = RoutineControlMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) routineControlContainer.add_positiveResponseFunction(positiveResponseFunction, humanName+qualifier) + if routineControlContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(routineControlContainer) + elif serviceId == IsoServices.RequestDownload: reqDownloadService_flag = True requestFunc = RequestDownloadMethodFactory.create_requestFunction(value, xmlElements) @@ -292,6 +321,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = RequestDownloadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) requestDownloadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if requestDownloadContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(requestDownloadContainer) + elif serviceId == IsoServices.RequestUpload: reqUploadService_flag = True requestFunc = RequestUploadMethodFactory.create_requestFunction(value, xmlElements) @@ -306,6 +338,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = RequestUploadMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) requestUploadContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if requestUploadContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(requestUploadContainer) + elif serviceId == IsoServices.TransferData: transDataService_flag = True requestFunc = TransferDataMethodFactory.create_requestFunction(value, xmlElements) @@ -320,6 +355,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = TransferDataMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) transferDataContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if transferDataContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(transferDataContainer) + elif serviceId == IsoServices.RequestTransferExit: transExitService_flag = True requestFunc = TransferExitMethodFactory.create_requestFunction(value, xmlElements) @@ -334,6 +372,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = TransferExitMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) transferExitContainer.add_positiveResponseFunction(positiveResponseFunction, humanName) + if transferExitContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(transferExitContainer) + elif serviceId == IsoServices.TesterPresent: # Note: Tester Present is presented here as an exposed service, but it will typically not be called directly, as we'll hook it # in to keep the session alive automatically if requested (details to come, but this is just getting the comms into place). @@ -350,6 +391,9 @@ def createUdsConnection(xmlFile, ecuName, ihexFile=None, **kwargs): positiveResponseFunction = TesterPresentMethodFactory.create_encodePositiveResponseFunction(value, xmlElements) testerPresentContainer.add_positiveResponseFunction(positiveResponseFunction, "TesterPresent") + if testerPresentContainer not in UdsContainerAccess.containers: + UdsContainerAccess.containers.append(testerPresentContainer) + #need to be able to extract the reqId and resId outputEcu = Uds(ihexFile=ihexFile, **kwargs) From 8e2ef50b02cf48096e6973e7727bb77a92df083f Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 21 Jun 2021 07:33:27 +0200 Subject: [PATCH 23/28] fix typo --- uds/uds_communications/Uds/Uds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uds/uds_communications/Uds/Uds.py b/uds/uds_communications/Uds/Uds.py index 8eede5a..0a5f844 100644 --- a/uds/uds_communications/Uds/Uds.py +++ b/uds/uds_communications/Uds/Uds.py @@ -129,7 +129,7 @@ def send(self, msg, responseRequired=True, functionalReq=False, tpWaitTime = 0.0 # We're moving to threaded operation, so putting a lock around the send operation. self.sendLock.acquire() try: - a = self.tp.send(msg, functionalReq, toWaitTime) + a = self.tp.send(msg, functionalReq, tpWaitTime) finally: self.sendLock.release() From 8f76e0b85310ee19d09b25cb266a5b30f0c4da5e Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 21 Jun 2021 07:46:55 +0200 Subject: [PATCH 24/28] fix return types --- uds/uds_communications/TransportProtocols/Can/CanTp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 18f154c..bbe67e1 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -174,8 +174,9 @@ def __checkKwargs(self, **kwargs): # @param [in] payload the payload to be sent def send(self, payload, functionalReq=False, tpWaitTime = 0.01): self.clearBufferedMessages() - self.encode_isotp(payload, functionalReq) + result = self.encode_isotp(payload, functionalReq) sleep(tpWaitTime) + return result ## # @brief encoding method @@ -290,7 +291,7 @@ def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rc # @param [in] timeout_ms The timeout to wait before exiting # @return a list def recv(self, timeout_s=1): - self.decode_isotp(timeout_s) + return self.decode_isotp(timeout_s) ## # @breif decoding method From 97179904ece8ee4e02c41809c99ef0975f0acdf8 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 21 Jun 2021 07:50:01 +0200 Subject: [PATCH 25/28] readd lost lines --- uds/uds_communications/TransportProtocols/Can/CanTp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index bbe67e1..0e0600a 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -97,6 +97,10 @@ def __init__(self, configPath=None, **kwargs): self.__resId, # <-filter configPath, **kwargs) + self.__recvBuffer = [] + + self.__discardNegResp = bool(self.__config['canTp']['discardNegResp']) + ## # @brief used to load the local configuration options and override them with any passed in from a config file def __loadConfiguration(self, configPath, **kwargs): From e9b4196ae539258e274b266b89d81bc0a413b52f Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 21 Jun 2021 10:28:36 +0200 Subject: [PATCH 26/28] fix isotp --- .../TransportProtocols/Can/CanTp.py | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index 0e0600a..e100187 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -187,35 +187,39 @@ def send(self, payload, functionalReq=False, tpWaitTime = 0.01): # @param payload the payload to be sent # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False): - data = None - endOfMessage_flag = False - while endOfMessage_flag is False: - rxPdu = self.getNextBufferedMessage() - payloadLength = len(payload) - payloadPtr = 0 - state = CanTpState.IDLE + payloadLength = len(payload) + payloadPtr = 0 - if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: - raise Exception("Payload too large for CAN Transport Protocol") + state = CanTpState.IDLE - if payloadLength < self.__maxPduLength: - state = CanTpState.SEND_SINGLE_FRAME - else: - # we might need a check for functional request as we may not be able to service functional requests for - # multi frame requests - state = CanTpState.SEND_FIRST_FRAME + if payloadLength > CANTP_MAX_PAYLOAD_LENGTH: + raise Exception("Payload too large for CAN Transport Protocol") - txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] + if payloadLength < self.__maxPduLength: + state = CanTpState.SEND_SINGLE_FRAME + else: + # we might need a check for functional request as we may not be able to service functional requests for + # multi frame requests + state = CanTpState.SEND_FIRST_FRAME - sequenceNumber = 1 + txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] - blockList = [] - currBlock = [] + sequenceNumber = 1 + endOfMessage_flag = False + + blockList = [] + currBlock = [] + + # this needs fixing to get the timing from the config + timeoutTimer = ResettableTimer(1) + stMinTimer = ResettableTimer() + + data = None + + while endOfMessage_flag is False: + rxPdu = self.getNextBufferedMessage() - # this needs fixing to get the timing from the config - timeoutTimer = ResettableTimer(1) - stMinTimer = ResettableTimer() if rxPdu is not None: N_PCI = (rxPdu[0] & 0xF0) >> 4 if N_PCI == CanTpMessageType.FLOW_CONTROL: From 5f17bb4680bd4df16cad9ef981df611c3934a94b Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 21 Jun 2021 11:41:58 +0200 Subject: [PATCH 27/28] fix wait --- uds/uds_communications/TransportProtocols/Can/CanTp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index e100187..e787c32 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -176,17 +176,18 @@ def __checkKwargs(self, **kwargs): ## # @brief send method # @param [in] payload the payload to be sent + # @param [in] tpWaitTime time to wait inside loop def send(self, payload, functionalReq=False, tpWaitTime = 0.01): self.clearBufferedMessages() - result = self.encode_isotp(payload, functionalReq) - sleep(tpWaitTime) + result = self.encode_isotp(payload, functionalReq, tpWaitTime = tpWaitTime) return result ## # @brief encoding method # @param payload the payload to be sent # @param use_external_snd_rcv_functions boolean to state if external sending and receiving functions shall be used - def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False): + # @param [in] tpWaitTime time to wait inside loop + def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rcv_functions: bool = False, tpWaitTime = 0.01): payloadLength = len(payload) payloadPtr = 0 @@ -287,6 +288,8 @@ def encode_isotp(self, payload, functionalReq: bool = False, use_external_snd_rc timeoutTimer.start() state = CanTpState.WAIT_FLOW_CONTROL # print("waiting for flow control") + else: + sleep(tpWaitTime) txPdu = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # timer / exit condition checks if timeoutTimer.isExpired(): From 596abab5b9e36255e9f1586f9ee5d52cd907d4ad Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Mon, 28 Jun 2021 13:30:46 +0200 Subject: [PATCH 28/28] fix thread overload while waiting for uds response --- uds/uds_communications/TransportProtocols/Can/CanConnection.py | 2 +- .../TransportProtocols/Can/CanConnectionFactory.py | 2 +- uds/uds_communications/TransportProtocols/Can/CanTp.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/uds/uds_communications/TransportProtocols/Can/CanConnection.py b/uds/uds_communications/TransportProtocols/Can/CanConnection.py index 117335d..3c840b9 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -22,7 +22,7 @@ def __init__(self, callback, filter, bus, is_external=False): self.__is_external = is_external listener = can.Listener() listener.on_message_received = callback - self.__notifier = can.Notifier(self.__bus, [listener], 0) + self.__notifier = can.Notifier(self.__bus, [listener], 1.0) 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 06aeb7f..66b9666 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnectionFactory.py @@ -84,7 +84,7 @@ def __call__(callback=None, filter=None, configPath=None, **kwargs): if CanConnectionFactory.bus: CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, CanConnectionFactory.bus, True) else: - serial = None; + serial = None if 'serial' in CanConnectionFactory.config['vector']: if str(CanConnectionFactory.config['vector']['serial']).upper() == "AUTO": serial = CanConnectionFactory.detectVectorSerial() diff --git a/uds/uds_communications/TransportProtocols/Can/CanTp.py b/uds/uds_communications/TransportProtocols/Can/CanTp.py index e787c32..d7a968a 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanTp.py +++ b/uds/uds_communications/TransportProtocols/Can/CanTp.py @@ -359,6 +359,8 @@ def decode_isotp(self, timeout_s=1, received_data=None, use_external_snd_rcv_fun timeoutTimer.restart() else: raise Exception("Unexpected PDU received") + else: + sleep(0.01) if state == CanTpState.SEND_FLOW_CONTROL: txPdu[N_PCI_INDEX] = 0x30