mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-06 15:08:53 +08:00
BlockParam: remove _extern_address and create a new class BlockParamExt for this
In most cases, _extern_address was unused, thus wasting cycles & RAM. This adds a separate class BlockParamExt with the field and uses it in ekf2_main Frees roughly 0.5KB of RAM on Pixracer
This commit is contained in:
@@ -82,10 +82,9 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
|
||||
|
||||
template <class T>
|
||||
BlockParam<T>::BlockParam(Block *block, const char *name,
|
||||
bool parent_prefix, T *extern_address) :
|
||||
bool parent_prefix) :
|
||||
BlockParamBase(block, name, parent_prefix),
|
||||
_val(),
|
||||
_extern_address(extern_address)
|
||||
_val()
|
||||
{
|
||||
update();
|
||||
}
|
||||
@@ -97,10 +96,6 @@ template <class T>
|
||||
void BlockParam<T>::set(T val)
|
||||
{
|
||||
_val = val;
|
||||
|
||||
if (_extern_address != NULL) {
|
||||
*_extern_address = val;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -108,10 +103,6 @@ void BlockParam<T>::update()
|
||||
{
|
||||
if (_handle != PARAM_INVALID) {
|
||||
param_get(_handle, &_val);
|
||||
|
||||
if (_extern_address != NULL) {
|
||||
*_extern_address = _val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +118,36 @@ BlockParam<T>::~BlockParam() {};
|
||||
template class __EXPORT BlockParam<float>;
|
||||
template class __EXPORT BlockParam<int>;
|
||||
|
||||
|
||||
template <class T>
|
||||
BlockParamExt<T>::BlockParamExt(Block *block, const char *name,
|
||||
bool parent_prefix, T &extern_val) :
|
||||
BlockParam<T>(block, name, parent_prefix),
|
||||
_extern_val(extern_val)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParamExt<T>::set(T val)
|
||||
{
|
||||
this->_val = val;
|
||||
_extern_val = val;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParamExt<T>::update()
|
||||
{
|
||||
if (this->_handle != PARAM_INVALID) {
|
||||
param_get(this->_handle, &this->_val);
|
||||
_extern_val = this->_val;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
BlockParamExt<T>::~BlockParamExt() {};
|
||||
|
||||
template class __EXPORT BlockParamExt<float>;
|
||||
template class __EXPORT BlockParamExt<int>;
|
||||
|
||||
} // namespace control
|
||||
|
||||
@@ -77,21 +77,45 @@ class BlockParam : public BlockParamBase
|
||||
{
|
||||
public:
|
||||
BlockParam(Block *block, const char *name,
|
||||
bool parent_prefix = true, T *extern_address = NULL);
|
||||
bool parent_prefix = true);
|
||||
BlockParam(const BlockParam &) = delete;
|
||||
BlockParam &operator=(const BlockParam &) = delete;
|
||||
|
||||
T get();
|
||||
void commit();
|
||||
void set(T val);
|
||||
void update();
|
||||
void update() override;
|
||||
virtual ~BlockParam();
|
||||
protected:
|
||||
T _val;
|
||||
T *_extern_address;
|
||||
};
|
||||
|
||||
typedef BlockParam<float> BlockParamFloat;
|
||||
typedef BlockParam<int> BlockParamInt;
|
||||
|
||||
|
||||
/**
|
||||
* Same as BlockParam, but in addition with a pointer to an external field that will be
|
||||
* set to the value of the parameter.
|
||||
* (BlockParam should be prefered over this)
|
||||
*/
|
||||
template <class T>
|
||||
class BlockParamExt : public BlockParam<T>
|
||||
{
|
||||
public:
|
||||
BlockParamExt(Block *block, const char *name,
|
||||
bool parent_prefix, T &extern_val);
|
||||
BlockParamExt(const BlockParamExt &) = delete;
|
||||
BlockParamExt &operator=(const BlockParamExt &) = delete;
|
||||
|
||||
void set(T val);
|
||||
void update() override;
|
||||
virtual ~BlockParamExt();
|
||||
protected:
|
||||
T &_extern_val;
|
||||
};
|
||||
|
||||
typedef BlockParamExt<float> BlockParamExtFloat;
|
||||
typedef BlockParamExt<int> BlockParamExtInt;
|
||||
|
||||
} // namespace control
|
||||
|
||||
Reference in New Issue
Block a user