⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 22, 2026

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

  • Add docs/development/parameter_groups/README.md with practical guide
  • Documents compile-time registry using linker sections
  • Explains version validation mechanism in pgLoad()
  • Provides clear rules for when to increment PG versions
  • Includes complete working examples based on actual code

Key Topics Covered

  • How the PG registry works (linker sections, __pg_registry_start/end)
  • Version encoding in top 4 bits of PGN field
  • Version checking: pgLoad() resets to defaults on mismatch
  • When to increment version (struct layout changes)
  • Registration macros (PG_REGISTER_WITH_RESET_TEMPLATE, etc.)
  • Complete examples developers can copy

Documentation Approach

  • Based only on verified code (parameter_group.h/c)
  • Conservative recommendations (increment version when in doubt)
  • References real examples (blackbox config)
  • Compared with Betaflight PG documentation for consistency

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

flowchart LR
  A["Developer needs PG guidance"] --> B["README.md documentation"]
  B --> C["How PG registry works"]
  B --> D["Version management rules"]
  B --> E["Complete code examples"]
  C --> F["Linker sections and macros"]
  D --> G["When to increment versions"]
  E --> H["Ready to implement PG"]
Loading

File Walkthrough

Relevant files
Documentation
README.md
Parameter Group system developer guide                                     

docs/development/parameter_groups/README.md

  • New comprehensive documentation file covering Parameter Group system
    architecture
  • Explains registration mechanism using linker sections and compile-time
    registry
  • Documents version checking behavior in pgLoad() and when to increment
    versions
  • Includes practical code examples for declaring, registering, and
    accessing parameter groups
  • Provides reference tables for registration macros and common patterns
  • Addresses real-world scenarios like field removal with version
    increment examples
+257/-0 

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.
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment on lines +52 to +65
```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
}
```
Copy link
Contributor

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]

Suggested change
```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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant