rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
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,...) __attribute__((format(printf
 
void 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
 
charlinePointer = 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:56
void reset()
char *const buffer
Definition datalogging.h:63
const int bufferSize
Definition datalogging.h:64
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 40 of file datalogging.h.

40 {
41 *linePointer = c;
43 }
char * linePointer
Definition datalogging.h:70

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,...) __attribute__((format(printf

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:49
@ CUSTOM_APPEND_STACK

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

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 45 of file datalogging.h.

45 {
46 return (uintptr_t)linePointer - (uintptr_t)buffer;
47 }

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

Here is the caller graph for this function:

◆ remainingSize()

size_t Logging::remainingSize ( ) const
inline

Definition at line 49 of file datalogging.h.

49 {
50 return bufferSize - loggingSize();
51 }
size_t loggingSize() const
Definition datalogging.h:45

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

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

◆ reset()

void Logging::reset ( )

Definition at line 128 of file datalogging.cpp.

128 {
130 *linePointer = 0;
131}

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

Here is the caller graph for this function:

◆ terminate()

void Logging::terminate ( )
inline

Definition at line 33 of file datalogging.h.

33 {
34 linePointer[0] = '\0';
35 }

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 63 of file datalogging.h.

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

◆ bufferSize

const int Logging::bufferSize = 0

Definition at line 64 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 70 of file datalogging.h.

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

◆ name

const char* const Logging::name = nullptr

Definition at line 56 of file datalogging.h.


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