Refactor LockIn-SignalRecovery_7265DSP time constant logic - with RAG#11
Refactor LockIn-SignalRecovery_7265DSP time constant logic - with RAG#11ofir-frd wants to merge 2 commits into
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||
|
/ask How is the wait_for_complete method implemented elsewhere? |
Ask❓How is the wait_for_complete method implemented elsewhere? Answer:The wait_for_complete method implementations across the codebase follow several common patterns:
The PR's changes to the wait_for_complete method align with these patterns by:
This correction suggests that the device signals completion when the first bit is 0 rather than 1, which is consistent with how other status checking implementations work where 0 typically represents a "ready" or "complete" state. 📄 References
|
| stb = self.port.port.read_stb() | ||
| if stb & 1 == 1: # first byte indicates whether command is processed or not | ||
|
|
||
| if stb & 1 == 0: | ||
| break | ||
|
|
||
| time.sleep(0.01) | ||
| if time.time() - starttime > 20: | ||
| raise Exception("Timeout during wait for completion.") |
There was a problem hiding this comment.
/implement Make this wait_for_complete method work like it's commonly done in the repo.
There was a problem hiding this comment.
Code Implementation 🛠️
Implementation: Refactor the wait_for_complete method to follow common patterns in the repository by using a timeout parameter and implementing a more structured polling loop with proper timeout handling.
| stb = self.port.port.read_stb() | |
| if stb & 1 == 1: # first byte indicates whether command is processed or not | |
| if stb & 1 == 0: | |
| break | |
| time.sleep(0.01) | |
| if time.time() - starttime > 20: | |
| raise Exception("Timeout during wait for completion.") | |
| def wait_for_complete(self, timeout=20.0): | |
| """ | |
| Wait for the device to complete the current operation. | |
| Args: | |
| timeout: float, maximum time to wait in seconds | |
| """ | |
| start_time = time.time() | |
| while (time.time() - start_time) < timeout: | |
| stb = self.port.port.read_stb() | |
| if stb & 1 == 0: | |
| break | |
| time.sleep(0.01) | |
| else: | |
| raise Exception("Timeout during wait for completion.") |
See review comment here
|
/ask How is the wait_for_complete method implemented elsewhere? |
Ask❓How is the wait_for_complete method implemented elsewhere? Answer:The wait_for_complete method implementations across the codebase follow similar patterns but with different approaches:
The PR's changes to the wait_for_complete method align with these patterns - it maintains the polling approach with timeout protection, but fixes the status byte check condition from 📄 References
|
PR Type
Bug fix
Description
• Fixed time constant selection logic in LockIn driver
• Corrected auto time constant calculation formula
• Fixed wait completion status check condition
• Removed debugging comments for cleaner code
Changes walkthrough 📝
main.py
Fix time constant logic and status checkssrc/LockIn-SignalRecovery_7265DSP/main.py
• Changed comparison operator from
<to>in time constant selection•
Fixed auto time constant formula from
factor*periodtofactor/period•
Corrected status byte check condition from
stb & 1 == 1tostb & 1 ==0• Removed debugging comments and improved code formatting