rusEFI
The most advanced open source ECU
Public Member Functions | Data Fields
Logging Class Reference

#include <datalogging.h>

Inheritance diagram for Logging:
Inheritance graph
[legend]
Collaboration diagram for Logging:
Collaboration graph
[legend]

Public Member Functions

 Logging ()=delete
 
 Logging (const char *name, char *buffer, int bufferSize)
 
void reset ()
 
void appendFast (const char *text)
 
void appendPrintf (const char *fmt,...)
 
void appendFloat (float value, int precision)
 
void terminate ()
 
void appendChar (char c)
 
size_t loggingSize () const
 
size_t remainingSize () const
 

Data Fields

const char *const name = nullptr
 
char *const buffer = nullptr
 
const int bufferSize = 0
 
char * linePointer = nullptr
 

Detailed Description

Definition at line 17 of file datalogging.h.

Constructor & Destructor Documentation

◆ Logging() [1/2]

Logging::Logging ( )
delete

◆ Logging() [2/2]

Logging::Logging ( const char *  name,
char *  buffer,
int  bufferSize 
)

Definition at line 133 of file datalogging.cpp.

134  : name(p_name)
135  , buffer(p_buffer)
136  , bufferSize(p_bufferSize)
137 {
138  reset();
139 }
const char *const name
Definition: datalogging.h:52
void reset()
char *const buffer
Definition: datalogging.h:59
const int bufferSize
Definition: datalogging.h:60
Here is the call graph for this function:

Member Function Documentation

◆ appendChar()

void Logging::appendChar ( char  c)
inline

This macro breaks the normal zero=termination constraint, please take care of this outside of this function

Definition at line 36 of file datalogging.h.

36  {
37  *linePointer = c;
38  linePointer++;
39  }
char * linePointer
Definition: datalogging.h:66

Referenced by WaveChart::addEvent3().

Here is the caller graph for this function:

◆ appendFast()

void Logging::appendFast ( const char *  text)
Note
This method if fast because it does not validate much, be sure what you are doing

Definition at line 73 of file datalogging.cpp.

73  {
74  char *s = linePointer;
75  while ((*s++ = *text++) != 0)
76  ;
77  linePointer = s - 1;
78 }

Referenced by WaveChart::addEvent3().

Here is the caller graph for this function:

◆ appendFloat()

void Logging::appendFloat ( float  value,
int  precision 
)

todo: #1 this implementation is less than perfect todo: #2 The only way to avoid double promotion would probably be using *float instead of float See also http://stackoverflow.com/questions/5522051/printing-a-float-in-c-while-avoiding-variadic-parameter-promotion-to-double

Definition at line 97 of file datalogging.cpp.

97  {
98  /**
99  * todo: #1 this implementation is less than perfect
100  * todo: #2 The only way to avoid double promotion would probably be using *float instead of float
101  * See also http://stackoverflow.com/questions/5522051/printing-a-float-in-c-while-avoiding-variadic-parameter-promotion-to-double
102  */
103  switch (precision) {
104  case 1:
105  appendPrintf("%.1f", value);
106  break;
107  case 2:
108  appendPrintf("%.2f", value);
109  break;
110  case 3:
111  appendPrintf("%.3f", value);
112  break;
113  case 4:
114  appendPrintf("%.4f", value);
115  break;
116  case 5:
117  appendPrintf("%.5f", value);
118  break;
119  case 6:
120  appendPrintf("%.6f", value);
121  break;
122 
123  default:
124  appendPrintf("%.2f", value);
125  }
126 }
void appendPrintf(const char *fmt,...)
Definition: datalogging.cpp:80

Referenced by reportWave().

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

◆ appendPrintf()

void Logging::appendPrintf ( const char *  fmt,
  ... 
)

Definition at line 80 of file datalogging.cpp.

80  {
81  efiAssertVoid(ObdCode::CUSTOM_APPEND_STACK, hasLotsOfRemainingStack(), "lowstck#4");
82 
83  size_t available = remainingSize();
84 
85  va_list ap;
86  va_start(ap, fmt);
87  size_t written = chvsnprintf(linePointer, available, fmt, ap);
88  va_end(ap);
89 
90  // chvnsprintf returns how many bytes WOULD HAVE been written if it fit,
91  // so clip it to the available space if necessary
92  linePointer += (written > available) ? available : written;
93  // ensure buffer is always null terminated
94  buffer[bufferSize - 1] = '\0';
95 }
size_t remainingSize() const
Definition: datalogging.h:45
@ CUSTOM_APPEND_STACK

Referenced by appendFloat(), printHistogram(), WaveChart::publish(), publishSensorChartIfFull(), reportWave(), WaveChart::reset(), and scAddData().

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

◆ loggingSize()

size_t Logging::loggingSize ( ) const
inline

Definition at line 41 of file datalogging.h.

41  {
42  return (uintptr_t)linePointer - (uintptr_t)buffer;
43  }

Referenced by WaveChart::publish(), and remainingSize().

Here is the caller graph for this function:

◆ remainingSize()

size_t Logging::remainingSize ( ) const
inline

Definition at line 45 of file datalogging.h.

45  {
46  return bufferSize - loggingSize();
47  }
size_t loggingSize() const
Definition: datalogging.h:41

Referenced by WaveChart::addEvent3(), appendPrintf(), and scAddData().

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

◆ reset()

void Logging::reset ( void  )

Definition at line 128 of file datalogging.cpp.

128  {
130  *linePointer = 0;
131 }

Referenced by Logging(), printHistogram(), WaveChart::reset(), scAddData(), and scheduleLogging().

Here is the caller graph for this function:

◆ terminate()

void Logging::terminate ( )
inline

Definition at line 29 of file datalogging.h.

29  {
30  linePointer[0] = '\0';
31  }

Referenced by WaveChart::addEvent3().

Here is the caller graph for this function:

Field Documentation

◆ buffer

char* const Logging::buffer = nullptr

Zero-terminated buffer of pending debug message

Unless a larger external buffer is specified, this is just a pointer to DEFAULT_BUFFER

Definition at line 59 of file datalogging.h.

Referenced by appendPrintf(), loggingSize(), WaveChart::publish(), reset(), and LogBuffer< TBufferSize >::writeLogger().

◆ bufferSize

const int Logging::bufferSize = 0

Definition at line 60 of file datalogging.h.

Referenced by appendPrintf(), and remainingSize().

◆ linePointer

char* Logging::linePointer = nullptr

This pointer is always pointing at the position within the buffer into which next write operation would append additional data

Definition at line 66 of file datalogging.h.

Referenced by appendChar(), appendFast(), appendPrintf(), loggingSize(), reset(), and terminate().

◆ name

const char* const Logging::name = nullptr

Definition at line 52 of file datalogging.h.


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