pylessard / python-udsoncan

Python implementation of UDS (ISO-14229) standard.
MIT License
575 stars 199 forks source link

Request/Response.from_payload(...) doesn't find IDs any more #157

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi pylessard,

in the latest releases (1.17 and 1.17.1), the from_payload(...) function from Request and Response does not seem to resolve CAN-IDs any more. The cause seems to be, that BaseService.__get_all_subclasses(cls) in BaseService.from_request_id(cls, given_id) seems to return an empty array.

I have attached a minimal working example, which works correctly in 1.16, but not in 1.17 and 1.17.1.

from udsoncan import Request, Response

def _extract_service_id_name(
    uds_payload = None
):
    if uds_payload is None:
        return None
    try:
        try:
            uds = Request.from_payload(uds_payload)
            service_id_string = f"{uds.service.__name__}"
        except AttributeError:
            uds = Response.from_payload(uds_payload)
            service_id_string = f"{uds.service.__name__ }: {uds.code_name}"
    except AttributeError:
        service_id_string = None
    return service_id_string

if __name__ == "__main__":
    extracted_service_id_name = _extract_service_id_name(bytearray([0x10, 0x02]))
    print(f"Service-ID-name: {extracted_service_id_name}")
    extracted_service_id_name = _extract_service_id_name(bytearray([0x50, 0x02]))
    print(f"Service-ID-name: {extracted_service_id_name}")

Is this an issue, or do i have to change something on my side for 1.17+?

I hope you have a nice day, Daniel

pylessard commented 1 year ago

You are right. I see the error. I have moved BaseService out of the service folder because of a circular dependency problem. __get_all_subclasses will work only if the service module is loaded.

Of course, when the unit test runs, this module gets loaded before the test_response ad the test_request test suite.

Will fix

pylessard commented 1 year ago

As a workaround, you can replace your first line by from udsoncan import Request, Response, services

ghost commented 1 year ago

Thanks for the fast reply and resolution. I approved your pr, as your change fixes the problem on my side :) Thanks for the workaround code, but I already excluded 1.17.0 and 1.17.1 from my pipeline. No problem from my side to stay at 1.16 until 1.17.2 or 1.18 goes live :)

pylessard commented 1 year ago

Fixed in v1.17.2 Cheers

ghost commented 1 year ago

Thanks a lot for the fast fix :)