pylessard / python-udsoncan

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

Allow Suppressing response from tester present message #236

Closed cperkulator closed 5 months ago

pylessard commented 5 months ago

Please, look at the doc here : https://udsoncan.readthedocs.io/en/latest/udsoncan/client.html#suppress-positive-response

cperkulator commented 5 months ago

Please, look at the doc here : https://udsoncan.readthedocs.io/en/latest/udsoncan/client.html#suppress-positive-response

Ah nice! thanks for the response!

cperkulator commented 5 months ago

@pylessard, using your method proposed, I'm having an issue where I am calling tester_present in a thread. using the context manager turns off all positive responses for that Client instance. So when I call start_routine and expect a response I don't get one. Any suggestions there? probably need a lock to make sure to UDS routine don't run at the same time.

pylessard commented 5 months ago

The lib is not thread safe. Use it in a single thread

cperkulator commented 5 months ago

Would you be open to adding my PR in that case? that would be really all you need to do to prevent the issue as I mentioned

pylessard commented 5 months ago

Not against, but I'm sure you're doing something fundamentally wrong. Why do you even have threads?

cperkulator commented 5 months ago

just have a diagnostic session where we periodically need to send the tester_present message to keep the session alive. rather than having tester_present sprinkled through the code, I'd rather have a context manager kick off a thread that just periodically transmits it.

We also have the issue where if we sleep while in the diagnostic session then we could time out because the UUT hadn't received any communication in time. so I would have to spin up a separate thread anyways or have a while loop periodically send tester_present and keep track of time. Neither of which are very clean

pylessard commented 5 months ago

Ok. Well it's risky to play across thread. If you launch a tester_present in another thread, and send another request in your main thread, the lib may confuse the 2 requests.

Put the client 100% in its own thread and trigger request using a queue or something like that

pylessard commented 5 months ago

Or use a lock to use the client like you said. There is no inter-call state that needs to be kept, so it should be fine