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 diff --git a/setup.py b/setup.py index 0a142eb..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.1.0', + 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/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 f1c6bea..3c840b9 100644 --- a/uds/uds_communications/TransportProtocols/Can/CanConnection.py +++ b/uds/uds_communications/TransportProtocols/Can/CanConnection.py @@ -11,16 +11,18 @@ import can +from uds import fillArray ## # @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) + self.__notifier = can.Notifier(self.__bus, [listener], 1.0) self.__listeners = [listener] self.addFilter(filter) @@ -45,10 +47,20 @@ 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 = can.Message(arbitration_id=reqId, is_extended_id=extended) + canMsg.dlc = len(data) + canMsg.data = data + canMsg.is_fd = True self.__bus.send(canMsg) + def shutdown(self): + self.__notifier.stop() + 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 aee217d..66b9666 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 @@ -14,6 +15,7 @@ class CanConnectionFactory(object): connections = {} config = None + bus = None @staticmethod def __call__(callback=None, filter=None, configPath=None, **kwargs): @@ -23,6 +25,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 = int(CanConnectionFactory.config['can']['baudrate']) + data_baudrate = int(CanConnectionFactory.config['can']['data_baudrate']) if connectionType == 'virtual': connectionName = CanConnectionFactory.config['virtual']['interfaceName'] @@ -36,12 +41,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: - baudrate = CanConnectionFactory.config['can']['baudrate'] - CanConnectionFactory.connections[channel] = CanConnection(callback, filter, - pcan.PcanBus(channel, - bitrate=baudrate)) + if 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']) + 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) @@ -50,14 +78,20 @@ 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, - vector.VectorBus(channel, - app_name=app_name, - data_bitrate=baudrate)) + if CanConnectionFactory.bus: + CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter, CanConnectionFactory.bus, True) + else: + serial = None + if 'serial' in CanConnectionFactory.config['vector']: + 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: CanConnectionFactory.connections[connectionKey].addCallback(callback) CanConnectionFactory.connections[connectionKey].addFilter(filter) @@ -68,7 +102,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) @@ -105,6 +140,32 @@ 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 + + @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 bff4871..d7a968a 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 @@ -82,13 +80,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 @@ -176,7 +176,18 @@ def __checkKwargs(self, **kwargs): ## # @brief send method # @param [in] payload the payload to be sent - def send(self, payload, functionalReq=False): + # @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, 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 + # @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 @@ -201,14 +212,13 @@ def send(self, payload, functionalReq=False): blockList = [] currBlock = [] - ## this needs fixing to get the timing from the config + # this needs fixing to get the timing from the config timeoutTimer = ResettableTimer(1) stMinTimer = ResettableTimer() - self.clearBufferedMessages() + data = None while endOfMessage_flag is False: - rxPdu = self.getNextBufferedMessage() if rxPdu is not None: @@ -241,52 +251,66 @@ 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) - self.transmit(txPdu, functionalReq) + 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 + 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") + else: + sleep(tpWaitTime) 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.001) + 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): + return 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 = [] @@ -305,9 +329,14 @@ 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: - 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] @@ -330,6 +359,8 @@ def recv(self, timeout_s): timeoutTimer.restart() else: raise Exception("Unexpected PDU received") + else: + sleep(0.01) if state == CanTpState.SEND_FLOW_CONTROL: txPdu[N_PCI_INDEX] = 0x30 @@ -352,7 +383,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 @@ -444,8 +476,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") @@ -462,5 +493,23 @@ 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 + 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 + diff --git a/uds/uds_communications/Uds/Uds.py b/uds/uds_communications/Uds/Uds.py index 35a3f55..0a5f844 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, tpWaitTime) finally: self.sendLock.release() 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) 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)