-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Parameter Group system documentation for developers #11271
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
base: maintenance-9.x
Are you sure you want to change the base?
Add Parameter Group system documentation for developers #11271
Conversation
Document INAV's PG system to help developers understand: - How the compile-time registry works using linker sections - When to increment PG version numbers (struct layout changes) - How to register new parameter groups with proper macros - Version validation mechanism in pgLoad() Includes practical examples based on actual code (blackbox PG) and references to related PRs for context.
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| ```c | ||
| void pgLoad(const pgRegistry_t* reg, int profileIndex, | ||
| const void *from, int size, int version) | ||
| { | ||
| pgReset(reg, profileIndex); // Always reset to defaults first | ||
|
|
||
| if (version == pgVersion(reg)) { | ||
| // Only copy if versions match | ||
| const int take = MIN(size, pgSize(reg)); | ||
| memcpy(pgOffset(reg, profileIndex), from, take); | ||
| } | ||
| // If version mismatch: defaults remain, no corruption | ||
| } | ||
| ``` |
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.
Suggestion: Update the documentation snippet to show basic input validation (e.g., from != NULL and size > 0) before calling memcpy, since real callers may pass invalid pointers/sizes; keep a safe fallback of “defaults only” when validation fails. [Learned best practice, importance: 6]
| ```c | |
| void pgLoad(const pgRegistry_t* reg, int profileIndex, | |
| const void *from, int size, int version) | |
| { | |
| pgReset(reg, profileIndex); // Always reset to defaults first | |
| if (version == pgVersion(reg)) { | |
| // Only copy if versions match | |
| const int take = MIN(size, pgSize(reg)); | |
| memcpy(pgOffset(reg, profileIndex), from, take); | |
| } | |
| // If version mismatch: defaults remain, no corruption | |
| } | |
| ``` | |
| ```c | |
| void pgLoad(const pgRegistry_t* reg, int profileIndex, | |
| const void *from, int size, int version) | |
| { | |
| pgReset(reg, profileIndex); // Always reset to defaults first | |
| if (version == pgVersion(reg) && from != NULL && size > 0) { | |
| // Only copy if versions match and input is valid | |
| const int take = MIN(size, pgSize(reg)); | |
| memcpy(pgOffset(reg, profileIndex), from, take); | |
| } | |
| // Otherwise: defaults remain, no corruption | |
| } |
User description
Summary
Add comprehensive developer documentation for INAV's Parameter Group (PG) system to help developers understand when to increment PG version numbers and how to register parameter groups correctly.
Changes
docs/development/parameter_groups/README.mdwith practical guidepgLoad()Key Topics Covered
__pg_registry_start/end)pgLoad()resets to defaults on mismatchPG_REGISTER_WITH_RESET_TEMPLATE, etc.)Documentation Approach
parameter_group.h/c)Related Context
PR Type
Documentation
Description
Add comprehensive Parameter Group system documentation for developers
Explains compile-time registry using linker sections and version validation
Documents when to increment PG version numbers with practical examples
Provides complete working examples and registration macro reference
Diagram Walkthrough
File Walkthrough
README.md
Parameter Group system developer guidedocs/development/parameter_groups/README.md
architecture
registry
pgLoad()and when to incrementversions
accessing parameter groups
increment examples