forked from Archive/PX4-Autopilot
param: Add contained-params-bitset export interface to the param layers
Allows for efficient looping over the contained data
This commit is contained in:
parent
bc872822bc
commit
f0dd9fa445
|
@ -51,6 +51,17 @@ public:
|
|||
return param < PARAM_COUNT;
|
||||
}
|
||||
|
||||
px4::AtomicBitset<PARAM_COUNT> containedAsBitset() const override
|
||||
{
|
||||
px4::AtomicBitset<PARAM_COUNT> set;
|
||||
|
||||
for (int i = 0; i < PARAM_COUNT; i++) {
|
||||
set.set(i);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
param_value_u get(param_t param) const override
|
||||
{
|
||||
if (param >= PARAM_COUNT) {
|
||||
|
|
|
@ -97,6 +97,19 @@ public:
|
|||
return _getIndex(param) < _next_slot;
|
||||
}
|
||||
|
||||
px4::AtomicBitset<PARAM_COUNT> containedAsBitset() const override
|
||||
{
|
||||
px4::AtomicBitset<PARAM_COUNT> set;
|
||||
const AtomicTransaction transaction;
|
||||
Slot *slots = _slots.load();
|
||||
|
||||
for (int i = 0; i < _next_slot; i++) {
|
||||
set.set(slots[i].param);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
param_value_u get(param_t param) const override
|
||||
{
|
||||
const AtomicTransaction transaction;
|
||||
|
|
|
@ -67,6 +67,11 @@ public:
|
|||
return param < PARAM_COUNT && _ownership_set[param];
|
||||
}
|
||||
|
||||
px4::AtomicBitset<PARAM_COUNT> containedAsBitset() const override
|
||||
{
|
||||
return _ownership_set;
|
||||
}
|
||||
|
||||
param_value_u get(param_t param) const override
|
||||
{
|
||||
if (param >= PARAM_COUNT) {
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PX4_PARAMLAYER_H
|
||||
#define PX4_PARAMLAYER_H
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/atomic_bitset.h>
|
||||
#include "atomic_transaction.h"
|
||||
#include "param.h"
|
||||
#include <stdlib.h>
|
||||
|
@ -55,6 +55,8 @@ public:
|
|||
|
||||
virtual bool contains(param_t param) const = 0;
|
||||
|
||||
virtual px4::AtomicBitset<PARAM_COUNT> containedAsBitset() const = 0;
|
||||
|
||||
virtual param_value_u get(param_t param) const = 0;
|
||||
|
||||
virtual void reset(param_t param) = 0;
|
||||
|
@ -68,5 +70,3 @@ public:
|
|||
protected:
|
||||
ParamLayer *const _parent;
|
||||
};
|
||||
|
||||
#endif //PX4_PARAMLAYER_H
|
||||
|
|
|
@ -74,6 +74,18 @@ public:
|
|||
return _getIndex(param) < _next_slot;
|
||||
}
|
||||
|
||||
px4::AtomicBitset<PARAM_COUNT> containedAsBitset() const override
|
||||
{
|
||||
px4::AtomicBitset<PARAM_COUNT> set;
|
||||
const AtomicTransaction transaction;
|
||||
|
||||
for (int i = 0; i < _next_slot; i++) {
|
||||
set.set(_slots[i].param);
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
param_value_u get(param_t param) const override
|
||||
{
|
||||
const AtomicTransaction transaction;
|
||||
|
|
|
@ -84,16 +84,17 @@ param_export_internal(param_filter_func filter)
|
|||
/* Use realloc */
|
||||
|
||||
bson_encoder_init_buf(&encoder, nullptr, 0);
|
||||
auto changed_params = user_config.containedAsBitset();
|
||||
|
||||
for (param_t param = 0; param < user_config.PARAM_COUNT; param++) {
|
||||
|
||||
int32_t i;
|
||||
float f;
|
||||
|
||||
if (filter && !filter(param)) {
|
||||
if (!changed_params[param] || (filter && !filter(param))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t i;
|
||||
float f;
|
||||
|
||||
/* append the appropriate BSON type object */
|
||||
|
||||
switch (param_type(param)) {
|
||||
|
|
|
@ -1039,6 +1039,7 @@ param_export(const char *filename, param_filter_func filter)
|
|||
static int param_export_internal(int fd, param_filter_func filter)
|
||||
{
|
||||
PX4_DEBUG("param_export_internal");
|
||||
const auto changed_params = user_config.containedAsBitset();
|
||||
|
||||
int result = -1;
|
||||
bson_encoder_s encoder{};
|
||||
|
@ -1054,7 +1055,7 @@ static int param_export_internal(int fd, param_filter_func filter)
|
|||
}
|
||||
|
||||
for (param_t param = 0; handle_in_range(param); param++) {
|
||||
if (filter && !filter(param)) {
|
||||
if (!changed_params[param] || (filter && !filter(param))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue