rusEFI
The most advanced open source ECU
Public Member Functions | Data Fields | Private Attributes
WaveChart Class Reference

rusEfi console sniffer data buffer More...

#include <engine_sniffer.h>

Collaboration diagram for WaveChart:
Collaboration graph
[legend]

Public Member Functions

 WaveChart ()
 
void init ()
 
void addEvent3 (const char *name, const char *msg)
 Register an event for digital sniffer. More...
 
void reset ()
 
void startDataCollection ()
 
void publishIfFull ()
 
void publish ()
 
bool isFull () const
 
bool isStartedTooLongAgo () const
 
int getSize ()
 

Data Fields

efitick_t pauseEngineSnifferUntilNt = 0
 

Private Attributes

Logging logging
 
char timeBuffer [_MAX_FILLER+2]
 
uint32_t counter = 0
 
bool collectingData = false
 
efitick_t startTimeNt = 0
 
volatile int isInitialized = false
 

Detailed Description

rusEfi console sniffer data buffer

Definition at line 35 of file engine_sniffer.h.

Constructor & Destructor Documentation

◆ WaveChart()

WaveChart::WaveChart ( )

Definition at line 77 of file engine_sniffer.cpp.

77  : logging("wave chart", WAVE_LOGGING_BUFFER, sizeof(WAVE_LOGGING_BUFFER)) {
78 }
Logging logging

Member Function Documentation

◆ addEvent3()

void WaveChart::addEvent3 ( const char *  name,
const char *  msg 
)

Register an event for digital sniffer.

We want smaller times within a chart in order to reduce packet size.

todo: migrate to binary fractions in order to eliminate this division? I do not like division

at least that's 32 bit division now

printf is a heavy method, append is used here as a performance optimization

Definition at line 158 of file engine_sniffer.cpp.

158  {
159 #if EFI_TEXT_LOGGING
161  efitick_t nowNt = getTimeNowNt();
162 
163  if (nowNt < pauseEngineSnifferUntilNt) {
164  return;
165  }
166  if (!getTriggerCentral()->isEngineSnifferEnabled) {
167  return;
168  }
169  if (skipUntilEngineCycle != 0 && getRevolutionCounter() < skipUntilEngineCycle)
170  return;
171 #if EFI_SIMULATOR
172  if (!collectingData) {
173  return;
174  }
175 #endif
176  efiAssertVoid(ObdCode::CUSTOM_ERR_6651, name!=NULL, "WC: NULL name");
177 
178 #if EFI_PROD_CODE
179  efiAssertVoid(ObdCode::CUSTOM_ERR_6652, getCurrentRemainingStack() > 32, "lowstck#2c");
180 #endif /* EFI_PROD_CODE */
181 
182  efiAssertVoid(ObdCode::CUSTOM_ERR_6653, isInitialized, "chart not initialized");
183 #if DEBUG_WAVE
184  efiPrintf("current", chart->counter);
185 #endif /* DEBUG_WAVE */
186  if (isFull()) {
187  return;
188  }
189 
190  // we have multiple threads writing to the same output buffer
191  chibios_rt::CriticalSectionLocker csl;
192 
193  if (counter == 0) {
194  startTimeNt = nowNt;
195  }
196  counter++;
197 
198  /**
199  * We want smaller times within a chart in order to reduce packet size.
200  */
201  /**
202  * todo: migrate to binary fractions in order to eliminate
203  * this division? I do not like division
204  *
205  * at least that's 32 bit division now
206  */
207  uint32_t diffNt = nowNt - startTimeNt;
208  uint32_t time100 = NT2US(diffNt / ENGINE_SNIFFER_UNIT_US);
209 
210  if (logging.remainingSize() > 35) {
211  /**
212  * printf is a heavy method, append is used here as a performance optimization
213  */
214  logging.appendFast(name);
215  logging.appendChar(CHART_DELIMETER);
216  logging.appendFast(msg);
217  logging.appendChar(CHART_DELIMETER);
218 // time100 -= startTime100;
219 
220  itoa10(timeBuffer, time100);
222  logging.appendChar(CHART_DELIMETER);
223  logging.terminate();
224  }
225 #endif /* EFI_TEXT_LOGGING */
226 }
void appendFast(const char *text)
Definition: datalogging.cpp:73
void appendChar(char c)
Definition: datalogging.h:36
size_t remainingSize() const
Definition: datalogging.h:45
void terminate()
Definition: datalogging.h:29
volatile int isInitialized
efitick_t startTimeNt
bool isFull() const
char timeBuffer[_MAX_FILLER+2]
efitick_t pauseEngineSnifferUntilNt
uint32_t counter
bool collectingData
char * itoa10(char *p, int num)
Definition: efilib.cpp:119
efitick_t getTimeNowNt()
Definition: efitime.cpp:19
TriggerCentral * getTriggerCentral()
Definition: engine.cpp:589
static uint32_t skipUntilEngineCycle
@ CUSTOM_ERR_6651
@ CUSTOM_ERR_6653
@ CUSTOM_ERR_6652
@ EngineSniffer
Here is the call graph for this function:

◆ getSize()

int WaveChart::getSize ( )

Definition at line 115 of file engine_sniffer.cpp.

115  {
116  return counter;
117 }

Referenced by triggerInfo().

Here is the caller graph for this function:

◆ init()

void WaveChart::init ( )

Definition at line 80 of file engine_sniffer.cpp.

80  {
81  isInitialized = true;
82  reset();
83 }

Referenced by initWaveChart().

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

◆ isFull()

bool WaveChart::isFull ( ) const

Definition at line 111 of file engine_sniffer.cpp.

111  {
113 }
engine_configuration_s * engineConfiguration

Referenced by addEvent3(), and publishIfFull().

Here is the caller graph for this function:

◆ isStartedTooLongAgo()

bool WaveChart::isStartedTooLongAgo ( ) const

Say at 300rpm we should get at least four events per revolution. That's 300/60*4=20 events per second engineChartSize/20 is the longest meaningful chart.

Definition at line 100 of file engine_sniffer.cpp.

100  {
101  /**
102  * Say at 300rpm we should get at least four events per revolution.
103  * That's 300/60*4=20 events per second
104  * engineChartSize/20 is the longest meaningful chart.
105  *
106  */
107  efidur_t chartDurationNt = getTimeNowNt() - startTimeNt;
108  return startTimeNt != 0 && NT2US(chartDurationNt) > engineConfiguration->engineChartSize * 1000000 / 20;
109 }
efitick_t efidur_t
Definition: rusefi_types.h:45

Referenced by publishIfFull().

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

◆ publish()

void WaveChart::publish ( )

Definition at line 141 of file engine_sniffer.cpp.

141  {
142 #if EFI_ENGINE_SNIFFER
143  logging.appendPrintf( LOG_DELIMITER);
145 #if DEBUG_WAVE
146  Logging *l = &chart->logging;
147  efiPrintf("IT'S TIME", strlen(l->buffer));
148 #endif // DEBUG_WAVE
149  if (getTriggerCentral()->isEngineSnifferEnabled) {
151  }
152 #endif /* EFI_ENGINE_SNIFFER */
153 }
void appendPrintf(const char *fmt,...)
Definition: datalogging.cpp:80
size_t loggingSize() const
Definition: datalogging.h:41
char *const buffer
Definition: datalogging.h:59
int waveChartUsedSize
void scheduleLogging(Logging *logging)

Referenced by publishIfFull().

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

◆ publishIfFull()

void WaveChart::publishIfFull ( )

Definition at line 134 of file engine_sniffer.cpp.

134  {
135  if (isFull() || isStartedTooLongAgo()) {
136  publish();
137  reset();
138  }
139 }
bool isStartedTooLongAgo() const

Referenced by printOverallStatus().

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

◆ reset()

void WaveChart::reset ( )

Definition at line 85 of file engine_sniffer.cpp.

85  {
86 #if DEBUG_WAVE
87  efiPrintf("reset while at ", counter);
88 #endif /* DEBUG_WAVE */
89  logging.reset();
90  counter = 0;
91  startTimeNt = 0;
92  collectingData = false;
93  logging.appendPrintf( "%s%s", PROTOCOL_ENGINE_SNIFFER, LOG_DELIMITER);
94 }
void reset()

Referenced by init(), publishIfFull(), Engine::resetEngineSnifferIfInTestMode(), and resetNow().

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

◆ startDataCollection()

void WaveChart::startDataCollection ( )

Definition at line 96 of file engine_sniffer.cpp.

96  {
97  collectingData = true;
98 }

Referenced by addEngineSnifferTdcEvent().

Here is the caller graph for this function:

Field Documentation

◆ collectingData

bool WaveChart::collectingData = false
private

We want to avoid visual jitter thus we want the left edge to be aligned https://github.com/rusefi/rusefi/issues/780

Definition at line 59 of file engine_sniffer.h.

Referenced by addEvent3(), reset(), and startDataCollection().

◆ counter

uint32_t WaveChart::counter = 0
private

Definition at line 54 of file engine_sniffer.h.

Referenced by addEvent3(), getSize(), isFull(), and reset().

◆ isInitialized

volatile int WaveChart::isInitialized = false
private

Definition at line 61 of file engine_sniffer.h.

Referenced by addEvent3(), and init().

◆ logging

Logging WaveChart::logging
private

Definition at line 51 of file engine_sniffer.h.

Referenced by addEvent3(), publish(), and reset().

◆ pauseEngineSnifferUntilNt

efitick_t WaveChart::pauseEngineSnifferUntilNt = 0

Definition at line 47 of file engine_sniffer.h.

Referenced by addEvent3(), and Engine::resetEngineSnifferIfInTestMode().

◆ startTimeNt

efitick_t WaveChart::startTimeNt = 0
private

Definition at line 60 of file engine_sniffer.h.

Referenced by addEvent3(), isStartedTooLongAgo(), and reset().

◆ timeBuffer

char WaveChart::timeBuffer[_MAX_FILLER+2]
private

Definition at line 52 of file engine_sniffer.h.

Referenced by addEvent3().


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