From ab86dafda7f0e24529812cddc0cf884829bde01d Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 4 Mar 2022 11:36:14 +1100 Subject: [PATCH] AP_RPM: move logging of RPM into RPM library --- libraries/AP_RPM/AP_RPM.cpp | 22 +++++++++++++++++++++- libraries/AP_RPM/AP_RPM.h | 2 ++ libraries/AP_RPM/LogStructure.h | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 libraries/AP_RPM/LogStructure.h diff --git a/libraries/AP_RPM/AP_RPM.cpp b/libraries/AP_RPM/AP_RPM.cpp index 0b86a22b47..83423955bb 100644 --- a/libraries/AP_RPM/AP_RPM.cpp +++ b/libraries/AP_RPM/AP_RPM.cpp @@ -189,9 +189,11 @@ void AP_RPM::update(void) } } +#if HAL_LOGGING_ENABLED 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; } +#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 AP_RPM *AP_RPM::_singleton; diff --git a/libraries/AP_RPM/AP_RPM.h b/libraries/AP_RPM/AP_RPM.h index 5d034b8a62..2b2c4070a2 100644 --- a/libraries/AP_RPM/AP_RPM.h +++ b/libraries/AP_RPM/AP_RPM.h @@ -104,6 +104,8 @@ private: uint8_t num_instances; void detect_instance(uint8_t instance); + + void Log_RPM(); }; namespace AP { diff --git a/libraries/AP_RPM/LogStructure.h b/libraries/AP_RPM/LogStructure.h new file mode 100644 index 0000000000..d870fabeda --- /dev/null +++ b/libraries/AP_RPM/LogStructure.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#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 },