linklayer / cantact

Drivers and Command Line Interface for CANtact tools
http://cantact.io
MIT License
46 stars 12 forks source link

udsoncan.py fails with pyo3_runtime.PanicException: index out of bounds: the len is 0 but the index is 0 #16

Closed brainstorm closed 3 years ago

brainstorm commented 3 years ago

This time I'm running cantact on a freshly installed RaspberryPi instead of OSX... cantact remains unusable out of the box as of version 0.1.1, despite following the README.md and install instructions to the letter. Would you mind reproducing it on your end please? :/

On this fresh system, it fails pretty much the same way as #12, the underlying Rust-PyO3 driver needs more work @ericevenchick.

$ cat udsoncan_simple.py
#!/usr/bin/env python3
import can
import isotp
import udsoncan
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client, Response, Request

from udsoncan.exceptions import *
from udsoncan.services import *

udsoncan.setup_logging()

bus = can.interface.Bus(bustype="cantact", channel="0", bitrate=500000)
addr = isotp.Address(addressing_mode=isotp.AddressingMode.Normal_29bits, txid=0x18CAFFEE, rxid=0x18CAFFEB)
tp = isotp.CanStack(bus, address=addr)
conn = PythonIsoTpConnection(tp)
client = Client(conn)

conn.open()
client.ecu_reset(ECUReset.ResetType.hardReset)
print("done")
conn.close()

Here's the output:

$ ./udsoncan_simple.py
2021-05-31 15:46:37 [INFO] Connection: Connection opened
2021-05-31 15:46:37 [INFO] UdsClient: ECUReset<0x11> - Requesting reset of type 0x01 (hardReset)
2021-05-31 15:46:37 [DEBUG] Connection: Sending 2 bytes : [b'1101']
thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', src/python.rs:128:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/udsoncan/connections.py", line 513, in rxthread_task
    self.isotp_layer.process()
  File "/usr/local/lib/python3.7/dist-packages/isotp/protocol.py", line 457, in process
    self.txfn(msg)
  File "/usr/local/lib/python3.7/dist-packages/isotp/protocol.py", line 888, in _tx_canbus_3plus
    self.bus.send(can.Message(arbitration_id=msg.arbitration_id, data = msg.data, is_extended_id=msg.is_extended_id, is_fd=msg.is_fd, bitrate_switch=msg.bitrate_switch))
  File "/usr/local/lib/python3.7/dist-packages/can/interfaces/cantact.py", line 112, in send
    msg.data,
pyo3_runtime.PanicException: index out of bounds: the len is 0 but the index is 0