jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
151 stars 50 forks source link

fix issue with alive check request #20

Closed stefankopf closed 2 years ago

stefankopf commented 2 years ago

This pull request proposes a fix to an issue with an alive check request from the server.

Let's consider the following situation: We are connected to a server, have sent a request to the server, and a waiting for the response from the server. While we are waiting, the server sends an alive check request, which we should answer immediately. --> To cover that situation, I have added the test "test_alive_check".

Running the test, we see that multiple alive_check_responses are sent, because the content of "data" is not cleared. --> This can be fixed with the change in line 313

After the change, not even one alive_check_response is sent. This is because the request_alive_check message has zero payload size, but the parser always expects a nonzero payload size. (When the parser is in state Parser.ParserState.READ_PAYLOAD, there are no bytes left to be read from self.rxbuffer and the loop while self.rxbuffer: exits.) --> This can be fixed by changing line 79 from elif to if. That results in an if-elif-elif-if-block which looks inconsistent. So I decided to change all elif to if and to remove the loop.

stefankopf commented 2 years ago

I stumbled upon this issue while writing a small python tool for testing an ECU prototype. Sometimes the communication was stopped by the ECU because the doipclient did not respond in time to an alive check request. Now the communication works fine.