[Dcm] Vehicle Diagnostic Communication Part 73 [Simulation 12]

[Dcm] Vehicle Diagnostic Communication Part 73 [Simulation 12] 車両診断通信
[Dcm] Vehicle Diagnostic Communication Part 73 [Simulation 12]

Click here for back issues.
https://www.simulationroom999.com/blog/diagnostic-communication-en-back-issue/

Introduction.

AUTOSAR-Dcm simulation explanation.

AUTOSAR-Dcm Simulation Configuration Review

We will start the simulation from this time.
Let’s review the configuration, since I’m sure you have already forgotten it.

Overall UDS Simulation Configuration,Dcm is not multi-channel compatible due to specifications.Pre-emption specification seems to be implemented, but it is not used this time.Python,diagnostic request,isotp,python-can,can.logger,Virtual CAN BUS,exe,Test program ECU side,Dcm,CanTp,Channel(1),Transmission(1)18DAF110,Received(2)18DA10F1,CanDrv

Python code to be used in AUTOSAR-Dcm simulation

The Python code for the off-board tester side is required.
Basically, we will use the code we have created so far.
For now, we will use the following as a base.

import isotp
import logging
import time
import threading

from can.interfaces.vector import VectorBus

class ThreadedApp:
   def __init__(self):
      isotp_params = {
         'stmin' : 0, 
         'blocksize' : 4,
         'wftmax' : 0,
         'll_data_length' : 8,
         'tx_padding' : 0xCC,
         'rx_flowcontrol_timeout' : 1000,
         'rx_consecutive_frame_timeout' : 1000,
         'squash_stmin_requirement' : False,
         'can_fd' : False,
         'tx_data_min_length' : 8
      }
      self.exit_requested = False
      #self.bus = VectorBus(channel='0', bitrate=500000)
      self.bus = VectorBus(channel='0', bitrate=500000, fd=True)
      addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits, source_address=0xF1, target_address=0x10) 
      self.stack = isotp.CanStack(self.bus, address=addr, params=isotp_params, error_handler=self.my_error_handler)

   def start(self):
      self.exit_requested = False
      self.thread = threading.Thread(target = self.thread_task)
      self.thread.start()

   def stop(self):
      self.exit_requested = True
      if self.thread.isAlive():
         self.thread.join()
   
   def send(self, msg):
      self.stack.send(msg)
   
   def my_error_handler(self, error):
      logging.warning('IsoTp error happened : %s - %s' % (error.__class__.__name__, str(error)))

   def thread_task(self):
      while self.exit_requested == False:
         self.stack.process()                # Non-blocking
         #time.sleep(self.stack.sleep_time()) # Variable sleep time based on state machine state
         time.sleep(0.001) # Variable sleep time based on state machine state

   def shutdown(self):
      self.stop()
      self.bus.shutdown()

def sendrecv( app, msg ):
   print("Send msg : %s" % (msg.hex()))
   app.send(msg)
   t1 = time.time()
   while time.time() - t1 < 5:
      if app.stack.available():
         payload = app.stack.recv()
         print("Recv msg : %s" % (payload.hex()))
         break
      time.sleep(0.2)


if __name__ == '__main__':
   app = ThreadedApp()
   app.start()
   
   datas=[
      bytes([0x22, 0x01, 0x0a]),
      bytes([0x22, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a]),
      bytes([0x22, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a, 0x01, 0x0a]),
      bytes([0x22, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10, 0x26, 0x10]),
   ]
   
   for i in range(len(datas)):
      sendrecv(app, datas[i])

   print("Exiting")
   app.shutdown()

This code was used in the following.

(This is the 73rd and this was the 37th? That was a long time ago…)

This is not enough to support S3 timeout or NRC$78, but we’ll extend that when it becomes necessary.

The order in which to try out the simulation

I will explain the order in which we will try out the simulation.

WriteDataByIdentifier should be the last one because it is set up with session transition and security.
SecurityAccess requires session transition by DiagnosticSessionControl as a prerequisite.
TesterPresent is effective for maintaining session and security unlock.
ReadDataByIdentifier and WriteDataByIdentifie should be in a row because of their nature of being at the end.
Therefore, let’s use the following order.

  • DiagnosticSessionControl
  • SecurityAccess
  • TesterPresent
  • ReadDataByIdentifier
  • WriteDataByIdentifier

Conclusion

  • Review of AUTOSAR Dcm simulation configuration
  • The Python code on the off-board tester side is the same as we have used so far.
    • Modifications will be made as needed.
  • The order in which the simulations are run is as follows.
    • DiagnosticSessionControl.
    • SecurityAccess.
    • TesterPresent.
    • ReadDataByIdentifier.
    • WriteDataByIdentifier.

Click here for back issues.

コメント

タイトルとURLをコピーしました