kentindell / canhack

The Yes We CAN project of Canis Labs
MIT License
326 stars 63 forks source link

CANID class does not seem to have get_id() method #5

Closed egribnau closed 2 years ago

egribnau commented 3 years ago

The PDF documentation 'CANPico MicroPython SDK reference manual.pdf' leads me to believe that the CANID object should have a get_id() method.

Hower, calling get_id() on a CANID gives a runtime error.

Error: "AttributeError: 'CANID' object has no attribute 'id'"

Code: "canid = frame.get_canid().get_id()"

I have run the following code on a CANID object to find about the supported methods:

object_methods = [method_name for method_name in dir(frame.get_canid())
                  if callable(getattr(frame.get_canid(), method_name))]
print(object_methods)

Result: ['__class__', 'get_arbitration_id', 'get_id_filter', 'is_extended']

kentindell commented 3 years ago

The CANID class has the following methods:

The arbitration ID is a 29-bit integer, and should be interpreted depending on whether it is an extended or standard ID.

The error message quoted is odd: all Python objects get an attribute of id (which makes it awkward in the context of naming an API for CAN).

The documentation is in error: it should be get_arbitration_id rather than get_id: there was a late change to the code to name this arbitration ID to try and prevent confusion between a CANID instance, an integer part of a CAN ID, and a Python ID. The change didn't make it into the documentation, leading to confusion about IDs..

I'll get the documentation fixed.

kentindell commented 2 years ago

https://github.com/kentindell/canhack/commit/bf0164745323aec535d66ae0b02859ef787725cd