From df3e60c07c7bca8acc4ac46fc8b5f125a1b9f05a Mon Sep 17 00:00:00 2001 From: Scott Smith Date: Thu, 18 Nov 2021 23:29:19 -0800 Subject: [PATCH] Extend LogField to support scaled_channel divisors. (#3575) Also move the type field and shrink the size field for better packing. Saves about 800 bytes of flash. This fixes #3574. --- firmware/console/binary_log/log_field.cpp | 2 +- firmware/console/binary_log/log_field.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/firmware/console/binary_log/log_field.cpp b/firmware/console/binary_log/log_field.cpp index 58e2c0bdbc..c5157f2967 100644 --- a/firmware/console/binary_log/log_field.cpp +++ b/firmware/console/binary_log/log_field.cpp @@ -34,7 +34,7 @@ void LogField::writeHeader(Writer& outBuffer) const { buffer[45] = 0; // Offset 46, length 4 = Scale - copyFloat(buffer + 46, 1.0f / m_multiplier); + copyFloat(buffer + 46, m_multiplier); // Offset 50, length 4 = shift before scaling (always 0) copyFloat(buffer + 50, 0); diff --git a/firmware/console/binary_log/log_field.h b/firmware/console/binary_log/log_field.h index 1df2b637b7..d04d75143d 100644 --- a/firmware/console/binary_log/log_field.h +++ b/firmware/console/binary_log/log_field.h @@ -7,11 +7,12 @@ struct Writer; class LogField { public: - template - constexpr LogField(const scaled_channel& toRead, const char* name, const char* units, int8_t digits) - : m_type(resolveType()) - , m_multiplier(TMult) + template + constexpr LogField(const scaled_channel& toRead, + const char* name, const char* units, int8_t digits) + : m_multiplier(float(TDiv) / TMult) , m_addr(toRead.getFirstByteAddr()) + , m_type(resolveType()) , m_digits(digits) , m_size(sizeForType(resolveType())) , m_name(name) @@ -59,11 +60,11 @@ private: } } - const Type m_type; const float m_multiplier; const char* const m_addr; + const Type m_type; const int8_t m_digits; - const size_t m_size; + const uint8_t m_size; const char* const m_name; const char* const m_units;