rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
binary_logging.cpp File Reference

Functions

int getSdCardFieldsCount ()
 
static constexpr uint16_t computeFieldsRecordLength ()
 
static size_t writeFileHeader (Writer &outBuffer)
 
static size_t writeSdBlock (Writer &outBuffer)
 
size_t writeSdLogLine (Writer &bufferedWriter)
 
void resetFileLogging ()
 

Variables

static scaled_channel< uint32_t, TIME_PRECISION > packedTime
 
static uint64_t binaryLogCount = 0
 
static const uint16_t recordLength = computeFieldsRecordLength()
 
static uint8_t blockRollCounter = 0
 

Function Documentation

◆ computeFieldsRecordLength()

static constexpr uint16_t computeFieldsRecordLength ( )
staticconstexpr

Definition at line 34 of file binary_logging.cpp.

34 {
35 uint16_t recLength = 0;
36 for (size_t i = 0; i < efi::size(fields); i++) {
37 recLength += fields[i].getSize();
38 }
39
40 return recLength;
41}
constexpr size_t getSize() const
Definition log_field.h:82
static const LogField fields[]
Here is the call graph for this function:

◆ getSdCardFieldsCount()

int getSdCardFieldsCount ( )

Definition at line 30 of file binary_logging.cpp.

30 {
31 return efi::size(fields);
32}

Referenced by sdStatistics().

Here is the caller graph for this function:

◆ resetFileLogging()

void resetFileLogging ( )

Definition at line 171 of file binary_logging.cpp.

171 {
172 binaryLogCount = 0;
174}
static uint64_t binaryLogCount
static uint8_t blockRollCounter

Referenced by sdLogger().

Here is the caller graph for this function:

◆ writeFileHeader()

static size_t writeFileHeader ( Writer outBuffer)
static

Definition at line 47 of file binary_logging.cpp.

47 {
48 size_t writen = 0;
49 char buffer[MLQ_HEADER_SIZE];
50 // File format: MLVLG\0
51 strncpy(buffer, "MLVLG", 6);
52
53 // Format version = 02
54 buffer[6] = 0;
55 buffer[7] = 2;
56
57 // Timestamp
58 buffer[8] = 0;
59 buffer[9] = 0;
60 buffer[10] = 0;
61 buffer[11] = 0;
62
63 // Info data start
64 buffer[12] = 0;
65 buffer[13] = 0;
66 buffer[14] = 0;
67 buffer[15] = 0;
68
69 size_t headerSize = MLQ_HEADER_SIZE + efi::size(fields) * MLQ_FIELD_HEADER_SIZE;
70
71 // Data begin index: begins immediately after the header
72 buffer[16] = (headerSize >> 24) & 0xFF;
73 buffer[17] = (headerSize >> 16) & 0xFF;
74 buffer[18] = (headerSize >> 8) & 0xFF;
75 buffer[19] = headerSize & 0xFF;
76
77 // Record length - length of a single data record: sum size of all fields
78 buffer[20] = recordLength >> 8;
79 buffer[21] = recordLength & 0xFF;
80
81 // Number of logger fields
82 int fieldsCount = efi::size(fields);
83 buffer[22] = fieldsCount >> 8;
84 buffer[23] = fieldsCount;
85
86 outBuffer.write(buffer, MLQ_HEADER_SIZE);
87 writen += MLQ_HEADER_SIZE;
88
89 // Write the actual logger fields, offset 22
90 for (size_t i = 0; i < efi::size(fields); i++) {
91 writen += fields[i].writeHeader(outBuffer);
92 }
93
94 return writen;
95}
static const uint16_t recordLength
size_t writeHeader(Writer &outBuffer) const
Definition log_field.cpp:20
virtual size_t write(const char *buffer, size_t count)=0
static BigBufferHandle buffer

Referenced by writeSdLogLine().

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

◆ writeSdBlock()

static size_t writeSdBlock ( Writer outBuffer)
static

Definition at line 99 of file binary_logging.cpp.

99 {
100 size_t writen = 0;
101 static char buffer[16];
102
103 // Offset 0 = Block type, standard data block in this case
104 buffer[0] = 0;
105
106 // Offset 1 = rolling counter sequence number
108
109 // Offset 2, size 2 = Timestamp at 10us resolution
110 efitimeus_t nowUs = getTimeNowUs();
111 uint16_t timestamp = nowUs / 10;
112 buffer[2] = timestamp >> 8;
113 buffer[3] = timestamp & 0xFF;
114
115 // TODO: check ret value!
116 outBuffer.write(buffer, 4);
117 writen += 4;
118
119 // todo: add a log field for SD card period
120// prevSdCardLineTime = nowUs;
121
122 packedTime = getTimeNowMs() * 1.0 / TIME_PRECISION;
123
124 uint8_t sum = 0;
125 for (size_t fieldIndex = 0; fieldIndex < efi::size(fields); fieldIndex++) {
126 #if EFI_UNIT_TEST
127 // dark magic: most elements of log_fields_generated.h were const-evaluated against 'nullptr' engine, let's add it!
128 void *offset = fields[fieldIndex].needsEngineOffsetHack(sizeof(*engine)) ? engine : nullptr;
129 #else
130 void *offset = nullptr;
131 #endif
132
133 size_t entrySize = fields[fieldIndex].writeData(buffer, offset);
134
135 for (size_t byteIndex = 0; byteIndex < entrySize; byteIndex++) {
136 // "CRC" at the end is just the sum of all bytes
137 sum += buffer[byteIndex];
138 }
139 // TODO: check ret value!
140 outBuffer.write(buffer, entrySize);
141 writen += entrySize;
142 }
143
144 buffer[0] = sum;
145 // 1 byte checksum footer
146 outBuffer.write(buffer, 1);
147 writen += 1;
148
149 return writen;
150}
static scaled_channel< uint32_t, TIME_PRECISION > packedTime
bool needsEngineOffsetHack(size_t size) const
Definition log_field.h:95
size_t writeData(char *buffer, void *offset) const
Definition log_field.cpp:61
efitimeus_t getTimeNowUs()
Definition efitime.cpp:26
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition efitime.cpp:34
static EngineAccessor engine
Definition engine.h:410
uint16_t offset
Definition tunerstudio.h:0

Referenced by writeSdLogLine().

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

◆ writeSdLogLine()

size_t writeSdLogLine ( Writer bufferedWriter)

Definition at line 152 of file binary_logging.cpp.

152 {
153#if EFI_PROD_CODE
154extern bool main_loop_started;
156 return 0;
157#endif //EFI_PROD_CODE
158
159 if (binaryLogCount == 0) {
161
162 return writeFileHeader(bufferedWriter);
163 } else {
165
167 return writeSdBlock(bufferedWriter);
168 }
169}
static size_t writeFileHeader(Writer &outBuffer)
static size_t writeSdBlock(Writer &outBuffer)
bool main_loop_started
Definition rusefi.cpp:143
void updateTunerStudioState()

Referenced by mlgLogger().

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

Variable Documentation

◆ binaryLogCount

uint64_t binaryLogCount = 0
static

Definition at line 43 of file binary_logging.cpp.

Referenced by resetFileLogging(), and writeSdLogLine().

◆ blockRollCounter

uint8_t blockRollCounter = 0
static

Definition at line 97 of file binary_logging.cpp.

Referenced by resetFileLogging(), and writeSdBlock().

◆ packedTime

scaled_channel<uint32_t, TIME_PRECISION> packedTime
static

Definition at line 23 of file binary_logging.cpp.

Referenced by writeSdBlock().

◆ recordLength

const uint16_t recordLength = computeFieldsRecordLength()
static

Definition at line 45 of file binary_logging.cpp.

Referenced by writeFileHeader().

Go to the source code of this file.