-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allwinner: Replace bc with awk for floating-point comparison in temperature check #8205
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 pull request updates the internal logic of the getboardtemp function in the Armbian Allwinner battery script. The changes replace the use of grep and bc for numeric validation and range checking of the raw temperature input with a Bash regex match and awk for comparison. The method for converting the raw temperature from millidegrees to degrees Celsius is also adjusted to properly quote the input variable. No changes are made to function signatures or exported entities; all modifications are internal to the function. Suggested labels
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ 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: 0
🧹 Nitpick comments (1)
packages/bsp/common/usr/lib/armbian/armbian-allwinner-battery (1)
18-18
: Proper variable quoting improvementAdding double quotes around
${raw_temp}
in the here-string prevents potential word splitting issues if the temperature value contains spaces or special characters.For consistency, similar unquoted variables appear in lines 67 and 73 in the
ambienttemp
function:-amb_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp}) +amb_temp=$(awk '{printf("%d",$1/1000)}' <<<"${raw_temp}")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/bsp/common/usr/lib/armbian/armbian-allwinner-battery
(1 hunks)
🔇 Additional comments (2)
packages/bsp/common/usr/lib/armbian/armbian-allwinner-battery (2)
14-14
: Good replacement of bc with shell regex + awkThe change effectively replaces the bc utility with a combination of Bash regex and awk for floating-point validation and comparison. This approach improves efficiency by:
- Using native Bash regex to validate numeric format
- Using awk for the comparison operation in a single process
14-19
: Verify the numeric validation logicThe validation logic has been changed from using
grep
to a Bash regex. The new pattern^[1-9][0-9]*\.?[0-9]*$
only matches positive numbers starting with 1-9, which excludes zero and negative temperatures.Confirm that negative temperatures or zero are not valid readings for this board. If they are valid, consider modifying the regex pattern to
^-?[0-9]+\.?[0-9]*$
to include negative values and zero.
Description
This pull request removes the dependency on bc for floating-point comparisons in the temperature checking logic. The updated implementation uses awk, which is more portable and avoids spawning an extra process for bc.
Closing #8143
Checklist: