mirror of https://github.com/FOME-Tech/fome-fw.git
constexpr-ify log field list (#2548)
* constexprify * reclaim ram * more constexpr Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
ccc7547190
commit
774f4416a7
|
@ -18,7 +18,7 @@ static scaled_channel<uint32_t, TIME_PRECISION> packedTime;
|
||||||
|
|
||||||
// todo: we are at the edge of sdLogBuffer size and at the moment we have no code to make sure buffer does not overflow
|
// todo: we are at the edge of sdLogBuffer size and at the moment we have no code to make sure buffer does not overflow
|
||||||
// todo: make this logic smarter
|
// todo: make this logic smarter
|
||||||
static const LogField fields[] = {
|
static constexpr LogField fields[] = {
|
||||||
{tsOutputChannels.rpm, GAUGE_NAME_RPM, "rpm", 0},
|
{tsOutputChannels.rpm, GAUGE_NAME_RPM, "rpm", 0},
|
||||||
{packedTime, GAUGE_NAME_TIME, "sec", 0},
|
{packedTime, GAUGE_NAME_TIME, "sec", 0},
|
||||||
{tsOutputChannels.totalTriggerErrorCounter, GAUGE_NAME_TRG_ERR, "err", 0},
|
{tsOutputChannels.totalTriggerErrorCounter, GAUGE_NAME_TRG_ERR, "err", 0},
|
||||||
|
@ -74,6 +74,17 @@ static const LogField fields[] = {
|
||||||
{tsOutputChannels.knockLevel, GAUGE_NAME_KNOCK_LEVEL, "dBv", 0},
|
{tsOutputChannels.knockLevel, GAUGE_NAME_KNOCK_LEVEL, "dBv", 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr uint16_t computeFieldsRecordLength() {
|
||||||
|
uint16_t recLength = 0;
|
||||||
|
for (size_t i = 0; i < efi::size(fields); i++) {
|
||||||
|
recLength += fields[i].getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
return recLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr uint16_t recordLength = computeFieldsRecordLength();
|
||||||
|
|
||||||
void writeHeader(Writer& outBuffer) {
|
void writeHeader(Writer& outBuffer) {
|
||||||
char buffer[MLQ_HEADER_SIZE];
|
char buffer[MLQ_HEADER_SIZE];
|
||||||
// File format: MLVLG\0
|
// File format: MLVLG\0
|
||||||
|
@ -102,13 +113,8 @@ void writeHeader(Writer& outBuffer) {
|
||||||
buffer[17] = headerSize & 0xFF;
|
buffer[17] = headerSize & 0xFF;
|
||||||
|
|
||||||
// Record length - length of a single data record: sum size of all fields
|
// Record length - length of a single data record: sum size of all fields
|
||||||
uint16_t recLength = 0;
|
buffer[18] = recordLength >> 8;
|
||||||
for (size_t i = 0; i < efi::size(fields); i++) {
|
buffer[19] = recordLength & 0xFF;
|
||||||
recLength += fields[i].getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[18] = recLength >> 8;
|
|
||||||
buffer[19] = recLength & 0xFF;
|
|
||||||
|
|
||||||
// Number of logger fields
|
// Number of logger fields
|
||||||
buffer[20] = 0;
|
buffer[20] = 0;
|
||||||
|
|
|
@ -8,10 +8,10 @@ struct Writer;
|
||||||
class LogField {
|
class LogField {
|
||||||
public:
|
public:
|
||||||
template <typename TValue, int TMult = 1>
|
template <typename TValue, int TMult = 1>
|
||||||
LogField(const scaled_channel<TValue, TMult>& toRead, const char* name, const char* units, int8_t digits)
|
constexpr LogField(const scaled_channel<TValue, TMult>& toRead, const char* name, const char* units, int8_t digits)
|
||||||
: m_type(resolveType<TValue>())
|
: m_type(resolveType<TValue>())
|
||||||
, m_multiplier(TMult)
|
, m_multiplier(TMult)
|
||||||
, m_addr(reinterpret_cast<const char*>(&toRead))
|
, m_addr(toRead.getFirstByteAddr())
|
||||||
, m_digits(digits)
|
, m_digits(digits)
|
||||||
, m_size(sizeForType(resolveType<TValue>()))
|
, m_size(sizeForType(resolveType<TValue>()))
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
F32 = 7,
|
F32 = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t getSize() const {
|
constexpr size_t getSize() const {
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static Type resolveType();
|
static constexpr Type resolveType();
|
||||||
|
|
||||||
static size_t sizeForType(Type t) {
|
static constexpr size_t sizeForType(Type t) {
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case Type::U08:
|
case Type::U08:
|
||||||
case Type::S08:
|
case Type::S08:
|
||||||
|
|
|
@ -709,7 +709,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
|
||||||
* UNUSED_SIZE constants.
|
* UNUSED_SIZE constants.
|
||||||
*/
|
*/
|
||||||
#ifndef RAM_UNUSED_SIZE
|
#ifndef RAM_UNUSED_SIZE
|
||||||
#define RAM_UNUSED_SIZE 2850
|
#define RAM_UNUSED_SIZE 4350
|
||||||
#endif
|
#endif
|
||||||
#ifndef CCM_UNUSED_SIZE
|
#ifndef CCM_UNUSED_SIZE
|
||||||
#define CCM_UNUSED_SIZE 2000
|
#define CCM_UNUSED_SIZE 2000
|
||||||
|
|
|
@ -23,19 +23,26 @@
|
||||||
template <typename T, int mult = 1>
|
template <typename T, int mult = 1>
|
||||||
class scaled_channel {
|
class scaled_channel {
|
||||||
public:
|
public:
|
||||||
scaled_channel() : m_value(static_cast<T>(0)) { }
|
constexpr scaled_channel() : m_value(static_cast<T>(0)) { }
|
||||||
scaled_channel(float val)
|
constexpr scaled_channel(float val)
|
||||||
: m_value(val * mult)
|
: m_value(val * mult)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow reading back out as a float (note: this may be lossy!)
|
// Allow reading back out as a float (note: this may be lossy!)
|
||||||
operator float() const {
|
constexpr operator float() const {
|
||||||
return m_value / (float)mult;
|
return m_value / (float)mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr const char* getFirstByteAddr() const {
|
||||||
|
return &m_firstByte;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T m_value;
|
union {
|
||||||
|
T m_value;
|
||||||
|
char m_firstByte;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to guarantee that scaled values containing some type are the same size
|
// We need to guarantee that scaled values containing some type are the same size
|
||||||
|
|
Loading…
Reference in New Issue