Skip to content

Commit

Permalink
AP_Param: simplify g2 object conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Feb 21, 2024
1 parent e01e697 commit 7ed0382
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libraries/AP_Param/AP_Param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,20 @@ void AP_Param::convert_class(uint16_t param_key, void *object_pointer,
flush();
}

void AP_Param::convert_g2_objects(const void *g2, const G2ObjectConversion g2_conversions[], uint8_t num_conversions)
{
// Find G2's Top Level Key
ConversionInfo info;
if (!find_top_level_key_by_pointer(g2, info.old_key)) {
return;
}
for (uint8_t i=0; i<num_conversions; i++) {
const auto &c { g2_conversions[i] };
convert_class(info.old_key, c.object_pointer, c.var_info, c.old_index, c.old_top_element, false);
}
}


/*
convert width of a parameter, allowing update to wider scalar values
without changing the parameter indexes
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_Param/AP_Param.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "float.h"

#include <array>

#define AP_MAX_NAME_SIZE 16

// optionally enable debug code for dumping keys
Expand Down Expand Up @@ -472,6 +474,14 @@ class AP_Param
// convert old vehicle parameters to new object parameters with scaling - assumes we use the same scaling factor for all values in the table
static void convert_old_parameters_scaled(const ConversionInfo *conversion_table, uint8_t table_size, float scaler, uint8_t flags);

struct G2ObjectConversion {
void *object_pointer;
const struct AP_Param::GroupInfo *var_info;
uint16_t old_index; // Old parameter index in g
uint16_t old_top_element; // Old group element in the tree for the first subgroup element (see AP_PARAM_KEY_DUMP)
};
static void convert_g2_objects(const void *g2, const G2ObjectConversion g2_conversions[], uint8_t num_conversions);

/*
convert width of a parameter, allowing update to wider scalar
values without changing the parameter indexes. This will return
Expand Down

0 comments on commit 7ed0382

Please sign in to comment.