mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 16:53:34 +08:00
Move the SimpleAnalyzer to a separate file
This commit is contained in:
@@ -43,8 +43,6 @@
|
||||
|
||||
#include "mavlink_stream.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
class StreamListItem
|
||||
{
|
||||
|
||||
@@ -63,56 +61,4 @@ public:
|
||||
const char *get_stream_name(const uint16_t msg_id);
|
||||
MavlinkStream *create_mavlink_stream(const char *stream_name, Mavlink *mavlink);
|
||||
|
||||
class SimpleAnalyzer
|
||||
{
|
||||
public:
|
||||
enum Mode {
|
||||
AVERAGE = 0,
|
||||
MIN,
|
||||
MAX,
|
||||
};
|
||||
|
||||
SimpleAnalyzer(Mode mode, float window = 60.0f);
|
||||
virtual ~SimpleAnalyzer();
|
||||
|
||||
void reset();
|
||||
void add_value(float val, float update_rate);
|
||||
bool valid() const;
|
||||
float get() const;
|
||||
float get_scaled(float scalingfactor) const;
|
||||
|
||||
template <typename T>
|
||||
void get_scaled(T &ret, float scalingfactor) const
|
||||
{
|
||||
float avg = get_scaled(scalingfactor);
|
||||
int_round(avg);
|
||||
check_limits(avg, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
|
||||
|
||||
ret = static_cast<T>(avg);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int _n = 0;
|
||||
float _window = 60.0f;
|
||||
Mode _mode = AVERAGE;
|
||||
float _result = 0.0f;
|
||||
|
||||
void check_limits(float &x, float min, float max) const;
|
||||
void int_round(float &x) const;
|
||||
};
|
||||
|
||||
template<typename Tin, typename Tout>
|
||||
void convert_limit_safe(Tin in, Tout *out)
|
||||
{
|
||||
if (in > std::numeric_limits<Tout>::max()) {
|
||||
*out = std::numeric_limits<Tout>::max();
|
||||
|
||||
} else if (in < std::numeric_limits<Tout>::min()) {
|
||||
*out = std::numeric_limits<Tout>::min();
|
||||
|
||||
} else {
|
||||
*out = static_cast<Tout>(in);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MAVLINK_MESSAGES_H_ */
|
||||
|
||||
Reference in New Issue
Block a user