[CanTp] Vehicle Diagnostic Communication Part 37 [Simulation 25]

[CanTp] Vehicle Diagnostic Communication Part 37 [Simulation 25] 車両診断通信
[CanTp] Vehicle Diagnostic Communication Part 37 [Simulation 25]

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

Introduction.

Let’s simulate ISO-TP. series.
In this article, we will build a request message to try to make AUTOSAR-CanTp actually work.
I will explain the details of the request and response according to IS14229-1 in the near future.

Python can-isotp code for requests

For requests to AUTOSAR CanTp, use the can-isotp script created previously, modified to allow continuous requests.
(Asset diversion is important!)

The code to enable continuous requests is shown below.

import isotp
import logging
import time
import threading

from can.interfaces.vector import VectorBus

class ThreadedApp:
   def __init__(self):
      isotp_params = {
         'stmin' : 0, 
         'blocksize' : 0,
         '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)
      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()
         time.sleep(0.001)
         
   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()
   
   # Request message byte array list
   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]),
   ]
   
   # Request message continuous transmission
   for i in range(len(datas)):
      sendrecv(app, datas[i])

   print("Exiting")
   app.shutdown()

The point is that the request message is a list of byte arrays.
This means that the request message can be changed, increased or decreased, simply by modifying this list.

What does the request message mean?

This request message is not a random value.
It is in accordance with ISO14229-1.
I haven’t talked about ISO14229-1 yet, so you don’t have to worry about it now, but the request message is in accordance with the Servcei$22 specification.

Assumed Response

The response to this request is assumed to be as follows, in conformity with ISO 14229-1.

0x62,0x01,0x0a,0x00…

The request side is implemented as a set of 0x01 and 0x0a, and the response side is implemented as a set of 0x01, 0x0a, and 0x00.

The modified Cantp is not disclosed for the following reasons.
Reason 1: The code is very dirty because it is forcibly connected.
Reason 2: It might not be good to disclose the A-COMSTACK code outside of the TOPPERS association for compliance reasons.
Reason 3: There is some secrecy in the code.

Next time, I’ll actually run it and log it.

Conclusion

  • Fixed the script for Python can-isotp requests.
    • The request is now ISO14229-1 compliant.
  • Implemented AUTOSAR-CanTp side.
    • The response is now SO14229-1 compliant as well.
    • The code has not been published yet for personal reasons.

Click here for back issues.

コメント

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