-
Notifications
You must be signed in to change notification settings - Fork 10
Fix periodic CAN sender #419
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
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
sinks/dashboard/items/periodic_can_sender.py (1)
74-95
: Messages are still published whenperiod == 0
→ violates “INACTIVE” state.
on_clock_update()
is executed every 60 ms regardless of the configured period, so even when the UI shows “INACTIVE” (period == 0
) the widget continues to blast CAN traffic. This defeats the purpose of the period parameter and can spam the bus.Minimal fix:
def on_clock_update(self, _): - can_message = { + if self.period == 0: + return + + can_message = { 'data': { ...A more robust approach would be to:
- Unsubscribe / resubscribe to the clock when
period
changes, or- Gate on the tick count:
if tick % self.period != 0: return
.Without this guard the sender remains permanently active.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
sinks/dashboard/items/periodic_can_sender.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
sinks/dashboard/items/periodic_can_sender.py (1)
sinks/dashboard/items/can_sender.py (1)
update_can_msg
(156-179)
'board_inst_id': 'GROUND', | ||
'time': 0, | ||
'actuator': self.actuator, | ||
'cmd_state': 'ACTUATOR_ON' if self.radio_on.isChecked() else 'ACTUATOR_OFF' | ||
'cmd_state': 'ACT_STATE_ON' if self.radio_on.isChecked() else 'ACT_STATE_OFF' | ||
}, |
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.
🛠️ Refactor suggestion
Use protocol enums instead of hard-coded strings for board_inst_id
and cmd_state
.
Hard-coding protocol literals ('GROUND'
, 'ACT_STATE_ON'
, 'ACT_STATE_OFF'
) makes the code fragile and error-prone if the CAN spec evolves. parsley.message_types
already exposes enums / constants for these fields—leveraging them avoids typos and ensures future updates are picked up automatically.
- 'board_inst_id': 'GROUND',
+ 'board_inst_id': mt.BoardInstId.GROUND,
...
- 'cmd_state': 'ACT_STATE_ON' if self.radio_on.isChecked() else 'ACT_STATE_OFF'
+ 'cmd_state': (
+ mt.ActState.ON if self.radio_on.isChecked() else mt.ActState.OFF
+ )
This also improves IDE autocompletion and static-analysis coverage.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
'board_inst_id': 'GROUND', | |
'time': 0, | |
'actuator': self.actuator, | |
'cmd_state': 'ACTUATOR_ON' if self.radio_on.isChecked() else 'ACTUATOR_OFF' | |
'cmd_state': 'ACT_STATE_ON' if self.radio_on.isChecked() else 'ACT_STATE_OFF' | |
}, | |
'board_inst_id': mt.BoardInstId.GROUND, | |
'time': 0, | |
'actuator': self.actuator, | |
'cmd_state': ( | |
mt.ActState.ON if self.radio_on.isChecked() else mt.ActState.OFF | |
) | |
}, |
🤖 Prompt for AI Agents
In sinks/dashboard/items/periodic_can_sender.py around lines 84 to 88, replace
the hard-coded string literals 'GROUND', 'ACT_STATE_ON', and 'ACT_STATE_OFF'
with the corresponding enums or constants provided by parsley.message_types.
Import the necessary enums if not already imported, then use them to assign
values to 'board_inst_id' and 'cmd_state' fields to improve code robustness and
maintainability.
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.
was tested in ops and I don't see any major issues with the change itself, would still wait on oliver and chris
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.
No detail context here, but based on the message_types
information LGTM
Description
I changed X and Y to accomplish Z.
This PR closes #XXX.
Developer Testing
Here's what I did to test my changes:
Reviewer Testing
Here's what you should do to quickly validate my changes:
This change is
Summary by CodeRabbit