|
|
@ -1,6 +1,6 @@ |
|
|
|
/****************************************************************************
|
|
|
|
/****************************************************************************
|
|
|
|
* |
|
|
|
* |
|
|
|
* Copyright (C) 2012 PX4 Development Team. All rights reserved. |
|
|
|
* Copyright (C) 2012-2017 PX4 Development Team. All rights reserved. |
|
|
|
* |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* modification, are permitted provided that the following conditions |
|
|
|
* modification, are permitted provided that the following conditions |
|
|
@ -37,19 +37,16 @@ |
|
|
|
* Controller library code |
|
|
|
* Controller library code |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "BlockParam.hpp" |
|
|
|
#include "BlockParam.hpp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstring> |
|
|
|
|
|
|
|
|
|
|
|
#include <containers/List.hpp> |
|
|
|
#include <containers/List.hpp> |
|
|
|
|
|
|
|
|
|
|
|
namespace control |
|
|
|
namespace control |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix) : |
|
|
|
BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix) |
|
|
|
_handle(PARAM_INVALID) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
char fullname[blockNameLengthMax]; |
|
|
|
char fullname[blockNameLengthMax]; |
|
|
|
|
|
|
|
|
|
|
@ -60,7 +57,7 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref |
|
|
|
char parentName[blockNameLengthMax]; |
|
|
|
char parentName[blockNameLengthMax]; |
|
|
|
parent->getName(parentName, blockNameLengthMax); |
|
|
|
parent->getName(parentName, blockNameLengthMax); |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(name, "")) { |
|
|
|
if (strcmp(name, "") == 0) { |
|
|
|
strncpy(fullname, parentName, blockNameLengthMax); |
|
|
|
strncpy(fullname, parentName, blockNameLengthMax); |
|
|
|
// ensure string is terminated
|
|
|
|
// ensure string is terminated
|
|
|
|
fullname[sizeof(fullname) - 1] = '\0'; |
|
|
|
fullname[sizeof(fullname) - 1] = '\0'; |
|
|
@ -80,81 +77,40 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref |
|
|
|
_handle = param_find(fullname); |
|
|
|
_handle = param_find(fullname); |
|
|
|
|
|
|
|
|
|
|
|
if (_handle == PARAM_INVALID) { |
|
|
|
if (_handle == PARAM_INVALID) { |
|
|
|
printf("error finding param: %s\n", fullname); |
|
|
|
PX4_ERR("error finding param: %s\n", fullname); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
template <> |
|
|
|
BlockParam<T>::BlockParam(Block *block, const char *name, |
|
|
|
BlockParam<int32_t>::BlockParam(Block *block, const char *name, bool parent_prefix) : |
|
|
|
bool parent_prefix) : |
|
|
|
|
|
|
|
BlockParamBase(block, name, parent_prefix), |
|
|
|
BlockParamBase(block, name, parent_prefix), |
|
|
|
_val() |
|
|
|
_val() |
|
|
|
{ |
|
|
|
{ |
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
template <> |
|
|
|
void BlockParam<T>::set(T val) |
|
|
|
BlockParam<float>::BlockParam(Block *block, const char *name, bool parent_prefix) : |
|
|
|
{ |
|
|
|
BlockParamBase(block, name, parent_prefix), |
|
|
|
_val = val; |
|
|
|
_val() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
|
|
|
|
void BlockParam<T>::update() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_handle != PARAM_INVALID) { |
|
|
|
|
|
|
|
param_get(_handle, &_val); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
|
|
|
|
void BlockParam<T>::commit() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_handle != PARAM_INVALID) { param_set(_handle, &_val); } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
|
|
|
|
void BlockParam<T>::commit_no_notification() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_handle != PARAM_INVALID) { param_set_no_notification(_handle, &_val); } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
|
|
|
|
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(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
template <> |
|
|
|
void BlockParamExt<T>::set(T val) |
|
|
|
BlockParam<int32_t &>::BlockParam(Block *block, const char *name, bool parent_prefix, int32_t &extern_val) : |
|
|
|
|
|
|
|
BlockParamBase(block, name, parent_prefix), |
|
|
|
|
|
|
|
_val(extern_val) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this->_val = val; |
|
|
|
update(); |
|
|
|
_extern_val = val; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
template <> |
|
|
|
void BlockParamExt<T>::update() |
|
|
|
BlockParam<float &>::BlockParam(Block *block, const char *name, bool parent_prefix, float &extern_val) : |
|
|
|
|
|
|
|
BlockParamBase(block, name, parent_prefix), |
|
|
|
|
|
|
|
_val(extern_val) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (this->_handle != PARAM_INVALID) { |
|
|
|
update(); |
|
|
|
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
|
|
|
|
} // namespace control
|
|
|
|