-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fixes, send/receive debug logs and Unsigned 24 support #267
base: master
Are you sure you want to change the base?
Changes from 1 commit
5141b19
3ce8ab4
bc06df4
3fb146e
659899d
9b9efb7
a8fcd87
d0d9bba
b14f43e
56b206a
a108eee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,9 @@ class SdoClient(SdoBase): | |
#: Seconds to wait before sending a request, for rate limiting | ||
PAUSE_BEFORE_SEND = 0.0 | ||
|
||
# Seconds to wait before next read attempt for response in queue. For delayed responses. | ||
PAUSE_BEFORE_READ = 0.2 | ||
|
||
def __init__(self, rx_cobid, tx_cobid, od): | ||
""" | ||
:param int rx_cobid: | ||
|
@@ -42,6 +45,7 @@ def __init__(self, rx_cobid, tx_cobid, od): | |
self.responses = queue.Queue() | ||
|
||
def on_response(self, can_id, data, timestamp): | ||
logger.debug(f"received response in {can_id} data {data}.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand it, it is preferable to use old-style string interpolation for logging because then the final message will only be constructed if needed. https://docs.python.org/3/howto/logging.html#logging-variable-data There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, we should keep a consistent style here, meaning |
||
self.responses.put(bytes(data)) | ||
|
||
def send_request(self, request): | ||
|
@@ -50,6 +54,7 @@ def send_request(self, request): | |
try: | ||
if self.PAUSE_BEFORE_SEND: | ||
time.sleep(self.PAUSE_BEFORE_SEND) | ||
logger.debug(f"sending to {self.rx_cobid} data {request} ") | ||
self.network.send_message(self.rx_cobid, request) | ||
except CanError as e: | ||
# Could be a buffer overflow. Wait some time before trying again | ||
|
@@ -88,6 +93,7 @@ def request_response(self, sdo_request): | |
if not retries_left: | ||
self.abort(0x5040000) | ||
raise | ||
time.sleep(self.PAUSE_BEFORE_READ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If an additional delay is appropriate here (see above), it should wait after logging, not before. |
||
logger.warning(str(e)) | ||
|
||
def abort(self, abort_code=0x08000000): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps RETRY_DELAY or something would be more easily understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of this mechanism?
read_response()
will already wait up toRESPONSE_TIMEOUT
seconds, so this additional delay only slows down communication in case a reply is already available shortly after the first timeout.If there is a special case that requires such behavior, we should maybe make it optional by defaulting the constant to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acolomb If it fails to respond to the send_request that may be a sign that the device isn't ready and not necessarily a communication error.
Why not use RESPONSE_TIMEOUT? I want to know about it in the log's as soon as it happens and yet, wait more time before the next read_response().
I used it only for debugging. I agree with you it should be optional by defaulting it to zero.
And I agree with @christiansandberg about the naming. I changed the name to RETRY_DELAY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a very slight notion, but
time.sleep(0)
will allow switching to a different thread AFAIK, while not calling it at all does not. I suppose that doesn't make much difference, but maybe better check the constant first and skip sleep if it's zero?