rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Private Member Functions | Private Attributes
LogField Class Reference

#include <log_field.h>

Collaboration diagram for LogField:
Collaboration graph
[legend]

Public Types

enum class  Type : uint8_t {
  U08 = 0 , S08 = 1 , U16 = 2 , S16 = 3 ,
  U32 = 4 , S32 = 5 , S64 = 6 , F32 = 7
}
 

Public Member Functions

template<typename TValue , int TMult, int TDiv>
constexpr LogField (const scaled_channel< TValue, TMult, TDiv > &toRead, const char *name, const char *units, int8_t digits, const char *category="none")
 
template<typename TValue , typename = typename std::enable_if<std::is_arithmetic_v<TValue>>::type>
constexpr LogField (TValue &toRead, const char *name, const char *units, int8_t digits, const char *category="none")
 
template<typename TValue >
constexpr LogField (TValue &toRead, const uint32_t bitsBlockOffset, const uint8_t bitNumber, const char *name, const char *units, const char *category="none")
 
constexpr size_t getSize () const
 
size_t writeHeader (Writer &outBuffer) const
 
size_t writeData (char *buffer, void *offset) const
 
bool needsEngineOffsetHack (size_t size) const
 

Static Private Member Functions

template<typename T >
static constexpr Type resolveType ()
 
static constexpr size_t sizeForType (Type t)
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 
template<>
constexpr LogField::Type resolveType ()
 

Private Attributes

const float m_multiplier
 
const void *const m_addr
 
const Type m_type
 
const int8_t m_digits
 
const uint8_t m_size
 
const char *const m_name
 
const char *const m_units
 
const char *const m_category
 
const bool m_isBitField
 
const uint32_t m_bitsBlockOffset
 
const uint8_t m_bitNumber
 

Detailed Description

Definition at line 9 of file log_field.h.

Member Enumeration Documentation

◆ Type

enum class LogField::Type : uint8_t
strong
Enumerator
U08 
S08 
U16 
S16 
U32 
S32 
S64 
F32 

Definition at line 69 of file log_field.h.

69 : uint8_t {
70 // NOTE THAT Ordinals are part of logging serialization as described in
71 // https://www.efianalytics.com/TunerStudio/docs/MLG_Binary_LogFormat_2.0.pdf
72 U08 = 0,
73 S08 = 1,
74 U16 = 2,
75 S16 = 3,
76 U32 = 4,
77 S32 = 5,
78 S64 = 6,
79 F32 = 7,
80 };

Constructor & Destructor Documentation

◆ LogField() [1/3]

template<typename TValue , int TMult, int TDiv>
constexpr LogField::LogField ( const scaled_channel< TValue, TMult, TDiv > &  toRead,
const char name,
const char units,
int8_t  digits,
const char category = "none" 
)
inlineconstexpr

Definition at line 13 of file log_field.h.

15 : m_multiplier(float(TDiv) / TMult)
16 , m_addr(toRead.getFirstByteAddr())
17 , m_type(resolveType<TValue>())
18 , m_digits(digits)
19 , m_size(sizeForType(resolveType<TValue>()))
20 , m_name(name)
21 , m_units(units)
22 , m_category(category)
23 , m_isBitField(false)
25 , m_bitNumber(0)
26 {
27 }
const Type m_type
Definition log_field.h:121
const bool m_isBitField
Definition log_field.h:129
const int8_t m_digits
Definition log_field.h:122
static constexpr size_t sizeForType(Type t)
Definition log_field.h:105
const uint8_t m_bitNumber
Definition log_field.h:131
const char *const m_category
Definition log_field.h:127
const char *const m_units
Definition log_field.h:126
const uint8_t m_size
Definition log_field.h:123
const char *const m_name
Definition log_field.h:125
const uint32_t m_bitsBlockOffset
Definition log_field.h:130
const float m_multiplier
Definition log_field.h:119
const void *const m_addr
Definition log_field.h:120

◆ LogField() [2/3]

template<typename TValue , typename = typename std::enable_if<std::is_arithmetic_v<TValue>>::type>
constexpr LogField::LogField ( TValue &  toRead,
const char name,
const char units,
int8_t  digits,
const char category = "none" 
)
inlineconstexpr

Definition at line 31 of file log_field.h.

33 : m_multiplier(1)
34 , m_addr(&toRead)
35 , m_type(resolveType<TValue>())
36 , m_digits(digits)
37 , m_size(sizeForType(resolveType<TValue>()))
38 , m_name(name)
39 , m_units(units)
40 , m_category(category)
41 , m_isBitField(false)
43 , m_bitNumber(0)
44 {
45 }

◆ LogField() [3/3]

template<typename TValue >
constexpr LogField::LogField ( TValue &  toRead,
const uint32_t  bitsBlockOffset,
const uint8_t  bitNumber,
const char name,
const char units,
const char category = "none" 
)
inlineconstexpr

Definition at line 49 of file log_field.h.

56 : m_multiplier(1)
57 , m_addr(&toRead)
59 , m_digits(0)
60 , m_size(1)
61 , m_name(name)
62 , m_units(units)
63 , m_category(category)
64 , m_isBitField(true)
65 , m_bitsBlockOffset(bitsBlockOffset)
66 , m_bitNumber(bitNumber)
67 {}

Member Function Documentation

◆ getSize()

constexpr size_t LogField::getSize ( ) const
inlineconstexpr

Definition at line 82 of file log_field.h.

82 {
83 return m_size;
84 }

Referenced by computeFieldsRecordLength().

Here is the caller graph for this function:

◆ needsEngineOffsetHack()

bool LogField::needsEngineOffsetHack ( size_t  size) const
inline

Definition at line 95 of file log_field.h.

95 {
96 // low addresses are offsets without engine reference
97 return (intptr_t)m_addr < size;
98 }
composite packet size

Referenced by writeSdBlock().

Here is the caller graph for this function:

◆ resolveType() [1/13]

template<typename T >
static constexpr Type LogField::resolveType ( )
staticconstexprprivate

◆ resolveType() [2/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 135 of file log_field.h.

135 {
136 return Type::U08;
137}

◆ resolveType() [3/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 140 of file log_field.h.

140 {
141 return Type::U08;
142}

◆ resolveType() [4/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 145 of file log_field.h.

145 {
146 return Type::S08;
147}

◆ resolveType() [5/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 150 of file log_field.h.

150 {
151 return Type::S08;
152}

◆ resolveType() [6/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 155 of file log_field.h.

155 {
156 return Type::U16;
157}

◆ resolveType() [7/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 161 of file log_field.h.

161 {
162 return Type::U16;
163}

◆ resolveType() [8/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 166 of file log_field.h.

166 {
167 return Type::S16;
168}

◆ resolveType() [9/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 171 of file log_field.h.

171 {
172 return Type::U32;
173}

◆ resolveType() [10/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 179 of file log_field.h.

179 {
180 return Type::S32;
181}

◆ resolveType() [11/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 185 of file log_field.h.

185 {
186 return Type::S32;
187}

◆ resolveType() [12/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 190 of file log_field.h.

190 {
191 return Type::F32;
192}

◆ resolveType() [13/13]

template<>
constexpr LogField::Type LogField::resolveType ( )
staticconstexprprivate

Definition at line 195 of file log_field.h.

195 {
196 return Type::F32;
197}

◆ sizeForType()

static constexpr size_t LogField::sizeForType ( Type  t)
inlinestaticconstexprprivate

Definition at line 105 of file log_field.h.

105 {
106 switch (t) {
107 case Type::U08:
108 case Type::S08:
109 return 1;
110 case Type::U16:
111 case Type::S16:
112 return 2;
113 default:
114 // float, uint32, int32
115 return 4;
116 }
117 }

◆ writeData()

size_t LogField::writeData ( char buffer,
void *  offset 
) const

Definition at line 61 of file log_field.cpp.

61 {
62 if (m_isBitField) {
63 const char* const bitsBlockAddr = static_cast<const char*>(m_addr) + m_bitsBlockOffset;
64 const char* const byteWithBitAddr = bitsBlockAddr + m_bitNumber / 8;
65 unsigned char byteWithBit = 0;
66 memcpy_swapend(&byteWithBit, byteWithBitAddr, 1, offset);
67 const uint8_t bitNumberInByte = m_bitNumber % 8;
68 buffer[0] = static_cast<char>(static_cast<bool>(byteWithBit & (1 << bitNumberInByte)));
69 } else {
71 }
72
73 return m_size;
74}
static void memcpy_swapend(void *dest, const void *src, size_t num, void *offset)
Definition log_field.cpp:7
static BigBufferHandle buffer
uint16_t offset
Definition tunerstudio.h:0

Referenced by writeSdBlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeHeader()

size_t LogField::writeHeader ( Writer outBuffer) const

Definition at line 20 of file log_field.cpp.

20 {
21 char buffer[MLQ_FIELD_HEADER_SIZE];
22
23 // Offset 0, length 1 = type
24 buffer[0] = static_cast<char>(m_type);
25
26 // Offset 1, length 34 = name
27 strncpy(&buffer[1], m_name, 34);
28
29 // Offset 35, length 10 = units
30 strncpy(&buffer[35], m_units, 10);
31
32 // Offset 45, length 1 = Display style
33 // value 0 -> floating point number
34 buffer[45] = 0;
35
36 // Offset 46, length 4 = Scale
38
39 // Offset 50, length 4 = shift before scaling (always 0)
40 copyFloat(buffer + 50, 0);
41
42 // Offset 54, size 1 = digits to display (signed int)
43 buffer[54] = m_digits;
44
45 // Offset 55, (optional) category string
46 if (m_category) {
47 size_t categoryLength = strlen(m_category);
48 size_t lengthAfterCategory = 34 - categoryLength;
49 memcpy(&buffer[55], m_category, categoryLength);
50 memset(&buffer[55] + categoryLength, 0, lengthAfterCategory);
51 } else {
52 memset(&buffer[55], 0, 34);
53 }
54
55 // Total size = 89
56 outBuffer.write(buffer, MLQ_FIELD_HEADER_SIZE);
57
58 return MLQ_FIELD_HEADER_SIZE;
59}
static void copyFloat(char *buffer, float value)
Definition log_field.cpp:16
virtual size_t write(const char *buffer, size_t count)=0

Referenced by writeFileHeader().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ m_addr

const void* const LogField::m_addr
private

Definition at line 120 of file log_field.h.

Referenced by needsEngineOffsetHack(), and writeData().

◆ m_bitNumber

const uint8_t LogField::m_bitNumber
private

Definition at line 131 of file log_field.h.

Referenced by writeData().

◆ m_bitsBlockOffset

const uint32_t LogField::m_bitsBlockOffset
private

Definition at line 130 of file log_field.h.

Referenced by writeData().

◆ m_category

const char* const LogField::m_category
private

Definition at line 127 of file log_field.h.

Referenced by writeHeader().

◆ m_digits

const int8_t LogField::m_digits
private

Definition at line 122 of file log_field.h.

Referenced by writeHeader().

◆ m_isBitField

const bool LogField::m_isBitField
private

Definition at line 129 of file log_field.h.

Referenced by writeData().

◆ m_multiplier

const float LogField::m_multiplier
private

Definition at line 119 of file log_field.h.

Referenced by writeHeader().

◆ m_name

const char* const LogField::m_name
private

Definition at line 125 of file log_field.h.

Referenced by writeHeader().

◆ m_size

const uint8_t LogField::m_size
private

Definition at line 123 of file log_field.h.

Referenced by getSize(), and writeData().

◆ m_type

const Type LogField::m_type
private

Definition at line 121 of file log_field.h.

Referenced by writeHeader().

◆ m_units

const char* const LogField::m_units
private

Definition at line 126 of file log_field.h.

Referenced by writeHeader().


The documentation for this class was generated from the following files: