pylessard / python-udsoncan

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

Expect `suppress_positive_response` response NRC #172

Closed amsyrena closed 11 months ago

amsyrena commented 12 months ago

The NRC response is expected when I request 'suppress_positive_response' massage. Like this:

        with pytest.raises(NegativeResponseException) as handle:
            with self.udsclient.suppress_positive_response:
                response = self.udsclient.start_routine(routine_id=routine_id, data=payload)
        assert handle.value.response.code == 0x33

But the code is 'return None', and will not check the response.

        # client.py
        if request.suppress_positive_response or override_suppress_positive_response:
            return None
pylessard commented 11 months ago

Yes, this is a limitation of the actual client, it works fully synchronously. We either return None or wait a certain amount of time in case a response happens. Maybe I could add a feature to do this wait.

Is it required in your case?

amsyrena commented 11 months ago

Thank you very much for your reply! According to ISO-14229, I think this situation exists. When we write test cases, we really need to test such situations. I would be grateful if you could add this feature! Thank you very much for providing this open source library, which has been of great help to us.

pylessard commented 11 months ago

Can you try this branch? https://github.com/pylessard/python-udsoncan/tree/support-wait-nrc-when-suppress-pos-resp

with client.suppress_positive_response(wait_nrc=True):
   pass
pylessard commented 11 months ago

I'm waiting on your feedback to merge

amsyrena commented 11 months ago

Sorry for replying to you only now. Thank you very much for your modification. I tested it and it works very well and meets my needs very well. Thank you very very much!

pylessard commented 11 months ago

Thank you for your feedback. Merged.

Fixed by #174

amsyrena commented 11 months ago

When will the official new version be released?

pylessard commented 11 months ago

I have no plan. I can do it now if it helps you

amsyrena commented 11 months ago

Yes, I need the new version, downloaded via pip. grateful!

pylessard commented 11 months ago

There you go sir. v1.19.0 is published on pypi. Cheers

amsyrena commented 11 months ago

Thanks! Have a great day or evening!

amsyrena commented 11 months ago

I use it like this:

                with pytest.raises(NegativeResponseException) as handle:
                    with uds.suppress_positive_response(wait_nrc=True):
                        uds.start_routine(routine_id=routine_id, data=data)
                assert handle.value.response.code == 0x13, 'nrc13 not raise'
            with pytest.raises(TimeoutError):
                with uds.suppress_positive_response(wait_nrc=True):
                    uds.change_session(2)