AP_RPM: move logging of RPM into RPM library

This commit is contained in:
Peter Barker 2022-03-04 11:36:14 +11:00 committed by Peter Barker
parent 23f2055330
commit ab86dafda7
3 changed files with 45 additions and 1 deletions

View File

@ -189,9 +189,11 @@ void AP_RPM::update(void)
} }
} }
#if HAL_LOGGING_ENABLED
if (enabled(0) || enabled(1)) { if (enabled(0) || enabled(1)) {
AP::logger().Write_RPM(*this); Log_RPM();
} }
#endif
} }
/* /*
@ -259,6 +261,24 @@ bool AP_RPM::arming_checks(size_t buflen, char *buffer) const
return true; return true;
} }
#if HAL_LOGGING_ENABLED
void AP_RPM::Log_RPM()
{
float rpm1 = -1, rpm2 = -1;
get_rpm(0, rpm1);
get_rpm(1, rpm2);
const struct log_RPM pkt{
LOG_PACKET_HEADER_INIT(LOG_RPM_MSG),
time_us : AP_HAL::micros64(),
rpm1 : rpm1,
rpm2 : rpm2
};
AP::logger().WriteBlock(&pkt, sizeof(pkt));
}
#endif
// singleton instance // singleton instance
AP_RPM *AP_RPM::_singleton; AP_RPM *AP_RPM::_singleton;

View File

@ -104,6 +104,8 @@ private:
uint8_t num_instances; uint8_t num_instances;
void detect_instance(uint8_t instance); void detect_instance(uint8_t instance);
void Log_RPM();
}; };
namespace AP { namespace AP {

View File

@ -0,0 +1,22 @@
#pragma once
#include <AP_Logger/LogStructure.h>
#define LOG_IDS_FROM_RPM \
LOG_RPM_MSG
// @LoggerMessage: RPM
// @Description: Data from RPM sensors
// @Field: TimeUS: Time since system startup
// @Field: rpm1: First sensor's data
// @Field: rpm2: Second sensor's data
struct PACKED log_RPM {
LOG_PACKET_HEADER;
uint64_t time_us;
float rpm1;
float rpm2;
};
#define LOG_STRUCTURE_FROM_RPM \
{ LOG_RPM_MSG, sizeof(log_RPM), \
"RPM", "Qff", "TimeUS,rpm1,rpm2", "sqq", "F00" , true },